[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] image: add support for GIF transparency
From: |
Julien Danjou |
Subject: |
[PATCH 1/2] image: add support for GIF transparency |
Date: |
Wed, 27 Oct 2010 16:27:32 +0200 |
Signed-off-by: Julien Danjou <address@hidden>
---
src/ChangeLog | 4 ++++
src/image.c | 23 +++++++++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 51645ac..3d9b6bf 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2010-10-27 Julien Danjou <address@hidden>
+
+ * image.c (gif_load): Add support for transparency.
+
2010-10-26 Juanma Barranquero <address@hidden>
* eval.c (init_eval_once): Set max_lisp_eval_depth to 600;
diff --git a/src/image.c b/src/image.c
index b7edf05..8a32aaf 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7096,6 +7096,8 @@ gif_read_from_memory (GifFileType *file, GifByteType
*buf, int len)
static const int interlace_start[] = {0, 4, 2, 1};
static const int interlace_increment[] = {8, 8, 4, 2};
+#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249
+
static int
gif_load (struct frame *f, struct image *img)
{
@@ -7110,6 +7112,7 @@ gif_load (struct frame *f, struct image *img)
int ino, image_height, image_width;
gif_memory_source memsrc;
unsigned char *raster;
+ int transparency_color_index = -1;
specified_file = image_spec_value (img->spec, QCfile, NULL);
specified_data = image_spec_value (img->spec, QCdata, NULL);
@@ -7182,6 +7185,13 @@ gif_load (struct frame *f, struct image *img)
return 0;
}
+ for(i = 0; i < gif->SavedImages[ino].ExtensionBlockCount; i++)
+ if (gif->SavedImages[ino].ExtensionBlocks[i].Function ==
GIF_LOCAL_DESCRIPTOR_EXTENSION
+ && gif->SavedImages[ino].ExtensionBlocks[i].ByteCount == 4
+ /* Transparency enabled? */
+ && gif->SavedImages[ino].ExtensionBlocks[i].Bytes[0] & 1)
+ transparency_color_index =
gif->SavedImages[ino].ExtensionBlocks[i].Bytes[3];
+
img->corners[TOP_CORNER] = gif->SavedImages[ino].ImageDesc.Top;
img->corners[LEFT_CORNER] = gif->SavedImages[ino].ImageDesc.Left;
image_height = gif->SavedImages[ino].ImageDesc.Height;
@@ -7220,10 +7230,15 @@ gif_load (struct frame *f, struct image *img)
if (gif_color_map)
for (i = 0; i < gif_color_map->ColorCount; ++i)
{
- int r = gif_color_map->Colors[i].Red << 8;
- int g = gif_color_map->Colors[i].Green << 8;
- int b = gif_color_map->Colors[i].Blue << 8;
- pixel_colors[i] = lookup_rgb_color (f, r, g, b);
+ if (transparency_color_index == i)
+ pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);
+ else
+ {
+ int r = gif_color_map->Colors[i].Red << 8;
+ int g = gif_color_map->Colors[i].Green << 8;
+ int b = gif_color_map->Colors[i].Blue << 8;
+ pixel_colors[i] = lookup_rgb_color (f, r, g, b);
+ }
}
#ifdef COLOR_TABLE_SUPPORT
--
1.7.2.3
- [PATCH 1/2] image: add support for GIF transparency,
Julien Danjou <=