aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJulien Danjou2010-11-03 16:08:48 -0400
committerChong Yidong2010-11-03 16:08:48 -0400
commit17c0c952f819ff6852f55071472c1ed6c65144bb (patch)
tree9eb61a7c3bbb98f0bd6dec12e84b946fc7628be0 /src
parent7977dcb80e598f1f933a0a280019186fda2d8abd (diff)
downloademacs-17c0c952f819ff6852f55071472c1ed6c65144bb.tar.gz
emacs-17c0c952f819ff6852f55071472c1ed6c65144bb.zip
Support for gif transparency.
* image.c (gif_load): Add support for transparency and specified :background.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/image.c36
2 files changed, 37 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c76c62124fc..efb2cccb3f1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12010-11-03 Julien Danjou <julien@danjou.info>
2
3 * image.c (gif_load): Add support for transparency and specified
4 :background.
5
12010-11-01 Kenichi Handa <handa@m17n.org> 62010-11-01 Kenichi Handa <handa@m17n.org>
2 7
3 * dispextern.h (lookup_glyphless_char_display): Extern it. 8 * dispextern.h (lookup_glyphless_char_display): Extern it.
diff --git a/src/image.c b/src/image.c
index b7edf05fea8..083d0720c15 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7096,12 +7096,15 @@ gif_read_from_memory (GifFileType *file, GifByteType *buf, int len)
7096static const int interlace_start[] = {0, 4, 2, 1}; 7096static const int interlace_start[] = {0, 4, 2, 1};
7097static const int interlace_increment[] = {8, 8, 4, 2}; 7097static const int interlace_increment[] = {8, 8, 4, 2};
7098 7098
7099#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249
7100
7099static int 7101static int
7100gif_load (struct frame *f, struct image *img) 7102gif_load (struct frame *f, struct image *img)
7101{ 7103{
7102 Lisp_Object file, specified_file; 7104 Lisp_Object file, specified_file;
7103 Lisp_Object specified_data; 7105 Lisp_Object specified_data;
7104 int rc, width, height, x, y, i; 7106 int rc, width, height, x, y, i;
7107 boolean transparent_p;
7105 XImagePtr ximg; 7108 XImagePtr ximg;
7106 ColorMapObject *gif_color_map; 7109 ColorMapObject *gif_color_map;
7107 unsigned long pixel_colors[256]; 7110 unsigned long pixel_colors[256];
@@ -7110,6 +7113,7 @@ gif_load (struct frame *f, struct image *img)
7110 int ino, image_height, image_width; 7113 int ino, image_height, image_width;
7111 gif_memory_source memsrc; 7114 gif_memory_source memsrc;
7112 unsigned char *raster; 7115 unsigned char *raster;
7116 unsigned int transparency_color_index;
7113 7117
7114 specified_file = image_spec_value (img->spec, QCfile, NULL); 7118 specified_file = image_spec_value (img->spec, QCfile, NULL);
7115 specified_data = image_spec_value (img->spec, QCdata, NULL); 7119 specified_data = image_spec_value (img->spec, QCdata, NULL);
@@ -7182,6 +7186,18 @@ gif_load (struct frame *f, struct image *img)
7182 return 0; 7186 return 0;
7183 } 7187 }
7184 7188
7189 for (i = 0; i < gif->SavedImages[ino].ExtensionBlockCount; i++)
7190 if ((gif->SavedImages[ino].ExtensionBlocks[i].Function
7191 == GIF_LOCAL_DESCRIPTOR_EXTENSION)
7192 && gif->SavedImages[ino].ExtensionBlocks[i].ByteCount == 4
7193 /* Transparency enabled? */
7194 && gif->SavedImages[ino].ExtensionBlocks[i].Bytes[0] & 1)
7195 {
7196 transparent_p = 1;
7197 transparency_color_index
7198 = (unsigned char) gif->SavedImages[ino].ExtensionBlocks[i].Bytes[3];
7199 }
7200
7185 img->corners[TOP_CORNER] = gif->SavedImages[ino].ImageDesc.Top; 7201 img->corners[TOP_CORNER] = gif->SavedImages[ino].ImageDesc.Top;
7186 img->corners[LEFT_CORNER] = gif->SavedImages[ino].ImageDesc.Left; 7202 img->corners[LEFT_CORNER] = gif->SavedImages[ino].ImageDesc.Left;
7187 image_height = gif->SavedImages[ino].ImageDesc.Height; 7203 image_height = gif->SavedImages[ino].ImageDesc.Height;
@@ -7220,10 +7236,22 @@ gif_load (struct frame *f, struct image *img)
7220 if (gif_color_map) 7236 if (gif_color_map)
7221 for (i = 0; i < gif_color_map->ColorCount; ++i) 7237 for (i = 0; i < gif_color_map->ColorCount; ++i)
7222 { 7238 {
7223 int r = gif_color_map->Colors[i].Red << 8; 7239 if (transparent_p && transparency_color_index == i)
7224 int g = gif_color_map->Colors[i].Green << 8; 7240 {
7225 int b = gif_color_map->Colors[i].Blue << 8; 7241 Lisp_Object specified_bg
7226 pixel_colors[i] = lookup_rgb_color (f, r, g, b); 7242 = image_spec_value (img->spec, QCbackground, NULL);
7243 pixel_colors[i] = STRINGP (specified_bg)
7244 ? x_alloc_image_color (f, img, specified_bg,
7245 FRAME_BACKGROUND_PIXEL (f))
7246 : FRAME_BACKGROUND_PIXEL (f);
7247 }
7248 else
7249 {
7250 int r = gif_color_map->Colors[i].Red << 8;
7251 int g = gif_color_map->Colors[i].Green << 8;
7252 int b = gif_color_map->Colors[i].Blue << 8;
7253 pixel_colors[i] = lookup_rgb_color (f, r, g, b);
7254 }
7227 } 7255 }
7228 7256
7229#ifdef COLOR_TABLE_SUPPORT 7257#ifdef COLOR_TABLE_SUPPORT