Mercurial > emacs
comparison src/image.c @ 111393:230a50b33a46
Support for gif transparency.
* image.c (gif_load): Add support for transparency and specified
:background.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Wed, 03 Nov 2010 16:08:48 -0400 |
parents | d5445d83cf4a |
children | 132f2dfd549f |
comparison
equal
deleted
inserted
replaced
111392:a2ba77c845e9 | 111393:230a50b33a46 |
---|---|
7094 successful. */ | 7094 successful. */ |
7095 | 7095 |
7096 static const int interlace_start[] = {0, 4, 2, 1}; | 7096 static const int interlace_start[] = {0, 4, 2, 1}; |
7097 static const int interlace_increment[] = {8, 8, 4, 2}; | 7097 static const int interlace_increment[] = {8, 8, 4, 2}; |
7098 | 7098 |
7099 #define GIF_LOCAL_DESCRIPTOR_EXTENSION 249 | |
7100 | |
7099 static int | 7101 static int |
7100 gif_load (struct frame *f, struct image *img) | 7102 gif_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]; |
7108 GifFileType *gif; | 7111 GifFileType *gif; |
7109 Lisp_Object image; | 7112 Lisp_Object image; |
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); |
7116 | 7120 |
7117 if (NILP (specified_data)) | 7121 if (NILP (specified_data)) |
7179 image_error ("Invalid image number `%s' in image `%s'", | 7183 image_error ("Invalid image number `%s' in image `%s'", |
7180 image, img->spec); | 7184 image, img->spec); |
7181 fn_DGifCloseFile (gif); | 7185 fn_DGifCloseFile (gif); |
7182 return 0; | 7186 return 0; |
7183 } | 7187 } |
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 } | |
7184 | 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; |
7188 img->corners[BOT_CORNER] = img->corners[TOP_CORNER] + image_height; | 7204 img->corners[BOT_CORNER] = img->corners[TOP_CORNER] + image_height; |
7218 memset (pixel_colors, 0, sizeof pixel_colors); | 7234 memset (pixel_colors, 0, sizeof pixel_colors); |
7219 | 7235 |
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 |
7230 img->colors = colors_in_color_table (&img->ncolors); | 7258 img->colors = colors_in_color_table (&img->ncolors); |
7231 free_color_table (); | 7259 free_color_table (); |