Skip to content

Commit 11e8cac

Browse files
committed
Bug 756389 - Color-managing grayscale images
Support creating linear/sRGB-gamma variants of gray profiles and rename gimp_color_profile_new_linear_rgb_from_color_profile() to gimp_color_profile_new_linear_gamma_from_color_profile() because it's not RGB-specific any longer.
1 parent bb482ba commit 11e8cac

File tree

5 files changed

+51
-33
lines changed

5 files changed

+51
-33
lines changed

app/core/gimpimage-convert-precision.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ gimp_image_convert_precision (GimpImage *image,
173173
if (gimp_babl_format_get_linear (new_format))
174174
{
175175
new_profile =
176-
gimp_color_profile_new_linear_rgb_from_color_profile (old_profile);
176+
gimp_color_profile_new_linear_gamma_from_color_profile (old_profile);
177177
}
178178
else
179179
{

app/core/gimplayer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ gimp_layer_convert_type (GimpDrawable *drawable,
11361136
if (gimp_babl_format_get_linear (new_format))
11371137
{
11381138
dest_profile =
1139-
gimp_color_profile_new_linear_rgb_from_color_profile (src_profile);
1139+
gimp_color_profile_new_linear_gamma_from_color_profile (src_profile);
11401140
}
11411141
else
11421142
{

libgimpcolor/gimpcolor.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ EXPORTS
4444
gimp_color_profile_new_from_file
4545
gimp_color_profile_new_from_icc_profile
4646
gimp_color_profile_new_from_lcms_profile
47+
gimp_color_profile_new_linear_gamma_from_color_profile
4748
gimp_color_profile_new_linear_gray
4849
gimp_color_profile_new_linear_rgb
49-
gimp_color_profile_new_linear_rgb_from_color_profile
5050
gimp_color_profile_new_srgb
5151
gimp_color_profile_new_srgb_gray
5252
gimp_color_profile_new_srgb_gamma_from_color_profile

libgimpcolor/gimpcolorprofile.c

+46-28
Original file line numberDiff line numberDiff line change
@@ -788,48 +788,35 @@ gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
788788
{
789789
GimpColorProfile *new_profile;
790790
cmsHPROFILE target_profile;
791-
GimpMatrix3 matrix;
792-
cmsCIEXYZ red;
793-
cmsCIEXYZ green;
794-
cmsCIEXYZ blue;
791+
GimpMatrix3 matrix = { 0, };
795792
cmsCIEXYZ *whitepoint;
796793
cmsToneCurve *curve;
797794
const gchar *model;
798795
gchar *new_model;
799796

800797
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
801798

802-
if (! gimp_color_profile_get_rgb_matrix_colorants (profile, &matrix))
803-
return NULL;
799+
if (gimp_color_profile_is_rgb (profile))
800+
{
801+
if (! gimp_color_profile_get_rgb_matrix_colorants (profile, &matrix))
802+
return NULL;
803+
}
804+
else if (! gimp_color_profile_is_gray (profile))
805+
{
806+
return NULL;
807+
}
804808

805809
whitepoint = cmsReadTag (profile->priv->lcms_profile,
806810
cmsSigMediaWhitePointTag);
807811

808-
red.X = matrix.coeff[0][0];
809-
red.Y = matrix.coeff[0][1];
810-
red.Z = matrix.coeff[0][2];
811-
812-
green.X = matrix.coeff[1][0];
813-
green.Y = matrix.coeff[1][1];
814-
green.Z = matrix.coeff[1][2];
815-
816-
blue.X = matrix.coeff[2][0];
817-
blue.Y = matrix.coeff[2][1];
818-
blue.Z = matrix.coeff[2][2];
819-
820812
target_profile = cmsCreateProfilePlaceholder (0);
821813

822814
cmsSetProfileVersion (target_profile, 4.3);
823815
cmsSetDeviceClass (target_profile, cmsSigDisplayClass);
824-
cmsSetColorSpace (target_profile, cmsSigRgbData);
825816
cmsSetPCS (target_profile, cmsSigXYZData);
826817

827818
cmsWriteTag (target_profile, cmsSigMediaWhitePointTag, whitepoint);
828819

829-
cmsWriteTag (target_profile, cmsSigRedColorantTag, &red);
830-
cmsWriteTag (target_profile, cmsSigGreenColorantTag, &green);
831-
cmsWriteTag (target_profile, cmsSigBlueColorantTag, &blue);
832-
833820
if (linear)
834821
{
835822
/* linear light */
@@ -850,9 +837,40 @@ gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
850837
"sRGB gamma variant generated by GIMP");
851838
}
852839

853-
cmsWriteTag (target_profile, cmsSigRedTRCTag, curve);
854-
cmsWriteTag (target_profile, cmsSigGreenTRCTag, curve);
855-
cmsWriteTag (target_profile, cmsSigBlueTRCTag, curve);
840+
if (gimp_color_profile_is_rgb (profile))
841+
{
842+
cmsCIEXYZ red;
843+
cmsCIEXYZ green;
844+
cmsCIEXYZ blue;
845+
846+
cmsSetColorSpace (target_profile, cmsSigRgbData);
847+
848+
red.X = matrix.coeff[0][0];
849+
red.Y = matrix.coeff[0][1];
850+
red.Z = matrix.coeff[0][2];
851+
852+
green.X = matrix.coeff[1][0];
853+
green.Y = matrix.coeff[1][1];
854+
green.Z = matrix.coeff[1][2];
855+
856+
blue.X = matrix.coeff[2][0];
857+
blue.Y = matrix.coeff[2][1];
858+
blue.Z = matrix.coeff[2][2];
859+
860+
cmsWriteTag (target_profile, cmsSigRedColorantTag, &red);
861+
cmsWriteTag (target_profile, cmsSigGreenColorantTag, &green);
862+
cmsWriteTag (target_profile, cmsSigBlueColorantTag, &blue);
863+
864+
cmsWriteTag (target_profile, cmsSigRedTRCTag, curve);
865+
cmsWriteTag (target_profile, cmsSigGreenTRCTag, curve);
866+
cmsWriteTag (target_profile, cmsSigBlueTRCTag, curve);
867+
}
868+
else
869+
{
870+
cmsSetColorSpace (target_profile, cmsSigGrayData);
871+
872+
cmsWriteTag (target_profile, cmsSigGrayTRCTag, curve);
873+
}
856874

857875
cmsFreeToneCurve (curve);
858876

@@ -906,7 +924,7 @@ gimp_color_profile_new_srgb_gamma_from_color_profile (GimpColorProfile *profile)
906924
}
907925

908926
/**
909-
* gimp_color_profile_new_linear_rgb_from_color_profile:
927+
* gimp_color_profile_new_linear_gamma_from_color_profile:
910928
* @profile: a #GimpColorProfile
911929
*
912930
* This function creates a new RGB #GimpColorProfile with a linear TRC
@@ -918,7 +936,7 @@ gimp_color_profile_new_srgb_gamma_from_color_profile (GimpColorProfile *profile)
918936
* Since: 2.10
919937
**/
920938
GimpColorProfile *
921-
gimp_color_profile_new_linear_rgb_from_color_profile (GimpColorProfile *profile)
939+
gimp_color_profile_new_linear_gamma_from_color_profile (GimpColorProfile *profile)
922940
{
923941
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
924942

libgimpcolor/gimpcolorprofile.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ GimpColorProfile * gimp_color_profile_new_srgb_gray (void);
7272
GimpColorProfile * gimp_color_profile_new_linear_gray (void);
7373

7474
GimpColorProfile *
75-
gimp_color_profile_new_srgb_gamma_from_color_profile (GimpColorProfile *profile);
75+
gimp_color_profile_new_srgb_gamma_from_color_profile (GimpColorProfile *profile);
7676
GimpColorProfile *
77-
gimp_color_profile_new_linear_rgb_from_color_profile (GimpColorProfile *profile);
77+
gimp_color_profile_new_linear_gamma_from_color_profile (GimpColorProfile *profile);
7878

7979
GimpColorProfile * gimp_color_profile_new_from_file (GFile *file,
8080
GError **error);

0 commit comments

Comments
 (0)