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 #include "../../external/darktable/src/common/srgb_tone_curve_values.h"
34
35
36
37 /* ***** Make profile: sRGB, D65, sRGB TRC */
38 /* http://en.wikipedia.org/wiki/Srgb */
39 /* Hewlett-Packard and Microsoft designed sRGB to match
40 * the color gamut of consumer-grade CRTs from the 1990s
41 * and to be the standard color space for the world wide web.
42 * When made using the standard sRGB TRC, this sRGB profile
43 * can be applied to DCF R03 camera-generated jpegs and
44 * is an excellent color space for editing 8-bit images.
45 * When made using the linear gamma TRC, the resulting profile
46 * should only be used for high bit depth image editing.
47 * */
48 static cmsCIExyYTRIPLE srgb_primaries = {
49 {0.6400, 0.3300, 1.0},
50 {0.3000, 0.6000, 1.0},
51 {0.1500, 0.0600, 1.0}
52 };
53
54 static cmsCIExyYTRIPLE srgb_primaries_pre_quantized = {
55 {0.639998686, 0.330010138, 1.0},
56 {0.300003784, 0.600003357, 1.0},
57 {0.150002046, 0.059997204, 1.0}
58 };
59
60 /* ************************** WHITE POINTS ************************** */
61
62 /* D65 WHITE POINTS */
63
64 static cmsCIExyY d65_srgb_adobe_specs = {0.3127, 0.3290, 1.0};
65 /* White point from the sRGB.icm and AdobeRGB1998 profile specs:
66 * http://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
67 * 4.2.1 Reference Display White Point
68 * The chromaticity coordinates of white displayed on
69 * the reference color monitor shall be x=0.3127, y=0.3290.
70 * . . . [which] correspond to CIE Standard Illuminant D65.
71 *
72 * Wikipedia gives this same white point for SMPTE-C.
73 * This white point is also given in the sRGB color space specs.
74 * It's probably correct for most or all of the standard D65 profiles.
75 *
76 * The D65 white point values used in the LCMS virtual sRGB profile
77 * is slightly different than the D65 white point values given in the
78 * sRGB color space specs, so the LCMS virtual sRGB profile
79 * doesn't match sRGB profiles made using the values given in the
80 * sRGB color space specs.
81 *
82 * */
83
84
sRGBProfile(TRC_type type)85 PF::sRGBProfile::sRGBProfile(TRC_type type): ICCProfile()
86 {
87 set_profile_type( PROF_TYPE_sRGB );
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 cmsCIExyY whitepoint = d65_srgb_adobe_specs;
119 cmsToneCurve* tone_curve[3] = {NULL};
120 switch( type ) {
121 case PF::PF_TRC_PERCEPTUAL: {
122 cmsFloat64Number labl_parameters[5] =
123 { 3.0, 0.862076, 0.137924, 0.110703, 0.080002 };
124 cmsToneCurve *curve =
125 cmsBuildParametricToneCurve(NULL, 4, labl_parameters);
126 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
127 break;
128 }
129 case PF::PF_TRC_UNKNOWN:
130 case PF::PF_TRC_LINEAR: {
131 cmsToneCurve *curve = cmsBuildGamma (NULL, 1.00);
132 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
133 break;
134 }
135 case PF::PF_TRC_STANDARD:
136 case PF::PF_TRC_sRGB: {
137 /* sRGB TRC */
138 cmsFloat64Number srgb_parameters[5] =
139 { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
140 cmsToneCurve *curve = cmsBuildParametricToneCurve(NULL, 4, srgb_parameters);
141 //cmsToneCurve *curve = cmsBuildTabulatedToneCurve16(NULL, dt_srgb_tone_curve_values_n, dt_srgb_tone_curve_values);
142 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
143 break;
144 }
145 case PF::PF_TRC_GAMMA_22: {
146 cmsToneCurve *curve = cmsBuildGamma (NULL, 2.20);
147 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
148 break;
149 }
150 case PF::PF_TRC_GAMMA_18: {
151 cmsToneCurve *curve = cmsBuildGamma (NULL, 1.80);
152 tone_curve[0] = tone_curve[1] = tone_curve[2] = curve;
153 break;
154 }
155 }
156 cmsHPROFILE profile = cmsCreateRGBProfile ( &whitepoint, &primaries, tone_curve );
157 cmsMLU *copyright = cmsMLUalloc(NULL, 1);
158 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).");
159 cmsWriteTag(profile, cmsSigCopyrightTag, copyright);
160 /* V4 */
161 cmsMLU *description = cmsMLUalloc(NULL, 1);
162 cmsMLUsetASCII(description, "en", "US", "sRGB-elle-V4.icc");
163 cmsWriteTag(profile, cmsSigProfileDescriptionTag, description);
164
165 //if( type == PF::PF_TRC_STANDARD ) {
166 // const char* filename = "/Users/aferrero/Scratch/sRGB-elle-V4-srgbtrc.icc";
167 // cmsSaveProfileToFile(profile, filename);
168 //}
169
170 //const char* filename = "sRGB-elle-V4-rec709.icc";
171 //cmsSaveProfileToFile(profile, filename);
172 cmsMLUfree(description);
173
174 //std::cout<<"Initializing sRGB profile"<<std::endl;
175 set_profile( profile );
176 }
177