Skip to content

Commit f0eb493

Browse files
committed
fix thumbnail with cmyk output
see libvips/php-vips#138 thanks AdamGaskins
1 parent 68a8bf4 commit f0eb493

File tree

3 files changed

+40
-72
lines changed

3 files changed

+40
-72
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
26/11/21 started 8.12.3
22
- better arg checking for hist_find_ndim [travisbell]
3+
- fix thumbnail with CMYK output [AdamGaskins]
34

45
26/11/21 started 8.12.2
56
- make exif resuint optional and default to inch

libvips/resample/thumbnail.c

Lines changed: 38 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,6 @@ vips_thumbnail_build( VipsObject *object )
649649
*/
650650
gboolean have_imported;
651651

652-
/* If we shrink in linear space, we need to return to the input
653-
* colourspace after the shrink.
654-
*/
655-
VipsInterpretation input_interpretation;
656-
657652
/* The format we need to revert to after unpremultiply.
658653
*/
659654
VipsBandFormat unpremultiplied_format;
@@ -701,10 +696,6 @@ vips_thumbnail_build( VipsObject *object )
701696
in = t[12];
702697
}
703698

704-
/* Note the interpretation we will revert to after linear.
705-
*/
706-
input_interpretation = in->Type;
707-
708699
/* In linear mode, we need to transform to a linear space before
709700
* vips_resize().
710701
*/
@@ -792,7 +783,7 @@ vips_thumbnail_build( VipsObject *object )
792783

793784
/* vips_premultiply() makes a float image, so when we unpremultiply
794785
* below we must cast back to the original format. Use NOTSET to
795-
* meran no pre/unmultiply.
786+
* mean no pre/unmultiply.
796787
*/
797788
unpremultiplied_format = VIPS_FORMAT_NOTSET;
798789

@@ -841,75 +832,51 @@ vips_thumbnail_build( VipsObject *object )
841832

842833
/* Colour management.
843834
*/
844-
if( have_imported ) {
845-
/* We've already imported, just export. Go to sRGB if there's
846-
* no export profile.
835+
if( have_imported ) {
836+
/* We are in PCS. Export with the output profile, if any (this
837+
* will export with the embedded input profile if there's no
838+
* export profile).
847839
*/
848-
if( thumbnail->export_profile ||
849-
vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
850-
g_info( "exporting to device space with a profile" );
851-
if( vips_icc_export( in, &t[7],
852-
"output_profile", thumbnail->export_profile,
853-
"intent", thumbnail->intent,
854-
NULL ) )
855-
return( -1 );
856-
in = t[7];
857-
}
858-
else {
859-
g_info( "converting to sRGB" );
860-
if( vips_colourspace( in, &t[7],
861-
VIPS_INTERPRETATION_sRGB, NULL ) )
862-
return( -1 );
863-
in = t[7];
864-
}
840+
g_info( "exporting to device space with a profile" );
841+
if( vips_icc_export( in, &t[7],
842+
"output_profile", thumbnail->export_profile,
843+
"intent", thumbnail->intent,
844+
NULL ) )
845+
return( -1 );
846+
in = t[7];
865847
}
866848
else if( thumbnail->export_profile ) {
867-
/* Not imported, but we are doing colour management. Transform
868-
* to the output space.
869-
*/
870-
g_info( "transforming to %s", thumbnail->export_profile );
871-
872-
/* If there's some kind of import profile, we can transform to
873-
* the output. Otherwise we have to convert to PCS and then
874-
* export.
849+
/* We are in one of the resize space (sRGB, scRGB, B_W, GREY16,
850+
* etc.) and we have an export profile. Go to PCS, then export.
875851
*/
876-
if( thumbnail->import_profile ||
877-
(vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ||
878-
thumbnail->import_profile) ) {
879-
g_info( "transforming with supplied profiles" );
880-
if( vips_icc_transform( in, &t[7],
881-
thumbnail->export_profile,
882-
"input_profile", thumbnail->import_profile,
852+
g_info( "exporting with %s",
853+
thumbnail->export_profile );
854+
if( vips_colourspace( in, &t[7],
855+
VIPS_INTERPRETATION_XYZ, NULL ) ||
856+
vips_icc_export( t[7], &t[10],
857+
"output_profile",
858+
thumbnail->export_profile,
883859
"intent", thumbnail->intent,
884-
"embedded", TRUE,
885-
NULL ) )
886-
return( -1 );
887-
888-
in = t[7];
889-
}
890-
else {
891-
g_info( "exporting with %s",
892-
thumbnail->export_profile );
893-
if( vips_colourspace( in, &t[7],
894-
VIPS_INTERPRETATION_XYZ, NULL ) ||
895-
vips_icc_export( t[7], &t[10],
896-
"output_profile",
897-
thumbnail->export_profile,
898-
"intent", thumbnail->intent,
899-
NULL ) )
900-
return( -1 );
901-
in = t[10];
902-
}
860+
NULL ) )
861+
return( -1 );
862+
in = t[10];
903863
}
904-
else if( thumbnail->linear ) {
905-
/* Linear mode, no colour management. We went to scRGB for
906-
* processing, so we now revert to the input colourspace.
864+
else {
865+
/* We are in one of the resize spaces and there's no export
866+
* profile. Output to sRGB or B_W
907867
*/
908-
g_info( "reverting to input space %s",
868+
VipsInterpretation interpretation;
869+
870+
if( in->Bands < 3 )
871+
interpretation = VIPS_INTERPRETATION_B_W;
872+
else
873+
interpretation = VIPS_INTERPRETATION_sRGB;
874+
875+
g_info( "converting to output space %s",
909876
vips_enum_nick( VIPS_TYPE_INTERPRETATION,
910-
input_interpretation ) );
911-
if( vips_colourspace( in, &t[7],
912-
input_interpretation, NULL ) )
877+
interpretation ) );
878+
if( vips_colourspace( in, &t[7], interpretation,
879+
NULL ) )
913880
return( -1 );
914881
in = t[7];
915882
}

test/test_thumbnail.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
echo building test image ...
1414
$vips extract_band $image $tmp/t1.v 1
1515
$vips linear $tmp/t1.v $tmp/t2.v 1 20 --uchar
16-
$vips replicate $tmp/t2.v $tmp/t1.v 2 2
16+
$vips replicate $tmp/t2.v $tmp/t1.v 4 4
1717
$vips crop $tmp/t1.v $tmp/t2.v 10 10 1000 1000
1818

1919
# is a difference beyond a threshold? return 0 (meaning all ok) or 1 (meaning

0 commit comments

Comments
 (0)