1 /*
2 */
3
4 /*
5
6 Copyright (C) 2014 Ferrero Andrea
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
22 */
23
24 /*
25
26 These files are distributed with PhotoFlow - http://aferrero2707.github.io/PhotoFlow/
27
28 */
29
30 #include <string>
31 #include <iostream>
32 #include "../iccstore.hh"
33
34
35 /* ***** Make profile: sRGB, D65, sRGB TRC */
36 /* http://en.wikipedia.org/wiki/Srgb */
37 /* Hewlett-Packard and Microsoft designed sRGB to match
38 * the color gamut of consumer-grade CRTs from the 1990s
39 * and to be the standard color space for the world wide web.
40 * When made using the standard sRGB TRC, this sRGB profile
41 * can be applied to DCF R03 camera-generated jpegs and
42 * is an excellent color space for editing 8-bit images.
43 * When made using the linear gamma TRC, the resulting profile
44 * should only be used for high bit depth image editing.
45 * */
46 static cmsCIExyYTRIPLE srgb_d50_primaries = {
47 {0.648431, 0.330856, 1.0},
48 {0.321152, 0.597871, 1.0},
49 {0.155886, 0.066044, 1.0}
50 };
51
52 static cmsCIExyYTRIPLE srgb_primaries_pre_quantized = {
53 {0.639998686, 0.330010138, 1.0},
54 {0.300003784, 0.600003357, 1.0},
55 {0.150002046, 0.059997204, 1.0}
56 };
57
58 /* ************************** WHITE POINTS ************************** */
59
60 static cmsCIExyY d50_illuminant_specs = {0.345702915, 0.358538597, 1.0};
61 /* calculated from D50 illuminant XYZ values in ICC specs */
62
63 /* D65 WHITE POINTS */
64
65 static cmsCIExyY d65_srgb_adobe_specs = {0.3127, 0.3290, 1.0};
66 /* White point from the sRGB.icm and AdobeRGB1998 profile specs:
67 * http://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
68 * 4.2.1 Reference Display White Point
69 * The chromaticity coordinates of white displayed on
70 * the reference color monitor shall be x=0.3127, y=0.3290.
71 * . . . [which] correspond to CIE Standard Illuminant D65.
72 *
73 * Wikipedia gives this same white point for SMPTE-C.
74 * This white point is also given in the sRGB color space specs.
75 * It's probably correct for most or all of the standard D65 profiles.
76 *
77 * The D65 white point values used in the LCMS virtual sRGB profile
78 * is slightly different than the D65 white point values given in the
79 * sRGB color space specs, so the LCMS virtual sRGB profile
80 * doesn't match sRGB profiles made using the values given in the
81 * sRGB color space specs.
82 *
83 * */
84
85
sRGBProfileD50(TRC_type type)86 PF::sRGBProfileD50::sRGBProfileD50(TRC_type type): ICCProfile()
87 {
88 set_trc_type( type );
89
90 /*
91 if( type == PF::PF_TRC_STANDARD ) {
92 // sRGB TRC
93 cmsFloat64Number srgb_parameters[5] =
94 { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
95 cmsToneCurve *srgb_parametic_curve =
96 cmsBuildParametricToneCurve(NULL, 4, srgb_parameters);
97 cmsToneCurve *srgb_parametic_curve_inv =
98 cmsBuildParametricToneCurve(NULL, 4, srgb_parameters);
99 srgb_parametic_curve_inv = cmsReverseToneCurve( srgb_parametic_curve_inv );
100 //init_trc( srgb_parametic_curve, srgb_parametic_curve_inv );
101 } else {
102 // LAB "L" (perceptually uniform) TRC
103 cmsFloat64Number labl_parameters[5] =
104 { 3.0, 0.862076, 0.137924, 0.110703, 0.080002 };
105 cmsToneCurve *labl_parametic_curve =
106 cmsBuildParametricToneCurve(NULL, 4, labl_parameters);
107 cmsToneCurve *labl_parametic_curve_inv =
108 cmsBuildParametricToneCurve(NULL, 4, labl_parameters);
109 labl_parametic_curve_inv = cmsReverseToneCurve( labl_parametic_curve_inv );
110 //init_trc( labl_parametic_curve, labl_parametic_curve_inv );
111 }
112 */
113
114 /* ***** Make profile: sRGB, D65, sRGB TRC */
115 /*
116 * */
117 //cmsCIExyYTRIPLE primaries = srgb_primaries_pre_quantized;
118 cmsCIExyYTRIPLE primaries = srgb_d50_primaries;
119 //cmsCIExyY whitepoint = d65_srgb_adobe_specs;
120 cmsCIExyY whitepoint = d50_illuminant_specs;
121 cmsToneCurve* tone_curve[3] = {NULL};
122 switch( type ) {
123 case PF::PF_TRC_STANDARD: {
124 /* sRGB TRC */
125 cmsFloat64Number srgb_parameters[5] =
126 { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
127 cmsToneCurve *curve = cmsBuildParametricToneCurve(NULL, 4, srgb_parameters);
128 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
129 break;
130 }
131 case PF::PF_TRC_PERCEPTUAL: {
132 cmsFloat64Number labl_parameters[5] =
133 { 3.0, 0.862076, 0.137924, 0.110703, 0.080002 };
134 cmsToneCurve *curve =
135 cmsBuildParametricToneCurve(NULL, 4, labl_parameters);
136 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
137 break;
138 }
139 case PF::PF_TRC_UNKNOWN:
140 case PF::PF_TRC_LINEAR: {
141 cmsToneCurve *curve = cmsBuildGamma (NULL, 1.00);
142 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
143 break;
144 }
145 case PF::PF_TRC_sRGB: {
146 /* sRGB TRC */
147 cmsFloat64Number srgb_parameters[5] =
148 { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
149 cmsToneCurve *curve = cmsBuildParametricToneCurve(NULL, 4, srgb_parameters);
150 //cmsToneCurve *curve = cmsBuildTabulatedToneCurve16(NULL, dt_srgb_tone_curve_values_n, dt_srgb_tone_curve_values);
151 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
152 break;
153 }
154 case PF::PF_TRC_GAMMA_22: {
155 cmsToneCurve *curve = cmsBuildGamma (NULL, 2.20);
156 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
157 break;
158 }
159 case PF::PF_TRC_GAMMA_18: {
160 cmsToneCurve *curve = cmsBuildGamma (NULL, 1.80);
161 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
162 break;
163 }
164 }
165 cmsHPROFILE profile = cmsCreateRGBProfile ( &whitepoint, &primaries, tone_curve );
166 cmsMLU *copyright = cmsMLUalloc(NULL, 1);
167 cmsMLUsetASCII(copyright, "en", "US", "Copyright 2015, Elle Stone (website: http://ninedegreesbelow.com/; email: ellestone@ninedegreesbelow.com). This ICC profile is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License (https://creativecommons.org/licenses/by-sa/3.0/legalcode).");
168 cmsWriteTag(profile, cmsSigCopyrightTag, copyright);
169 /* V4 */
170 cmsMLU *description = cmsMLUalloc(NULL, 1);
171 cmsMLUsetASCII(description, "en", "US", "sRGB-D50-elle-V4.icc");
172 cmsWriteTag(profile, cmsSigProfileDescriptionTag, description);
173
174 //if( type == PF::PF_TRC_STANDARD ) {
175 // const char* filename = "sRGB-elle-V4-D50.icc";
176 // cmsSaveProfileToFile(profile, filename);
177 //}
178
179 cmsMLUfree(description);
180
181 //std::cout<<"Initializing sRGB profile"<<std::endl;
182 set_profile( profile );
183 }
184