]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pictordec.c
Support transparency in 32bit bmp files.
[ffmpeg] / libavcodec / pictordec.c
index ae6e488161f64f73b78ee5c6a20f3c3e2275b938..ca3e791f9a86b7fc44589f5f66ab6057ea7b9986 100644 (file)
@@ -126,7 +126,7 @@ 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;
     }
 
@@ -177,7 +177,7 @@ static int decode_frame(AVCodecContext *avctx,
         npal = FFMIN(esize / 3, 256);
         for (i = 0; i < npal; i++) {
             palette[i] = AV_RB24(buf + i*3) << 2;
-            palette[i] |= 0xFF << 24;
+            palette[i] |= 0xFF << 24 | palette[i] >> 6 & 0x30303;
         }
     } else {
         if (bpp == 1) {
@@ -202,13 +202,13 @@ static int decode_frame(AVCodecContext *avctx,
     y = s->height - 1;
     plane = 0;
     if (bytestream_get_le16(&buf)) {
-        while (buf_end - buf >= 6) {
+        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) {
@@ -222,15 +222,13 @@ 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");
+        av_log_ask_for_sample(avctx, "uncompressed image\n");
         return buf_size;
     }