From 0e25d3345f2ae31fc987fbf0515c29ea043ac526 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Tue, 12 Jun 2012 18:08:39 +0800 Subject: [PATCH] Handle availability of MagickMergeImageLayers and MagickExportImagePixels * configure.in: Check for MagickMergeImageLayers. * src/image.c (imagemagick_load_image): Use MagickFlattenImage if MagickMergeImageLayers is undefined. Use pixel pusher loop if MagickExportImagePixels is undefined. Fixes: debbugs:11678 --- ChangeLog | 4 +++ configure.in | 1 + src/ChangeLog | 6 ++++ src/image.c | 101 ++++++++++++++++++++++++++++------------------------------ 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b9378b3cc9..55496500f99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-06-12 Chong Yidong + + * configure.in: Check for MagickMergeImageLayers (Bug#11678). + 2012-06-11 Glenn Morris * configure.in (SYSTEM_TYPE): New AC_DEFINE. diff --git a/configure.in b/configure.in index 48644658586..f11b6651c1d 100644 --- a/configure.in +++ b/configure.in @@ -1855,6 +1855,7 @@ if test "${HAVE_X11}" = "yes"; then CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS" LIBS="$IMAGEMAGICK_LIBS $LIBS" AC_CHECK_FUNCS(MagickExportImagePixels) + AC_CHECK_FUNCS(MagickMergeImageLayers) fi fi fi diff --git a/src/ChangeLog b/src/ChangeLog index fd5169c1498..3a011fc7432 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2012-06-12 Chong Yidong + + * image.c (imagemagick_load_image): Use MagickFlattenImage if + MagickMergeImageLayers is undefined. Use pixel pusher loop if + MagickExportImagePixels is undefined. + 2012-06-12 Paul Eggert * image.c (imagemagick_load_image): Remove unused label. diff --git a/src/image.c b/src/image.c index 8a6d7861f91..bd3a0822fe9 100644 --- a/src/image.c +++ b/src/image.c @@ -7783,7 +7783,11 @@ imagemagick_load_image (struct frame *f, struct image *img, { MagickWand *new_wand; MagickSetImageBackgroundColor (image_wand, bg_wand); +#ifdef HAVE_MAGICKMERGEIMAGELAYERS new_wand = MagickMergeImageLayers (image_wand, MergeLayer); +#else + new_wand = MagickFlattenImages (image_wand); +#endif DestroyMagickWand (image_wand); image_wand = new_wand; } @@ -7800,7 +7804,50 @@ imagemagick_load_image (struct frame *f, struct image *img, init_color_table (); - if (imagemagick_render_type == 0) +#ifdef HAVE_MAGICKEXPORTIMAGEPIXELS + if (imagemagick_render_type != 0) + { + /* Magicexportimage is normally faster than pixelpushing. This + method is also well tested. Some aspects of this method are + ad-hoc and needs to be more researched. */ + int imagedepth = 24; /*MagickGetImageDepth(image_wand);*/ + const char *exportdepth = imagedepth <= 8 ? "I" : "BGRP"; /*"RGBP";*/ + /* Try to create a x pixmap to hold the imagemagick pixmap. */ + if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, + &ximg, &img->pixmap)) + { +#ifdef COLOR_TABLE_SUPPORT + free_color_table (); +#endif + image_error ("Imagemagick X bitmap allocation failure", Qnil, Qnil); + goto imagemagick_error; + } + + /* Oddly, the below code doesn't seem to work:*/ + /* switch(ximg->bitmap_unit){ */ + /* case 8: */ + /* pixelwidth=CharPixel; */ + /* break; */ + /* case 16: */ + /* pixelwidth=ShortPixel; */ + /* break; */ + /* case 32: */ + /* pixelwidth=LongPixel; */ + /* break; */ + /* } */ + /* + Here im just guessing the format of the bitmap. + happens to work fine for: + - bw djvu images + on rgb display. + seems about 3 times as fast as pixel pushing(not carefully measured) + */ + pixelwidth = CharPixel; /*??? TODO figure out*/ + MagickExportImagePixels (image_wand, 0, 0, width, height, + exportdepth, pixelwidth, ximg->data); + } + else +#endif /* HAVE_MAGICKEXPORTIMAGEPIXELS */ { size_t image_height; @@ -7850,58 +7897,6 @@ imagemagick_load_image (struct frame *f, struct image *img, } DestroyPixelIterator (iterator); } - else /* imagemagick_render_type != 0 */ - { - /* Magicexportimage is normally faster than pixelpushing. This - method is also well tested. Some aspects of this method are - ad-hoc and needs to be more researched. */ - int imagedepth = 24;/*MagickGetImageDepth(image_wand);*/ - const char *exportdepth = imagedepth <= 8 ? "I" : "BGRP";/*"RGBP";*/ - /* Try to create a x pixmap to hold the imagemagick pixmap. */ - if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, - &ximg, &img->pixmap)) - { -#ifdef COLOR_TABLE_SUPPORT - free_color_table (); -#endif - image_error ("Imagemagick X bitmap allocation failure", Qnil, Qnil); - goto imagemagick_error; - } - - - /* Oddly, the below code doesn't seem to work:*/ - /* switch(ximg->bitmap_unit){ */ - /* case 8: */ - /* pixelwidth=CharPixel; */ - /* break; */ - /* case 16: */ - /* pixelwidth=ShortPixel; */ - /* break; */ - /* case 32: */ - /* pixelwidth=LongPixel; */ - /* break; */ - /* } */ - /* - Here im just guessing the format of the bitmap. - happens to work fine for: - - bw djvu images - on rgb display. - seems about 3 times as fast as pixel pushing(not carefully measured) - */ - pixelwidth = CharPixel;/*??? TODO figure out*/ -#ifdef HAVE_MAGICKEXPORTIMAGEPIXELS - MagickExportImagePixels (image_wand, - 0, 0, - width, height, - exportdepth, - pixelwidth, - ximg->data); -#else - image_error ("You don't have MagickExportImagePixels, upgrade ImageMagick!", - Qnil, Qnil); -#endif - } - #ifdef COLOR_TABLE_SUPPORT /* Remember colors allocated for this image. */ -- 2.11.4.GIT