Merge branch '8.5' into tweak-smartcrop-8.5

This commit is contained in:
John Cupitt 2017-07-28 18:04:23 +01:00
commit 69f70a7e24
8 changed files with 113 additions and 34 deletions

View File

@ -1,5 +1,9 @@
9/6/17 started 8.5.7
- better smartcrop
- transform cmyk->rgb automatically on write if there's an embedded profile
and the saver does not support cmyk
- fix DPI mixup in svgload ... we were writing images about 20% too large,
thanks Fosk
19/5/17 started 8.5.6
- tiff read with start page > 0 could break edge tiles or strips

View File

@ -14,6 +14,8 @@
* - forward progress signals from load
* 23/5/16
* - remove max-alpha stuff, this is now automatic
* 12/6/17
* - transform cmyk->rgb if there's an embedded profile
*/
/*
@ -1190,6 +1192,37 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
}
}
/* If this image is CMYK and the saver is RGB-only, use lcms to try to
* import to XYZ. This will only work if the image has an embedded
* profile.
*/
if( in->Type == VIPS_INTERPRETATION_CMYK &&
in->Bands >= 4 &&
(saveable == VIPS_SAVEABLE_RGB ||
saveable == VIPS_SAVEABLE_RGBA ||
saveable == VIPS_SAVEABLE_RGBA_ONLY) ) {
VipsImage *out;
if( vips_icc_import( in, &out,
"pcs", VIPS_PCS_XYZ,
NULL ) ) {
g_object_unref( in );
return( -1 );
}
g_object_unref( in );
in = out;
/* We've imported to PCS, we must remove the embedded profile,
* since it no longer matches the image.
*
* For example, when converting CMYK JPG to RGB PNG, we need
* to remove the CMYK profile on import, or the png writer will
* try to attach it when we write the image as RGB.
*/
vips_image_remove( in, VIPS_META_ICC_NAME );
}
/* If this is something other than CMYK or RAD, eg. maybe a LAB image,
* we need to transform to RGB.
*/

View File

@ -6,6 +6,8 @@
* - add svgz support
* 18/1/17
* - invalidate operation on read error
* 8/7/17
* - fix DPI mixup, thanks Fosk
*/
/*
@ -107,21 +109,6 @@ vips_foreign_load_svg_dispose( GObject *gobject )
dispose( gobject );
}
static int
vips_foreign_load_svg_build( VipsObject *object )
{
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) object;
if( !vips_object_argument_isset( object, "scale" ) )
svg->scale = svg->dpi / 72.0;
if( VIPS_OBJECT_CLASS( vips_foreign_load_svg_parent_class )->
build( object ) )
return( -1 );
return( 0 );
}
static VipsForeignFlags
vips_foreign_load_svg_get_flags_filename( const char *filename )
{
@ -143,6 +130,7 @@ vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg,
RsvgDimensionData dimensions;
double res;
rsvg_handle_set_dpi( svg->page, svg->dpi * svg->scale );
rsvg_handle_get_dimensions( svg->page, &dimensions );
/* We need pixels/mm for vips.
@ -150,7 +138,7 @@ vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg,
res = svg->dpi / 25.4;
vips_image_init_fields( out,
dimensions.width * svg->scale, dimensions.height * svg->scale,
dimensions.width, dimensions.height,
4, VIPS_FORMAT_UCHAR,
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, res, res );
@ -194,9 +182,7 @@ vips_foreign_load_svg_generate( VipsRegion *or,
cr = cairo_create( surface );
cairo_surface_destroy( surface );
cairo_scale( cr, svg->scale, svg->scale );
cairo_translate( cr,
-r->left / svg->scale, -r->top / svg->scale );
cairo_translate( cr, -r->left, -r->top );
/* rsvg is single-threaded, but we don't need to lock since we're
* running inside a non-threaded tilecache.
@ -272,7 +258,6 @@ vips_foreign_load_svg_class_init( VipsForeignLoadSvgClass *class )
object_class->nickname = "svgload";
object_class->description = _( "load SVG with rsvg" );
object_class->build = vips_foreign_load_svg_build;
load_class->get_flags_filename =
vips_foreign_load_svg_get_flags_filename;
@ -557,8 +542,8 @@ vips_foreign_load_svg_buffer_init( VipsForeignLoadSvgBuffer *buffer )
* Render a SVG file into a VIPS image. Rendering uses the librsvg library
* and should be fast.
*
* Use @dpi to set the rendering resolution. The default is 72. Alternatively,
* you can scale the rendering from the default 1 point == 1 pixel by @scale.
* Use @dpi to set the rendering resolution. The default is 72. You can also
* scale the rendering by @scale.
*
* This function only reads the image header and does not render any pixel
* data. Rendering occurs when pixels are accessed.

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -1,3 +1,58 @@
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 595 842">
<path stroke="#fff" fill="#fff" d="M0 0h595v842H0z"/>
<?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"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1"
viewBox="0 0 793.70079 1122.5197"
id="svg4"
sodipodi:docname="blankpage.svg"
width="210mm"
height="297mm"
inkscape:version="0.92.1 r15371">
<metadata
id="metadata10">
<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="defs8" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1052"
id="namedview6"
showgrid="false"
units="mm"
inkscape:document-units="mm"
inkscape:zoom="0.28028504"
inkscape:cx="308.20339"
inkscape:cy="421"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg4" />
<path
d="M 0,280.51969 H 595 V 1122.5197 H 0 Z"
id="path2"
inkscape:connector-curvature="0"
style="fill:#ffffff;stroke:#ffffff" />
</svg>

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -595,9 +595,9 @@ class TestForeign(unittest.TestCase):
def svg_valid(self, im):
a = im(10, 10)
self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
self.assertEqual(im.width, 360)
self.assertEqual(im.height, 588)
self.assertAlmostEqualObjects(a, [79, 79, 132, 255])
self.assertEqual(im.width, 288)
self.assertEqual(im.height, 470)
self.assertEqual(im.bands, 4)
self.file_loader("svgload", self.svg_file, svg_valid)

View File

@ -10,11 +10,11 @@ set -e
# poppler / pdfload reference image
poppler=$test_images/blankpage.pdf
poppler_ref=$test_images/blankpage.png
poppler_ref=$test_images/blankpage.pdf.png
# rsvg / svgload reference image
rsvg=$test_images/blankpage.svg
rsvg_ref=$test_images/blankpage.png
rsvg_ref=$test_images/blankpage.svg.png
# giflib / gifload reference image
giflib=$test_images/trans-x.gif
@ -139,13 +139,14 @@ test_loader() {
ref=$1
in=$2
format=$3
thresh=$4
printf "testing $(basename $in) $format ... "
$vips copy $ref $tmp/before.v
$vips copy $in $tmp/after.v
test_difference $tmp/before.v $tmp/after.v 0
test_difference $tmp/before.v $tmp/after.v $thresh
echo "ok"
}
@ -229,19 +230,20 @@ test_raw $mono
test_raw $image
if test_supported pdfload; then
test_loader $poppler_ref $poppler pdfload
test_loader $poppler_ref $poppler pdfload 0
fi
if test_supported svgload; then
test_loader $rsvg_ref $rsvg svgload
# librsvg can give small differences on some platforms
test_loader $rsvg_ref $rsvg svgload 10
fi
if test_supported gifload; then
test_loader $giflib_ref $giflib gifload
test_loader $giflib_ref $giflib gifload 0
fi
if test_supported matload; then
test_loader $matlab_ref $matlab matlab
test_loader $matlab_ref $matlab matlab 0
fi
if test_supported dzsave; then