Skip to content

Commit 3c60e9d

Browse files
committed
start tinkering
1 parent ec67002 commit 3c60e9d

File tree

2 files changed

+91
-67
lines changed

2 files changed

+91
-67
lines changed

libvips/conversion/flatten.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef struct _VipsFlatten {
6767
*/
6868
VipsArrayDouble *background;
6969

70-
/* The [double] converted to the input image format.
70+
/* The [double] background converted to the input image format.
7171
*/
7272
VipsPel *ink;
7373

libvips/resample/thumbnail.c

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,17 @@ vips_thumbnail_build( VipsObject *object )
626626
int preshrunk_page_height;
627627
double hshrink;
628628
double vshrink;
629-
VipsInterpretation interpretation;
630629

631630
/* TRUE if we've done the import of an ICC transform and still need to
632631
* export.
633632
*/
634633
gboolean have_imported;
635634

635+
/* If we shrink in linear space, we need to return to the input
636+
* colourspace after the shrink.
637+
*/
638+
VipsInterpretation input_interpretation;
639+
636640
/* TRUE if we've premultiplied and need to unpremultiply.
637641
*/
638642
gboolean have_premultiplied;
@@ -669,7 +673,7 @@ vips_thumbnail_build( VipsObject *object )
669673
*/
670674
preshrunk_page_height = vips_image_get_page_height( in );
671675

672-
/* RAD needs special unpacking.
676+
/* Coded forms need special unpacking.
673677
*/
674678
if( in->Coding == VIPS_CODING_RAD ) {
675679
g_info( "unpacking Rad to float" );
@@ -680,62 +684,69 @@ vips_thumbnail_build( VipsObject *object )
680684
return( -1 );
681685
in = t[12];
682686
}
687+
else if( in->Coding == VIPS_CODING_LABQ ) {
688+
g_info( "unpacking LABQ to float" );
683689

684-
/* In linear mode, we import right at the start.
685-
*
686-
* We also have to import the whole image if it's CMYK, since
687-
* vips_colourspace() (see below) doesn't let you specify the fallback
688-
* profile.
690+
if( vips_LabQ2Lab( in, &t[12], NULL ) )
691+
return( -1 );
692+
in = t[12];
693+
}
694+
695+
/* In linear mode, we need to transform to a linear space before
696+
* vips_resize().
689697
*
690-
* This is only going to work for images in device space. If you have
691-
* an image in PCS which also has an attached profile, strange things
692-
* will happen.
698+
* If we are doing colour management (there's an import profile),
699+
* then we use XYZ PCS as the resize space.
693700
*/
694701
have_imported = FALSE;
695-
if( thumbnail->linear &&
696-
in->Coding == VIPS_CODING_NONE &&
697-
(in->BandFmt == VIPS_FORMAT_UCHAR ||
698-
in->BandFmt == VIPS_FORMAT_USHORT) &&
699-
(vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ||
700-
thumbnail->import_profile) ) {
701-
g_info( "importing to XYZ PCS" );
702-
if( thumbnail->import_profile )
703-
g_info( "fallback input profile %s",
704-
thumbnail->import_profile );
705-
706-
if( vips_icc_import( in, &t[1],
707-
"input_profile", thumbnail->import_profile,
708-
"embedded", TRUE,
709-
"intent", thumbnail->intent,
710-
"pcs", VIPS_PCS_XYZ,
711-
NULL ) )
712-
return( -1 );
702+
if( thumbnail->linear ) {
703+
if( in->Coding == VIPS_CODING_NONE &&
704+
(in->BandFmt == VIPS_FORMAT_UCHAR ||
705+
in->BandFmt == VIPS_FORMAT_USHORT) &&
706+
(vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ||
707+
thumbnail->import_profile) ) {
708+
g_info( "importing to XYZ PCS" );
709+
if( thumbnail->import_profile )
710+
g_info( "fallback input profile %s",
711+
thumbnail->import_profile );
712+
713+
if( vips_icc_import( in, &t[1],
714+
"input_profile", thumbnail->import_profile,
715+
"embedded", TRUE,
716+
"intent", thumbnail->intent,
717+
"pcs", VIPS_PCS_XYZ,
718+
NULL ) )
719+
return( -1 );
713720

714-
in = t[1];
721+
in = t[1];
715722

716-
have_imported = TRUE;
723+
have_imported = TRUE;
724+
}
725+
else {
726+
/* Otherwise, use scRGB or GREY16 for linear shrink.
727+
*/
728+
VipsInterpretation interpretation;
729+
730+
/* Note the interpretation we will revert to after
731+
* linear.
732+
*/
733+
input_interpretation = in->Type;
734+
735+
if( in->Bands < 3 )
736+
interpretation = VIPS_INTERPRETATION_GREY16;
737+
else
738+
interpretation = VIPS_INTERPRETATION_scRGB;
739+
740+
g_info( "converting to processing space %s",
741+
vips_enum_nick( VIPS_TYPE_INTERPRETATION,
742+
interpretation ) );
743+
if( vips_colourspace( in, &t[2], interpretation,
744+
NULL ) )
745+
return( -1 );
746+
in = t[2];
747+
}
717748
}
718749

719-
/* To the processing colourspace. This will unpack LABQ, import CMYK,
720-
* etc.
721-
*
722-
* If this is a CMYK image, we need to set have_imported since we only
723-
* want to export at the end.
724-
*/
725-
if( in->Type == VIPS_INTERPRETATION_CMYK )
726-
have_imported = TRUE;
727-
if( thumbnail->linear )
728-
interpretation = VIPS_INTERPRETATION_scRGB;
729-
else if( in->Bands < 3 )
730-
interpretation = VIPS_INTERPRETATION_B_W;
731-
else
732-
interpretation = VIPS_INTERPRETATION_sRGB;
733-
g_info( "converting to processing space %s",
734-
vips_enum_nick( VIPS_TYPE_INTERPRETATION, interpretation ) );
735-
if( vips_colourspace( in, &t[2], interpretation, NULL ) )
736-
return( -1 );
737-
in = t[2];
738-
739750
/* Shrink to preshrunk_page_height, so we work for multi-page images.
740751
*/
741752
vips_thumbnail_calculate_shrink( thumbnail,
@@ -767,7 +778,7 @@ vips_thumbnail_build( VipsObject *object )
767778

768779
/* vips_premultiply() makes a float image. When we
769780
* vips_unpremultiply() below, we need to cast back to the
770-
* pre-premultiply format.
781+
* pre-premultiplied format.
771782
*/
772783
unpremultiplied_format = in->BandFmt;
773784
in = t[3];
@@ -779,6 +790,14 @@ vips_thumbnail_build( VipsObject *object )
779790
return( -1 );
780791
in = t[4];
781792

793+
if( have_premultiplied ) {
794+
g_info( "unpremultiplying alpha" );
795+
if( vips_unpremultiply( in, &t[5], NULL ) ||
796+
vips_cast( t[5], &t[6], unpremultiplied_format, NULL ) )
797+
return( -1 );
798+
in = t[6];
799+
}
800+
782801
/* Only set page-height if we have more than one page, or this could
783802
* accidentally turn into an animated image later.
784803
*/
@@ -794,21 +813,12 @@ vips_thumbnail_build( VipsObject *object )
794813
VIPS_META_PAGE_HEIGHT, output_page_height );
795814
}
796815

797-
if( have_premultiplied ) {
798-
g_info( "unpremultiplying alpha" );
799-
if( vips_unpremultiply( in, &t[5], NULL ) ||
800-
vips_cast( t[5], &t[6], unpremultiplied_format, NULL ) )
801-
return( -1 );
802-
in = t[6];
803-
}
804-
805816
/* Colour management.
806-
*
807-
* If we've already imported, just export. Otherwise, we're in
808-
* device space and we need a combined import/export to transform to
809-
* the target space.
810817
*/
811818
if( have_imported ) {
819+
/* We've already imported, just export. Go to sRGB if there's
820+
* no export profile.
821+
*/
812822
if( thumbnail->export_profile ||
813823
vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
814824
g_info( "exporting to device space with a profile" );
@@ -827,9 +837,10 @@ vips_thumbnail_build( VipsObject *object )
827837
in = t[7];
828838
}
829839
}
830-
else if( thumbnail->export_profile &&
831-
(vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ||
832-
thumbnail->import_profile) ) {
840+
else if( thumbnail->export_profile ) {
841+
/* Not imported, but we are doing colourmanagement. Transform
842+
* to the output space.
843+
*/
833844
g_info( "transforming to %s", thumbnail->export_profile );
834845
if( thumbnail->import_profile )
835846
g_info( "fallback input profile %s",
@@ -844,6 +855,19 @@ vips_thumbnail_build( VipsObject *object )
844855
return( -1 );
845856
in = t[7];
846857
}
858+
else if( thumbnail->linear ) {
859+
/* Linear mode, no colour management. We went to scRGB for
860+
* precessing, so we now revert to the input
861+
* colourspace.
862+
*/
863+
g_info( "reverting to input space %s",
864+
vips_enum_nick( VIPS_TYPE_INTERPRETATION,
865+
input_interpretation ) );
866+
if( vips_colourspace( in, &t[7],
867+
input_interpretation, NULL ) )
868+
return( -1 );
869+
in = t[7];
870+
}
847871

848872
if( thumbnail->auto_rotate &&
849873
thumbnail->orientation != 1 ) {

0 commit comments

Comments
 (0)