]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/idcinvideo.c
declare and use UID type
[ffmpeg] / libavcodec / idcinvideo.c
index 2a6ae360f804b4421d6838668e7bd3ce2f9b8120..7e7e6aab1b90fb878a212388f8c1163866d5d307 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
  */
 
  * For more information about the Id CIN format, visit:
  *   http://www.csse.monash.edu.au/~timf/
  *
- * This video decoder outputs PAL8 colorspace data.
+ * This video decoder outputs PAL8 colorspace data. Interacting with this
+ * decoder is a little involved. During initialization, the demuxer must
+ * transmit the 65536-byte Huffman table(s) to the decoder via extradata.
+ * Then, whenever a palette change is encountered while demuxing the file,
+ * the demuxer must use the same extradata space to transmit an
+ * AVPaletteControl structure.
  *
  * Id CIN video is purely Huffman-coded, intraframe-only codec. It achieves
  * a little more compression by exploiting the fact that adjacent pixels
@@ -67,8 +72,6 @@ typedef struct IdcinContext {
     unsigned char *buf;
     int size;
 
-    unsigned char palette[PALETTE_COUNT * 4];
-
     hnode_t huff_nodes[256][HUF_TOKENS*2];
     int num_huff_nodes[256];
 
@@ -155,7 +158,7 @@ static int idcin_decode_init(AVCodecContext *avctx)
 
     /* make sure the Huffman tables make it */
     if (s->avctx->extradata_size != HUFFMAN_TABLE_SIZE) {
-        printf("  Id CIN video: expected extradata size of %d\n", HUFFMAN_TABLE_SIZE);
+        av_log(s->avctx, AV_LOG_ERROR, "  Id CIN video: expected extradata size of %d\n", HUFFMAN_TABLE_SIZE);
         return -1;
     }
 
@@ -189,8 +192,8 @@ static void idcin_decode_vlcs(IdcinContext *s)
 
             while(node_num >= HUF_TOKENS) {
                 if(!bit_pos) {
-                    if(dat_pos > s->size) {
-                        printf("Huffman decode error.\n");
+                    if(dat_pos >= s->size) {
+                        av_log(s->avctx, AV_LOG_ERROR, "Huffman decode error.\n");
                         return;
                     }
                     bit_pos = 8;
@@ -213,39 +216,28 @@ static int idcin_decode_frame(AVCodecContext *avctx,
                               uint8_t *buf, int buf_size)
 {
     IdcinContext *s = (IdcinContext *)avctx->priv_data;
-    AVPaletteControl *palette_control = 
-        (AVPaletteControl *)avctx->extradata;
-    int i;
-    unsigned int *palette32;
-    int palette_index = 0;
-    unsigned char r, g, b;
+    AVPaletteControl *palette_control = avctx->palctrl;
 
     s->buf = buf;
     s->size = buf_size;
 
-    if (palette_control->palette_changed) {
-        palette32 = (unsigned int *)s->palette;
-        for (i = 0; i < PALETTE_COUNT; i++) {
-            r = palette_control->palette[palette_index++] * 1;
-            g = palette_control->palette[palette_index++] * 1;
-            b = palette_control->palette[palette_index++] * 1;
-            palette32[i] = (r << 16) | (g << 8) | (b);
-        }
-        palette_control->palette_changed = 0;
-    }
-
     if (s->frame.data[0])
         avctx->release_buffer(avctx, &s->frame);
 
     if (avctx->get_buffer(avctx, &s->frame)) {
-        printf ("  Id CIN Video: get_buffer() failed\n");
+        av_log(avctx, AV_LOG_ERROR, "  Id CIN Video: get_buffer() failed\n");
         return -1;
     }
 
     idcin_decode_vlcs(s);
 
     /* make the palette available on the way out */
-    memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
+    memcpy(s->frame.data[1], palette_control->palette, PALETTE_COUNT * 4);
+    /* If palette changed inform application*/
+    if (palette_control->palette_changed) {
+        palette_control->palette_changed = 0;
+        s->frame.palette_has_changed = 1;
+    }
 
     *data_size = sizeof(AVFrame);
     *(AVFrame*)data = s->frame;