/* Functions for image support on window system.
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#define FRAME_X_VISUAL(f) FRAME_X_DISPLAY_INFO (f)->visual
#define x_defined_color w32_defined_color
#define DefaultDepthOfScreen(screen) (one_w32_display_info.n_cbits)
+
+/* Functions from w32term.c that depend on XColor (so can't go in w32term.h
+ without modifying lots of files). */
+extern void x_query_colors (struct frame *f, XColor *colors, int ncolors);
+extern void x_query_color (struct frame *f, XColor *color);
#endif /* HAVE_NTGUI */
#ifdef HAVE_NS
{
Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap);
img->pixmap = NO_PIXMAP;
-#ifdef HAVE_NS
- if (img->background_valid)
- ns_free_indexed_color(img->background);
-#endif
+ /* NOTE (HAVE_NS): background color is NOT an indexed color! */
img->background_valid = 0;
}
}
if (!check_image_size (f, *width, *height))
- goto failure;
+ {
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
+ goto failure;
+ }
else if (data == NULL)
goto success;
if (!check_image_size (f, width, height))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
goto failure;
}
{
XColor *row = p;
-#ifdef HAVE_X_WINDOWS
+#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
for (x = 0; x < img->width; ++x, ++p)
- p->pixel = XGetPixel (ximg, x, y);
+ p->pixel = GET_PIXEL (ximg, x, y);
if (rgb_p)
x_query_colors (f, row, img->width);
p->pixel = GET_PIXEL (ximg, x, y);
if (rgb_p)
{
-#if defined (HAVE_NS)
p->red = RED16_FROM_ULONG (p->pixel);
p->green = GREEN16_FROM_ULONG (p->pixel);
p->blue = BLUE16_FROM_ULONG (p->pixel);
-#endif /* HAVE_NS */
-#ifdef HAVE_NTGUI
- p->red = 256 * GetRValue (p->pixel);
- p->green = 256 * GetGValue (p->pixel);
- p->blue = 256 * GetBValue (p->pixel);
-#endif /* HAVE_NTGUI */
}
}
#endif /* HAVE_X_WINDOWS */
if (!check_image_size (f, width, height))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
goto error;
}
&interlace_type, NULL, NULL);
if (!check_image_size (f, width, height))
- goto error;
-
+ {
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
+ goto error;
+ }
/* If image contains simply transparency data, we prefer to
construct a clipping mask. */
if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
if (STRINGP (specified_bg))
/* The user specified `:background', use that. */
{
- /* W32 version incorrectly used COLORREF here!! ++kfs */
XColor color;
if (x_defined_color (f, SDATA (specified_bg), &color, 0))
{
{
/* We use the current frame background, ignoring any default
background color set by the image. */
-#ifdef HAVE_X_WINDOWS
+#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
XColor color;
png_color_16 frame_background;
frame_background.blue = color.blue >> shift;
#endif /* HAVE_X_WINDOWS */
-#ifdef HAVE_NTGUI
- COLORREF color;
- png_color_16 frame_background;
- color = FRAME_BACKGROUND_PIXEL (f);
-#if 0 /* W32 TODO : Colormap support. */
- x_query_color (f, &color);
-#endif
- bzero (&frame_background, sizeof frame_background);
- frame_background.red = GetRValue (color);
- frame_background.green = GetGValue (color);
- frame_background.blue = GetBValue (color);
-#endif /* HAVE_NTGUI */
-
fn_png_set_background (png_ptr, &frame_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
}
if (!check_image_size (f, width, height))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
longjmp (mgr.setjmp_buffer, 2);
}
TIFF_HEURISTIC_MASK,
TIFF_MASK,
TIFF_BACKGROUND,
+ TIFF_INDEX,
TIFF_LAST
};
{":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
{":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
{":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
- {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
+ {":background", IMAGE_STRING_OR_NIL_VALUE, 0},
+ {":index", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0}
};
/* Structure describing the image type `tiff'. */
DEF_IMGLIB_FN (TIFFGetField);
DEF_IMGLIB_FN (TIFFReadRGBAImage);
DEF_IMGLIB_FN (TIFFClose);
+DEF_IMGLIB_FN (TIFFSetDirectory);
static int
init_tiff_functions (Lisp_Object libraries)
LOAD_IMGLIB_FN (library, TIFFGetField);
LOAD_IMGLIB_FN (library, TIFFReadRGBAImage);
LOAD_IMGLIB_FN (library, TIFFClose);
+ LOAD_IMGLIB_FN (library, TIFFSetDirectory);
return 1;
}
#define fn_TIFFGetField TIFFGetField
#define fn_TIFFReadRGBAImage TIFFReadRGBAImage
#define fn_TIFFClose TIFFClose
-
+#define fn_TIFFSetDirectory TIFFSetDirectory
#endif /* HAVE_NTGUI */
Lisp_Object file, specified_file;
Lisp_Object specified_data;
TIFF *tiff;
- int width, height, x, y;
+ int width, height, x, y, count;
uint32 *buf;
- int rc;
+ int rc, rc2;
XImagePtr ximg;
struct gcpro gcpro1;
tiff_memory_source memsrc;
+ Lisp_Object image;
specified_file = image_spec_value (img->spec, QCfile, NULL);
specified_data = image_spec_value (img->spec, QCdata, NULL);
}
}
+ image = image_spec_value (img->spec, QCindex, NULL);
+ if (INTEGERP (image))
+ {
+ int ino = XFASTINT (image);
+ if (!fn_TIFFSetDirectory (tiff, ino))
+ {
+ image_error ("Invalid image number `%s' in image `%s'",
+ image, img->spec);
+ fn_TIFFClose (tiff);
+ UNGCPRO;
+ return 0;
+ }
+ }
+
/* Get width and height of the image, and allocate a raster buffer
of width x height 32-bit values. */
fn_TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width);
if (!check_image_size (f, width, height))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
+ fn_TIFFClose (tiff);
UNGCPRO;
return 0;
}
buf = (uint32 *) xmalloc (width * height * sizeof *buf);
rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0);
+
+ /* Count the number of images in the file. */
+ for (count = 1, rc2 = 1; rc2; count++)
+ rc2 = fn_TIFFSetDirectory (tiff, count);
+
+ if (count > 1)
+ img->data.lisp_val = Fcons (Qcount,
+ Fcons (make_number (count),
+ img->data.lisp_val));
+
fn_TIFFClose (tiff);
if (!rc)
{
{":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
{":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
{":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
- {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0},
+ {":index", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0},
{":background", IMAGE_STRING_OR_NIL_VALUE, 0}
};
/* Before reading entire contents, check the declared image size. */
if (!check_image_size (f, gif->SWidth, gif->SHeight))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
fn_DGifCloseFile (gif);
UNGCPRO;
return 0;
if (!check_image_size (f, width, height))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
fn_DGifCloseFile (gif);
UNGCPRO;
return 0;
DEF_IMGLIB_FN (g_object_unref);
DEF_IMGLIB_FN (g_error_free);
-Lisp_Object Qgdk_pixbuf, Qglib;
+Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
static int
init_svg_functions (Lisp_Object libraries)
{
- HMODULE library, gdklib, glib;
+ HMODULE library, gdklib, glib, gobject;
if (!(glib = w32_delayed_load (libraries, Qglib))
+ || !(gobject = w32_delayed_load (libraries, Qgobject))
|| !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf))
|| !(library = w32_delayed_load (libraries, Qsvg)))
return 0;
LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_has_alpha);
LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_bits_per_sample);
- LOAD_IMGLIB_FN (glib, g_type_init);
- LOAD_IMGLIB_FN (glib, g_object_unref);
+ LOAD_IMGLIB_FN (gobject, g_type_init);
+ LOAD_IMGLIB_FN (gobject, g_object_unref);
LOAD_IMGLIB_FN (glib, g_error_free);
+
return 1;
}
gnome type library functions. */
fn_g_type_init ();
/* Make a handle to a new rsvg object. */
- rsvg_handle = fn_rsvg_handle_new ();
+ rsvg_handle = (RsvgHandle *) fn_rsvg_handle_new ();
/* Parse the contents argument and fill in the rsvg_handle. */
fn_rsvg_handle_write (rsvg_handle, contents, size, &error);
fn_rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
if (! check_image_size (f, dimension_data.width, dimension_data.height))
- goto rsvg_error;
+ {
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
+ goto rsvg_error;
+ }
/* We can now get a valid pixel buffer from the svg file, if all
went ok. */
- pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle);
+ pixbuf = (GdkPixbuf *) fn_rsvg_handle_get_pixbuf (rsvg_handle);
if (!pixbuf) goto rsvg_error;
fn_g_object_unref (rsvg_handle);
/* Extract some meta data from the svg handle. */
width = fn_gdk_pixbuf_get_width (pixbuf);
height = fn_gdk_pixbuf_get_height (pixbuf);
- pixels = fn_gdk_pixbuf_get_pixels (pixbuf);
+ pixels = (const guint8 *) fn_gdk_pixbuf_get_pixels (pixbuf);
rowstride = fn_gdk_pixbuf_get_rowstride (pixbuf);
/* Validate the svg meta data. */
/* Handle alpha channel by combining the image with a background
color. */
specified_bg = image_spec_value (img->spec, QCbackground, NULL);
- if (STRINGP (specified_bg)
- && x_defined_color (f, SDATA (specified_bg), &background, 0))
- {
- background.red >>= 8;
- background.green >>= 8;
- background.blue >>= 8;
- }
- else
+ if (!STRINGP (specified_bg)
+ || !x_defined_color (f, SDATA (specified_bg), &background, 0))
{
-#ifdef HAVE_X_WINDOWS
- background.pixel = FRAME_BACKGROUND_PIXEL (f);
- x_query_color (f, &background);
-
- /* SVG pixmaps specify transparency in the last byte, so right
- shift 8 bits to get rid of it, since emacs doesn't support
- transparency. */
- background.red >>= 8;
- background.green >>= 8;
- background.blue >>= 8;
-#elif defined (HAVE_NTGUI)
+#ifndef HAVE_NS
background.pixel = FRAME_BACKGROUND_PIXEL (f);
-#if 0 /* W32 TODO : Colormap support. */
x_query_color (f, &background);
-#endif
-
- /* SVG pixmaps specify transparency in the last byte, so right
- shift 8 bits to get rid of it, since emacs doesn't support
- transparency. */
- background.red >>= 8;
- background.green >>= 8;
- background.blue >>= 8;
-#else /* not HAVE_X_WINDOWS*/
-#error FIXME
+#else
+ ns_query_color(FRAME_BACKGROUND_COLOR (f), &background, 1);
#endif
}
+ /* SVG pixmaps specify transparency in the last byte, so right
+ shift 8 bits to get rid of it, since emacs doesn't support
+ transparency. */
+ background.red >>= 8;
+ background.green >>= 8;
+ background.blue >>= 8;
+
/* This loop handles opacity values, since Emacs assumes
non-transparent images. Each pixel must be "flattened" by
calculating the resulting color, given the transparency of the
if (!check_image_size (f, img->width, img->height))
{
- image_error ("Invalid image size", Qnil, Qnil);
+ image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
return 0;
}
staticpro (&Qsvg);
ADD_IMAGE_TYPE (Qsvg);
#ifdef HAVE_NTGUI
+ /* Other libraries used directly by svg code. */
Qgdk_pixbuf = intern ("gdk-pixbuf");
staticpro (&Qgdk_pixbuf);
Qglib = intern ("glib");
staticpro (&Qglib);
+ Qgobject = intern ("gobject");
+ staticpro (&Qgobject);
#endif /* HAVE_NTGUI */
#endif /* HAVE_RSVG */