fix build against graphicsmagick

- add tests for more features missing in GM
- simplify the IM/GM configure tests
- revise the test suite to pass with GM and IM
This commit is contained in:
John Cupitt 2019-08-07 16:17:27 +01:00
parent f0d1a5d82b
commit f36927e78d
11 changed files with 103 additions and 2158 deletions

View File

@ -4,6 +4,7 @@
- always fetch HEIC metadata from the main image [zhoux2016]
- fix loop in malformed ppm [Kyle-Kyle]
- better support for PNGs with long comment names
- fix build with GM
24/5/19 started 8.8.1
- improve realpath() use on older libc

View File

@ -662,68 +662,6 @@ else
with_magickpackage=none
fi
if test x"$magick6" = x"yes"; then
# we SetImageOption to disable some DICOM read processing, but that's only
# in more recent imagemagicks and not in graphicsmagick
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(SetImageOption,
AC_DEFINE(HAVE_SETIMAGEOPTION,1,[define if your magick has SetImageOption.])
)
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# newer ImageMagicks use MagickCoreGenesis instead of InitializeMagick argh
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(MagickCoreGenesis,
AC_DEFINE(HAVE_MAGICKCOREGENESIS,1,
[define if your magick has MagickCoreGenesis.]))
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# newer ImageMagicks use ResetImagePropertyIterator instead of
# ResetImageAttributeIterator argh
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(ResetImagePropertyIterator,
AC_DEFINE(HAVE_RESETIMAGEPROPERTYITERATOR,1,
[define if your magick has ResetImagePropertyIterator.]))
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# so ... do we have ResetImageAttributeIterator()? GM does not
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(ResetImageAttributeIterator,
AC_DEFINE(HAVE_RESETIMAGEATTRIBUTEITERATOR,1,
[define if your magick has ResetImageAttributeIterator.]))
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# GM does not have ResetImageProfileIterator
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(ResetImageProfileIterator,
AC_DEFINE(HAVE_RESETIMAGEPROFILEITERATOR,1,
[define if your magick has ResetImageProfileIterator.]))
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# more recent magicks have GetVirtualPixels rather than GetImagePixels
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(GetVirtualPixels,
AC_DEFINE(HAVE_GETVIRTUALPIXELS,1,
[define if your magick has GetVirtualPixels.]))
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# do we have number_scenes in image_info ... imagemagick uses this
save_CFLAGS="$CFLAGS"
@ -737,63 +675,41 @@ if test x"$magick6" = x"yes"; then
fi
if test x"$magick6" = x"yes"; then
# more recent magick6s have AcquireImage rather than AllocateImage argh
# the magick6 API varies a lot between magick versions, and between GM and
# IM
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(AcquireImage,
AC_DEFINE(HAVE_ACQUIREIMAGE,1,
[define if your magick has AcquireImage.]))
AC_CHECK_FUNCS([InheritException AcquireExceptionInfo SetImageProperty SetImageExtent AcquireImage GetVirtualPixels ResetImageProfileIterator ResetImageAttributeIterator ResetImagePropertyIterator MagickCoreGenesis SetImageOption BlobToStringInfo])
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# more recent magick6s have SetImageExtent
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(SetImageExtent,
AC_DEFINE(HAVE_SETIMAGEEXTENT,1,
[define if your magick has SetImageExtent.]))
LIBS="$save_LIBS"
fi
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $MAGICK_CFLAGS"
if test x"$magick6" = x"yes"; then
# GM uses SetImageAttribute(), IM uses SetImageProperty()
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(SetImageProperty,
AC_DEFINE(HAVE_SETIMAGEPROPERTY,1,
[define if your magick has SetImageProperty.]))
LIBS="$save_LIBS"
fi
# the range of ColorspaceType has expanded several times
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[#include <magick/api.h>],
[ColorspaceType colorspace = CMYColorspace]
)],
[AC_DEFINE(HAVE_CMYCOLORSPACE,1,
[define if your Magick has CMYColorspace.])
]
)
if test x"$magick6" = x"yes"; then
# IM uses SetImageProfile() with StringInfo
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(BlobToStringInfo,
AC_DEFINE(HAVE_BLOBTOSTRINGINFO,1,
[define if your magick has BlobToStringInfo().]))
LIBS="$save_LIBS"
fi
# GetImageMagick() takes two args under GM, three under IM
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[#include <magick/api.h>],
[(void)GetImageMagick(NULL, 0, NULL)]
)],
[AC_DEFINE(HAVE_GETIMAGEMAGICK3,1,
[define if your GetImageMagick() takes three arguments.])
]
)
if test x"$magick6" = x"yes"; then
# GM is missing InheritException
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(InheritException,
AC_DEFINE(HAVE_INHERITEXCEPTION,1,
[define if your magick has InheritException.]))
LIBS="$save_LIBS"
fi
if test x"$magick6" = x"yes"; then
# GM is missing AcquireExceptionInfo
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(AcquireExceptionInfo,
AC_DEFINE(HAVE_ACQUIREEXCEPTIONINFO,1,
[define if your magick has AcquireExceptionInfo.]))
LIBS="$save_LIBS"
CFLAGS="$save_CFLAGS"
fi
# have flags to turn load and save off independently ... some people will want

View File

@ -278,7 +278,7 @@ magick_set_profile( Image *image,
string = BlobToStringInfo( data, length );
result = SetImageProfile( image, name, string );
DestroyStringInfo( string );
#else /*HAVE_BLOBTOSTRINGINFO*/
#else /*!HAVE_BLOBTOSTRINGINFO*/
result = SetImageProfile( image, name, data, length );
#endif /*HAVE_BLOBTOSTRINGINFO*/
@ -410,16 +410,32 @@ typedef struct _MagickColorspaceTypeNames {
static MagickColorspaceTypeNames magick_colorspace_names[] = {
{ UndefinedColorspace, "UndefinedColorspace" },
{ CMYColorspace, "CMYColorspace" },
{ CMYKColorspace, "CMYKColorspace" },
{ GRAYColorspace, "GRAYColorspace" },
{ HSLColorspace, "HSLColorspace" },
{ HWBColorspace, "HWBColorspace" },
{ OHTAColorspace, "OHTAColorspace" },
{ Rec601YCbCrColorspace, "Rec601YCbCrColorspace" },
{ Rec709YCbCrColorspace, "Rec709YCbCrColorspace" },
{ RGBColorspace, "RGBColorspace" },
{ sRGBColorspace, "sRGBColorspace" },
{ TransparentColorspace, "TransparentColorspace" },
{ XYZColorspace, "XYZColorspace" },
{ YCbCrColorspace, "YCbCrColorspace" },
{ YCCColorspace, "YCCColorspace" },
{ YIQColorspace, "YIQColorspace" },
{ YPbPrColorspace, "YPbPrColorspace" },
{ YUVColorspace, "YUVColorspace" },
/* More recent imagemagicks add these.
*/
#ifdef HAVE_CMYCOLORSPACE
{ CMYColorspace, "CMYColorspace" },
{ HCLColorspace, "HCLColorspace" },
{ HCLpColorspace, "HCLpColorspace" },
{ HSBColorspace, "HSBColorspace" },
{ HSIColorspace, "HSIColorspace" },
{ HSLColorspace, "HSLColorspace" },
{ HSVColorspace, "HSVColorspace" },
{ HWBColorspace, "HWBColorspace" },
{ LabColorspace, "LabColorspace" },
{ LCHColorspace, "LCHColorspace" },
{ LCHabColorspace, "LCHabColorspace" },
@ -427,23 +443,12 @@ static MagickColorspaceTypeNames magick_colorspace_names[] = {
{ LogColorspace, "LogColorspace" },
{ LMSColorspace, "LMSColorspace" },
{ LuvColorspace, "LuvColorspace" },
{ OHTAColorspace, "OHTAColorspace" },
{ Rec601YCbCrColorspace, "Rec601YCbCrColorspace" },
{ Rec709YCbCrColorspace, "Rec709YCbCrColorspace" },
{ RGBColorspace, "RGBColorspace" },
{ scRGBColorspace, "scRGBColorspace" },
{ sRGBColorspace, "sRGBColorspace" },
{ TransparentColorspace, "TransparentColorspace" },
{ xyYColorspace, "xyYColorspace" },
{ XYZColorspace, "XYZColorspace" },
{ YCbCrColorspace, "YCbCrColorspace" },
{ YCCColorspace, "YCCColorspace" },
{ YDbDrColorspace, "YDbDrColorspace" },
{ YIQColorspace, "YIQColorspace" },
{ YPbPrColorspace, "YPbPrColorspace" },
{ YUVColorspace, "YUVColorspace" }
#endif /*HAVE_CMYCOLORSPACE*/
/* More recent imagemagicks add these.
/* im7 has this, I think
*
{ LinearGRAYColorspace, "LinearGRAYColorspace" }
*
@ -645,6 +650,12 @@ magick_set_magick_profile( Image *image,
*/
gboolean
magick_ismagick( const unsigned char *bytes, size_t length )
{
magick_genesis();
/* Try with our custom sniffers first.
*/
#ifdef HAVE_GETIMAGEMAGICK3
{
#ifdef HAVE_MAGICK7
char format[MagickPathExtent];
@ -652,12 +663,15 @@ magick_ismagick( const unsigned char *bytes, size_t length )
char format[MaxTextExtent];
#endif
magick_genesis();
/* Try with our custom sniffers first.
*/
return( magick_sniff( bytes, length ) ||
GetImageMagick( bytes, length, format ) );
}
#else /*!HAVE_GETIMAGEMAGICK3*/
/* The GM one returns a static string.
*/
return( magick_sniff( bytes, length ) ||
GetImageMagick( bytes, length ) );
#endif
}
#endif /*HAVE_MAGICK*/

View File

@ -21,9 +21,9 @@ FITS_FILE = os.path.join(IMAGES, "WFPC2u5780205r_c0fx.fits")
OPENSLIDE_FILE = os.path.join(IMAGES, "CMU-1-Small-Region.svs")
PDF_FILE = os.path.join(IMAGES, "ISO_12233-reschart.pdf")
CMYK_PDF_FILE = os.path.join(IMAGES, "cmyktest.pdf")
SVG_FILE = os.path.join(IMAGES, "vips-profile.svg")
SVGZ_FILE = os.path.join(IMAGES, "vips-profile.svgz")
SVG_GZ_FILE = os.path.join(IMAGES, "vips-profile.svg.gz")
SVG_FILE = os.path.join(IMAGES, "logo.svg")
SVGZ_FILE = os.path.join(IMAGES, "logo.svgz")
SVG_GZ_FILE = os.path.join(IMAGES, "logo.svg.gz")
GIF_ANIM_FILE = os.path.join(IMAGES, "cogs.gif")
DICOM_FILE = os.path.join(IMAGES, "dicom_test_image.dcm")
BMP_FILE = os.path.join(IMAGES, "MARBLES.BMP")

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 736 552"
height="552"
width="736"
version="1.1"
id="svg2">
<metadata
id="metadata8">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs6" />
<path
id="path4138"
d="m 292.55701,403.97015 c -11.55,-6.6492 -21.7875,-12.78153 -22.75,-13.62741 l -1.75,-1.53795 0,-110.29412 0,-110.29412 3.25,-2.39996 c 1.7875,-1.31998 12.16249,-7.46556 23.05553,-13.65685 l 19.80554,-11.25689 2.35848,0.45085 c 3.38665,0.6474 45.32224,24.87039 46.25225,26.7164 0.42801,0.84957 1.0032,15.33435 1.2782,32.18841 l 0.5,30.64374 13.2416,-7.64374 13.2416,-7.64374 0.008,-22.1849 0.008,-22.1849 0.89115,-2.3439 0.89115,-2.34389 21.61628,-12.3613 c 11.88896,-6.79871 22.7123,-12.57081 24.05186,-12.82688 l 2.43557,-0.46559 19.80699,11.26988 c 10.89385,6.19843 21.2695,12.34389 23.057,13.65657 l 3.25,2.38669 0,110.29412 0,110.29412 -1.75,1.53301 c -3.17195,2.77933 -44.15638,25.77697 -45.93672,25.77697 -2.41398,0 -46.05066,-24.9883 -47.02375,-26.92789 -0.4338,-0.86466 -1.01373,-15.38962 -1.28873,-32.27769 l -0.5,-30.70558 -13.25,7.64134 -13.25,7.64133 0,22.26719 0,22.26719 -1.06982,2.348 -1.06982,2.348 -22.1867,12.69906 c -12.20269,6.98448 -23.08377,12.68664 -24.18018,12.67147 -1.09641,-0.0152 -11.44348,-5.46784 -22.99348,-12.11704 z m 36.66752,-10.52924 13.07742,-7.67387 -1.87247,-1.3783 c -2.32846,-1.71395 -24.12972,-14.27397 -24.77627,-14.27397 -0.25977,0 -6.38523,3.42995 -13.61214,7.62211 l -13.13984,7.62211 0.82789,0.76651 c 0.84799,0.78513 25.58999,14.97831 26.12294,14.98537 0.16228,0.002 6.17989,-3.44934 13.37247,-7.66996 z M 431.6602,303.38463 c -0.22923,-0.22923 -6.19622,2.90054 -13.25999,6.95504 l -12.8432,7.37183 -0.2623,31.95164 -0.26229,31.95163 13.26229,7.57763 13.2623,7.57763 0.25999,-46.48431 c 0.14299,-25.56637 0.0724,-46.67186 -0.1568,-46.90109 z m 31.89681,83.96099 10,-5.82586 0.25495,-97.89754 0.25496,-97.89754 -0.77667,-0.77667 -0.77667,-0.77667 -13.22828,7.53761 -13.22829,7.53761 0,22.85232 c 0,12.56877 -0.25005,23.50394 -0.55567,24.30037 -0.30562,0.79643 -26.36178,16.24574 -57.90259,34.33179 -31.5408,18.08605 -57.17657,33.16074 -56.96838,33.49931 0.60109,0.97753 25.30452,14.88442 26.43986,14.88442 0.563,0 9.45284,-4.86996 19.75521,-10.82212 10.30236,-5.95217 27.95657,-16.14861 39.23157,-22.65877 l 20.5,-11.83663 2.73709,-0.008 2.7371,-0.008 2.0129,1.82165 2.01291,1.82166 0,54.86533 0,54.86534 3.75,-1.99197 c 2.0625,-1.09558 8.25,-4.61361 13.75,-7.81783 z m -167.93925,-21.85645 13.43925,-7.6256 0,-23.18327 0,-23.18327 1.25,-1.59478 c 1.03952,-1.32625 47.61139,-28.38858 101.5,-58.98038 6.7375,-3.82479 12.25,-7.3305 12.25,-7.79048 0,-0.95802 -24.25765,-15.01662 -25.91067,-15.01662 -0.59882,0 -16.05138,8.62241 -34.33904,19.1609 -18.28766,10.5385 -36.47479,20.85631 -40.41586,22.92847 l -7.16556,3.76755 -2.01967,-0.52815 c -1.11082,-0.29049 -2.71993,-1.30194 -3.57581,-2.24768 l -1.55614,-1.71951 -0.25863,-54.68424 -0.25862,-54.68423 -13.5,7.75345 -13.5,7.75344 -0.25488,98.75 c -0.14018,54.3125 -3.4e-4,98.75 0.31076,98.75 0.31109,0 6.61329,-3.43152 14.00487,-7.6256 z m 54.42846,-8.1244 -0.0108,-15.75 -13.51373,-7.69805 -13.51372,-7.69804 0.27452,16.07811 0.27452,16.07812 12.5,7.31478 c 6.875,4.02313 12.8375,7.3396 13.25,7.36993 0.4125,0.0303 0.74514,-7.03235 0.73921,-15.69485 z m -12.98921,-110.65695 12.5,-7.32761 0.26354,-31.89276 0.26353,-31.89276 -9.26353,-5.24435 c -5.09495,-2.88438 -11.17604,-6.39287 -13.51354,-7.79663 l -4.25,-2.5523 0,47.05668 c 0,25.88117 0.3375,47.03883 0.75,47.01701 0.4125,-0.0218 6.375,-3.3371 13.25,-7.36728 z m 94.77539,-32.191 -0.27539,-15.59794 -12,-7.00283 c -6.6,-3.85155 -12.5625,-7.23062 -13.25,-7.50904 l -1.25,-0.50622 0.005,15.85699 0.005,15.85699 12.74458,7.23989 c 7.00951,3.98194 13.0935,7.24444 13.51996,7.25 0.42647,0.006 0.65147,-7.00897 0.5,-15.58784 z m 20.92694,-34.96236 c 7.31372,-4.15818 13.29767,-7.72445 13.29767,-7.92505 0,-0.3088 -24.07649,-14.42153 -26.13916,-15.32179 -0.38706,-0.16893 -6.80326,3.18335 -14.25821,7.44952 l -13.55448,7.75668 9.22593,5.38371 c 5.07425,2.96103 11.02592,6.45369 13.22592,7.76145 2.2,1.30776 4.20355,2.39531 4.45233,2.41677 0.24878,0.0215 6.43628,-3.36312 13.75,-7.52129 z"
style="fill:#000000" />
</svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 297 KiB

View File

@ -388,9 +388,9 @@ class TestForeign:
self.buffer_loader("magickload_buffer", BMP_FILE, bmp_valid)
# we should have rgb or rgba for svg files ... different versions of
# IM handle this differently
# IM handle this differently. GM even gives 1 band.
im = pyvips.Image.magickload(SVG_FILE)
assert im.bands == 3 or im.bands == 4
assert im.bands == 3 or im.bands == 4 or im.bands == 1
# density should change size of generated svg
im = pyvips.Image.magickload(SVG_FILE, density='100')
@ -454,10 +454,10 @@ class TestForeign:
assert self.colour.height == x.height
assert self.colour.bands == x.bands
max_diff = (self.colour - x).abs().max()
assert max_diff < 40
assert max_diff < 60
self.save_load_buffer("magicksave_buffer", "magickload_buffer",
self.colour, 40, format="JPG")
self.colour, 60, format="JPG")
@skip_if_no("webpload")
def test_webp(self):
@ -644,15 +644,9 @@ class TestForeign:
def test_svgload(self):
def svg_valid(im):
a = im(10, 10)
# some old rsvg versions are way, way off
assert abs(a[0] - 79) < 2
assert abs(a[1] - 79) < 2
assert abs(a[2] - 132) < 2
assert abs(a[3] - 255) < 2
assert im.width == 288
assert im.height == 470
assert_almost_equal_objects(a, [0, 0, 0, 0])
assert im.width == 736
assert im.height == 552
assert im.bands == 4
self.file_loader("svgload", SVG_FILE, svg_valid)