Skip to content

Commit

Permalink
add support for GraphicsMagick as ImageMagick alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
spadix0 committed Aug 7, 2011
1 parent 7ae7502 commit 8674cb4
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 37 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
current:
* add support for GraphicsMagick as ImageMagick alternative
* mention xmlto in HACKING (patch #3297039)
- thanks to jarekczek for the patch!
* disable addons by default until synchronization with main symbol is working
Expand Down
110 changes: 83 additions & 27 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -284,46 +284,100 @@ set appropriately or configure --without-jpeg])],
])
AM_CONDITIONAL([HAVE_JPEG], [test "x$with_jpeg" = "xyes"])

dnl ImageMagick
dnl ImageMagick or GraphicsMagick
dnl disable both if IM is explicitly disabled to preserve old behavior

AC_ARG_WITH([imagemagick],
[AS_HELP_STRING([--without-imagemagick],
[disable support for scanning images with ImageMagick])],
[],
[with_imagemagick="yes"])
[with_imagemagick="check"])

AS_IF([test "x$with_imagemagick" != "xno"],
[PKG_CHECK_MODULES([MAGICK], [MagickWand >= 6.2.6], [],
[dnl Wand is deprecated in favor of MagickWand,
dnl but the latter doesn't exist in older verisons (bug #2848437)
AC_ARG_WITH([graphicsmagick],
[AS_HELP_STRING([--with-graphicsmagick],
[use GraphicsMagick alternative to ImageMagick])],
[],
[with_graphicsmagick="check"])

magick="UnknownMagick"
have_IM="maybe"
AS_IF([test "x$with_imagemagick" = "xno"], [],
[test "x$with_imagemagick" = "xyes" || \
test "x$with_graphicsmagick" != "xyes"],
[looked_for="ImageMagick >= 6.2.6"
PKG_CHECK_MODULES([MAGICK], [MagickWand >= 6.2.6],
[MAGICK_VERSION=`$PKG_CONFIG MagickWand --modversion`],
[dnl
dnl Wand is deprecated in favor of MagickWand,
dnl but the latter doesn't exist in older verisons (bug #2848437)
saved_error=$MAGICK_PKG_ERRORS
PKG_CHECK_MODULES([MAGICK], [Wand >= 6.2.6], [],
[AC_MSG_FAILURE([dnl
Unable to find ImageMagick >= 6.2.6:
PKG_CHECK_MODULES([MAGICK], [Wand >= 6.2.6],
[MAGICK_VERSION=`$PKG_CONFIG Wand --modversion`],
[have_IM="no"])])
AS_IF([test "x$have_IM" != "xno"],
[magick="ImageMagick"
AC_MSG_NOTICE([trying ImageMagick version $MAGICK_VERSION])
dnl double check ImageMagick install (bug #2582232)
CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MAGICK_CFLAGS"
AC_CHECK_HEADER([wand/MagickWand.h],
[have_IM="yes"],
[have_IM="broken"])
CPPFLAGS="$CPPFLAGS_save"])])

have_GM="maybe"
AS_IF([test "x$have_IM" = "xyes"], [],
[test "x$with_graphicsmagick" = "xno"], [],
[test "x$with_graphicsmagick" = "xyes" || \
test "x$with_imagemagick" = "xcheck"],
[AS_IF([test "x$looked_for" = "x"],
[looked_for="GraphicsMagick"],
[looked_for="$looked_for or GraphicsMagick"])
PKG_CHECK_MODULES([MAGICK], [GraphicsMagickWand],
[have_GM="yes"
magick="GraphicsMagick"
MAGICK_VERSION=`$PKG_CONFIG GraphicsMagickWand --modversion`],
[have_GM="no"
AS_IF([test "x$saved_error" = "x"],
[saved_error=$MAGICK_PKG_ERRORS])])])

dnl now that we have collected all the info abt what Magick is available
dnl let the user know what we will or can't do
AS_IF([test "x$have_IM" = "xbroken" && test "x$have_GM" = "xyes"],
[AC_MSG_WARN([Your ImageMagick install is broken, using GraphicsMagick instead])])

AS_IF([test "x$have_IM" = "xyes" || test "x$have_GM" = "xyes"],
[AC_MSG_NOTICE([using $magick version $MAGICK_VERSION])],
[test "x$with_imagemagick" = "xno" && \
test "x$with_graphicsmagick" != "xyes"],
[AC_MSG_NOTICE([image scanning disabled -- zbarimg will *not* be built])],
[test "x$have_IM" = "xbroken"],
[AC_MSG_FAILURE([$magick package found but wand/MagickWand.h not installed?!
this is a problem with your $magick install, please try again after
resolving the inconsistency or installing GraphicsMagick alternative...])],
[AC_MSG_FAILURE([dnl
Unable to find $looked_for:
$saved_error
* Ensure that you installed any "development" packages for ImageMagick.
* Ensure that you installed any "development" packages for ImageMagick or
GraphicsMagick.
* Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
* You may set the environment variables MAGICK_CFLAGS and MAGICK_LIBS
to avoid the need to call pkg-config.
See the pkg-config man page for more details.
* To avoid using ImageMagick altogether you may add the --without-imagemagick
flag to the configure command; the zbarimg program will not be built.
])])])
MAGICK_VERSION=`$PKG_CONFIG MagickWand --modversion`
AC_MSG_NOTICE([using ImageMagick version $MAGICK_VERSION])
dnl double check ImageMagick install (bug #2582232)
CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MAGICK_CFLAGS"
AC_CHECK_HEADER([wand/MagickWand.h], [],
[AC_MSG_FAILURE([ImageMagick package found but wand/MagickWand.h not installed?!
this is a problem with your ImageMagick install,
please resolve the inconsistency and try again...])])
CPPFLAGS="$CPPFLAGS_save"])
* To avoid using ImageMagick or GraphicsMagick altogether you may add the
--without-imagemagick flag to the configure command; the zbarimg program
will *not* be built.
])])

AM_CONDITIONAL([HAVE_MAGICK], [test "x$with_imagemagick" = "xyes"])
AS_IF([test "x$have_IM" = "xyes"],
[AC_DEFINE([HAVE_IMAGEMAGICK], [1], [Define to 1 to use ImageMagick])],
[test "x$have_GM" = "xyes"],
[AC_DEFINE([HAVE_GRAPHICSMAGICK], [1], [Define to 1 to use GraphicsMagick])])
AM_CONDITIONAL([HAVE_MAGICK],
[test "x$have_IM" = "xyes" || test "x$have_GM" = "xyes"])

dnl Mozilla NPAPI
AC_ARG_WITH([npapi],
Expand Down Expand Up @@ -506,8 +560,10 @@ AS_IF([test "x$enable_video" != "xyes"],
echo "jpeg --with-jpeg=$with_jpeg"
AS_IF([test "x$with_jpeg" != "xyes"],
[echo " => JPEG image conversions will *NOT* be supported"])
echo "Magick++ --with-imagemagick=$with_imagemagick"
AS_IF([test "x$with_imagemagick" != "xyes"],
AS_IF([test "x$have_GM" = "xyes"],
[echo "GraphicsMagick --with-graphicsmagick=yes"],
[echo "ImageMagick --with-imagemagick=$with_imagemagick"])
AS_IF([test "x$have_IM" != "xyes" && test "x$have_GM" != "xyes"],
[echo " => the zbarimg file scanner will *NOT* be built"])
echo "Python --with-python=$with_python"
echo "GTK+ --with-gtk=$with_gtk"
Expand Down
7 changes: 5 additions & 2 deletions test/barcodetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def distdir_search(subdir, base, suffixes=('',)):
import re
makefile = open('Makefile')
for line in makefile:
if re.match('^VPATH\s*=', line):
if re.match(r'^VPATH\s*=', line):
vpath = line.split('=', 1)[1].strip()
if vpath and vpath != rundir:
search.append(vpath)
Expand Down Expand Up @@ -352,7 +352,10 @@ def loadTestsFromURL(self, url=None, file=None):
continue
if src.tag == ET.QName(BC, 'source'):
test = TestCase()
src.set('href', urljoin(url, href))
# convert file URLs to filesystem paths
href = urljoin(url, href)
href = re.sub(r'^file://', '', href)
src.set('href', href)
test.source = src
suite.addTest(test)
elif src.tag == ET.QName(TS, 'index'):
Expand Down
3 changes: 3 additions & 0 deletions test/test_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,9 @@ int main (int argc, char **argv)
decoder = zbar_decoder_create();
/* allow empty CODE39 symbologies */
zbar_decoder_set_config(decoder, ZBAR_CODE39, ZBAR_CFG_MIN_LEN, 0);
/* enable addons */
zbar_decoder_set_config(decoder, ZBAR_EAN2, ZBAR_CFG_ENABLE, 1);
zbar_decoder_set_config(decoder, ZBAR_EAN5, ZBAR_CFG_ENABLE, 1);
zbar_decoder_set_handler(decoder, symbol_handler);

encode_junk(rnd_size + 1);
Expand Down
30 changes: 22 additions & 8 deletions zbarimg/zbarimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,29 @@
#include <assert.h>

#include <zbar.h>
#include <wand/MagickWand.h>

#ifdef HAVE_GRAPHICSMAGICK
# include <wand/wand_api.h>
#endif

#ifdef HAVE_IMAGEMAGICK
# include <wand/MagickWand.h>

/* ImageMagick frequently changes API names - just use the original
* (more stable?) names to match GraphicsMagick
*/
# define InitializeMagick(f) MagickWandGenesis()
# define DestroyMagick MagickWandTerminus
# define MagickSetImageIndex MagickSetIteratorIndex

/* in 6.4.5.4 MagickGetImagePixels changed to MagickExportImagePixels.
* (still not sure this check is quite right...
* how does MagickGetAuthenticImagePixels fit in?)
* ref http://bugs.gentoo.org/247292
*/
#if MagickLibVersion <= 0x645
# define MagickExportImagePixels MagickGetImagePixels
# if MagickLibVersion > 0x645
# define MagickGetImagePixels MagickExportImagePixels
# endif
#endif

static const char *note_usage =
Expand Down Expand Up @@ -133,7 +147,7 @@ static int scan_image (const char *filename)
if(exit_code == 3)
return(-1);

if(!MagickSetIteratorIndex(images, seq) && dump_error(images))
if(!MagickSetImageIndex(images, seq) && dump_error(images))
return(-1);

zbar_image_t *zimage = zbar_image_create();
Expand All @@ -151,8 +165,8 @@ static int scan_image (const char *filename)
unsigned char *blob = malloc(bloblen);
zbar_image_set_data(zimage, blob, bloblen, zbar_image_free_data);

if(!MagickExportImagePixels(images, 0, 0, width, height,
"I", CharPixel, blob))
if(!MagickGetImagePixels(images, 0, 0, width, height,
"I", CharPixel, blob))
return(-1);

if(xmllvl == 1) {
Expand Down Expand Up @@ -312,7 +326,7 @@ int main (int argc, const char *argv[])
return(usage(1, "ERROR: specify image file(s) to scan", NULL));
num_images = 0;

MagickWandGenesis();
InitializeMagick("zbarimg");

processor = zbar_processor_create(0);
assert(processor);
Expand Down Expand Up @@ -425,6 +439,6 @@ int main (int argc, const char *argv[])
exit_code = 4;

zbar_processor_destroy(processor);
MagickWandTerminus();
DestroyMagick();
return(exit_code);
}

0 comments on commit 8674cb4

Please sign in to comment.