Skip to content

Commit 678443c

Browse files
committed
colour: use cmsFLAGS_NOOPTIMIZE to keep all precision
1 parent 65c9921 commit 678443c

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

libvips/colour/icc_transform.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,9 @@ vips_icc_build( VipsObject *object )
438438

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

444445
if( icc->black_point_compensation )
445446
flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
@@ -773,7 +774,7 @@ vips_icc_import_build( VipsObject *object )
773774

774775
if( icc->pcs == VIPS_PCS_LAB ) {
775776
cmsCIExyY white;
776-
cmsWhitePointFromTemp( &white, 6500 );
777+
cmsWhitePointFromTemp( &white, 6504 );
777778

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

810811
for( i = 0; i < n; i++ ) {
812+
/*cmsCIELab Lab;
813+
cmsLabEncoded2FloatV2(&Lab, fixed);
814+
815+
lab[0] = (float) Lab.L;
816+
lab[1] = (float) Lab.a;
817+
lab[2] = (float) Lab.b;*/
818+
811819
lab[0] = (double) fixed[0] / 652.800;
812820
lab[1] = ((double) fixed[1] / 256.0) - 128.0;
813821
lab[2] = ((double) fixed[2] / 256.0) - 128.0;
@@ -827,6 +835,13 @@ decode_xyz( guint16 *fixed, float *xyz, int n )
827835
int i;
828836

829837
for( i = 0; i < n; i++ ) {
838+
/*cmsCIEXYZ XYZ;
839+
cmsXYZEncoded2Float(&XYZ, fixed);
840+
841+
xyz[0] = XYZ.X * 100;
842+
xyz[1] = XYZ.Y * 100;
843+
xyz[2] = XYZ.Z * 100;*/
844+
830845
xyz[0] = (double) fixed[0] / X_FAC;
831846
xyz[1] = (double) fixed[1] / Y_FAC;
832847
xyz[2] = (double) fixed[2] / Z_FAC;
@@ -936,7 +951,7 @@ vips_icc_export_build( VipsObject *object )
936951

937952
if( icc->pcs == VIPS_PCS_LAB ) {
938953
cmsCIExyY white;
939-
cmsWhitePointFromTemp( &white, 6500 );
954+
cmsWhitePointFromTemp( &white, 6504 );
940955

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

979994
for( i = 0; i < n; i++ ) {
995+
/*cmsCIELab Lab = {.L = lab[0], .a = lab[1], .b = lab[2]};
996+
cmsFloat2LabEncodedV2(fixed, &Lab);*/
997+
980998
float L = lab[0];
981999
float a = lab[1];
9821000
float b = lab[2];
@@ -1014,6 +1032,9 @@ encode_xyz( float *xyz, guint16 *fixed, int n )
10141032
int i;
10151033

10161034
for( i = 0; i < n; i++ ) {
1035+
/*cmsCIEXYZ XYZ = {.X = xyz[0], .Y = xyz[1], .Z = xyz[2]};
1036+
cmsFloat2XYZEncoded(fixed, &XYZ);*/
1037+
10171038
float X = xyz[0];
10181039
float Y = xyz[1];
10191040
float Z = xyz[2];
@@ -1228,7 +1249,7 @@ vips_icc_transform_init( VipsIccTransform *transform )
12281249
* @out: (out): output image
12291250
* @profile_filename: use this profile
12301251
*
1231-
* Transform an image from absolute to relative colorimetry using the
1252+
* Transform an image from absolute to relative colorimetric using the
12321253
* MediaWhitePoint stored in the ICC profile.
12331254
*
12341255
* See also: vips_icc_transform(), vips_icc_import().

test/test-suite/test_resample.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ def test_thumbnail_icc(self):
237237
assert im.width == 290
238238
assert im.height == 442
239239
assert im.bands == 3
240-
assert im.bands == 3
241240

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

0 commit comments

Comments
 (0)