aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorPaul Eggert2014-05-06 14:13:37 -0700
committerPaul Eggert2014-05-06 14:13:37 -0700
commitf62bc934f022be3c4af03ec9877f4ba32628822e (patch)
treec9e308f3bb6e2d1e199301790ebf9b85a1dc9570 /src/image.c
parent2ddb358900f579f626fe2bf27d1fa1327e4fb9ab (diff)
downloademacs-f62bc934f022be3c4af03ec9877f4ba32628822e.tar.gz
emacs-f62bc934f022be3c4af03ec9877f4ba32628822e.zip
* image.c: Do not use libpng if HAVE_NS, as NS does its own thing.
[HAVE_NS]: Do not include png.h. (x_query_frame_background_color): New function. (png_load_body, imagemagick_load_image, svg_load_image): Use it. (png_load_body): Coalesce duplicate code.
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c91
1 files changed, 32 insertions, 59 deletions
diff --git a/src/image.c b/src/image.c
index c26c0db2b4f..c459122a1b5 100644
--- a/src/image.c
+++ b/src/image.c
@@ -21,10 +21,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21#include "sysstdio.h" 21#include "sysstdio.h"
22#include <unistd.h> 22#include <unistd.h>
23 23
24#ifdef HAVE_PNG
25# include <png.h>
26#endif
27
28#include <setjmp.h> 24#include <setjmp.h>
29#include <c-ctype.h> 25#include <c-ctype.h>
30 26
@@ -1229,6 +1225,18 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1229 return img->background_transparent; 1225 return img->background_transparent;
1230} 1226}
1231 1227
1228/* Store F's background color into *BGCOLOR. */
1229static void
1230x_query_frame_background_color (struct frame *f, XColor *bgcolor)
1231{
1232#ifndef HAVE_NS
1233 bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
1234 x_query_color (f, bgcolor);
1235#else
1236 ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, 1);
1237#endif
1238}
1239
1232 1240
1233/*********************************************************************** 1241/***********************************************************************
1234 Helper functions for X image types 1242 Helper functions for X image types
@@ -5502,7 +5510,9 @@ png_image_p (Lisp_Object object)
5502#endif /* HAVE_PNG || HAVE_NS */ 5510#endif /* HAVE_PNG || HAVE_NS */
5503 5511
5504 5512
5505#ifdef HAVE_PNG 5513#if defined HAVE_PNG && !defined HAVE_NS
5514
5515#include <png.h>
5506 5516
5507#ifdef WINDOWSNT 5517#ifdef WINDOWSNT
5508/* PNG library details. */ 5518/* PNG library details. */
@@ -5880,43 +5890,23 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5880 /* png_color_16 *image_bg; */ 5890 /* png_color_16 *image_bg; */
5881 Lisp_Object specified_bg 5891 Lisp_Object specified_bg
5882 = image_spec_value (img->spec, QCbackground, NULL); 5892 = image_spec_value (img->spec, QCbackground, NULL);
5883 int shift = (bit_depth == 16) ? 0 : 8; 5893 XColor color;
5884 5894
5885 if (STRINGP (specified_bg)) 5895 /* If the user specified a color, try to use it; if not, use the
5896 current frame background, ignoring any default background
5897 color set by the image. */
5898 if (STRINGP (specified_bg)
5899 ? x_defined_color (f, SSDATA (specified_bg), &color, false)
5900 : (x_query_frame_background_color (f, &color), true))
5886 /* The user specified `:background', use that. */ 5901 /* The user specified `:background', use that. */
5887 { 5902 {
5888 XColor color; 5903 int shift = bit_depth == 16 ? 0 : 8;
5889 if (x_defined_color (f, SSDATA (specified_bg), &color, 0)) 5904 png_color_16 bg = { 0 };
5890 { 5905 bg.red = color.red >> shift;
5891 png_color_16 user_bg; 5906 bg.green = color.green >> shift;
5892 5907 bg.blue = color.blue >> shift;
5893 memset (&user_bg, 0, sizeof user_bg);
5894 user_bg.red = color.red >> shift;
5895 user_bg.green = color.green >> shift;
5896 user_bg.blue = color.blue >> shift;
5897
5898 fn_png_set_background (png_ptr, &user_bg,
5899 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
5900 }
5901 }
5902 else
5903 {
5904 /* We use the current frame background, ignoring any default
5905 background color set by the image. */
5906#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
5907 XColor color;
5908 png_color_16 frame_background;
5909
5910 color.pixel = FRAME_BACKGROUND_PIXEL (f);
5911 x_query_color (f, &color);
5912
5913 memset (&frame_background, 0, sizeof frame_background);
5914 frame_background.red = color.red >> shift;
5915 frame_background.green = color.green >> shift;
5916 frame_background.blue = color.blue >> shift;
5917#endif /* HAVE_X_WINDOWS */
5918 5908
5919 fn_png_set_background (png_ptr, &frame_background, 5909 fn_png_set_background (png_ptr, &bg,
5920 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); 5910 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
5921 } 5911 }
5922 } 5912 }
@@ -6058,9 +6048,8 @@ png_load (struct frame *f, struct image *img)
6058 return png_load_body (f, img, &c); 6048 return png_load_body (f, img, &c);
6059} 6049}
6060 6050
6061#else /* HAVE_PNG */ 6051#elif defined HAVE_NS
6062 6052
6063#ifdef HAVE_NS
6064static bool 6053static bool
6065png_load (struct frame *f, struct image *img) 6054png_load (struct frame *f, struct image *img)
6066{ 6055{
@@ -6068,10 +6057,8 @@ png_load (struct frame *f, struct image *img)
6068 image_spec_value (img->spec, QCfile, NULL), 6057 image_spec_value (img->spec, QCfile, NULL),
6069 image_spec_value (img->spec, QCdata, NULL)); 6058 image_spec_value (img->spec, QCdata, NULL));
6070} 6059}
6071#endif /* HAVE_NS */
6072
6073 6060
6074#endif /* !HAVE_PNG */ 6061#endif /* HAVE_NS */
6075 6062
6076 6063
6077 6064
@@ -8225,14 +8212,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
8225 specified_bg = image_spec_value (img->spec, QCbackground, NULL); 8212 specified_bg = image_spec_value (img->spec, QCbackground, NULL);
8226 if (!STRINGP (specified_bg) 8213 if (!STRINGP (specified_bg)
8227 || !x_defined_color (f, SSDATA (specified_bg), &bgcolor, 0)) 8214 || !x_defined_color (f, SSDATA (specified_bg), &bgcolor, 0))
8228 { 8215 x_query_frame_background_color (f, &bgcolor);
8229#ifndef HAVE_NS
8230 bgcolor.pixel = FRAME_BACKGROUND_PIXEL (f);
8231 x_query_color (f, &bgcolor);
8232#else
8233 ns_query_color (FRAME_BACKGROUND_COLOR (f), &bgcolor, 1);
8234#endif
8235 }
8236 8216
8237 bg_wand = NewPixelWand (); 8217 bg_wand = NewPixelWand ();
8238 PixelSetRed (bg_wand, (double) bgcolor.red / 65535); 8218 PixelSetRed (bg_wand, (double) bgcolor.red / 65535);
@@ -8868,14 +8848,7 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8868 specified_bg = image_spec_value (img->spec, QCbackground, NULL); 8848 specified_bg = image_spec_value (img->spec, QCbackground, NULL);
8869 if (!STRINGP (specified_bg) 8849 if (!STRINGP (specified_bg)
8870 || !x_defined_color (f, SSDATA (specified_bg), &background, 0)) 8850 || !x_defined_color (f, SSDATA (specified_bg), &background, 0))
8871 { 8851 x_query_frame_background_color (f, &background);
8872#ifndef HAVE_NS
8873 background.pixel = FRAME_BACKGROUND_PIXEL (f);
8874 x_query_color (f, &background);
8875#else
8876 ns_query_color (FRAME_BACKGROUND_COLOR (f), &background, 1);
8877#endif
8878 }
8879 8852
8880 /* SVG pixmaps specify transparency in the last byte, so right 8853 /* SVG pixmaps specify transparency in the last byte, so right
8881 shift 8 bits to get rid of it, since emacs doesn't support 8854 shift 8 bits to get rid of it, since emacs doesn't support