[FFmpeg-cvslog] Mark one colour as transparent in the gif image encoder

Carl Eugen Hoyos git at videolan.org
Thu Dec 8 02:50:11 CET 2011


ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos at ag.or.at> | Thu Dec  8 02:48:31 2011 +0100| [0cc9949eadc8378000f7c165e3809411651357dc] | committer: Carl Eugen Hoyos

Mark one colour as transparent in the gif image encoder

if the input palette contains at least one colour
that is more than 50% transparent.

Fixes ticket #715.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0cc9949eadc8378000f7c165e3809411651357dc
---

 libavcodec/gif.c     |   16 +++++++++++++++-
 libavcodec/version.h |    2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 8736f0f..830a059 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -62,7 +62,7 @@ static int gif_image_write_header(AVCodecContext *avctx,
                                   uint8_t **bytestream, uint32_t *palette)
 {
     int i;
-    unsigned int v;
+    unsigned int v, smallest_alpha = 0xFF, alpha_component = 0;
 
     bytestream_put_buffer(bytestream, "GIF", 3);
     bytestream_put_buffer(bytestream, "89a", 3);
@@ -77,6 +77,20 @@ static int gif_image_write_header(AVCodecContext *avctx,
     for(i=0;i<256;i++) {
         v = palette[i];
         bytestream_put_be24(bytestream, v);
+        if (v >> 24 < smallest_alpha) {
+            smallest_alpha = v >> 24;
+            alpha_component = i;
+        }
+    }
+
+    if (smallest_alpha < 128) {
+        bytestream_put_byte(bytestream, 0x21); /* Extension Introducer */
+        bytestream_put_byte(bytestream, 0xf9); /* Graphic Control Label */
+        bytestream_put_byte(bytestream, 0x04); /* block length */
+        bytestream_put_byte(bytestream, 0x01); /* Transparent Color Flag */
+        bytestream_put_le16(bytestream, 0x00); /* no delay */
+        bytestream_put_byte(bytestream, alpha_component);
+        bytestream_put_byte(bytestream, 0x00);
     }
 
     return 0;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 3c9c4dc..9042e26 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -22,7 +22,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR 53
 #define LIBAVCODEC_VERSION_MINOR 41
-#define LIBAVCODEC_VERSION_MICRO  1
+#define LIBAVCODEC_VERSION_MICRO  2
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list