[FFmpeg-devel] [PATCH]Read alpha value from 32bit bmp files

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Dec 1 17:47:20 CET 2011


Hi!

Attached patch allows to read bmp files with transparency made with GIMP and 
(newer versions) of ImageMagick (older versions produced a file with inverted 
transparency).

I will apply if nobody objects, please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/bmp.c b/libavcodec/bmp.c
index 22973aa..56888cf 100644
--- a/libavcodec/bmp.c
+++ b/libavcodec/bmp.c
@@ -154,7 +154,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
             rgb[2] = 0;
         }
 
-        avctx->pix_fmt = PIX_FMT_BGR24;
+        avctx->pix_fmt = PIX_FMT_BGRA;
         break;
     case 24:
         avctx->pix_fmt = PIX_FMT_BGR24;
@@ -319,7 +319,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
                     dst[0] = src[rgb[2]];
                     dst[1] = src[rgb[1]];
                     dst[2] = src[rgb[0]];
+/* The Microsoft documentation states:
+ * "The high byte in each DWORD is not used."
+ * Both GIMP and ImageMagick store the alpha transparency value
+ * in the high byte for 32bit bmp files.
+ */
+                    dst[3] = src[3];
-                    dst += 3;
+                    dst += 4;
                     src += 4;
                 }
 


More information about the ffmpeg-devel mailing list