Subject: bug#14358: Option to use GraphicsMagick instead of ImageMagick

From: Glenn Morris <[email-masked]>
Date: Tue, 07 May 2013 03:12:36 -0400

Package: emacs
Version: 24.3
Severity: wishlist

Is it possible/desirable for Emacs to be able to use GraphicsMagick
instead of ImageMagick? I'm assuming they provide the same
functionality, but I know nothing about it.

I has a rough'n'ready go at the trivial stuff (see below), but then gave
up with these errors:

image.c: In function 'imagemagick_error':
image.c:7607: warning: cast to pointer from integer of different size
image.c: In function 'imagemagick_load_image':
image.c:7633: error: 'PixelIterator' undeclared (first use in this function)
image.c:7633: error: (Each undeclared identifier is reported only once
image.c:7633: error: for each function it appears in.)
image.c:7633: error: 'iterator' undeclared (first use in this function)
image.c:7635: error: 'MagickPixelPacket' undeclared (first use in this
function)
image.c:7635: error: expected ';' before 'pixel'
image.c:7658: warning: implicit declaration of function 'MagickPingImageBlob'
image.c:7895: warning: implicit declaration of function 'NewPixelIterator'
image.c:7896: error: expected expression before ')' token
image.c:7910: warning: implicit declaration of function 'PixelGetNextIteratorRow'
image.c:7915: warning: implicit declaration of function 'PixelGetMagickColor'
image.c:7915: error: 'pixel' undeclared (first use in this function)
image.c:7923: warning: implicit declaration of function 'DestroyPixelIterator'
image.c: In function 'Fimagemagick_types':
image.c:8023: warning: implicit declaration of function 'GetMagickList'
image.c:8023: warning: assignment makes pointer from integer without a cast
make: *** [image.o] Error 1

=== modified file 'configure.ac'
*** configure.ac	2013-05-07 01:12:22 +0000
--- configure.ac	2013-05-07 01:43:25 +0000
***************
*** 183,188 ****
--- 183,189 ----
  OPTION_DEFAULT_ON([rsvg],[don't compile with SVG image support])
  OPTION_DEFAULT_ON([xml2],[don't compile with XML parsing support])
  OPTION_DEFAULT_ON([imagemagick],[don't compile with ImageMagick image support])
+ OPTION_DEFAULT_OFF([graphicsmagick],[use GraphicsMagick rather than ImageMagick])
  
  OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts])
  OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support])
***************
*** 1931,1955 ****
  fi
  
  HAVE_IMAGEMAGICK=no
  if test "${HAVE_X11}" = "yes"; then
!   if test "${with_imagemagick}" != "no"; then
      ## 6.2.8 is the earliest version known to work, but earlier versions
      ## might work - let us know if you find one.
      ## 6.0.7 does not work.  See bug#7955.
      ## 6.8.2 makes Emacs crash; see Bug#13867.
      IMAGEMAGICK_MODULE="Wand >= 6.2.8 Wand != 6.8.2"
!     PKG_CHECK_MODULES(IMAGEMAGICK, $IMAGEMAGICK_MODULE, HAVE_IMAGEMAGICK=yes, :)
!     AC_SUBST(IMAGEMAGICK_CFLAGS)
!     AC_SUBST(IMAGEMAGICK_LIBS)
  
      if test $HAVE_IMAGEMAGICK = yes; then
        AC_DEFINE(HAVE_IMAGEMAGICK, 1, [Define to 1 if using imagemagick.])
!       CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS"
!       LIBS="$IMAGEMAGICK_LIBS $LIBS"
        AC_CHECK_FUNCS(MagickExportImagePixels MagickMergeImageLayers)
      fi
    fi
! fi

  HAVE_GTK=no
--- 1932,1976 ----
  fi
  
  HAVE_IMAGEMAGICK=no
+ HAVE_GRAPHICSMAGICK=no
+ 
  if test "${HAVE_X11}" = "yes"; then
! 
!   if test "${with_imagemagick}" != "no" && \
!       test "${with_graphicsmagick}" != "yes"; then
      ## 6.2.8 is the earliest version known to work, but earlier versions
      ## might work - let us know if you find one.
      ## 6.0.7 does not work.  See bug#7955.
      ## 6.8.2 makes Emacs crash; see Bug#13867.
      IMAGEMAGICK_MODULE="Wand >= 6.2.8 Wand != 6.8.2"
!     PKG_CHECK_MODULES(MAGICK, $IMAGEMAGICK_MODULE, HAVE_IMAGEMAGICK=yes, :)
!     AC_SUBST(MAGICK_CFLAGS)
!     AC_SUBST(MAGICK_LIBS)
  
      if test $HAVE_IMAGEMAGICK = yes; then
        AC_DEFINE(HAVE_IMAGEMAGICK, 1, [Define to 1 if using imagemagick.])
!       CFLAGS="$CFLAGS $MAGICK_CFLAGS"
!       LIBS="$MAGICK_LIBS $LIBS"
        AC_CHECK_FUNCS(MagickExportImagePixels MagickMergeImageLayers)
      fi
    fi
! 
!   if test "${with_graphicsmagick}" != "no" && \
!       test "${with_imagemagick}" != "no" && \
!       test $HAVE_IMAGEMAGICK != yes; then
!     GRAPHICSMAGICK_MODULE="GraphicsMagickWand"
!     PKG_CHECK_MODULES(MAGICK, $GRAPHICSMAGICK_MODULE, HAVE_GRAPHICSMAGICK=yes, :)
!     AC_SUBST(MAGICK_CFLAGS)
!     AC_SUBST(MAGICK_LIBS)
! 
!     if test $HAVE_GRAPHICSMAGICK = yes; then
!       AC_DEFINE(HAVE_GRAPHICSMAGICK, 1, [Define to 1 if using GraphicsMagick.])
!       CFLAGS="$CFLAGS $MAGICK_CFLAGS"
!       LIBS="$MAGICK_LIBS $LIBS"
!     fi
!   fi
! 
! fi                              dnl HAVE_X11

  HAVE_GTK=no
***************
*** 4385,4390 ****
--- 4406,4412 ----
  echo "  Does Emacs use -lpng?                                   ${HAVE_PNG}"
  echo "  Does Emacs use -lrsvg-2?                                ${HAVE_RSVG}"
  echo "  Does Emacs use imagemagick?                             ${HAVE_IMAGEMAGICK}"
+ echo "  Does Emacs use graphicsmagick?                          ${HAVE_GRAPHICSMAGICK}"
  
  echo "  Does Emacs use -lgpm?                                   ${HAVE_GPM}"
  echo "  Does Emacs use -ldbus?                                  ${HAVE_DBUS}"

=== modified file 'src/Makefile.in'
*** src/Makefile.in	2013-05-07 01:12:22 +0000
--- src/Makefile.in	2013-05-07 01:37:58 +0000
***************
*** 226,233 ****
  RSVG_LIBS= @RSVG_LIBS@
  RSVG_CFLAGS= @RSVG_CFLAGS@
  
! IMAGEMAGICK_LIBS= @IMAGEMAGICK_LIBS@
! IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
  
  LIBXML2_LIBS = @LIBXML2_LIBS@
  LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
--- 226,233 ----
  RSVG_LIBS= @RSVG_LIBS@
  RSVG_CFLAGS= @RSVG_CFLAGS@
  
! MAGICK_LIBS= @MAGICK_LIBS@
! MAGICK_CFLAGS= @MAGICK_CFLAGS@
  
  LIBXML2_LIBS = @LIBXML2_LIBS@
  LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
***************
*** 320,326 ****
  ALL_CFLAGS=-Demacs $(MYCPPFLAGS) -I. -I$(srcdir) \
    -I$(lib) -I$(srcdir)/../lib \
    $(C_SWITCH_MACHINE) $(C_SWITCH_SYSTEM) $(C_SWITCH_X_SITE) \
!   $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \
    $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) \
    $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
    $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
--- 320,326 ----
  ALL_CFLAGS=-Demacs $(MYCPPFLAGS) -I. -I$(srcdir) \
    -I$(lib) -I$(srcdir)/../lib \
    $(C_SWITCH_MACHINE) $(C_SWITCH_SYSTEM) $(C_SWITCH_X_SITE) \
!   $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(MAGICK_CFLAGS) \
    $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) \
    $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
    $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
***************
*** 397,403 ****
  ## Construct full set of libraries to be linked.
  LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
     $(LIBX_OTHER) $(LIBSOUND) \
!    $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
     $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
     $(LIB_EXECINFO) $(XRANDR_LIBS) $(XINERAMA_LIBS) \
     $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
--- 397,403 ----
  ## Construct full set of libraries to be linked.
  LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
     $(LIBX_OTHER) $(LIBSOUND) \
!    $(RSVG_LIBS) $(MAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
     $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
     $(LIB_EXECINFO) $(XRANDR_LIBS) $(XINERAMA_LIBS) \
     $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \

=== modified file 'src/image.c'
*** src/image.c	2013-04-07 04:41:19 +0000
--- src/image.c	2013-05-07 01:50:27 +0000
***************
*** 7473,7479 ****
  /***********************************************************************
  				 ImageMagick
  ***********************************************************************/
! #if defined (HAVE_IMAGEMAGICK)
  
  static Lisp_Object Qimagemagick;
  
--- 7473,7485 ----
  /***********************************************************************
  				 ImageMagick
  ***********************************************************************/
! #if defined (HAVE_IMAGEMAGICK) || defined (HAVE_GRAPHICSMAGICK)
! 
! #ifdef HAVE_GRAPHICSMAGICK
! #define MagickWandGenesis() InitializeMagick(NULL)
! #define MagickWandTerminus DestroyMagick
! #define MagickBooleanType int
! #endif
  
  static Lisp_Object Qimagemagick;
  
***************
*** 7571,7577 ****
--- 7577,7587 ----
  /* The GIF library also defines DrawRectangle, but its never used in Emacs.
     Therefore rename the function so it doesn't collide with ImageMagick.  */
  #define DrawRectangle DrawRectangleGif
+ #ifdef HAVE_GRAPHICSMAGICK
+ #include <wand/magick_wand.h>
+ #else
  #include <wand/MagickWand.h>
+ #endif
  
  /* ImageMagick 6.5.3 through 6.6.5 hid PixelGetMagickColor for some reason.
     Emacs seems to work fine with the hidden version, so unhide it.  */