Skip to content

Commit

Permalink
Incorporate Fedora patch from Ville Skyttä to allow using GraphicsMagick
Browse files Browse the repository at this point in the history
instead of ImageMagick
  • Loading branch information
Lawrence D'Oliveiro committed Jan 1, 2010
1 parent 1fc1cf3 commit 101466d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
32 changes: 25 additions & 7 deletions configure.ac
Expand Up @@ -27,21 +27,41 @@ AC_CHECK_FUNCS( \
setmode \
)

AC_CHECK_PROGS(MAGICKCONFIG, [Magick-config GraphicsMagick-config])

usemagick=0

AC_CHECK_PROGS(MAGICKCONFIG, [Magick-config])
if test -n "$MAGICKCONFIG"; then
ac_save_CPPFLAGS="$CPPFLAGS"
ac_save_LIBS="$LIBS"
MAGICK_CPPFLAGS="`$MAGICKCONFIG --cppflags`"
MAGICK_LIBS="`$MAGICKCONFIG --ldflags` `$MAGICKCONFIG --libs`"
CPPFLAGS="$CPPFLAGS $MAGICK_CPPFLAGS"
LIBS="$MAGICK_LIBS $LIBS"
AC_CHECK_FUNC(ExportImagePixels, usemagick=1, AC_MSG_NOTICE([ImageMagick/GraphicsMagick does not support the function
ExportImagePixels. Please upgrade to ImageMagick 5.5.7 or newer (or
the corresponding GraphicsMagick version)]))
AC_CHECK_FUNC(ExportImagePixels, usemagick=1, AC_MSG_NOTICE([ImageMagick does not support the function
ExportImagePixels. Please upgrade to ImageMagick 5.5.7 or newer]))
CPPFLAGS="$ac_save_CPPFLAGS"
LIBS="$ac_save_LIBS"
if test "$usemagick" = 1; then
AC_DEFINE(HAVE_MAGICK, 1, [Whether the ImageMagick libraries are available])
fi
fi

if test "$usemagick" != 1; then
AC_CHECK_PROGS(GMAGICKCONFIG, [GraphicsMagick-config])
if test -n "$GMAGICKCONFIG"; then
ac_save_CPPFLAGS="$CPPFLAGS"
ac_save_LIBS="$LIBS"
MAGICK_CPPFLAGS="`$GMAGICKCONFIG --cppflags`"
MAGICK_LIBS="`$GMAGICKCONFIG --ldflags` `$GMAGICKCONFIG --libs`"
CPPFLAGS="$CPPFLAGS $MAGICK_CPPFLAGS"
LIBS="$MAGICK_LIBS $LIBS"
AC_CHECK_FUNC(DispatchImage, usemagick=1)
CPPFLAGS="$ac_save_CPPFLAGS"
LIBS="$ac_save_LIBS"
if test "$usemagick" = 1; then
AC_DEFINE(HAVE_GMAGICK, 1, [Whether the GraphicsMagick libraries are available])
fi
fi
fi

if test "$usemagick" != 1; then
Expand All @@ -50,8 +70,6 @@ if test "$usemagick" != 1; then
AC_CHECK_LIB(png, png_sig_cmp, test, AC_MSG_ERROR([You must have libpng(-devel) installed]), -lz -lm)
MAGICK_CPPFLAGS=
MAGICK_LIBS="-lpng -lz -lm"
else
AC_DEFINE(HAVE_MAGICK, 1, [Whether the ImageMagick or GraphicsMagick libraries are available])
fi

AC_SUBST(MAGICK_CPPFLAGS)
Expand Down
6 changes: 5 additions & 1 deletion src/compat.h
Expand Up @@ -49,10 +49,14 @@

// this doesn't really belong here, but it was easiest
#ifdef HAVE_MAGICK
#define BUILDSPEC_MAGICK " magick"
#define BUILDSPEC_MAGICK " imagemagick"
#else
#ifdef HAVE_GMAGICK
#define BUILDSPEC_MAGICK " graphicsmagick"
#else
#define BUILDSPEC_MAGICK ""
#endif
#endif

#ifdef HAVE_GETOPT_LONG
#define BUILDSPEC_GETOPT " gnugetopt"
Expand Down
21 changes: 14 additions & 7 deletions src/subgen-image.c
Expand Up @@ -28,7 +28,7 @@
#include <fcntl.h>
#include <math.h>

#ifdef HAVE_MAGICK
#if defined(HAVE_MAGICK) || defined(HAVE_GMAGICK)
#include <stdarg.h>
#include <magick/api.h>
#else
Expand Down Expand Up @@ -154,7 +154,7 @@ static void createimage(pict *s,int w,int h)
}
}

#ifdef HAVE_MAGICK
#if defined(HAVE_MAGICK) || defined(HAVE_GMAGICK)
static int read_magick(pict *s)
/* uses ImageMagick to read image s from s->fname. */
{
Expand Down Expand Up @@ -182,7 +182,13 @@ static int read_magick(pict *s)
for( y=0; y<im->rows; y++ ) {
char pdata[MAXX*4];

if(!ExportImagePixels(im,0,y,im->columns,1,"RGBA",CharPixel,pdata,&ei)) {
if(!
#ifdef HAVE_MAGICK
ExportImagePixels
#else // HAVE_GMAGICK
DispatchImage
#endif
(im,0,y,im->columns,1,"RGBA",CharPixel,pdata,&ei)) {
fprintf(stderr,"ERR: Extracting row %d from %s (%s,%s)\n",y,s->fname,ei.reason,ei.description);
CatchException(&ei);
MagickError(ei.severity,ei.reason,ei.description);
Expand All @@ -196,7 +202,8 @@ static int read_magick(pict *s)
p.g=pdata[x*4+1];
p.b=pdata[x*4+2];
// the meaning of RGBA swapped with ImageMagick 6.0.0...
#if MagickLibVersion >= 0x600
// ...but not with GraphicsMagick
#if defined(HAVE_MAGICK) && MagickLibVersion >= 0x600
p.t=pdata[x*4+3];
#else
p.t=255-pdata[x*4+3];
Expand Down Expand Up @@ -336,7 +343,7 @@ static int read_pic(stinfo *s,pict *p)
{
if( !p->fname )
return 0;
#ifdef HAVE_MAGICK
#if defined(HAVE_MAGICK) || defined(HAVE_GMAGICK)
r=read_magick(p);
#else
r=read_png(p);
Expand Down Expand Up @@ -1074,14 +1081,14 @@ int process_subtitle(stinfo *s)

void image_init()
{
#ifdef HAVE_MAGICK
#if defined(HAVE_MAGICK) || defined(HAVE_GMAGICK)
InitializeMagick(NULL);
#endif
}

void image_shutdown()
{
#ifdef HAVE_MAGICK
#if defined(HAVE_MAGICK) || defined(HAVE_GMAGICK)
DestroyMagick();
#endif
}

0 comments on commit 101466d

Please sign in to comment.