diff options
| author | Lars Magne Ingebrigtsen | 2013-08-13 19:45:34 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2013-08-13 19:45:34 +0200 |
| commit | 8259030d684cc11dcaf548a1aea29d7badf921fe (patch) | |
| tree | 311bb547de8203a631fbb11cbf0a94987da62905 /src | |
| parent | ad75644970a5deccb1d40465e20087f5806ed3df (diff) | |
| download | emacs-8259030d684cc11dcaf548a1aea29d7badf921fe.tar.gz emacs-8259030d684cc11dcaf548a1aea29d7badf921fe.zip | |
Enable giving hints to ImageMagick via :content-type
2013-08-13 Lars Magne Ingebrigtsen <larsi@gnus.org>
* image.el (image-content-type-suffixes): New variable.
2013-08-13 Lars Magne Ingebrigtsen <larsi@gnus.org>
* image.c (imagemagick_filename_hint): New function to possibly
apply `image-content-type-suffixes'.
(imagemagick_load_image): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/image.c | 43 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 1cb8002ccf7..c60b2c19acf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-08-13 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 2 | |||
| 3 | * image.c (imagemagick_filename_hint): New function to possibly | ||
| 4 | apply `image-content-type-suffixes'. | ||
| 5 | (imagemagick_load_image): Use it. | ||
| 6 | |||
| 1 | 2013-08-13 Eli Zaretskii <eliz@gnu.org> | 7 | 2013-08-13 Eli Zaretskii <eliz@gnu.org> |
| 2 | 8 | ||
| 3 | * decompress.c (Fzlib_decompress_region) [WINDOWSNT]: Return Qnil | 9 | * decompress.c (Fzlib_decompress_region) [WINDOWSNT]: Return Qnil |
diff --git a/src/image.c b/src/image.c index ae38b4f7648..35cbbb631ae 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -551,6 +551,7 @@ static Lisp_Object QCheuristic_mask; | |||
| 551 | static Lisp_Object QCcolor_symbols; | 551 | static Lisp_Object QCcolor_symbols; |
| 552 | static Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry; | 552 | static Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry; |
| 553 | static Lisp_Object QCcrop, QCrotation; | 553 | static Lisp_Object QCcrop, QCrotation; |
| 554 | static Lisp_Object QCcontent_type; | ||
| 554 | 555 | ||
| 555 | /* Other symbols. */ | 556 | /* Other symbols. */ |
| 556 | 557 | ||
| @@ -7740,6 +7741,7 @@ enum imagemagick_keyword_index | |||
| 7740 | IMAGEMAGICK_WIDTH, | 7741 | IMAGEMAGICK_WIDTH, |
| 7741 | IMAGEMAGICK_MAX_HEIGHT, | 7742 | IMAGEMAGICK_MAX_HEIGHT, |
| 7742 | IMAGEMAGICK_MAX_WIDTH, | 7743 | IMAGEMAGICK_MAX_WIDTH, |
| 7744 | IMAGEMAGICK_CONTENT_TYPE, | ||
| 7743 | IMAGEMAGICK_ROTATION, | 7745 | IMAGEMAGICK_ROTATION, |
| 7744 | IMAGEMAGICK_CROP, | 7746 | IMAGEMAGICK_CROP, |
| 7745 | IMAGEMAGICK_LAST | 7747 | IMAGEMAGICK_LAST |
| @@ -7764,6 +7766,7 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] = | |||
| 7764 | {":width", IMAGE_INTEGER_VALUE, 0}, | 7766 | {":width", IMAGE_INTEGER_VALUE, 0}, |
| 7765 | {":max-height", IMAGE_INTEGER_VALUE, 0}, | 7767 | {":max-height", IMAGE_INTEGER_VALUE, 0}, |
| 7766 | {":max-width", IMAGE_INTEGER_VALUE, 0}, | 7768 | {":max-width", IMAGE_INTEGER_VALUE, 0}, |
| 7769 | {":content-type", IMAGE_SYMBOL_VALUE, 0}, | ||
| 7767 | {":rotation", IMAGE_NUMBER_VALUE, 0}, | 7770 | {":rotation", IMAGE_NUMBER_VALUE, 0}, |
| 7768 | {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 7771 | {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0} |
| 7769 | }; | 7772 | }; |
| @@ -7842,6 +7845,30 @@ imagemagick_error (MagickWand *wand) | |||
| 7842 | description = (char *) MagickRelinquishMemory (description); | 7845 | description = (char *) MagickRelinquishMemory (description); |
| 7843 | } | 7846 | } |
| 7844 | 7847 | ||
| 7848 | /* Possibly give ImageMagick some extra help to determine the image | ||
| 7849 | type by supplying a "dummy" filename based on the Content-Type. */ | ||
| 7850 | |||
| 7851 | static char* | ||
| 7852 | imagemagick_filename_hint (Lisp_Object spec) | ||
| 7853 | { | ||
| 7854 | Lisp_Object content_type = image_spec_value (spec, QCcontent_type, NULL); | ||
| 7855 | Lisp_Object symbol = intern ("image-content-type-suffixes"); | ||
| 7856 | Lisp_Object suffix; | ||
| 7857 | char *name, *prefix = "/tmp/foo."; | ||
| 7858 | |||
| 7859 | if (NILP (Fboundp (symbol))) | ||
| 7860 | return NULL; | ||
| 7861 | |||
| 7862 | suffix = Fcar (Fcdr (Fassq (content_type, Fsymbol_value (symbol)))); | ||
| 7863 | if (! STRINGP (suffix)) | ||
| 7864 | return NULL; | ||
| 7865 | |||
| 7866 | name = xmalloc (strlen (prefix) + SBYTES (suffix) + 1); | ||
| 7867 | strcpy(name, prefix); | ||
| 7868 | strcat(name, SDATA (suffix)); | ||
| 7869 | return name; | ||
| 7870 | } | ||
| 7871 | |||
| 7845 | /* Helper function for imagemagick_load, which does the actual loading | 7872 | /* Helper function for imagemagick_load, which does the actual loading |
| 7846 | given contents and size, apart from frame and image structures, | 7873 | given contents and size, apart from frame and image structures, |
| 7847 | passed from imagemagick_load. Uses librimagemagick to do most of | 7874 | passed from imagemagick_load. Uses librimagemagick to do most of |
| @@ -7875,6 +7902,7 @@ imagemagick_load_image (struct frame *f, struct image *img, | |||
| 7875 | int desired_width, desired_height; | 7902 | int desired_width, desired_height; |
| 7876 | double rotation; | 7903 | double rotation; |
| 7877 | int pixelwidth; | 7904 | int pixelwidth; |
| 7905 | char *filename_hint = NULL; | ||
| 7878 | 7906 | ||
| 7879 | /* Handle image index for image types who can contain more than one image. | 7907 | /* Handle image index for image types who can contain more than one image. |
| 7880 | Interface :index is same as for GIF. First we "ping" the image to see how | 7908 | Interface :index is same as for GIF. First we "ping" the image to see how |
| @@ -7888,6 +7916,12 @@ imagemagick_load_image (struct frame *f, struct image *img, | |||
| 7888 | ping_wand = NewMagickWand (); | 7916 | ping_wand = NewMagickWand (); |
| 7889 | /* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */ | 7917 | /* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */ |
| 7890 | 7918 | ||
| 7919 | if (! filename) | ||
| 7920 | filename_hint = imagemagick_filename_hint (img->spec); | ||
| 7921 | |||
| 7922 | if (filename_hint) | ||
| 7923 | MagickSetFilename (ping_wand, filename_hint); | ||
| 7924 | |||
| 7891 | status = filename | 7925 | status = filename |
| 7892 | ? MagickPingImage (ping_wand, filename) | 7926 | ? MagickPingImage (ping_wand, filename) |
| 7893 | : MagickPingImageBlob (ping_wand, contents, size); | 7927 | : MagickPingImageBlob (ping_wand, contents, size); |
| @@ -7920,6 +7954,9 @@ imagemagick_load_image (struct frame *f, struct image *img, | |||
| 7920 | 7954 | ||
| 7921 | image_wand = NewMagickWand (); | 7955 | image_wand = NewMagickWand (); |
| 7922 | 7956 | ||
| 7957 | if (filename_hint) | ||
| 7958 | MagickSetFilename (image_wand, filename_hint); | ||
| 7959 | |||
| 7923 | if ((filename | 7960 | if ((filename |
| 7924 | ? MagickReadImage (image_wand, filename) | 7961 | ? MagickReadImage (image_wand, filename) |
| 7925 | : MagickReadImageBlob (image_wand, contents, size)) | 7962 | : MagickReadImageBlob (image_wand, contents, size)) |
| @@ -8163,11 +8200,16 @@ imagemagick_load_image (struct frame *f, struct image *img, | |||
| 8163 | /* `MagickWandTerminus' terminates the imagemagick environment. */ | 8200 | /* `MagickWandTerminus' terminates the imagemagick environment. */ |
| 8164 | MagickWandTerminus (); | 8201 | MagickWandTerminus (); |
| 8165 | 8202 | ||
| 8203 | if (filename_hint) | ||
| 8204 | free (filename_hint); | ||
| 8205 | |||
| 8166 | return 1; | 8206 | return 1; |
| 8167 | 8207 | ||
| 8168 | imagemagick_error: | 8208 | imagemagick_error: |
| 8169 | DestroyMagickWand (image_wand); | 8209 | DestroyMagickWand (image_wand); |
| 8170 | if (bg_wand) DestroyPixelWand (bg_wand); | 8210 | if (bg_wand) DestroyPixelWand (bg_wand); |
| 8211 | if (filename_hint) | ||
| 8212 | free (filename_hint); | ||
| 8171 | 8213 | ||
| 8172 | MagickWandTerminus (); | 8214 | MagickWandTerminus (); |
| 8173 | /* TODO more cleanup. */ | 8215 | /* TODO more cleanup. */ |
| @@ -9105,6 +9147,7 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 9105 | DEFSYM (Qpostscript, "postscript"); | 9147 | DEFSYM (Qpostscript, "postscript"); |
| 9106 | DEFSYM (QCmax_width, ":max-width"); | 9148 | DEFSYM (QCmax_width, ":max-width"); |
| 9107 | DEFSYM (QCmax_height, ":max-height"); | 9149 | DEFSYM (QCmax_height, ":max-height"); |
| 9150 | DEFSYM (QCcontent_type, ":content-type"); | ||
| 9108 | #ifdef HAVE_GHOSTSCRIPT | 9151 | #ifdef HAVE_GHOSTSCRIPT |
| 9109 | ADD_IMAGE_TYPE (Qpostscript); | 9152 | ADD_IMAGE_TYPE (Qpostscript); |
| 9110 | DEFSYM (QCloader, ":loader"); | 9153 | DEFSYM (QCloader, ":loader"); |