@@ -226,8 +226,8 @@ static VipsIccInfo vips_icc_info_table[] = {
226
226
{ cmsSigGrayData , 1 , TYPE_GRAY_8 , TYPE_GRAY_16 },
227
227
228
228
{ cmsSigRgbData , 3 , TYPE_RGB_8 , TYPE_RGB_16 },
229
- { cmsSigLabData , 3 , TYPE_Lab_8 , TYPE_Lab_16 },
230
- { cmsSigXYZData , 3 , -1 , TYPE_XYZ_16 },
229
+ { cmsSigLabData , 3 , TYPE_Lab_FLT , TYPE_Lab_16 },
230
+ { cmsSigXYZData , 3 , TYPE_XYZ_FLT , TYPE_XYZ_16 },
231
231
232
232
{ cmsSigCmykData , 4 , TYPE_CMYK_8 , TYPE_CMYK_16 },
233
233
{ cmsSig4colorData , 4 , TYPE_CMYK_8 , TYPE_CMYK_16 },
@@ -308,14 +308,14 @@ vips_icc_build( VipsObject *object )
308
308
code -> input_format = VIPS_FORMAT_FLOAT ;
309
309
code -> input_interpretation =
310
310
VIPS_INTERPRETATION_LAB ;
311
- icc -> in_icc_format = info -> lcms_type16 ;
311
+ icc -> in_icc_format = info -> lcms_type8 ;
312
312
break ;
313
313
314
314
case cmsSigXYZData :
315
315
code -> input_format = VIPS_FORMAT_FLOAT ;
316
316
code -> input_interpretation =
317
317
VIPS_INTERPRETATION_XYZ ;
318
- icc -> in_icc_format = info -> lcms_type16 ;
318
+ icc -> in_icc_format = info -> lcms_type8 ;
319
319
break ;
320
320
321
321
case cmsSigCmykData :
@@ -654,14 +654,13 @@ vips_icc_load_profile_blob( VipsBlob *blob,
654
654
* unref the blob if it's useless.
655
655
*/
656
656
static cmsHPROFILE
657
- vips_icc_verify_blob ( VipsBlob * * blob ,
658
- VipsImage * image , VipsIntent intent , int direction )
657
+ vips_icc_verify_blob ( VipsBlob * * blob , VipsImage * image , VipsIntent intent )
659
658
{
660
659
if ( * blob ) {
661
660
cmsHPROFILE profile ;
662
661
663
662
if ( !(profile = vips_icc_load_profile_blob ( * blob ,
664
- image , intent , direction )) ) {
663
+ image , intent , LCMS_USED_AS_INPUT )) ) {
665
664
vips_area_unref ( (VipsArea * ) * blob );
666
665
* blob = NULL ;
667
666
}
@@ -701,7 +700,7 @@ vips_icc_set_import( VipsIcc *icc,
701
700
(embedded || !input_profile_filename ) ) {
702
701
icc -> in_blob = vips_icc_get_profile_image ( code -> in );
703
702
icc -> in_profile = vips_icc_verify_blob ( & icc -> in_blob ,
704
- code -> in , icc -> intent , LCMS_USED_AS_INPUT );
703
+ code -> in , icc -> intent );
705
704
}
706
705
707
706
/* Try profile from filename.
@@ -713,7 +712,7 @@ vips_icc_set_import( VipsIcc *icc,
713
712
!vips_profile_load ( input_profile_filename ,
714
713
& icc -> in_blob , NULL ) &&
715
714
(icc -> in_profile = vips_icc_verify_blob ( & icc -> in_blob ,
716
- code -> in , icc -> intent , LCMS_USED_AS_INPUT )) )
715
+ code -> in , icc -> intent )) )
717
716
icc -> non_standard_input_profile = TRUE;
718
717
}
719
718
@@ -727,7 +726,7 @@ vips_icc_set_import( VipsIcc *icc,
727
726
if (
728
727
!vips_profile_load ( name , & icc -> in_blob , NULL ) &&
729
728
(icc -> in_profile = vips_icc_verify_blob ( & icc -> in_blob ,
730
- code -> in , icc -> intent , LCMS_USED_AS_INPUT )) )
729
+ code -> in , icc -> intent )) )
731
730
icc -> non_standard_input_profile = TRUE;
732
731
}
733
732
@@ -840,44 +839,48 @@ vips_icc_import_build( VipsObject *object )
840
839
return ( 0 );
841
840
}
842
841
843
- static void
842
+ static void
844
843
decode_lab ( guint16 * fixed , float * lab , int n )
845
844
{
846
845
int i ;
847
846
848
- for ( i = 0 ; i < n ; i ++ ) {
849
- lab [0 ] = (double ) fixed [0 ] / 652.800 ;
850
- lab [1 ] = ((double ) fixed [1 ] / 256.0 ) - 128.0 ;
851
- lab [2 ] = ((double ) fixed [2 ] / 256.0 ) - 128.0 ;
847
+ for ( i = 0 ; i < n ; i ++ ) {
848
+ /* cmsLabEncoded2Float inlined.
849
+ */
850
+ lab [0 ] = (double ) fixed [0 ] / 655.35 ;
851
+ lab [1 ] = ((double ) fixed [1 ] / 257.0 ) - 128.0 ;
852
+ lab [2 ] = ((double ) fixed [2 ] / 257.0 ) - 128.0 ;
852
853
853
- lab += 3 ;
854
- fixed += 3 ;
855
- }
854
+ lab += 3 ;
855
+ fixed += 3 ;
856
+ }
856
857
}
857
858
858
- #define X_FAC (VIPS_D50_X0 * 32768 / ( VIPS_D65_X0 * 100) )
859
- #define Y_FAC (VIPS_D50_Y0 * 32768 / ( VIPS_D65_Y0 * 100) )
860
- #define Z_FAC (VIPS_D50_Z0 * 32768 / ( VIPS_D65_Z0 * 100) )
859
+ #define X_FAC (cmsD50X / VIPS_D65_X0)
860
+ #define Y_FAC (cmsD50Y / VIPS_D65_Y0)
861
+ #define Z_FAC (cmsD50Z / VIPS_D65_Z0)
861
862
862
- static void
863
+ static void
863
864
decode_xyz ( guint16 * fixed , float * xyz , int n )
864
865
{
865
866
int i ;
866
867
867
- for ( i = 0 ; i < n ; i ++ ) {
868
- xyz [0 ] = (double ) fixed [0 ] / X_FAC ;
869
- xyz [1 ] = (double ) fixed [1 ] / Y_FAC ;
870
- xyz [2 ] = (double ) fixed [2 ] / Z_FAC ;
868
+ for ( i = 0 ; i < n ; i ++ ) {
869
+ /* cmsXYZEncoded2Float inlined.
870
+ */
871
+ xyz [0 ] = (double ) fixed [0 ] / (X_FAC * 32768.0 );
872
+ xyz [1 ] = (double ) fixed [1 ] / (Y_FAC * 32768.0 );
873
+ xyz [2 ] = (double ) fixed [2 ] / (Z_FAC * 32768.0 );
871
874
872
- xyz += 3 ;
873
- fixed += 3 ;
874
- }
875
+ xyz += 3 ;
876
+ fixed += 3 ;
877
+ }
875
878
}
876
879
877
880
/* Process a buffer of data.
878
881
*/
879
882
static void
880
- vips_icc_import_line ( VipsColour * colour ,
883
+ vips_icc_import_line ( VipsColour * colour ,
881
884
VipsPel * out , VipsPel * * in , int width )
882
885
{
883
886
VipsIcc * icc = (VipsIcc * ) colour ;
@@ -897,7 +900,7 @@ vips_icc_import_line( VipsColour *colour,
897
900
898
901
cmsDoTransform ( icc -> trans , p , encoded , chunk );
899
902
900
- if ( icc -> pcs == VIPS_PCS_LAB )
903
+ if ( icc -> pcs == VIPS_PCS_LAB )
901
904
decode_lab ( encoded , q , chunk );
902
905
else
903
906
decode_xyz ( encoded , q , chunk );
@@ -1006,84 +1009,23 @@ vips_icc_export_build( VipsObject *object )
1006
1009
return ( 0 );
1007
1010
}
1008
1011
1009
- /* Pack a buffer of floats into lcms's fixed-point formats. Cut from
1010
- * lcms-1.0.8.
1011
- */
1012
- static void
1013
- encode_lab ( float * lab , guint16 * fixed , int n )
1014
- {
1015
- int i ;
1016
-
1017
- for ( i = 0 ; i < n ; i ++ ) {
1018
- float L = lab [0 ];
1019
- float a = lab [1 ];
1020
- float b = lab [2 ];
1021
-
1022
- if ( L < 0 )
1023
- L = 0 ;
1024
- if ( L > 100. )
1025
- L = 100. ;
1026
-
1027
- if ( a < -128. )
1028
- a = -128 ;
1029
- if ( a > 127.9961 )
1030
- a = 127.9961 ;
1031
- if ( b < -128. )
1032
- b = -128 ;
1033
- if ( b > 127.9961 )
1034
- b = 127.9961 ;
1035
-
1036
- fixed [0 ] = L * 652.800 + 0.5 ;
1037
- fixed [1 ] = (a + 128.0 ) * 256.0 + 0.5 ;
1038
- fixed [2 ] = (b + 128.0 ) * 256.0 + 0.5 ;
1039
-
1040
- lab += 3 ;
1041
- fixed += 3 ;
1042
- }
1043
- }
1044
-
1045
- #define MAX_ENCODEABLE_XYZ (100 * (1.0 + 32767.0 / 32768.0))
1046
-
1047
- // 1.15 fixed point for XYZ
1048
-
1049
- static void
1050
- encode_xyz ( float * xyz , guint16 * fixed , int n )
1012
+ static void
1013
+ encode_xyz ( float * in , float * out , int n )
1051
1014
{
1052
1015
int i ;
1053
1016
1054
1017
for ( i = 0 ; i < n ; i ++ ) {
1055
- float X = xyz [0 ];
1056
- float Y = xyz [1 ];
1057
- float Z = xyz [2 ];
1058
-
1059
- if ( X < 0 )
1060
- X = 0 ;
1061
- if ( X > MAX_ENCODEABLE_XYZ )
1062
- X = MAX_ENCODEABLE_XYZ ;
1063
-
1064
- if ( Y < 0 )
1065
- Y = 0 ;
1066
- if ( Y > MAX_ENCODEABLE_XYZ )
1067
- Y = MAX_ENCODEABLE_XYZ ;
1018
+ out [0 ] = in [0 ] * X_FAC ;
1019
+ out [1 ] = in [1 ] * Y_FAC ;
1020
+ out [2 ] = in [2 ] * Z_FAC ;
1068
1021
1069
- if ( Z < 0 )
1070
- Z = 0 ;
1071
- if ( Z > MAX_ENCODEABLE_XYZ )
1072
- Z = MAX_ENCODEABLE_XYZ ;
1073
-
1074
- fixed [0 ] = X * X_FAC + 0.5 ;
1075
- fixed [1 ] = Y * Y_FAC + 0.5 ;
1076
- fixed [2 ] = Z * Z_FAC + 0.5 ;
1077
-
1078
- xyz += 3 ;
1079
- fixed += 3 ;
1022
+ in += 3 ;
1023
+ out += 3 ;
1080
1024
}
1081
1025
}
1082
1026
1083
- /* Process a buffer of data.
1084
- */
1085
1027
static void
1086
- vips_icc_export_line ( VipsColour * colour ,
1028
+ vips_icc_export_line_xyz ( VipsColour * colour ,
1087
1029
VipsPel * out , VipsPel * * in , int width )
1088
1030
{
1089
1031
VipsIcc * icc = (VipsIcc * ) colour ;
@@ -1092,27 +1034,37 @@ vips_icc_export_line( VipsColour *colour,
1092
1034
VipsPel * q ;
1093
1035
int x ;
1094
1036
1095
- /* Buffer of encoded 16-bit pixels we transform.
1037
+ /* Buffer of encoded float pixels we transform.
1096
1038
*/
1097
- guint16 encoded [3 * PIXEL_BUFFER_SIZE ];
1039
+ float encoded [3 * PIXEL_BUFFER_SIZE ];
1098
1040
1099
1041
p = (float * ) in [0 ];
1100
1042
q = (VipsPel * ) out ;
1101
1043
for ( x = 0 ; x < width ; x += PIXEL_BUFFER_SIZE ) {
1102
1044
const int chunk = VIPS_MIN ( width - x , PIXEL_BUFFER_SIZE );
1103
1045
1104
- if ( icc -> pcs == VIPS_PCS_LAB )
1105
- encode_lab ( p , encoded , chunk );
1106
- else
1107
- encode_xyz ( p , encoded , chunk );
1108
-
1046
+ encode_xyz ( p , encoded , chunk );
1109
1047
cmsDoTransform ( icc -> trans , encoded , q , chunk );
1110
1048
1111
1049
p += PIXEL_BUFFER_SIZE * 3 ;
1112
1050
q += PIXEL_BUFFER_SIZE * VIPS_IMAGE_SIZEOF_PEL ( colour -> out );
1113
1051
}
1114
1052
}
1115
1053
1054
+ /* Process a buffer of data.
1055
+ */
1056
+ static void
1057
+ vips_icc_export_line ( VipsColour * colour ,
1058
+ VipsPel * out , VipsPel * * in , int width )
1059
+ {
1060
+ VipsIcc * icc = (VipsIcc * ) colour ;
1061
+
1062
+ if ( icc -> pcs == VIPS_PCS_LAB )
1063
+ cmsDoTransform ( icc -> trans , in [0 ], out , width );
1064
+ else
1065
+ vips_icc_export_line_xyz ( colour , out , in , width );
1066
+ }
1067
+
1116
1068
static void
1117
1069
vips_icc_export_class_init ( VipsIccExportClass * class )
1118
1070
{
0 commit comments