Skip to content

Commit

Permalink
colour: use cmsFLAGS_NOOPTIMIZE to keep all precision
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Feb 28, 2023
1 parent 65c9921 commit 678443c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
29 changes: 25 additions & 4 deletions libvips/colour/icc_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,9 @@ vips_icc_build( VipsObject *object )

/* Use cmsFLAGS_NOCACHE to disable the 1-pixel cache and make
* calling cmsDoTransform() from multiple threads safe.
* Use cmsFLAGS_NOOPTIMIZE to ensure we keep all precision.
*/
flags = cmsFLAGS_NOCACHE;
flags = cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE;

if( icc->black_point_compensation )
flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
Expand Down Expand Up @@ -773,7 +774,7 @@ vips_icc_import_build( VipsObject *object )

if( icc->pcs == VIPS_PCS_LAB ) {
cmsCIExyY white;
cmsWhitePointFromTemp( &white, 6500 );
cmsWhitePointFromTemp( &white, 6504 );

icc->out_profile = cmsCreateLab4Profile( &white );
}
Expand Down Expand Up @@ -808,6 +809,13 @@ decode_lab( guint16 *fixed, float *lab, int n )
int i;

for( i = 0; i < n; i++ ) {
/*cmsCIELab Lab;
cmsLabEncoded2FloatV2(&Lab, fixed);
lab[0] = (float) Lab.L;
lab[1] = (float) Lab.a;
lab[2] = (float) Lab.b;*/

lab[0] = (double) fixed[0] / 652.800;
lab[1] = ((double) fixed[1] / 256.0) - 128.0;
lab[2] = ((double) fixed[2] / 256.0) - 128.0;
Expand All @@ -827,6 +835,13 @@ decode_xyz( guint16 *fixed, float *xyz, int n )
int i;

for( i = 0; i < n; i++ ) {
/*cmsCIEXYZ XYZ;
cmsXYZEncoded2Float(&XYZ, fixed);
xyz[0] = XYZ.X * 100;
xyz[1] = XYZ.Y * 100;
xyz[2] = XYZ.Z * 100;*/

xyz[0] = (double) fixed[0] / X_FAC;
xyz[1] = (double) fixed[1] / Y_FAC;
xyz[2] = (double) fixed[2] / Z_FAC;
Expand Down Expand Up @@ -936,7 +951,7 @@ vips_icc_export_build( VipsObject *object )

if( icc->pcs == VIPS_PCS_LAB ) {
cmsCIExyY white;
cmsWhitePointFromTemp( &white, 6500 );
cmsWhitePointFromTemp( &white, 6504 );

icc->in_profile = cmsCreateLab4Profile( &white );
}
Expand Down Expand Up @@ -977,6 +992,9 @@ encode_lab( float *lab, guint16 *fixed, int n )
int i;

for( i = 0; i < n; i++ ) {
/*cmsCIELab Lab = {.L = lab[0], .a = lab[1], .b = lab[2]};
cmsFloat2LabEncodedV2(fixed, &Lab);*/

float L = lab[0];
float a = lab[1];
float b = lab[2];
Expand Down Expand Up @@ -1014,6 +1032,9 @@ encode_xyz( float *xyz, guint16 *fixed, int n )
int i;

for( i = 0; i < n; i++ ) {
/*cmsCIEXYZ XYZ = {.X = xyz[0], .Y = xyz[1], .Z = xyz[2]};
cmsFloat2XYZEncoded(fixed, &XYZ);*/

float X = xyz[0];
float Y = xyz[1];
float Z = xyz[2];
Expand Down Expand Up @@ -1228,7 +1249,7 @@ vips_icc_transform_init( VipsIccTransform *transform )
* @out: (out): output image
* @profile_filename: use this profile
*
* Transform an image from absolute to relative colorimetry using the
* Transform an image from absolute to relative colorimetric using the
* MediaWhitePoint stored in the ICC profile.
*
* See also: vips_icc_transform(), vips_icc_import().
Expand Down
1 change: 0 additions & 1 deletion test/test-suite/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def test_thumbnail_icc(self):
assert im.width == 290
assert im.height == 442
assert im.bands == 3
assert im.bands == 3

# the colour distance should not deviate too much
# (i.e. the embedded profile should not be ignored)
Expand Down

0 comments on commit 678443c

Please sign in to comment.