all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] image: add support for GIF transparency
@ 2010-10-27 14:27 Julien Danjou
  2010-10-27 14:27 ` [PATCH 2/2] image: add support for specified :background on GIF Julien Danjou
  2010-10-27 14:57 ` [PATCH 1/2] image: add support for GIF transparency Julien Danjou
  0 siblings, 2 replies; 8+ messages in thread
From: Julien Danjou @ 2010-10-27 14:27 UTC (permalink / raw)
  To: emacs-devel; +Cc: Julien Danjou

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 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  <julien@danjou.info>
+
+	* image.c (gif_load): Add support for transparency.
+
 2010-10-26  Juanma Barranquero  <lekktu@gmail.com>
 
 	* 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




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] image: add support for specified :background on GIF
  2010-10-27 14:27 [PATCH 1/2] image: add support for GIF transparency Julien Danjou
@ 2010-10-27 14:27 ` Julien Danjou
  2010-10-27 14:57 ` [PATCH 1/2] image: add support for GIF transparency Julien Danjou
  1 sibling, 0 replies; 8+ messages in thread
From: Julien Danjou @ 2010-10-27 14:27 UTC (permalink / raw)
  To: emacs-devel; +Cc: Julien Danjou

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 src/ChangeLog |    1 +
 src/image.c   |   10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3d9b6bf..65d2730 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,7 @@
 2010-10-27  Julien Danjou  <julien@danjou.info>
 
 	* image.c (gif_load): Add support for transparency.
+	(gif_load): Add support for specified :background.
 
 2010-10-26  Juanma Barranquero  <lekktu@gmail.com>
 
diff --git a/src/image.c b/src/image.c
index 8a32aaf..5bdba51 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7231,7 +7231,15 @@ gif_load (struct frame *f, struct image *img)
     for (i = 0; i < gif_color_map->ColorCount; ++i)
       {
         if (transparency_color_index == i)
-          pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);
+          {
+            XColor color;
+            Lisp_Object specified_bg
+              = image_spec_value (img->spec, QCbackground, NULL);
+            if (STRINGP (specified_bg))
+              pixel_colors[i] = x_alloc_image_color (f, img, specified_bg, FRAME_BACKGROUND_PIXEL (f));
+            else
+              pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);
+          }
         else
           {
             int r = gif_color_map->Colors[i].Red << 8;
-- 
1.7.2.3




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] image: add support for GIF transparency
  2010-10-27 14:27 [PATCH 1/2] image: add support for GIF transparency Julien Danjou
  2010-10-27 14:27 ` [PATCH 2/2] image: add support for specified :background on GIF Julien Danjou
@ 2010-10-27 14:57 ` Julien Danjou
  2010-10-27 15:00   ` Julien Danjou
  2010-10-27 15:00   ` [PATCH 2/2] image: add support for specified :background on GIF Julien Danjou
  1 sibling, 2 replies; 8+ messages in thread
From: Julien Danjou @ 2010-10-27 14:57 UTC (permalink / raw)
  To: emacs-devel

On Wed, Oct 27 2010, Julien Danjou wrote:

Ok, I just spot a little bug, new version following. :)

-- 
Julien Danjou
// ᐰ <julien@danjou.info>   http://julien.danjou.info



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] image: add support for GIF transparency
  2010-10-27 14:57 ` [PATCH 1/2] image: add support for GIF transparency Julien Danjou
@ 2010-10-27 15:00   ` Julien Danjou
  2010-11-03 20:09     ` Chong Yidong
  2010-11-04  1:44     ` YAMAMOTO Mitsuharu
  2010-10-27 15:00   ` [PATCH 2/2] image: add support for specified :background on GIF Julien Danjou
  1 sibling, 2 replies; 8+ messages in thread
From: Julien Danjou @ 2010-10-27 15:00 UTC (permalink / raw)
  To: emacs-devel; +Cc: Julien Danjou

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 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  <julien@danjou.info>
+
+	* image.c (gif_load): Add support for transparency.
+
 2010-10-26  Juanma Barranquero  <lekktu@gmail.com>
 
 	* 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




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] image: add support for specified :background on GIF
  2010-10-27 14:57 ` [PATCH 1/2] image: add support for GIF transparency Julien Danjou
  2010-10-27 15:00   ` Julien Danjou
@ 2010-10-27 15:00   ` Julien Danjou
  1 sibling, 0 replies; 8+ messages in thread
From: Julien Danjou @ 2010-10-27 15:00 UTC (permalink / raw)
  To: emacs-devel; +Cc: Julien Danjou

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 src/ChangeLog |    1 +
 src/image.c   |    9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3d9b6bf..65d2730 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,7 @@
 2010-10-27  Julien Danjou  <julien@danjou.info>
 
 	* image.c (gif_load): Add support for transparency.
+	(gif_load): Add support for specified :background.
 
 2010-10-26  Juanma Barranquero  <lekktu@gmail.com>
 
diff --git a/src/image.c b/src/image.c
index e9b85fa..ef6a6d0 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7235,7 +7235,14 @@ gif_load (struct frame *f, struct image *img)
     for (i = 0; i < gif_color_map->ColorCount; ++i)
       {
         if (transparent_p && transparency_color_index == i)
-            pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);
+          {
+            Lisp_Object specified_bg
+              = image_spec_value (img->spec, QCbackground, NULL);
+            if (STRINGP (specified_bg))
+              pixel_colors[i] = x_alloc_image_color (f, img, specified_bg, FRAME_BACKGROUND_PIXEL (f));
+            else
+              pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);
+          }
         else
           {
             int r = gif_color_map->Colors[i].Red << 8;
-- 
1.7.2.3




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] image: add support for GIF transparency
  2010-10-27 15:00   ` Julien Danjou
@ 2010-11-03 20:09     ` Chong Yidong
  2010-11-04  1:44     ` YAMAMOTO Mitsuharu
  1 sibling, 0 replies; 8+ messages in thread
From: Chong Yidong @ 2010-11-03 20:09 UTC (permalink / raw)
  To: Julien Danjou; +Cc: emacs-devel

Julien Danjou <julien@danjou.info> writes:

> +2010-10-27  Julien Danjou  <julien@danjou.info>
> +
> +	* image.c (gif_load): Add support for transparency.
> +

Looks good; applied.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] image: add support for GIF transparency
  2010-10-27 15:00   ` Julien Danjou
  2010-11-03 20:09     ` Chong Yidong
@ 2010-11-04  1:44     ` YAMAMOTO Mitsuharu
  2010-11-04 23:01       ` Miles Bader
  1 sibling, 1 reply; 8+ messages in thread
From: YAMAMOTO Mitsuharu @ 2010-11-04  1:44 UTC (permalink / raw)
  To: Julien Danjou; +Cc: emacs-devel

>>>>> On Wed, 27 Oct 2010 17:00:50 +0200, Julien Danjou <julien@danjou.info> said:

> +        if (transparent_p && transparency_color_index == i)
> +            pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);

If we don't have multiple transparency levels in GIF (unlike PNG or
SVG), then we can construct a clipping mask as we currently do in XPM,
and that would give us a better result.

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] image: add support for GIF transparency
  2010-11-04  1:44     ` YAMAMOTO Mitsuharu
@ 2010-11-04 23:01       ` Miles Bader
  0 siblings, 0 replies; 8+ messages in thread
From: Miles Bader @ 2010-11-04 23:01 UTC (permalink / raw)
  To: YAMAMOTO Mitsuharu; +Cc: Julien Danjou, emacs-devel

YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> writes:
>> +        if (transparent_p && transparency_color_index == i)
>> +            pixel_colors[i] = FRAME_BACKGROUND_PIXEL (f);
>
> If we don't have multiple transparency levels in GIF (unlike PNG or
> SVG), then we can construct a clipping mask as we currently do in XPM,
> and that would give us a better result.

A clipping mask might be a better solution even for PNG etc -- it will
have exactly the same appearance on the default background, and will at
least give a better approximation on non-default backgrounds...

-Miles

-- 
97% of everything is grunge



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-11-04 23:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-27 14:27 [PATCH 1/2] image: add support for GIF transparency Julien Danjou
2010-10-27 14:27 ` [PATCH 2/2] image: add support for specified :background on GIF Julien Danjou
2010-10-27 14:57 ` [PATCH 1/2] image: add support for GIF transparency Julien Danjou
2010-10-27 15:00   ` Julien Danjou
2010-11-03 20:09     ` Chong Yidong
2010-11-04  1:44     ` YAMAMOTO Mitsuharu
2010-11-04 23:01       ` Miles Bader
2010-10-27 15:00   ` [PATCH 2/2] image: add support for specified :background on GIF Julien Danjou

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.