changeset 97635:eb8c3a9e1565

(enum tiff_keyword_index, tiff_format): Add :index keyword. (fn_TIFFSetDirectory): New library function used. (init_tiff_functions) [HAVE_NTGUI]: Initialize it. (tiff_load): Use :index to select among multiple images. Set count property when multiple images exist. (gif_format): Use :index, not :image.
author Jason Rumney <jasonr@gnu.org>
date Sat, 23 Aug 2008 03:48:06 +0000
parents 04c7229f90ae
children 6fab4ff7571d
files src/ChangeLog src/image.c
diffstat 2 files changed, 44 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Aug 23 03:20:09 2008 +0000
+++ b/src/ChangeLog	Sat Aug 23 03:48:06 2008 +0000
@@ -1,3 +1,12 @@
+2008-08-23  Jason Rumney  <jasonr@gnu.org>
+
+	* image.c (enum tiff_keyword_index, tiff_format): Add :index keyword.
+	(fn_TIFFSetDirectory): New library function used.
+	(init_tiff_functions) [HAVE_NTGUI]: Initialize it.
+	(tiff_load): Use :index to select among multiple images.  Set count
+	property when multiple images exist.
+	(gif_format): Use :index, not :image.
+
 2008-08-23  Chong Yidong  <cyd@stupidchicken.com>
 
 	* xdisp.c (try_scrolling): Check INT_MAX instead of
--- a/src/image.c	Sat Aug 23 03:20:09 2008 +0000
+++ b/src/image.c	Sat Aug 23 03:48:06 2008 +0000
@@ -6926,6 +6926,7 @@
   TIFF_HEURISTIC_MASK,
   TIFF_MASK,
   TIFF_BACKGROUND,
+  TIFF_INDEX,
   TIFF_LAST
 };
 
@@ -6943,7 +6944,8 @@
   {":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'.  */
@@ -6989,6 +6991,7 @@
 DEF_IMGLIB_FN (TIFFGetField);
 DEF_IMGLIB_FN (TIFFReadRGBAImage);
 DEF_IMGLIB_FN (TIFFClose);
+DEF_IMGLIB_FN (TIFFSetDirectory);
 
 static int
 init_tiff_functions (Lisp_Object libraries)
@@ -7005,6 +7008,7 @@
   LOAD_IMGLIB_FN (library, TIFFGetField);
   LOAD_IMGLIB_FN (library, TIFFReadRGBAImage);
   LOAD_IMGLIB_FN (library, TIFFClose);
+  LOAD_IMGLIB_FN (library, TIFFSetDirectory);
   return 1;
 }
 
@@ -7017,7 +7021,7 @@
 #define fn_TIFFGetField			TIFFGetField
 #define fn_TIFFReadRGBAImage		TIFFReadRGBAImage
 #define fn_TIFFClose			TIFFClose
-
+#define fn_TIFFSetDirectory		TIFFSetDirectory
 #endif /* HAVE_NTGUI */
 
 
@@ -7170,12 +7174,13 @@
   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);
@@ -7231,6 +7236,20 @@
 	}
     }
 
+  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);
@@ -7239,6 +7258,7 @@
   if (!check_image_size (f, width, height))
     {
       image_error ("Invalid image size", Qnil, Qnil);
+      fn_TIFFClose (tiff);
       UNGCPRO;
       return 0;
     }
@@ -7246,6 +7266,16 @@
   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)
     {
@@ -7366,7 +7396,7 @@
   {":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}
 };