1 /** @file
2 File: IccMpeACS.cpp
3
4 Contains: Implementation of ACS Elements
5
6 Version: V1
7
8 Copyright: � see ICC Software License
9 */
10
11 /*
12 * The ICC Software License, Version 0.2
13 *
14 *
15 * Copyright (c) 2003-2010 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 1-30-2006
68 //
69 //////////////////////////////////////////////////////////////////////
70
71 #if defined(WIN32) || defined(WIN64)
72 #pragma warning( disable: 4786) //disable warning in <list.h>
73 #endif
74
75 #include <stdio.h>
76 #include <math.h>
77 #include <string.h>
78 #include <stdlib.h>
79 #include "IccMpeACS.h"
80 #include "IccIO.h"
81 #include <map>
82 #include "IccUtil.h"
83
84 #ifdef USESAMPLEICCNAMESPACE
85 namespace sampleICC {
86 #endif
87
88
89 /**
90 ******************************************************************************
91 * Name: CIccMpeAcs::CIccMpeACS
92 *
93 * Purpose:
94 * Base constructor (protected)
95 ******************************************************************************/
CIccMpeAcs()96 CIccMpeAcs::CIccMpeAcs()
97 {
98 m_pData = NULL;
99 m_nDataSize = 0;
100
101 m_nReserved = 0;
102 }
103
104 /**
105 ******************************************************************************
106 * Name: CIccMpeAcs::~CIccMpeAcs
107 *
108 * Purpose:
109 * Base destructor
110 ******************************************************************************/
~CIccMpeAcs()111 CIccMpeAcs::~CIccMpeAcs()
112 {
113 if (m_pData)
114 free(m_pData);
115 }
116
117 /**
118 ******************************************************************************
119 * Name: CIccMpeAcs::Describe
120 *
121 * Purpose:
122 *
123 * Args:
124 *
125 * Return:
126 ******************************************************************************/
Describe(std::string & sDescription)127 void CIccMpeAcs::Describe(std::string &sDescription)
128 {
129 icChar sigBuf[30];
130
131 if (GetBAcsSig())
132 sDescription += "ELEM_bACS\r\n";
133 else
134 sDescription += "ELEM_eACS\r\n";
135
136 icGetSig(sigBuf, m_signature);
137 sDescription += " Signature = ";
138 sDescription += sigBuf;
139 sDescription += "\r\n";
140
141 if (m_pData) {
142 sDescription += "\r\nData Follows:\r\n";
143
144 icMemDump(sDescription, m_pData, m_nDataSize);
145 }
146 }
147
148 /**
149 ******************************************************************************
150 * Name: CIccMpeAcs::Read
151 *
152 * Purpose:
153 *
154 * Args:
155 *
156 * Return:
157 ******************************************************************************/
Read(icUInt32Number size,CIccIO * pIO)158 bool CIccMpeAcs::Read(icUInt32Number size, CIccIO *pIO)
159 {
160 icTagTypeSignature sig;
161
162 icUInt32Number headerSize = sizeof(icTagTypeSignature) +
163 sizeof(icUInt32Number) +
164 sizeof(icUInt16Number) +
165 sizeof(icUInt16Number) +
166 sizeof(icUInt32Number);
167
168 if (headerSize > size)
169 return false;
170
171 if (!pIO) {
172 return false;
173 }
174
175 if (!pIO->Read32(&sig))
176 return false;
177
178 if (!pIO->Read32(&m_nReserved))
179 return false;
180
181 if (!pIO->Read16(&m_nInputChannels))
182 return false;
183
184 if (!pIO->Read16(&m_nOutputChannels))
185 return false;
186
187 if (!pIO->Read32(&m_signature))
188 return false;
189
190 icUInt32Number dataSize = size - headerSize;
191
192 if (!AllocData(dataSize))
193 return false;
194
195 if (dataSize) {
196 if (pIO->Read8(m_pData, dataSize)!=(icInt32Number)dataSize)
197 return false;
198 }
199
200 return true;
201 }
202
203 /**
204 ******************************************************************************
205 * Name: CIccMpeAcs::Write
206 *
207 * Purpose:
208 *
209 * Args:
210 *
211 * Return:
212 ******************************************************************************/
Write(CIccIO * pIO)213 bool CIccMpeAcs::Write(CIccIO *pIO)
214 {
215 icElemTypeSignature sig = GetType();
216
217 if (!pIO)
218 return false;
219
220 if (!pIO->Write32(&sig))
221 return false;
222
223 if (!pIO->Write32(&m_nReserved))
224 return false;
225
226 if (!pIO->Write16(&m_nInputChannels))
227 return false;
228
229 if (!pIO->Write16(&m_nOutputChannels))
230 return false;
231
232 if (!pIO->Write32(&m_signature))
233 return false;
234
235 if (m_pData && m_nDataSize) {
236 if (!pIO->Write8(m_pData, m_nDataSize)!=m_nDataSize)
237 return false;
238 }
239
240 return true;
241 }
242
243 /**
244 ******************************************************************************
245 * Name: CIccMpeAcs::Begin
246 *
247 * Purpose:
248 *
249 * Args:
250 *
251 * Return:
252 ******************************************************************************/
Begin(icElemInterp nInterp,CIccTagMultiProcessElement * pMPE)253 bool CIccMpeAcs::Begin(icElemInterp nInterp, CIccTagMultiProcessElement *pMPE)
254 {
255 if (m_nInputChannels!=m_nOutputChannels)
256 return false;
257
258 return true;
259 }
260
261 /**
262 ******************************************************************************
263 * Name: CIccMpeAcs::Apply
264 *
265 * Purpose:
266 *
267 * Args:
268 *
269 * Return:
270 ******************************************************************************/
Apply(CIccApplyMpe * pApply,icFloatNumber * dstPixel,const icFloatNumber * srcPixel) const271 void CIccMpeAcs::Apply(CIccApplyMpe *pApply, icFloatNumber *dstPixel, const icFloatNumber *srcPixel) const
272 {
273 memcpy(dstPixel, srcPixel, m_nInputChannels*sizeof(icFloatNumber));
274 }
275
276 /**
277 ******************************************************************************
278 * Name: CIccMpeAcs::Validate
279 *
280 * Purpose:
281 *
282 * Args:
283 *
284 * Return:
285 ******************************************************************************/
Validate(icTagSignature sig,std::string & sReport,const CIccTagMultiProcessElement * pMPE) const286 icValidateStatus CIccMpeAcs::Validate(icTagSignature sig, std::string &sReport, const CIccTagMultiProcessElement* pMPE/*=NULL*/) const
287 {
288 icValidateStatus rv = CIccMultiProcessElement::Validate(sig, sReport, pMPE);
289
290 return rv;
291 }
292
293 /**
294 ******************************************************************************
295 * Name: CIccMpeAcs::AllocData
296 *
297 * Purpose:
298 *
299 * Args:
300 *
301 * Return:
302 ******************************************************************************/
AllocData(icUInt32Number size)303 bool CIccMpeAcs::AllocData(icUInt32Number size)
304 {
305 if (m_pData)
306 free(m_pData);
307
308 if (size) {
309 m_pData = (icUInt8Number*)malloc(size);
310 if (m_pData)
311 m_nDataSize = size;
312 }
313 else {
314 m_pData = NULL;
315 m_nDataSize = 0;
316 }
317
318 return (size==0 || m_pData!=NULL);
319 }
320
321
322 /**
323 ******************************************************************************
324 * Name: CIccMpeBeginAcs::CIccMpeBeginAcs
325 *
326 * Purpose:
327 *
328 * Args:
329 *
330 * Return:
331 ******************************************************************************/
CIccMpeBAcs(icUInt16Number nChannels,icAcsSignature sig)332 CIccMpeBAcs::CIccMpeBAcs(icUInt16Number nChannels/* =0 */, icAcsSignature sig /* = icSigUnknownAcs */)
333 {
334 m_signature = sig;
335
336 m_nInputChannels = nChannels;
337 m_nOutputChannels = nChannels;
338 }
339
340 /**
341 ******************************************************************************
342 * Name: CIccMpeBeginAcs::CIccMpeBeginAcs
343 *
344 * Purpose:
345 *
346 * Args:
347 *
348 * Return:
349 ******************************************************************************/
CIccMpeBAcs(const CIccMpeBAcs & elemAcs)350 CIccMpeBAcs::CIccMpeBAcs(const CIccMpeBAcs &elemAcs)
351 {
352
353 m_signature = elemAcs.m_signature;
354 m_nReserved = elemAcs.m_nReserved;
355 m_nInputChannels = elemAcs.m_nInputChannels;
356 m_nOutputChannels = elemAcs.m_nOutputChannels;
357
358 m_pData = NULL;
359 m_nDataSize = 0;
360
361 AllocData(elemAcs.m_nDataSize);
362 if (m_pData && elemAcs.m_nDataSize) {
363 memcpy(m_pData, elemAcs.m_pData, m_nDataSize);
364 }
365
366 m_nReserved = 0;
367 }
368
369 /**
370 ******************************************************************************
371 * Name: &CIccMpeBeginAcs::operator=
372 *
373 * Purpose:
374 *
375 * Args:
376 *
377 * Return:
378 ******************************************************************************/
operator =(const CIccMpeBAcs & elemAcs)379 CIccMpeBAcs &CIccMpeBAcs::operator=(const CIccMpeBAcs &elemAcs)
380 {
381 m_signature = elemAcs.m_signature;
382 m_nReserved = elemAcs.m_nReserved;
383 m_nInputChannels = elemAcs.m_nInputChannels;
384 m_nOutputChannels = elemAcs.m_nOutputChannels;
385
386 AllocData(elemAcs.m_nDataSize);
387 if (m_pData && elemAcs.m_nDataSize) {
388 memcpy(m_pData, elemAcs.m_pData, m_nDataSize);
389 }
390
391 return *this;
392 }
393
394 /**
395 ******************************************************************************
396 * Name: CIccMpeBeginAcs::~CIccMpeBeginAcs
397 *
398 * Purpose:
399 *
400 * Args:
401 *
402 * Return:
403 ******************************************************************************/
~CIccMpeBAcs()404 CIccMpeBAcs::~CIccMpeBAcs()
405 {
406 }
407
408 /**
409 ******************************************************************************
410 * Name: CIccMpeEndAcs::CIccMpeEndAcs
411 *
412 * Purpose:
413 *
414 * Args:
415 *
416 * Return:
417 ******************************************************************************/
CIccMpeEAcs(icUInt16Number nChannels,icAcsSignature sig)418 CIccMpeEAcs::CIccMpeEAcs(icUInt16Number nChannels/* =0 */, icAcsSignature sig /* = icSigUnknownAcs */)
419 {
420 m_signature = sig;
421
422 m_nInputChannels = nChannels;
423 m_nOutputChannels = nChannels;
424 }
425
426 /**
427 ******************************************************************************
428 * Name: CIccMpeEndAcs::CIccMpeEndAcs
429 *
430 * Purpose:
431 *
432 * Args:
433 *
434 * Return:
435 ******************************************************************************/
CIccMpeEAcs(const CIccMpeEAcs & elemAcs)436 CIccMpeEAcs::CIccMpeEAcs(const CIccMpeEAcs &elemAcs)
437 {
438 m_signature = elemAcs.m_signature;
439 m_nReserved = elemAcs.m_nReserved;
440
441 m_nInputChannels = elemAcs.m_nInputChannels;
442 m_nOutputChannels = elemAcs.m_nOutputChannels;
443
444 AllocData(elemAcs.m_nDataSize);
445 if (m_pData && elemAcs.m_nDataSize) {
446 memcpy(m_pData, elemAcs.m_pData, m_nDataSize);
447 }
448 }
449
450 /**
451 ******************************************************************************
452 * Name: &CIccMpeEndAcs::operator=
453 *
454 * Purpose:
455 *
456 * Args:
457 *
458 * Return:
459 ******************************************************************************/
operator =(const CIccMpeEAcs & elemAcs)460 CIccMpeEAcs &CIccMpeEAcs::operator=(const CIccMpeEAcs &elemAcs)
461 {
462 m_signature = elemAcs.m_signature;
463 m_nReserved = elemAcs.m_nReserved;
464 m_nInputChannels = elemAcs.m_nInputChannels;
465 m_nOutputChannels = elemAcs.m_nOutputChannels;
466
467 AllocData(elemAcs.m_nDataSize);
468 if (m_pData && elemAcs.m_nDataSize) {
469 memcpy(m_pData, elemAcs.m_pData, m_nDataSize);
470 }
471
472 return *this;
473 }
474
475 /**
476 ******************************************************************************
477 * Name: CIccMpeEndAcs::~CIccMpeEndAcs
478 *
479 * Purpose:
480 *
481 * Args:
482 *
483 * Return:
484 ******************************************************************************/
~CIccMpeEAcs()485 CIccMpeEAcs::~CIccMpeEAcs()
486 {
487 }
488
489 #ifdef USESAMPLEICCNAMESPACE
490 } //namespace sampleICC
491 #endif
492