changeset 116:6026a7f8ff78 libavformat

transparency support
author bellard
date Mon, 21 Apr 2003 21:18:51 +0000
parents af07cbf4f24a
children 497ae2790081
files gifdec.c
diffstat 1 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/gifdec.c	Mon Apr 21 21:18:15 2003 +0000
+++ b/gifdec.c	Mon Apr 21 21:18:51 2003 +0000
@@ -94,7 +94,8 @@
 {
     const uint8_t *p, *p_end;
     int bits_per_pixel, has_global_palette, ext_code, ext_len;
-    
+    int gce_flags, gce_disposal;
+
     if (pd->buf_size < 24 ||
 	memcmp(pd->buf, gif89a_sig, 6) != 0)
         return 0;
@@ -114,16 +115,28 @@
         if (p >= p_end)
             return 0;
         ext_code = *p++;
-        /* if GCE extension found: it is likely to be an animation */
-        if (ext_code == 0xf9)
-            return AVPROBE_SCORE_MAX;
+        if (p >= p_end)
+            return 0;
+        ext_len = *p++;
+        if (ext_code == 0xf9) {
+            if (p >= p_end)
+                return 0;
+            /* if GCE extension found with gce_disposal != 0: it is
+               likely to be an animation */
+            gce_flags = *p++;
+            gce_disposal = (gce_flags >> 2) & 0x7;
+            if (gce_disposal != 0)
+                return AVPROBE_SCORE_MAX;
+            else
+                return 0;
+        }
         for(;;) {
+            if (ext_len == 0)
+                break;
+            p += ext_len;
             if (p >= p_end)
                 return 0;
             ext_len = *p++;
-            if (ext_len == 0)
-                break;
-            p += ext_len;
         }
     }
     return 0;
@@ -320,6 +333,9 @@
         }
         for(; i < 256; i++)
             s->image_palette[i] = (0xff << 24);
+        /* handle transparency */
+        if (s->transparent_color_index >= 0)
+            s->image_palette[s->transparent_color_index] = 0;
         line = NULL;
     }