1
1
/* Functions for image support on window system.
2
2
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4
4
Free Software Foundation, Inc.
6
6
This file is part of GNU Emacs.
79
79
#define FRAME_X_VISUAL(f) FRAME_X_DISPLAY_INFO (f)->visual
80
80
#define x_defined_color w32_defined_color
81
81
#define DefaultDepthOfScreen(screen) (one_w32_display_info.n_cbits)
83
/* Functions from w32term.c that depend on XColor (so can't go in w32term.h
84
without modifying lots of files). */
85
extern void x_query_colors (struct frame *f, XColor *colors, int ncolors);
86
extern void x_query_color (struct frame *f, XColor *color);
82
87
#endif /* HAVE_NTGUI */
1623
1628
Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap);
1624
1629
img->pixmap = NO_PIXMAP;
1626
if (img->background_valid)
1627
ns_free_indexed_color(img->background, f);
1630
/* NOTE (HAVE_NS): background color is NOT an indexed color! */
1629
1631
img->background_valid = 0;
4201
4206
if (!check_image_size (f, width, height))
4203
image_error ("Invalid image size", Qnil, Qnil);
4208
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
4787
4792
XColor *row = p;
4789
#ifdef HAVE_X_WINDOWS
4794
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
4790
4795
for (x = 0; x < img->width; ++x, ++p)
4791
p->pixel = XGetPixel (ximg, x, y);
4796
p->pixel = GET_PIXEL (ximg, x, y);
4793
4798
x_query_colors (f, row, img->width);
4800
4805
p->pixel = GET_PIXEL (ximg, x, y);
4803
#if defined (HAVE_NS)
4804
4808
p->red = RED16_FROM_ULONG (p->pixel);
4805
4809
p->green = GREEN16_FROM_ULONG (p->pixel);
4806
4810
p->blue = BLUE16_FROM_ULONG (p->pixel);
4807
#endif /* HAVE_NS */
4809
p->red = 256 * GetRValue (p->pixel);
4810
p->green = 256 * GetGValue (p->pixel);
4811
p->blue = 256 * GetBValue (p->pixel);
4812
#endif /* HAVE_NTGUI */
4815
4813
#endif /* HAVE_X_WINDOWS */
5549
5547
if (!check_image_size (f, width, height))
5551
image_error ("Invalid image size", Qnil, Qnil);
5549
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
6084
6082
&interlace_type, NULL, NULL);
6086
6084
if (!check_image_size (f, width, height))
6086
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
6089
6089
/* If image contains simply transparency data, we prefer to
6090
6090
construct a clipping mask. */
6091
6091
if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
6123
6123
if (STRINGP (specified_bg))
6124
6124
/* The user specified `:background', use that. */
6126
/* W32 version incorrectly used COLORREF here!! ++kfs */
6128
6127
if (x_defined_color (f, SDATA (specified_bg), &color, 0))
6143
6142
/* We use the current frame background, ignoring any default
6144
6143
background color set by the image. */
6145
#ifdef HAVE_X_WINDOWS
6144
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
6147
6146
png_color_16 frame_background;
6155
6154
frame_background.blue = color.blue >> shift;
6156
6155
#endif /* HAVE_X_WINDOWS */
6160
png_color_16 frame_background;
6161
color = FRAME_BACKGROUND_PIXEL (f);
6162
#if 0 /* W32 TODO : Colormap support. */
6163
x_query_color (f, &color);
6165
bzero (&frame_background, sizeof frame_background);
6166
frame_background.red = GetRValue (color);
6167
frame_background.green = GetGValue (color);
6168
frame_background.blue = GetBValue (color);
6169
#endif /* HAVE_NTGUI */
6171
6157
fn_png_set_background (png_ptr, &frame_background,
6172
6158
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
6807
6793
if (!check_image_size (f, width, height))
6809
image_error ("Invalid image size", Qnil, Qnil);
6795
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
6810
6796
longjmp (mgr.setjmp_buffer, 2);
7258
7244
if (!check_image_size (f, width, height))
7260
image_error ("Invalid image size", Qnil, Qnil);
7246
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7261
7247
fn_TIFFClose (tiff);
7596
7582
/* Before reading entire contents, check the declared image size. */
7597
7583
if (!check_image_size (f, gif->SWidth, gif->SHeight))
7599
image_error ("Invalid image size", Qnil, Qnil);
7585
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7600
7586
fn_DGifCloseFile (gif);
7640
7626
if (!check_image_size (f, width, height))
7642
image_error ("Invalid image size", Qnil, Qnil);
7628
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7643
7629
fn_DGifCloseFile (gif);
7901
7887
DEF_IMGLIB_FN (g_object_unref);
7902
7888
DEF_IMGLIB_FN (g_error_free);
7904
Lisp_Object Qgdk_pixbuf, Qglib;
7890
Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
7907
7893
init_svg_functions (Lisp_Object libraries)
7909
HMODULE library, gdklib, glib;
7895
HMODULE library, gdklib, glib, gobject;
7911
7897
if (!(glib = w32_delayed_load (libraries, Qglib))
7898
|| !(gobject = w32_delayed_load (libraries, Qgobject))
7912
7899
|| !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf))
7913
7900
|| !(library = w32_delayed_load (libraries, Qsvg)))
7929
7916
LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_has_alpha);
7930
7917
LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_bits_per_sample);
7932
LOAD_IMGLIB_FN (glib, g_type_init);
7933
LOAD_IMGLIB_FN (glib, g_object_unref);
7919
LOAD_IMGLIB_FN (gobject, g_type_init);
7920
LOAD_IMGLIB_FN (gobject, g_object_unref);
7934
7921
LOAD_IMGLIB_FN (glib, g_error_free);
8051
8039
gnome type library functions. */
8052
8040
fn_g_type_init ();
8053
8041
/* Make a handle to a new rsvg object. */
8054
rsvg_handle = fn_rsvg_handle_new ();
8042
rsvg_handle = (RsvgHandle *) fn_rsvg_handle_new ();
8056
8044
/* Parse the contents argument and fill in the rsvg_handle. */
8057
8045
fn_rsvg_handle_write (rsvg_handle, contents, size, &error);
8065
8053
fn_rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
8066
8054
if (! check_image_size (f, dimension_data.width, dimension_data.height))
8056
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
8069
8060
/* We can now get a valid pixel buffer from the svg file, if all
8071
pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle);
8062
pixbuf = (GdkPixbuf *) fn_rsvg_handle_get_pixbuf (rsvg_handle);
8072
8063
if (!pixbuf) goto rsvg_error;
8073
8064
fn_g_object_unref (rsvg_handle);
8075
8066
/* Extract some meta data from the svg handle. */
8076
8067
width = fn_gdk_pixbuf_get_width (pixbuf);
8077
8068
height = fn_gdk_pixbuf_get_height (pixbuf);
8078
pixels = fn_gdk_pixbuf_get_pixels (pixbuf);
8069
pixels = (const guint8 *) fn_gdk_pixbuf_get_pixels (pixbuf);
8079
8070
rowstride = fn_gdk_pixbuf_get_rowstride (pixbuf);
8081
8072
/* Validate the svg meta data. */
8096
8087
/* Handle alpha channel by combining the image with a background
8098
8089
specified_bg = image_spec_value (img->spec, QCbackground, NULL);
8099
if (STRINGP (specified_bg)
8100
&& x_defined_color (f, SDATA (specified_bg), &background, 0))
8102
background.red >>= 8;
8103
background.green >>= 8;
8104
background.blue >>= 8;
8108
#ifdef HAVE_X_WINDOWS
8109
background.pixel = FRAME_BACKGROUND_PIXEL (f);
8110
x_query_color (f, &background);
8112
/* SVG pixmaps specify transparency in the last byte, so right
8113
shift 8 bits to get rid of it, since emacs doesn't support
8115
background.red >>= 8;
8116
background.green >>= 8;
8117
background.blue >>= 8;
8118
#elif defined (HAVE_NTGUI)
8119
background.pixel = FRAME_BACKGROUND_PIXEL (f);
8120
#if 0 /* W32 TODO : Colormap support. */
8121
x_query_color (f, &background);
8124
/* SVG pixmaps specify transparency in the last byte, so right
8125
shift 8 bits to get rid of it, since emacs doesn't support
8127
background.red >>= 8;
8128
background.green >>= 8;
8129
background.blue >>= 8;
8130
#else /* not HAVE_X_WINDOWS*/
8090
if (!STRINGP (specified_bg)
8091
|| !x_defined_color (f, SDATA (specified_bg), &background, 0))
8094
background.pixel = FRAME_BACKGROUND_PIXEL (f);
8095
x_query_color (f, &background);
8097
ns_query_color(FRAME_BACKGROUND_COLOR (f), &background, 1);
8101
/* SVG pixmaps specify transparency in the last byte, so right
8102
shift 8 bits to get rid of it, since emacs doesn't support
8104
background.red >>= 8;
8105
background.green >>= 8;
8106
background.blue >>= 8;
8135
8108
/* This loop handles opacity values, since Emacs assumes
8136
8109
non-transparent images. Each pixel must be "flattened" by
8356
8329
if (!check_image_size (f, img->width, img->height))
8358
image_error ("Invalid image size", Qnil, Qnil);
8331
image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);