Skip to content

Commit 69f70a7

Browse files
committed
Merge branch '8.5' into tweak-smartcrop-8.5
2 parents 3c3cd77 + 060bdd2 commit 69f70a7

File tree

8 files changed

+113
-34
lines changed

8 files changed

+113
-34
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
9/6/17 started 8.5.7
22
- better smartcrop
3+
- transform cmyk->rgb automatically on write if there's an embedded profile
4+
and the saver does not support cmyk
5+
- fix DPI mixup in svgload ... we were writing images about 20% too large,
6+
thanks Fosk
37

48
19/5/17 started 8.5.6
59
- tiff read with start page > 0 could break edge tiles or strips

libvips/foreign/foreign.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* - forward progress signals from load
1515
* 23/5/16
1616
* - remove max-alpha stuff, this is now automatic
17+
* 12/6/17
18+
* - transform cmyk->rgb if there's an embedded profile
1719
*/
1820

1921
/*
@@ -1190,6 +1192,37 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
11901192
}
11911193
}
11921194

1195+
/* If this image is CMYK and the saver is RGB-only, use lcms to try to
1196+
* import to XYZ. This will only work if the image has an embedded
1197+
* profile.
1198+
*/
1199+
if( in->Type == VIPS_INTERPRETATION_CMYK &&
1200+
in->Bands >= 4 &&
1201+
(saveable == VIPS_SAVEABLE_RGB ||
1202+
saveable == VIPS_SAVEABLE_RGBA ||
1203+
saveable == VIPS_SAVEABLE_RGBA_ONLY) ) {
1204+
VipsImage *out;
1205+
1206+
if( vips_icc_import( in, &out,
1207+
"pcs", VIPS_PCS_XYZ,
1208+
NULL ) ) {
1209+
g_object_unref( in );
1210+
return( -1 );
1211+
}
1212+
g_object_unref( in );
1213+
1214+
in = out;
1215+
1216+
/* We've imported to PCS, we must remove the embedded profile,
1217+
* since it no longer matches the image.
1218+
*
1219+
* For example, when converting CMYK JPG to RGB PNG, we need
1220+
* to remove the CMYK profile on import, or the png writer will
1221+
* try to attach it when we write the image as RGB.
1222+
*/
1223+
vips_image_remove( in, VIPS_META_ICC_NAME );
1224+
}
1225+
11931226
/* If this is something other than CMYK or RAD, eg. maybe a LAB image,
11941227
* we need to transform to RGB.
11951228
*/

libvips/foreign/svgload.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* - add svgz support
77
* 18/1/17
88
* - invalidate operation on read error
9+
* 8/7/17
10+
* - fix DPI mixup, thanks Fosk
911
*/
1012

1113
/*
@@ -107,21 +109,6 @@ vips_foreign_load_svg_dispose( GObject *gobject )
107109
dispose( gobject );
108110
}
109111

110-
static int
111-
vips_foreign_load_svg_build( VipsObject *object )
112-
{
113-
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) object;
114-
115-
if( !vips_object_argument_isset( object, "scale" ) )
116-
svg->scale = svg->dpi / 72.0;
117-
118-
if( VIPS_OBJECT_CLASS( vips_foreign_load_svg_parent_class )->
119-
build( object ) )
120-
return( -1 );
121-
122-
return( 0 );
123-
}
124-
125112
static VipsForeignFlags
126113
vips_foreign_load_svg_get_flags_filename( const char *filename )
127114
{
@@ -143,14 +130,15 @@ vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg,
143130
RsvgDimensionData dimensions;
144131
double res;
145132

133+
rsvg_handle_set_dpi( svg->page, svg->dpi * svg->scale );
146134
rsvg_handle_get_dimensions( svg->page, &dimensions );
147135

148136
/* We need pixels/mm for vips.
149137
*/
150138
res = svg->dpi / 25.4;
151139

152140
vips_image_init_fields( out,
153-
dimensions.width * svg->scale, dimensions.height * svg->scale,
141+
dimensions.width, dimensions.height,
154142
4, VIPS_FORMAT_UCHAR,
155143
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, res, res );
156144

@@ -194,9 +182,7 @@ vips_foreign_load_svg_generate( VipsRegion *or,
194182
cr = cairo_create( surface );
195183
cairo_surface_destroy( surface );
196184

197-
cairo_scale( cr, svg->scale, svg->scale );
198-
cairo_translate( cr,
199-
-r->left / svg->scale, -r->top / svg->scale );
185+
cairo_translate( cr, -r->left, -r->top );
200186

201187
/* rsvg is single-threaded, but we don't need to lock since we're
202188
* running inside a non-threaded tilecache.
@@ -272,7 +258,6 @@ vips_foreign_load_svg_class_init( VipsForeignLoadSvgClass *class )
272258

273259
object_class->nickname = "svgload";
274260
object_class->description = _( "load SVG with rsvg" );
275-
object_class->build = vips_foreign_load_svg_build;
276261

277262
load_class->get_flags_filename =
278263
vips_foreign_load_svg_get_flags_filename;
@@ -557,8 +542,8 @@ vips_foreign_load_svg_buffer_init( VipsForeignLoadSvgBuffer *buffer )
557542
* Render a SVG file into a VIPS image. Rendering uses the librsvg library
558543
* and should be fast.
559544
*
560-
* Use @dpi to set the rendering resolution. The default is 72. Alternatively,
561-
* you can scale the rendering from the default 1 point == 1 pixel by @scale.
545+
* Use @dpi to set the rendering resolution. The default is 72. You can also
546+
* scale the rendering by @scale.
562547
*
563548
* This function only reads the image header and does not render any pixel
564549
* data. Rendering occurs when pixels are accessed.
File renamed without changes.

test/images/blankpage.svg

Lines changed: 57 additions & 2 deletions
Loading

test/images/blankpage.svg.png

3.33 KB
Loading

test/test_foreign.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,9 @@ def test_svgload(self):
595595

596596
def svg_valid(self, im):
597597
a = im(10, 10)
598-
self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
599-
self.assertEqual(im.width, 360)
600-
self.assertEqual(im.height, 588)
598+
self.assertAlmostEqualObjects(a, [79, 79, 132, 255])
599+
self.assertEqual(im.width, 288)
600+
self.assertEqual(im.height, 470)
601601
self.assertEqual(im.bands, 4)
602602

603603
self.file_loader("svgload", self.svg_file, svg_valid)

test/test_formats.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ set -e
1010

1111
# poppler / pdfload reference image
1212
poppler=$test_images/blankpage.pdf
13-
poppler_ref=$test_images/blankpage.png
13+
poppler_ref=$test_images/blankpage.pdf.png
1414

1515
# rsvg / svgload reference image
1616
rsvg=$test_images/blankpage.svg
17-
rsvg_ref=$test_images/blankpage.png
17+
rsvg_ref=$test_images/blankpage.svg.png
1818

1919
# giflib / gifload reference image
2020
giflib=$test_images/trans-x.gif
@@ -139,13 +139,14 @@ test_loader() {
139139
ref=$1
140140
in=$2
141141
format=$3
142+
thresh=$4
142143

143144
printf "testing $(basename $in) $format ... "
144145

145146
$vips copy $ref $tmp/before.v
146147
$vips copy $in $tmp/after.v
147148

148-
test_difference $tmp/before.v $tmp/after.v 0
149+
test_difference $tmp/before.v $tmp/after.v $thresh
149150

150151
echo "ok"
151152
}
@@ -229,19 +230,20 @@ test_raw $mono
229230
test_raw $image
230231

231232
if test_supported pdfload; then
232-
test_loader $poppler_ref $poppler pdfload
233+
test_loader $poppler_ref $poppler pdfload 0
233234
fi
234235

235236
if test_supported svgload; then
236-
test_loader $rsvg_ref $rsvg svgload
237+
# librsvg can give small differences on some platforms
238+
test_loader $rsvg_ref $rsvg svgload 10
237239
fi
238240

239241
if test_supported gifload; then
240-
test_loader $giflib_ref $giflib gifload
242+
test_loader $giflib_ref $giflib gifload 0
241243
fi
242244

243245
if test_supported matload; then
244-
test_loader $matlab_ref $matlab matlab
246+
test_loader $matlab_ref $matlab matlab 0
245247
fi
246248

247249
if test_supported dzsave; then

0 commit comments

Comments
 (0)