]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pictordec.c
timecode: fix typo
[ffmpeg] / libavcodec / pictordec.c
index 2bbb63633dfda9d36800874092a19908922bfad0..b3b5f7ef4fd06901ea91cc814f814a37bffefa74 100644 (file)
@@ -126,11 +126,11 @@ static int decode_frame(AVCodecContext *avctx,
     s->nb_planes      = (*buf++ >> 4) + 1;
     bpp               = s->nb_planes ? bits_per_plane*s->nb_planes : bits_per_plane;
     if (bits_per_plane > 8 || bpp < 1 || bpp > 32) {
-        av_log_ask_for_sample(s, "unsupported bit depth\n");
+        av_log_ask_for_sample(avctx, "unsupported bit depth\n");
         return AVERROR_INVALIDDATA;
     }
 
-    if (*buf == 0xFF) {
+    if (*buf == 0xFF || bpp == 8) {
         buf += 2;
         etype  = bytestream_get_le16(&buf);
         esize  = bytestream_get_le16(&buf);
@@ -175,13 +175,15 @@ static int decode_frame(AVCodecContext *avctx,
             palette[i] = ff_ega_palette[ FFMIN(buf[i], 63)];
     } else if (etype == 4 || etype == 5) {
         npal = FFMIN(esize / 3, 256);
-        for (i = 0; i < npal; i++)
+        for (i = 0; i < npal; i++) {
             palette[i] = AV_RB24(buf + i*3) << 2;
+            palette[i] |= 0xFF << 24 | palette[i] >> 6 & 0x30303;
+        }
     } else {
         if (bpp == 1) {
             npal = 2;
-            palette[0] = 0x000000;
-            palette[1] = 0xFFFFFF;
+            palette[0] = 0xFF000000;
+            palette[1] = 0xFFFFFFFF;
         } else if (bpp == 2) {
             npal = 4;
             for (i = 0; i < npal; i++)
@@ -196,17 +198,17 @@ static int decode_frame(AVCodecContext *avctx,
     buf += esize;
 
 
-    x = 0;
     y = s->height - 1;
-    plane = 0;
     if (bytestream_get_le16(&buf)) {
-        while (buf_end - buf >= 6) {
+        x = 0;
+        plane = 0;
+        while (y >= 0 && buf_end - buf >= 6) {
             const uint8_t *buf_pend = buf + FFMIN(AV_RL16(buf), buf_end - buf);
             //ignore uncompressed block size reported at buf[2]
             int marker = buf[4];
             buf += 5;
 
-            while (plane < s->nb_planes && buf_pend - buf >= 1) {
+            while (plane < s->nb_planes && y >= 0 && buf_pend - buf >= 1) {
                 int run = 1;
                 int val = *buf++;
                 if (val == marker) {
@@ -220,16 +222,17 @@ static int decode_frame(AVCodecContext *avctx,
 
                 if (bits_per_plane == 8) {
                     picmemset_8bpp(s, val, run, &x, &y);
-                    if (y < 0)
-                        break;
                 } else {
                     picmemset(s, val, run, &x, &y, &plane, bits_per_plane);
                 }
             }
         }
     } else {
-        av_log_ask_for_sample(s, "uncompressed image\n");
-        return buf_size;
+        while (y >= 0 && buf < buf_end) {
+            memcpy(s->frame.data[0] + y * s->frame.linesize[0], buf, FFMIN(avctx->width, buf_end - buf));
+            buf += avctx->width;
+            y--;
+        }
     }
 
     *data_size = sizeof(AVFrame);
@@ -250,7 +253,7 @@ AVCodec ff_pictor_decoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = CODEC_ID_PICTOR,
     .priv_data_size = sizeof(PicContext),
-    decode_init,
+    .init           = decode_init,
     .close          = decode_end,
     .decode         = decode_frame,
     .capabilities   = CODEC_CAP_DR1,