Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccV5DspObsToV4Dsp.cpp
Go to the documentation of this file.
1/*
2 File: iccV5DspObsToV4Dsp.cpp
3
4 Contains: Console app to parse and display profile contents
5
6 Version: V1
7
8 Copyright: (c) see below
9*/
10
11/*
12 * The ICC Software License, Version 0.2
13 *
14 *
15 * Copyright (c) 2003-2023 The International Color Consortium. All rights
16 * reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 *
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 *
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in
27 * the documentation and/or other materials provided with the
28 * distribution.
29 *
30 * 3. In the absence of prior written permission, the names "ICC" and "The
31 * International Color Consortium" must not be used to imply that the
32 * ICC organization endorses or promotes products derived from this
33 * software.
34 *
35 *
36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39 * DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
40 * ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This software consists of voluntary contributions made by many
51 * individuals on behalf of the The International Color Consortium.
52 *
53 *
54 * Membership in the ICC is encouraged when this software is used for
55 * commercial purposes.
56 *
57 *
58 * For more information on The International Color Consortium, please
59 * see <http://www.color.org/>.
60 *
61 *
62 */
63
64//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -Initial implementation by Max Derhak 10-11-2023
68//
69//////////////////////////////////////////////////////////////////////
70
71
72#include <stdio.h>
73#include <cstring>
74#include "IccProfile.h"
75#include "IccTag.h"
76#include "IccTagMPE.h"
77#include "IccTagLut.h"
78#include "IccMpeBasic.h"
79#include "IccMpeSpectral.h"
80#include "IccUtil.h"
81#include "IccProfLibVer.h"
82#include <memory>
83
84typedef std::shared_ptr<CIccProfile> CIccProfileSharedPtr;
85
86int main(int argc, char* argv[])
87{
88 if (argc <= 3) {
89 printf("Usage: iccV5DspObsToV4Dsp v5DspIccPath v5ObsPcc v4DspIccPath\n");
90 printf("Built with IccProfLib version " ICCPROFLIBVER "\n");
91
92 return -1;
93 }
94
96
97 if (!dspIcc) {
98 printf("Unable to parse '%s'\n", argv[1]);
99 return -2;
100 }
101
102 if (dspIcc->m_Header.version < icVersionNumberV5 ||
103 dspIcc->m_Header.deviceClass != icSigDisplayClass) {
104 printf("%s is not a V5 display profile\n", argv[1]);
105 return -2;
106 }
107
109
110 if (!pTagIn) {
111 printf("%s doesn't have an AToB1Tag of type mulitProcessElementType\n", argv[1]);
112 return -2;
113 }
114
115 CIccMultiProcessElement *curveMpe, *matrixMpe;
116
117 if (pTagIn->NumElements() != 2 ||
118 pTagIn->NumInputChannels() != 3 ||
119 pTagIn->NumOutputChannels() != 3 ||
120 ((curveMpe = pTagIn->GetElement(0))==nullptr) ||
121 curveMpe->GetType()!= icSigCurveSetElemType ||
122 ((matrixMpe = pTagIn->GetElement(1))==nullptr) ||
123 matrixMpe->GetType()!=icSigEmissionMatrixElemType) {
124 printf("%s doesn't have a spectral emission AToB1Tag\n", argv[1]);
125 return -2;
126 }
127
129
130 if (!pccIcc) {
131 printf("Unable to parse '%s'\n", argv[2]);
132 return -2;
133 }
134
135 if (pccIcc->m_Header.version < icVersionNumberV5) {
136 printf("%s is not a V5 profile\n", argv[1]);
137 return -2;
138 }
139
142
143 if (!pTagSvcn ||
144 !pTagC2S ||
145 pTagC2S->NumInputChannels() != 3 ||
146 pTagC2S->NumOutputChannels() != 3) {
147 printf("%s doesn't have Profile Connection Conditions\n", argv[2]);
148 return -2;
149 }
150
151 pTagIn->Begin(icElemInterpLinear, dspIcc.get(), pccIcc.get());
152
153 std::shared_ptr<CIccApplyTagMpe> pApplyMpe = std::shared_ptr<CIccApplyTagMpe>(pTagIn->GetNewApply());
154
155 auto applyList = pApplyMpe->GetList();
156 auto applyIter = applyList->begin();
157 auto curveApply = applyIter->ptr;
158 applyIter++;
159 auto mtxApply = applyIter->ptr;
160
161 pTagC2S->Begin(icElemInterpLinear, pccIcc.get());
162
163 std::shared_ptr<CIccApplyTagMpe> pAppyC2S = std::shared_ptr<CIccApplyTagMpe>(pTagC2S->GetNewApply());
164
165
166 CIccProfilePtr pIcc = CIccProfilePtr(new CIccProfile());
167
168 pIcc->InitHeader();
169 pIcc->m_Header.deviceClass = icSigDisplayClass;
170 pIcc->m_Header.version = icVersionNumberV4_3;
171
172 CIccTag* pDesc = dspIcc->FindTag(icSigProfileDescriptionTag);
173
175 std::string text;
176 if (!icGetTagText(pDesc, text))
177 text = std::string("Display profile from '") + argv[1] + "' and PCC '" + argv[2] + "'";
178 pDspText->SetText(text.c_str());
179
180 pIcc->AttachTag(icSigProfileDescriptionTag, pDspText);
181
182 pDspText = new CIccTagMultiLocalizedUnicode();
183 pDspText->SetText("Copyright (C) 2023 International Color Consortium");
184
185 pIcc->AttachTag(icSigCopyrightTag, pDspText);
186
187 CIccTagCurve* pTrcR = new CIccTagCurve(2048);
188 CIccTagCurve* pTrcG = new CIccTagCurve(2048);
189 CIccTagCurve* pTrcB = new CIccTagCurve(2048);
190
191 icFloatNumber in[3], out[3];
192 for (icUInt16Number i=0; i<2048; i++) {
193 in[0] = in[1] = in[2] = (icFloatNumber)i / 2047.0f;
194 curveMpe->Apply(curveApply, out, in);
195 (*pTrcR)[i] = out[0];
196 (*pTrcG)[i] = out[1];
197 (*pTrcB)[i] = out[2];
198 }
199
200 const icFloatNumber rRGB[3] = { 1.0f, 0.0f, 0.0f };
201 const icFloatNumber gRGB[3] = { 0.0f, 1.0f, 0.0f };
202 const icFloatNumber bRGB[3] = { 0.0f, 0.0f, 1.0f };
203
204 CIccTagS15Fixed16* primaryXYZ;
205
206 matrixMpe->Apply(mtxApply, in, rRGB);
207 pTagC2S->Apply(pAppyC2S.get(), out, in);
208
209 primaryXYZ = new CIccTagS15Fixed16(3);
210 (*primaryXYZ)[0] = icDtoF(out[0]); (*primaryXYZ)[1] = icDtoF(out[1]); (*primaryXYZ)[2] = icDtoF(out[2]);
211 pIcc->AttachTag(icSigRedColorantTag, primaryXYZ);
212
213 matrixMpe->Apply(mtxApply, in, gRGB);
214 pTagC2S->Apply(pAppyC2S.get(), out, in);
215
216 primaryXYZ = new CIccTagS15Fixed16(3);
217 (*primaryXYZ)[0] = icDtoF(out[0]); (*primaryXYZ)[1] = icDtoF(out[1]); (*primaryXYZ)[2] = icDtoF(out[2]);
218 pIcc->AttachTag(icSigGreenColorantTag, primaryXYZ);
219
220 matrixMpe->Apply(mtxApply, in, bRGB);
221 pTagC2S->Apply(pAppyC2S.get(), out, in);
222
223 primaryXYZ = new CIccTagS15Fixed16(3);
224 (*primaryXYZ)[0] = icDtoF(out[0]); (*primaryXYZ)[1] = icDtoF(out[1]); (*primaryXYZ)[2] = icDtoF(out[2]);
225 pIcc->AttachTag(icSigBlueColorantTag, primaryXYZ);
226
227 SaveIccProfile(argv[3], pIcc);
228 printf("%s successfully created\n", argv[3]);
229
230 return 0;
231 }
232
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
Definition IccDefs.h:100
File: IccMpeBasic.h.
File: IccMpeSpectral.h.
#define ICCPROFLIBVER
bool SaveIccProfile(const icChar *szFilename, CIccProfile *pIcc, icProfileIDSaveMethod nWriteId)
Name: SaveIccProfile.
CIccProfile * ReadIccProfile(const icChar *szFilename, bool bUseSubProfile)
Name: ReadIccProfile.
File: IccProfile.h.
File: IccTag.h.
bool icGetTagText(const CIccTag *pTag, std::string &text)
CIccTagFixedNum< icS15Fixed16Number, icSigS15Fixed16ArrayType > CIccTagS15Fixed16
Class: CIccTagS15Fixed16.
File: IccTagLut.h.
File: IccTagMPE.h.
@ icElemInterpLinear
Definition IccTagMPE.h:94
icS15Fixed16Number icDtoF(icFloatNumber num)
Definition IccUtil.cpp:545
File: IccUtil.h.
std::shared_ptr< CIccProfile > CIccProfileSharedPtr
int main()
Core and external libraries necessary for the fuzzer functionality.
Class: CIccMultiProcessElement.
Definition IccTagMPE.h:146
virtual void Apply(CIccApplyMpe *pApply, icFloatNumber *pDestPixel, const icFloatNumber *pSrcPixel) const =0
virtual icElemTypeSignature GetType() const =0
Class: CIccTagCurve.
Definition IccTagLut.h:128
Class: CIccTagFixedNum.
Class: CIccTag.
Class: CIccTagMultiLocalizedUnicode.
void SetText(const icChar *szText, icLanguageCode nLanguageCode=icLanguageCodeEnglish, icCountryCode nRegionCode=icCountryCodeUSA)
Name: refIccMAX::CIccTagMultiLocalizedUnicode::SetText.
Class: CIccTagMultiProcessElement.
Definition IccTagMPE.h:358
icUInt16Number NumInputChannels() const
Definition IccTagMPE.h:393
virtual bool Begin(icElemInterp nInterp=icElemInterpLinear, IIccProfileConnectionConditions *pProfilePCC=NULL, IIccProfileConnectionConditions *pAppliedPCC=NULL, IIccCmmEnvVarLookup *pCmmEnvVarLookup=NULL)
Name: CIccTagMultiProcessElement::Begin.
icUInt16Number NumOutputChannels() const
Definition IccTagMPE.h:394
virtual CIccApplyTagMpe * GetNewApply()
Name: CIccTagMultiProcessElement::GetNewApply.
virtual void Apply(CIccApplyTagMpe *pApply, icFloatNumber *pDestPixel, const icFloatNumber *pSrcPixel) const
Name: CIccTagMultiProcessElement::Apply.
icUInt32Number NumElements() const
Definition IccTagMPE.h:398
CIccMultiProcessElement * GetElement(int nIndex)
Name: CIccTagMultiProcessElement::GetElement.
Class: CIccTagSpectralViewingConditions.
#define icVersionNumberV4_3
unsigned short icUInt16Number
@ icSigDisplayClass
@ icSigEmissionMatrixElemType
@ icSigCurveSetElemType
@ icSigMultiProcessElementType
@ icSigSpectralViewingConditionsType
#define icVersionNumberV5
@ icSigSpectralViewingConditionsTag
@ icSigCustomToStandardPccTag
@ icSigProfileDescriptionTag
@ icSigRedColorantTag
@ icSigCopyrightTag
@ icSigAToB1Tag
@ icSigGreenColorantTag
@ icSigBlueColorantTag