[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r113851: Enable giving hints to ImageMagick via :con
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] trunk r113851: Enable giving hints to ImageMagick via :content-type |
Date: |
Tue, 13 Aug 2013 17:45:38 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 113851
revision-id: address@hidden
parent: address@hidden
committer: Lars Magne Ingebrigtsen <address@hidden>
branch nick: trunk
timestamp: Tue 2013-08-13 19:45:34 +0200
message:
Enable giving hints to ImageMagick via :content-type
2013-08-13 Lars Magne Ingebrigtsen <address@hidden>
* image.el (image-content-type-suffixes): New variable.
2013-08-13 Lars Magne Ingebrigtsen <address@hidden>
* image.c (imagemagick_filename_hint): New function to possibly
apply `image-content-type-suffixes'.
(imagemagick_load_image): Use it.
modified:
doc/lispref/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-6155
doc/lispref/display.texi
display.texi-20091113204419-o5vbwnq5f7feedwu-6172
etc/NEWS news-20100311060928-aoit31wvzf25yr1z-1
lisp/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1432
lisp/image.el image.el-20091113204419-o5vbwnq5f7feedwu-1320
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/image.c image.c-20091113204419-o5vbwnq5f7feedwu-2969
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog 2013-08-13 14:26:39 +0000
+++ b/doc/lispref/ChangeLog 2013-08-13 17:45:34 +0000
@@ -1,3 +1,8 @@
+2013-08-13 Lars Magne Ingebrigtsen <address@hidden>
+
+ * display.texi (ImageMagick Images): Mention :content-type and
+ `image-content-type-suffixes'.
+
2013-08-13 Xue Fuqiao <address@hidden>
* positions.texi (Word Motion): Remove redundant sentence.
=== modified file 'doc/lispref/display.texi'
--- a/doc/lispref/display.texi 2013-08-07 02:25:52 +0000
+++ b/doc/lispref/display.texi 2013-08-13 17:45:34 +0000
@@ -4664,6 +4664,14 @@
wish. @code{:max-width} and @code{:max-height} will always preserve
the aspect ratio.
address@hidden :content-type
+ImageMagick tries to auto-detect the image type, but it isn't always
+able to. By using @code{:content-type}, we can give ImageMagick a
+hint to try to help it. It's used in conjuction with the
address@hidden variable, which provides a mapping
+from content types to file name suffixes. This is then given to
+ImageMagick as a file name hint.
+
@item :rotation
Specifies a rotation angle in degrees.
=== modified file 'etc/NEWS'
--- a/etc/NEWS 2013-08-12 17:02:31 +0000
+++ b/etc/NEWS 2013-08-13 17:45:34 +0000
@@ -896,6 +896,10 @@
*** ImageMagick images now support the :max-width and :max-height
keywords.
+*** Some data types aren't auto-detected by ImageMagick. Adding
+:content-type to `create-image' may help if the content type is in the
+new variable `image-content-type-suffixes'.
+
** Minibuffer
*** In minibuffer filename prompts, `C-M-f' and `C-M-b' now move to the
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2013-08-13 16:36:32 +0000
+++ b/lisp/ChangeLog 2013-08-13 17:45:34 +0000
@@ -1,3 +1,7 @@
+2013-08-13 Lars Magne Ingebrigtsen <address@hidden>
+
+ * image.el (image-content-type-suffixes): New variable.
+
2013-08-13 Fabián Ezequiel Gallina <address@hidden>
* progmodes/python.el (python-imenu--build-tree)
=== modified file 'lisp/image.el'
--- a/lisp/image.el 2013-05-30 03:24:30 +0000
+++ b/lisp/image.el 2013-08-13 17:45:34 +0000
@@ -99,6 +99,14 @@
- maybe auto-detect only if the image type is available
(see `image-type-available-p').")
+(defvar image-content-type-suffixes
+ '((image/x-icon "ico"))
+ "Alist of MIME Content-Type headers to file name suffixes.
+This is used as a hint by the ImageMagick library when detecting
+image types. If `create-image' is called with a :content-type
+matching found in this alist, the ImageMagick library will be
+told that the data would have this suffix if saved to a file.")
+
(defcustom image-load-path
(list (file-name-as-directory (expand-file-name "images" data-directory))
'data-directory 'load-path)
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-08-13 16:20:39 +0000
+++ b/src/ChangeLog 2013-08-13 17:45:34 +0000
@@ -1,3 +1,9 @@
+2013-08-13 Lars Magne Ingebrigtsen <address@hidden>
+
+ * image.c (imagemagick_filename_hint): New function to possibly
+ apply `image-content-type-suffixes'.
+ (imagemagick_load_image): Use it.
+
2013-08-13 Eli Zaretskii <address@hidden>
* decompress.c (Fzlib_decompress_region) [WINDOWSNT]: Return Qnil
=== modified file 'src/image.c'
--- a/src/image.c 2013-08-11 01:30:20 +0000
+++ b/src/image.c 2013-08-13 17:45:34 +0000
@@ -551,6 +551,7 @@
static Lisp_Object QCcolor_symbols;
static Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry;
static Lisp_Object QCcrop, QCrotation;
+static Lisp_Object QCcontent_type;
/* Other symbols. */
@@ -7740,6 +7741,7 @@
IMAGEMAGICK_WIDTH,
IMAGEMAGICK_MAX_HEIGHT,
IMAGEMAGICK_MAX_WIDTH,
+ IMAGEMAGICK_CONTENT_TYPE,
IMAGEMAGICK_ROTATION,
IMAGEMAGICK_CROP,
IMAGEMAGICK_LAST
@@ -7764,6 +7766,7 @@
{":width", IMAGE_INTEGER_VALUE, 0},
{":max-height", IMAGE_INTEGER_VALUE, 0},
{":max-width", IMAGE_INTEGER_VALUE, 0},
+ {":content-type", IMAGE_SYMBOL_VALUE, 0},
{":rotation", IMAGE_NUMBER_VALUE, 0},
{":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0}
};
@@ -7842,6 +7845,30 @@
description = (char *) MagickRelinquishMemory (description);
}
+/* Possibly give ImageMagick some extra help to determine the image
+ type by supplying a "dummy" filename based on the Content-Type. */
+
+static char*
+imagemagick_filename_hint (Lisp_Object spec)
+{
+ Lisp_Object content_type = image_spec_value (spec, QCcontent_type, NULL);
+ Lisp_Object symbol = intern ("image-content-type-suffixes");
+ Lisp_Object suffix;
+ char *name, *prefix = "/tmp/foo.";
+
+ if (NILP (Fboundp (symbol)))
+ return NULL;
+
+ suffix = Fcar (Fcdr (Fassq (content_type, Fsymbol_value (symbol))));
+ if (! STRINGP (suffix))
+ return NULL;
+
+ name = xmalloc (strlen (prefix) + SBYTES (suffix) + 1);
+ strcpy(name, prefix);
+ strcat(name, SDATA (suffix));
+ return name;
+}
+
/* Helper function for imagemagick_load, which does the actual loading
given contents and size, apart from frame and image structures,
passed from imagemagick_load. Uses librimagemagick to do most of
@@ -7875,6 +7902,7 @@
int desired_width, desired_height;
double rotation;
int pixelwidth;
+ char *filename_hint = NULL;
/* Handle image index for image types who can contain more than one image.
Interface :index is same as for GIF. First we "ping" the image to see how
@@ -7888,6 +7916,12 @@
ping_wand = NewMagickWand ();
/* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */
+ if (! filename)
+ filename_hint = imagemagick_filename_hint (img->spec);
+
+ if (filename_hint)
+ MagickSetFilename (ping_wand, filename_hint);
+
status = filename
? MagickPingImage (ping_wand, filename)
: MagickPingImageBlob (ping_wand, contents, size);
@@ -7920,6 +7954,9 @@
image_wand = NewMagickWand ();
+ if (filename_hint)
+ MagickSetFilename (image_wand, filename_hint);
+
if ((filename
? MagickReadImage (image_wand, filename)
: MagickReadImageBlob (image_wand, contents, size))
@@ -8163,11 +8200,16 @@
/* `MagickWandTerminus' terminates the imagemagick environment. */
MagickWandTerminus ();
+ if (filename_hint)
+ free (filename_hint);
+
return 1;
imagemagick_error:
DestroyMagickWand (image_wand);
if (bg_wand) DestroyPixelWand (bg_wand);
+ if (filename_hint)
+ free (filename_hint);
MagickWandTerminus ();
/* TODO more cleanup. */
@@ -9105,6 +9147,7 @@
DEFSYM (Qpostscript, "postscript");
DEFSYM (QCmax_width, ":max-width");
DEFSYM (QCmax_height, ":max-height");
+ DEFSYM (QCcontent_type, ":content-type");
#ifdef HAVE_GHOSTSCRIPT
ADD_IMAGE_TYPE (Qpostscript);
DEFSYM (QCloader, ":loader");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r113851: Enable giving hints to ImageMagick via :content-type,
Lars Ingebrigtsen <=