1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir *
31584ef18SPedro Giffuni * Apache OpenOffice - a multi-platform office productivity suite
4cdf0e10cSrcweir *
5cdf0e10cSrcweir
6cdf0e10cSrcweir Derived by beppec56@openoffice.org from various examples
7cdf0e10cSrcweir in SampleICC library, the original copyright retained.
8cdf0e10cSrcweir
9cdf0e10cSrcweir Copyright: � see below
10cdf0e10cSrcweir */
11cdf0e10cSrcweir
12cdf0e10cSrcweir /*
13cdf0e10cSrcweir * The ICC Software License, Version 0.1
14cdf0e10cSrcweir *
15cdf0e10cSrcweir *
16cdf0e10cSrcweir * Copyright (c) 2003-2006 The International Color Consortium. All rights
17cdf0e10cSrcweir * reserved.
18cdf0e10cSrcweir *
19cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without
20cdf0e10cSrcweir * modification, are permitted provided that the following conditions
21cdf0e10cSrcweir * are met:
22cdf0e10cSrcweir *
23cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright
24cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer.
25cdf0e10cSrcweir *
26cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright
27cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in
28cdf0e10cSrcweir * the documentation and/or other materials provided with the
29cdf0e10cSrcweir * distribution.
30cdf0e10cSrcweir *
31cdf0e10cSrcweir * 3. The end-user documentation included with the redistribution,
32cdf0e10cSrcweir * if any, must include the following acknowledgment:
33cdf0e10cSrcweir * "This product includes software developed by the
34cdf0e10cSrcweir * The International Color Consortium (www.color.org)"
35cdf0e10cSrcweir * Alternately, this acknowledgment may appear in the software itself,
36cdf0e10cSrcweir * if and wherever such third-party acknowledgments normally appear.
37cdf0e10cSrcweir *
38cdf0e10cSrcweir * 4. The names "ICC" and "The International Color Consortium" must
39cdf0e10cSrcweir * not be used to imply that the ICC organization endorses or
40cdf0e10cSrcweir * promotes products derived from this software without prior
41cdf0e10cSrcweir * written permission. For written permission, please see
42cdf0e10cSrcweir * <http://www.color.org/>.
43cdf0e10cSrcweir *
44cdf0e10cSrcweir *
45cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46cdf0e10cSrcweir * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47cdf0e10cSrcweir * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48cdf0e10cSrcweir * DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
49cdf0e10cSrcweir * ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50cdf0e10cSrcweir * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51cdf0e10cSrcweir * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52cdf0e10cSrcweir * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54cdf0e10cSrcweir * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55cdf0e10cSrcweir * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56cdf0e10cSrcweir * SUCH DAMAGE.
57cdf0e10cSrcweir * ====================================================================
58cdf0e10cSrcweir *
59cdf0e10cSrcweir * This software consists of voluntary contributions made by many
60cdf0e10cSrcweir * individuals on behalf of the The International Color Consortium.
61cdf0e10cSrcweir *
62cdf0e10cSrcweir *
63cdf0e10cSrcweir * Membership in the ICC is encouraged when this software is used for
64cdf0e10cSrcweir * commercial purposes.
65cdf0e10cSrcweir *
66cdf0e10cSrcweir *
67cdf0e10cSrcweir * For more information on The International Color Consortium, please
68cdf0e10cSrcweir * see <http://www.color.org/>.
69cdf0e10cSrcweir *
70cdf0e10cSrcweir *
71cdf0e10cSrcweir */
72cdf0e10cSrcweir
73cdf0e10cSrcweir #include <math.h>
74cdf0e10cSrcweir #include <iostream>
75cdf0e10cSrcweir #include <fstream>
76cdf0e10cSrcweir using namespace std;
77cdf0e10cSrcweir
78cdf0e10cSrcweir #include "IccUtil.h"
79cdf0e10cSrcweir #include "IccProfile.h"
80cdf0e10cSrcweir
81cdf0e10cSrcweir #include "Vetters.h"
82cdf0e10cSrcweir #include "CAT.h"
83cdf0e10cSrcweir #include "CLUT.h"
84cdf0e10cSrcweir
85cdf0e10cSrcweir const char * const icc_file_name = "sRGB-IEC61966-2.1.icc";
86cdf0e10cSrcweir const char * const hxx_file_name = "sRGB-IEC61966-2.1.hxx";
87cdf0e10cSrcweir const char * const this_file_name_and_location =" * icc/source/create_sRGB_profile/create_sRGB_profile.cpp";
88cdf0e10cSrcweir
89cdf0e10cSrcweir const char* const description = "sRGB IEC61966-2.1";
90cdf0e10cSrcweir //const char* const devicemanufact = "IEC http://www.iec.ch"; not used, device manufactured by OOo seems funny...
91cdf0e10cSrcweir const char* const devicemodel = "IEC 61966-2.1 Default RGB colour space - sRGB";
927c6ea1afSpfg const char* const copyright = "Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements; and to You under the Apache License, Version 2.0. ";
93cdf0e10cSrcweir
94cdf0e10cSrcweir // the creation date is fixed, corresponds to the last time this file has been changed
95cdf0e10cSrcweir // NOTE: change this date values whenever the data inside the profile are changed.
967c6ea1afSpfg const int data_last_changed_year = 2016;
977c6ea1afSpfg const int data_last_changed_month = 12;
987c6ea1afSpfg const int data_last_day = 24;
997c6ea1afSpfg const int data_last_changed_hour = 43;
1007c6ea1afSpfg const int data_last_changed_minute = 00;
101cdf0e10cSrcweir
102cdf0e10cSrcweir // the following string array it's the standard OOo header format
103cdf0e10cSrcweir const char * const TheHeader1[] =
104cdf0e10cSrcweir {
105cdf0e10cSrcweir "/*************************************************************************",
106cdf0e10cSrcweir " *",
1071584ef18SPedro Giffuni " * Apache OpenOffice - a multi-platform office productivity suite",
108cdf0e10cSrcweir " *",
109cdf0e10cSrcweir " * sRGB-IEC61966-2.1.hxx",
110cdf0e10cSrcweir " *",
111cdf0e10cSrcweir " * creator: create_sRGB_profile",
112cdf0e10cSrcweir NULL
113cdf0e10cSrcweir };
114cdf0e10cSrcweir
115cdf0e10cSrcweir const char * const TheHeader2[] =
116cdf0e10cSrcweir {
117cdf0e10cSrcweir " *",
1187c6ea1afSpfg " * Licensed to the Apache Software Foundation (ASF) under one",
1197c6ea1afSpfg " * or more contributor license agreements. See the NOTICE file",
1207c6ea1afSpfg " * distributed with this work for additional information",
1217c6ea1afSpfg " * regarding copyright ownership. The ASF licenses this file",
1227c6ea1afSpfg " * to you under the Apache License, Version 2.0 (the",
1237c6ea1afSpfg " * \"License\"); you may not use this file except in compliance",
124*265d1466Spfg " * with the License. You may obtain a copy of the License at",
125cdf0e10cSrcweir " *",
1267c6ea1afSpfg " * http://www.apache.org/licenses/LICENSE-2.0",
127cdf0e10cSrcweir " *",
1287c6ea1afSpfg " * Unless required by applicable law or agreed to in writing,",
1297c6ea1afSpfg " * software distributed under the License is distributed on an",
1307c6ea1afSpfg " * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY",
1317c6ea1afSpfg " * KIND, either express or implied. See the License for the",
132*265d1466Spfg " * specific language governing permissions and limitations",
133*265d1466Spfg " * under the License.",
134cdf0e10cSrcweir " ************************************************************************/",
135cdf0e10cSrcweir "",
136cdf0e10cSrcweir "#ifndef INCLUDED_ICC_SRGB_IEC61966_2_1_H",
137cdf0e10cSrcweir "#define INCLUDED_ICC_SRGB_IEC61966_2_1_H",
138cdf0e10cSrcweir "",
139cdf0e10cSrcweir "/***********************************************************************",
140cdf0e10cSrcweir " * NOTE:",
141cdf0e10cSrcweir " * this file is automatically generated by running the program",
142cdf0e10cSrcweir " * obtained building:",
143cdf0e10cSrcweir this_file_name_and_location,
144cdf0e10cSrcweir " * contained in module icc",
145cdf0e10cSrcweir " * modify that program if you need to change something.",
146cdf0e10cSrcweir " ***********************************************************************/",
147cdf0e10cSrcweir NULL // last string, a null
148cdf0e10cSrcweir };
149cdf0e10cSrcweir
150cdf0e10cSrcweir const char * const TheTail[] =
151cdf0e10cSrcweir {
152cdf0e10cSrcweir "#endif /* INCLUDED_ICC_SRGB_IEC61966_2_1_H */",
153cdf0e10cSrcweir NULL
154cdf0e10cSrcweir };
155cdf0e10cSrcweir
computeIEC_RGBtoXYZ(icFloatNumber indata)156cdf0e10cSrcweir icFloatNumber computeIEC_RGBtoXYZ( icFloatNumber indata )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir double retval = 0.0;
159cdf0e10cSrcweir if(indata < 0.04045)
160cdf0e10cSrcweir retval = indata/12.92;
161cdf0e10cSrcweir else // apply the other conversion
162cdf0e10cSrcweir retval = pow( (indata + 0.055)/1.055 , 2.4);
163cdf0e10cSrcweir
164cdf0e10cSrcweir return retval;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
computeIEC_XYZtoRGB(icFloatNumber indata)167cdf0e10cSrcweir icFloatNumber computeIEC_XYZtoRGB( icFloatNumber indata )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir icFloatNumber retval = 0.0;
170cdf0e10cSrcweir if(indata < 0.0031308)
171cdf0e10cSrcweir retval = indata*12.92;
172cdf0e10cSrcweir else // apply the other conversion
173cdf0e10cSrcweir retval = 1.055*pow( indata , icFloatNumber(1.0/2.4)) - 0.055;
174cdf0e10cSrcweir
175cdf0e10cSrcweir // cout << retval << endl;
176cdf0e10cSrcweir return retval;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
dumpTag(FILE * outfile,CIccProfile * pIcc,icTagSignature sig)179cdf0e10cSrcweir void dumpTag(FILE *outfile, CIccProfile *pIcc, icTagSignature sig)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir CIccTag *pTag = pIcc->FindTag(sig);
182cdf0e10cSrcweir char buf[64];
183cdf0e10cSrcweir CIccInfo Fmt;
184cdf0e10cSrcweir
185cdf0e10cSrcweir std::string contents;
186cdf0e10cSrcweir
187cdf0e10cSrcweir if (pTag)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir fprintf(outfile, "\nContents of %s tag (%s)\n", Fmt.GetTagSigName(sig), icGetSig(buf, sig));
190cdf0e10cSrcweir fprintf(outfile,"Type: ");
191cdf0e10cSrcweir
192cdf0e10cSrcweir if (pTag->IsArrayType()) fprintf(outfile, "Array of ");
193cdf0e10cSrcweir
194cdf0e10cSrcweir fprintf(outfile, "%s\n", Fmt.GetTagTypeSigName(pTag->GetType()));
195cdf0e10cSrcweir pTag->Describe(contents);
196cdf0e10cSrcweir fwrite(contents.c_str(), contents.length(), 1, outfile);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir else
199cdf0e10cSrcweir fprintf(outfile, "Tag (%s) not found in profile\n", icGetSig(buf, sig));
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
dumpProfile(FILE * outfile,const char * profileName)202cdf0e10cSrcweir void dumpProfile(FILE *outfile, const char * profileName)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir CIccProfile *pIcc;
205cdf0e10cSrcweir icValidateStatus nStatus;
206cdf0e10cSrcweir
207cdf0e10cSrcweir pIcc = OpenIccProfile(profileName);
208cdf0e10cSrcweir
209cdf0e10cSrcweir if (!pIcc)
210cdf0e10cSrcweir printf("Unable to open '%s'\n", profileName);
211cdf0e10cSrcweir else
212cdf0e10cSrcweir {
213cdf0e10cSrcweir icHeader *pHdr = &pIcc->m_Header;
214cdf0e10cSrcweir CIccInfo Fmt;
215cdf0e10cSrcweir char buf[64];
216cdf0e10cSrcweir
217cdf0e10cSrcweir fprintf(outfile,"Profile: '%s'\n", profileName);
218cdf0e10cSrcweir if(Fmt.IsProfileIDCalculated(&pHdr->profileID))
219cdf0e10cSrcweir fprintf(outfile,"Profile ID: %s\n", Fmt.GetProfileID(&pHdr->profileID));
220cdf0e10cSrcweir else
221cdf0e10cSrcweir fprintf(outfile,"Profile ID: Profile ID not calculated.\n");
222cdf0e10cSrcweir fprintf(outfile,"Size: %ld(0x%lx) bytes\n", pHdr->size, pHdr->size);
223cdf0e10cSrcweir
224cdf0e10cSrcweir fprintf(outfile,"\nHeader\n");
225cdf0e10cSrcweir fprintf(outfile,"------\n");
226cdf0e10cSrcweir fprintf(outfile,"Attributes: %s\n", Fmt.GetDeviceAttrName(pHdr->attributes));
227cdf0e10cSrcweir fprintf(outfile,"Cmm: %s\n", Fmt.GetCmmSigName((icCmmSignature)(pHdr->cmmId)));
228cdf0e10cSrcweir fprintf(outfile,"Creation Date: %d/%d/%d %02u:%02u:%02u\n",
229cdf0e10cSrcweir pHdr->date.month, pHdr->date.day, pHdr->date.year,
230cdf0e10cSrcweir pHdr->date.hours, pHdr->date.minutes, pHdr->date.seconds);
231cdf0e10cSrcweir fprintf(outfile,"Creator: %s\n", icGetSig(buf, pHdr->creator));
232cdf0e10cSrcweir fprintf(outfile,"Data Color Space: %s\n", Fmt.GetColorSpaceSigName(pHdr->colorSpace));
233cdf0e10cSrcweir fprintf(outfile,"Flags %s\n", Fmt.GetProfileFlagsName(pHdr->flags));
234cdf0e10cSrcweir fprintf(outfile,"PCS Color Space: %s\n", Fmt.GetColorSpaceSigName(pHdr->pcs));
235cdf0e10cSrcweir fprintf(outfile,"Platform: %s\n", Fmt.GetPlatformSigName(pHdr->platform));
236cdf0e10cSrcweir fprintf(outfile,"Rendering Intent: %s\n", Fmt.GetRenderingIntentName((icRenderingIntent)(pHdr->renderingIntent)));
237cdf0e10cSrcweir fprintf(outfile,"Type: %s\n", Fmt.GetProfileClassSigName(pHdr->deviceClass));
238cdf0e10cSrcweir fprintf(outfile,"Version: %s\n", Fmt.GetVersionName(pHdr->version));
239cdf0e10cSrcweir fprintf(outfile,"Illuminant: X=%.4lf, Y=%.4lf, Z=%.4lf\n",
240cdf0e10cSrcweir icFtoD(pHdr->illuminant.X),
241cdf0e10cSrcweir icFtoD(pHdr->illuminant.Y),
242cdf0e10cSrcweir icFtoD(pHdr->illuminant.Z));
243cdf0e10cSrcweir
244cdf0e10cSrcweir fprintf(outfile,"\nProfile Tags\n");
245cdf0e10cSrcweir fprintf(outfile,"------------\n");
246cdf0e10cSrcweir
247cdf0e10cSrcweir fprintf(outfile,"%25s ID %8s\t%8s\n", "Tag", "Offset", "Size");
248cdf0e10cSrcweir fprintf(outfile,"%25s ------ %8s\t%8s\n", "----", "------", "----");
249cdf0e10cSrcweir
250cdf0e10cSrcweir int n;
251cdf0e10cSrcweir TagEntryList::iterator i;
252cdf0e10cSrcweir
253cdf0e10cSrcweir for (n=0, i=pIcc->m_Tags->begin(); i!=pIcc->m_Tags->end(); i++, n++)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir fprintf(outfile,"%25s %s %8ld\t%8ld\n", Fmt.GetTagSigName(i->TagInfo.sig),
256cdf0e10cSrcweir icGetSig(buf, i->TagInfo.sig, false),
257cdf0e10cSrcweir i->TagInfo.offset, i->TagInfo.size);
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir for (n=0, i=pIcc->m_Tags->begin(); i!=pIcc->m_Tags->end(); i++, n++)
261cdf0e10cSrcweir dumpTag(outfile, pIcc, i->TagInfo.sig);
262cdf0e10cSrcweir }
263cdf0e10cSrcweir delete pIcc;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
main(int argc,char * argv[])266cdf0e10cSrcweir int main(int argc, char* argv[])
267cdf0e10cSrcweir {
268cdf0e10cSrcweir const char* myName = path_tail(argv[0]);
269cdf0e10cSrcweir
270cdf0e10cSrcweir try
271cdf0e10cSrcweir {
272cdf0e10cSrcweir const char* const out_file_pathname = icc_file_name;
273cdf0e10cSrcweir
274cdf0e10cSrcweir CIccProfile profile;
275cdf0e10cSrcweir profile.InitHeader();
276cdf0e10cSrcweir
277cdf0e10cSrcweir profile.m_Header.date.year = data_last_changed_year;
278cdf0e10cSrcweir profile.m_Header.date.month = data_last_changed_month;
279cdf0e10cSrcweir profile.m_Header.date.day = data_last_day;
280cdf0e10cSrcweir profile.m_Header.date.hours = data_last_changed_hour;
281cdf0e10cSrcweir profile.m_Header.date.minutes = data_last_changed_minute;
282cdf0e10cSrcweir profile.m_Header.date.seconds = 0;
283cdf0e10cSrcweir
284cdf0e10cSrcweir profile.m_Header.deviceClass = icSigDisplayClass;
285cdf0e10cSrcweir profile.m_Header.colorSpace = icSigRgbData;
286cdf0e10cSrcweir profile.m_Header.pcs = icSigXYZData;
287cdf0e10cSrcweir profile.m_Header.platform = icSigUnkownPlatform;
288cdf0e10cSrcweir profile.m_Header.attributes = static_cast<icUInt64Number>(icReflective);
289cdf0e10cSrcweir profile.m_Header.renderingIntent = icPerceptual;
290cdf0e10cSrcweir
291cdf0e10cSrcweir profile.m_Header.cmmId = 0x6E6F6E65; /* 'none' */
292cdf0e10cSrcweir profile.m_Header.model = 0x73524742;//sRGB
293cdf0e10cSrcweir
294cdf0e10cSrcweir profile.m_Header.version=icVersionNumberV2_1;
295cdf0e10cSrcweir
296cdf0e10cSrcweir // Required tags for a three-component matrix-based display profile, as laid
297cdf0e10cSrcweir // out by specification ICC.1:1998-09 (clause 6.3) are:
298cdf0e10cSrcweir //
299cdf0e10cSrcweir // copyrightTag
300cdf0e10cSrcweir // profileDescriptionTag
301cdf0e10cSrcweir // redMatrixColumnTag
302cdf0e10cSrcweir // greenMatrixColumnTag
303cdf0e10cSrcweir // blueMatrixColumnTag
304cdf0e10cSrcweir // redTRCTag
305cdf0e10cSrcweir // greenTRCTag
306cdf0e10cSrcweir // blueTRCTag
307cdf0e10cSrcweir // mediaWhitePointTag
308cdf0e10cSrcweir
309cdf0e10cSrcweir // the other tags:
310cdf0e10cSrcweir //
311cdf0e10cSrcweir // technologyTag
312cdf0e10cSrcweir // deviceModelTag
313cdf0e10cSrcweir // deviceMfgDescTag
314cdf0e10cSrcweir // mediaBlackPointTag
315cdf0e10cSrcweir // viewingCondDescTag
316cdf0e10cSrcweir // viewingConditionsTag
317cdf0e10cSrcweir // luminanceTag
318cdf0e10cSrcweir // measurementTag
319cdf0e10cSrcweir //
320cdf0e10cSrcweir // are optionals, added for completeness
321cdf0e10cSrcweir
322cdf0e10cSrcweir // the element below are sorted in the same order as
323cdf0e10cSrcweir // the list above, but the LUT table,
324cdf0e10cSrcweir // embedded at the end of the profile
325cdf0e10cSrcweir
326cdf0e10cSrcweir // copyrightTag
327cdf0e10cSrcweir CIccTagText* copyrightTag = new CIccTagText;
328cdf0e10cSrcweir copyrightTag->SetText(copyright);
329cdf0e10cSrcweir profile.AttachTag(icSigCopyrightTag, copyrightTag);
330cdf0e10cSrcweir
331cdf0e10cSrcweir // profileDescriptionTag
332cdf0e10cSrcweir CIccTagTextDescription* descriptionTag = new CIccTagTextDescription;
333cdf0e10cSrcweir descriptionTag->SetText(description);
334cdf0e10cSrcweir profile.AttachTag(icSigProfileDescriptionTag, descriptionTag);
335cdf0e10cSrcweir
336cdf0e10cSrcweir CIccTagXYZ* redMatrixColumnTag = new CIccTagXYZ;
337cdf0e10cSrcweir //values from raccomandation of ICC for sRGB, D50 referenced characterisation data
338cdf0e10cSrcweir //should be: 0.4361, 0.2225, 0.0139 according to application notes,
339cdf0e10cSrcweir // the 'X' value below is the one commonly in use on a very
340cdf0e10cSrcweir // diffused sRGB profile
341cdf0e10cSrcweir (*redMatrixColumnTag)[0].X = icDtoF(0.4361);
342cdf0e10cSrcweir (*redMatrixColumnTag)[0].Y = icDtoF(0.2225);
343cdf0e10cSrcweir (*redMatrixColumnTag)[0].Z = icDtoF(0.0139);
344cdf0e10cSrcweir profile.AttachTag(icSigRedMatrixColumnTag, redMatrixColumnTag);
345cdf0e10cSrcweir
346cdf0e10cSrcweir CIccTagXYZ* greenMatrixColumnTag = new CIccTagXYZ;
347cdf0e10cSrcweir //values from raccomandation of ICC for sRGB, D50 referenced characterisation data
348cdf0e10cSrcweir (*greenMatrixColumnTag)[0].X = icDtoF(0.3851);
349cdf0e10cSrcweir (*greenMatrixColumnTag)[0].Y = icDtoF(0.7169);
350cdf0e10cSrcweir (*greenMatrixColumnTag)[0].Z = icDtoF(0.0971);
351cdf0e10cSrcweir profile.AttachTag(icSigGreenMatrixColumnTag, greenMatrixColumnTag);
352cdf0e10cSrcweir
353cdf0e10cSrcweir CIccTagXYZ* blueMatrixColumnTag = new CIccTagXYZ;
354cdf0e10cSrcweir //values from raccomandation of ICC for sRGB, D50 referenced characterisation data
355cdf0e10cSrcweir //should be: 0.1431, 0.0606, 0.7139 according to application notes,
356cdf0e10cSrcweir // the 'Z' value below is the one commonly in use on a very
357cdf0e10cSrcweir // diffused sRGB profile
358cdf0e10cSrcweir (*blueMatrixColumnTag)[0].X = icDtoF(0.1431);
359cdf0e10cSrcweir (*blueMatrixColumnTag)[0].Y = icDtoF(0.0606);
360cdf0e10cSrcweir (*blueMatrixColumnTag)[0].Z = icDtoF(0.7141);
361cdf0e10cSrcweir profile.AttachTag(icSigBlueMatrixColumnTag, blueMatrixColumnTag);
362cdf0e10cSrcweir
363cdf0e10cSrcweir // mediaWhitePointTag
364cdf0e10cSrcweir CIccTagXYZ* whitePointTag = new CIccTagXYZ;
365cdf0e10cSrcweir (*whitePointTag)[0].X = icDtoF(0.9505);
366cdf0e10cSrcweir (*whitePointTag)[0].Y = icDtoF(1.0);
367cdf0e10cSrcweir (*whitePointTag)[0].Z = icDtoF(1.0891);
368cdf0e10cSrcweir profile.AttachTag(icSigMediaWhitePointTag, whitePointTag);
369cdf0e10cSrcweir
370cdf0e10cSrcweir //device signature (technologytag)
371cdf0e10cSrcweir CIccTagSignature* deviceSign = new CIccTagSignature;
372cdf0e10cSrcweir deviceSign->SetValue( icSigCRTDisplay );
373cdf0e10cSrcweir profile.AttachTag( icSigTechnologyTag, deviceSign );
374cdf0e10cSrcweir
375cdf0e10cSrcweir //device model tag
376cdf0e10cSrcweir CIccTagTextDescription* deviceModelTag = new CIccTagTextDescription;
377cdf0e10cSrcweir deviceModelTag->SetText("IEC 61966-2.1 Default RGB colour space - sRGB");
378cdf0e10cSrcweir profile.AttachTag( icSigDeviceModelDescTag, deviceModelTag);
379cdf0e10cSrcweir
380cdf0e10cSrcweir // deviceMfgDescTag
381cdf0e10cSrcweir CIccTagTextDescription* deviceMfgTag = new CIccTagTextDescription;
382cdf0e10cSrcweir deviceMfgTag->SetText("IEC http://www.iec.ch");
383cdf0e10cSrcweir profile.AttachTag( icSigDeviceMfgDescTag, deviceMfgTag);
384cdf0e10cSrcweir
385cdf0e10cSrcweir // mediaBlackPointTag
386cdf0e10cSrcweir CIccTagXYZ* blackPointTag = new CIccTagXYZ;
387cdf0e10cSrcweir (*blackPointTag)[0].X =
388cdf0e10cSrcweir (*blackPointTag)[0].Y =
389cdf0e10cSrcweir (*blackPointTag)[0].Z = icDtoF(0.0);
390cdf0e10cSrcweir profile.AttachTag(icSigMediaBlackPointTag, blackPointTag);
391cdf0e10cSrcweir
392cdf0e10cSrcweir // viewingCondDescTag
393cdf0e10cSrcweir CIccTagTextDescription* viewingCondDescTag = new CIccTagTextDescription;
394cdf0e10cSrcweir viewingCondDescTag->SetText("Reference viewing condition according to IEC 61966-2.1");
395cdf0e10cSrcweir profile.AttachTag( icSigViewingCondDescTag, viewingCondDescTag );
396cdf0e10cSrcweir
397cdf0e10cSrcweir // viewingConditionsTag
398cdf0e10cSrcweir CIccTagViewingConditions* viewingConditionsTag = new CIccTagViewingConditions;
399cdf0e10cSrcweir // Illuminant tristimulus value
400cdf0e10cSrcweir (*viewingConditionsTag).m_XYZIllum.X = icDtoF(19.6445);
401cdf0e10cSrcweir (*viewingConditionsTag).m_XYZIllum.Y = icDtoF(20.3718);
402cdf0e10cSrcweir (*viewingConditionsTag).m_XYZIllum.Z = icDtoF(16.8089);
403cdf0e10cSrcweir // surround tristimulus value
404cdf0e10cSrcweir (*viewingConditionsTag).m_XYZSurround.X = icDtoF(3.9289);
405cdf0e10cSrcweir (*viewingConditionsTag).m_XYZSurround.Y = icDtoF(4.0744);
406cdf0e10cSrcweir (*viewingConditionsTag).m_XYZSurround.Z = icDtoF(3.3618);
407cdf0e10cSrcweir (*viewingConditionsTag).m_illumType = icIlluminantD50;
408cdf0e10cSrcweir profile.AttachTag( icSigViewingConditionsType, viewingConditionsTag );
409cdf0e10cSrcweir
410cdf0e10cSrcweir // luminanceTag
411cdf0e10cSrcweir CIccTagXYZ* luminanceTag = new CIccTagXYZ;
412cdf0e10cSrcweir (*luminanceTag)[0].X = icDtoF(76.0365);
413cdf0e10cSrcweir (*luminanceTag)[0].Y = icDtoF(80.0);
414cdf0e10cSrcweir (*luminanceTag)[0].Z = icDtoF(87.1246);
415cdf0e10cSrcweir profile.AttachTag(icSigLuminanceTag, luminanceTag);
416cdf0e10cSrcweir
417cdf0e10cSrcweir // measurementTag
418cdf0e10cSrcweir CIccTagMeasurement* measurementTag = new CIccTagMeasurement;
419cdf0e10cSrcweir (*measurementTag).m_Data.stdObserver = icStdObs1931TwoDegrees;
420cdf0e10cSrcweir (*measurementTag).m_Data.backing.X =
421cdf0e10cSrcweir (*measurementTag).m_Data.backing.Y =
422cdf0e10cSrcweir (*measurementTag).m_Data.backing.Z = icDtoF(0.0);
423cdf0e10cSrcweir (*measurementTag).m_Data.geometry = icGeometryUnknown;
424cdf0e10cSrcweir // the flare is 1%, but the library doesn't seem all right with this
425cdf0e10cSrcweir // see specification ICC.1:1998-09, clause 6.5.8, table 55 fot the right
426cdf0e10cSrcweir // format of the data value
427cdf0e10cSrcweir (*measurementTag).m_Data.flare = static_cast< icMeasurementFlare > ( icDtoUF( 0.01 ) );//means 1%
428cdf0e10cSrcweir (*measurementTag).m_Data.illuminant = icIlluminantD65;
429cdf0e10cSrcweir profile.AttachTag(icSigMeasurementTag, measurementTag );
430cdf0e10cSrcweir
431cdf0e10cSrcweir // compute the LUT curves, they are equal for all three colors
432cdf0e10cSrcweir // so only one LUT is computed and stored
433cdf0e10cSrcweir int N = 1024; // number of points in LUTs
434cdf0e10cSrcweir CIccTagCurve* colorTRCTag = new CIccTagCurve(N);
435cdf0e10cSrcweir // apply conversion from RGB to XYZ, stepping the RGB value linearly from 0 to 100%
436cdf0e10cSrcweir // 1024 steps are computed
437cdf0e10cSrcweir for (int i = 0; i < N; ++i)
438cdf0e10cSrcweir (*colorTRCTag)[i] = computeIEC_RGBtoXYZ( (icFloatNumber)i/(N-1));
439cdf0e10cSrcweir
440cdf0e10cSrcweir profile.AttachTag(icSigRedTRCTag, colorTRCTag);
441cdf0e10cSrcweir profile.AttachTag(icSigGreenTRCTag, colorTRCTag);
442cdf0e10cSrcweir profile.AttachTag(icSigBlueTRCTag, colorTRCTag);
443cdf0e10cSrcweir
444cdf0e10cSrcweir //Verify things
445cdf0e10cSrcweir string validationReport;
446cdf0e10cSrcweir icValidateStatus validationStatus = profile.Validate(validationReport);
447cdf0e10cSrcweir
448cdf0e10cSrcweir switch (validationStatus)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir case icValidateOK:
451cdf0e10cSrcweir break;
452cdf0e10cSrcweir
453cdf0e10cSrcweir case icValidateWarning:
454cdf0e10cSrcweir clog << "Profile validation warning" << endl
455cdf0e10cSrcweir << validationReport;
456cdf0e10cSrcweir break;
457cdf0e10cSrcweir
458cdf0e10cSrcweir case icValidateNonCompliant:
459cdf0e10cSrcweir clog << "Profile non compliancy" << endl
460cdf0e10cSrcweir << validationReport;
461cdf0e10cSrcweir break;
462cdf0e10cSrcweir
463cdf0e10cSrcweir case icValidateCriticalError:
464cdf0e10cSrcweir default:
465cdf0e10cSrcweir clog << "Profile Error" << endl
466cdf0e10cSrcweir << validationReport;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir
469cdf0e10cSrcweir // Out it goes
470cdf0e10cSrcweir CIccFileIO out;
471cdf0e10cSrcweir out.Open(out_file_pathname, "wb+");
472cdf0e10cSrcweir profile.Write(&out);
473cdf0e10cSrcweir out.Close();
474cdf0e10cSrcweir
475cdf0e10cSrcweir FILE *headerfile = fopen(hxx_file_name,"w");
476cdf0e10cSrcweir
477cdf0e10cSrcweir //print OpenOffice standard file header
478cdf0e10cSrcweir const char *the_string;
479cdf0e10cSrcweir
480cdf0e10cSrcweir int idx = 0;
481cdf0e10cSrcweir
482cdf0e10cSrcweir while((the_string = TheHeader1[idx++]) != NULL )
483cdf0e10cSrcweir fprintf(headerfile,"%s\n",the_string);
484cdf0e10cSrcweir // print the creation date (today)
485cdf0e10cSrcweir // print the date of sRGB ICC profile data
486cdf0e10cSrcweir fprintf(headerfile," * the date of last change to sRGB ICC profile data is:\n * %4d/%02d/%02d - %02d:%02d\n",
487cdf0e10cSrcweir data_last_changed_year, data_last_changed_month,
488cdf0e10cSrcweir data_last_day, data_last_changed_hour,data_last_changed_minute );
489cdf0e10cSrcweir
490cdf0e10cSrcweir idx = 0;
491cdf0e10cSrcweir
492cdf0e10cSrcweir while((the_string = TheHeader2[idx++]) != NULL )
493cdf0e10cSrcweir fprintf(headerfile,"%s\n",the_string);
494cdf0e10cSrcweir
495cdf0e10cSrcweir {
496cdf0e10cSrcweir // spit out the data structure (an array of unsigned char)
497cdf0e10cSrcweir FILE *infile;
498cdf0e10cSrcweir
499cdf0e10cSrcweir int achar, number = 1;
500cdf0e10cSrcweir
501cdf0e10cSrcweir infile = fopen(out_file_pathname,"rb");
502cdf0e10cSrcweir
503cdf0e10cSrcweir fseek(infile,0,SEEK_END);
504cdf0e10cSrcweir long int thesize= ftell(infile);
505cdf0e10cSrcweir fseek(infile,0,SEEK_SET);
506cdf0e10cSrcweir
507cdf0e10cSrcweir fprintf(headerfile,"\nsal_uInt8 nsRGB_ICC_profile[%d]=\n{\n ",thesize);
508cdf0e10cSrcweir
509cdf0e10cSrcweir do
510cdf0e10cSrcweir {
511cdf0e10cSrcweir achar = fgetc(infile);
512cdf0e10cSrcweir if(achar == EOF)
513cdf0e10cSrcweir break;
514cdf0e10cSrcweir fprintf(headerfile,"0x%02x",achar);
515cdf0e10cSrcweir if(number % 12 == 0)
516cdf0e10cSrcweir fprintf(headerfile,",\n ");
517cdf0e10cSrcweir else
518cdf0e10cSrcweir fprintf(headerfile,", ");
519cdf0e10cSrcweir number++;
520cdf0e10cSrcweir } while(achar != EOF );
521cdf0e10cSrcweir fprintf(headerfile,"\n};\n\n");
522cdf0e10cSrcweir
523cdf0e10cSrcweir fclose(infile);
524cdf0e10cSrcweir }
525cdf0e10cSrcweir // append the file contents, in human readable form, as comment in the header
526cdf0e10cSrcweir // get the functions from iccDump
527cdf0e10cSrcweir
528cdf0e10cSrcweir fprintf(headerfile,"/*****************\n\n");
529cdf0e10cSrcweir
530cdf0e10cSrcweir fprintf(headerfile,"This ICC profile contains the following data:\n\n");
531cdf0e10cSrcweir
532cdf0e10cSrcweir dumpProfile(headerfile, out_file_pathname );
533cdf0e10cSrcweir
534cdf0e10cSrcweir fprintf(headerfile,"\n*****************/\n");
535cdf0e10cSrcweir //now append the tail
536cdf0e10cSrcweir idx = 0;
537cdf0e10cSrcweir while((the_string = TheTail[idx++]) != NULL )
538cdf0e10cSrcweir fprintf(headerfile,"%s\n",the_string);
539cdf0e10cSrcweir
540cdf0e10cSrcweir fclose(headerfile);
541cdf0e10cSrcweir
542cdf0e10cSrcweir return EXIT_SUCCESS;
543cdf0e10cSrcweir }
544cdf0e10cSrcweir catch (const std::exception& e)
545cdf0e10cSrcweir {
546cdf0e10cSrcweir cout << myName << ": error: " << e.what() << endl;
547cdf0e10cSrcweir return EXIT_FAILURE;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir }
550