From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Julien Danjou Newsgroups: gmane.emacs.devel Subject: [PATCH 1/2] image: add support for GIF transparency Date: Wed, 27 Oct 2010 17:00:50 +0200 Message-ID: <1288191651-3958-1-git-send-email-julien@danjou.info> References: NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1288196351 12192 80.91.229.12 (27 Oct 2010 16:19:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 27 Oct 2010 16:19:11 +0000 (UTC) Cc: Julien Danjou To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 27 18:19:10 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PB8iK-0005i2-Ir for ged-emacs-devel@m.gmane.org; Wed, 27 Oct 2010 18:19:06 +0200 Original-Received: from localhost ([127.0.0.1]:41338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PB8i6-0007sh-Dv for ged-emacs-devel@m.gmane.org; Wed, 27 Oct 2010 12:18:46 -0400 Original-Received: from [140.186.70.92] (port=36740 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PB8DC-0002Ay-0N for emacs-devel@gnu.org; Wed, 27 Oct 2010 11:47:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PB7Uj-0008Td-Q7 for emacs-devel@gnu.org; Wed, 27 Oct 2010 11:01:05 -0400 Original-Received: from coquelicot-s.easter-eggs.com ([213.215.37.94]:57239) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PB7Uj-0008TR-Kj for emacs-devel@gnu.org; Wed, 27 Oct 2010 11:00:53 -0400 Original-Received: from cigue.easter-eggs.fr (cigue.easter-eggs.fr [10.0.0.33]) by rose.easter-eggs.fr (Postfix) with ESMTPS id 307B71409D; Wed, 27 Oct 2010 17:00:49 +0200 (CEST) Original-Received: from jdanjou by cigue.easter-eggs.fr with local (Exim 4.72) (envelope-from ) id 1PB7Ui-00012M-Lo; Wed, 27 Oct 2010 17:00:52 +0200 X-Mailer: git-send-email 1.7.2.3 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:132145 Archived-At: Signed-off-by: Julien Danjou --- src/ChangeLog | 4 ++++ src/image.c | 27 +++++++++++++++++++++++---- 2 files changed, 27 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 + + * image.c (gif_load): Add support for transparency. + 2010-10-26 Juanma Barranquero * eval.c (init_eval_once): Set max_lisp_eval_depth to 600; diff --git a/src/image.c b/src/image.c index b7edf05..e9b85fa 100644 --- a/src/image.c +++ b/src/image.c @@ -7096,12 +7096,15 @@ 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) { Lisp_Object file, specified_file; Lisp_Object specified_data; int rc, width, height, x, y, i; + boolean transparent_p; XImagePtr ximg; ColorMapObject *gif_color_map; unsigned long pixel_colors[256]; @@ -7110,6 +7113,7 @@ gif_load (struct frame *f, struct image *img) int ino, image_height, image_width; gif_memory_source memsrc; unsigned char *raster; + unsigned int transparency_color_index; specified_file = image_spec_value (img->spec, QCfile, NULL); specified_data = image_spec_value (img->spec, QCdata, NULL); @@ -7182,6 +7186,16 @@ 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) + { + transparent_p = 1; + transparency_color_index = (unsigned char) 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 +7234,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 (transparent_p && 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