235{
236 int minargs = 2;
237 if (argc < minargs) {
239 return -1;
240 }
241
245
246 if (argc > 2 && !
stricmp(argv[1],
"-cfg")) {
247 json cfg;
249 printf("Unable to read configuration from '%s'\n", argv[2]);
250 return -1;
251 }
252
253 if (cfg.find(
"dataFiles") == cfg.end() || !cfgApply.
fromJson(cfg[
"dataFiles"])) {
254 printf("Unable to parse dataFile configuration from '%s'\n", argv[2]);
255 return -1;
256 }
257
258 if (cfg.find(
"profileSequence") == cfg.end() || !cfgProfiles.
fromJson(cfg[
"profileSequence"])) {
259 printf("Unable to parse profileSequence configuration from '%s'\n", argv[2]);
260 return -1;
261 }
262
265 if (!cfgData.
fromJson(cfg[
"colorData"])) {
266 printf("Unable to parse colorData configuration from '%s'\n", argv[2]);
267 }
268 }
269 else {
270 json data;
272 printf(
"Unable to load color data from '%s'\n", cfgApply.
m_srcFile.c_str());
273 return -1;
274 }
275 }
276 }
277 }
278 else {
279 argv++;
280 argc--;
281
282 if (argc > 1 && !
stricmp(argv[0],
"-debugcalc")) {
284
285 argv++;
286 argc--;
287 }
288
289 int nArg = cfgApply.
fromArgs(&argv[0], argc);
290 if (!nArg) {
291 printf("Unable to parse configuration arguments\n");
292 return -1;
293 }
294 argv += nArg;
295 argc -= nArg;
296
297 nArg = cfgProfiles.
fromArgs(&argv[0], argc);
298 if (!nArg) {
299 printf("Unable to parse profile sequence arguments\n");
300 return -1;
301 }
302
304 printf(
"Unable to parse legacy data file '%s'\n", cfgApply.
m_srcFile.c_str());
305 return -1;
306 }
307 }
309
313 }
314
315 char precisionStr[30];
317
318 icFloatColorEncoding srcEncoding, destEncoding;
319
320
322
324
325
326 bool bInputProfile = !
IsSpacePCS(SrcspaceSig);
327 if (!bInputProfile) {
329 if (pProf) {
331 bInputProfile = true;
332 delete pProf;
333 }
334 }
335
336
339
341 bool bUseSubProfile = false;
342
343 for (
auto pProfIter = cfgProfiles.
m_profiles.begin(); pProfIter != cfgProfiles.
m_profiles.end(); pProfIter++) {
345
346 if (!pProfCfg)
347 continue;
348
349 CIccProfile *pPccProfile = NULL;
350
351
352 CIccCreateXformHintManager Hint;
355
357 Hint.AddHint(new CIccLuminanceMatchingHint());
358 }
359
362 if (!pPccProfile) {
363 printf(
"Unable to open Profile Connections Conditions from '%s'\n", pProfCfg->
m_pccFile.c_str());
364 return -1;
365 }
366
367 pccList.push_back(pPccProfile);
368 }
369
370
373 }
374
377 }
378
379
380 if (namedCmm.AddXform(pProfCfg->
m_iccFile.c_str(),
382 pProfCfg->m_interpolation,
383 pPccProfile,
384 pProfCfg->m_transform,
385 pProfCfg->m_useD2BxB2Dx,
386 &Hint,
387 pProfCfg->m_useV5SubProfile)) {
388 printf(
"Invalid Profile: %s\n", pProfCfg->
m_iccFile.c_str());
389 return -1;
390 }
391 }
392
394
395
396 if((stat=namedCmm.Begin())) {
397 printf("Error %d - Unable to begin profile application - Possibly invalid or incompatible profiles\n", stat);
398 return -1;
399 }
400
401 CIccCmm *pMruCmm = NULL;
402
403
404 IccProfilePtrList::iterator pcc;
405 for (pcc=pccList.begin(); pcc!=pccList.end(); pcc++) {
406 CIccProfile *pPccProfile = *pcc;
407 delete pPccProfile;
408 }
409 pccList.clear();
410
411
412 SrcspaceSig = namedCmm.GetSourceSpace();
414
415 bool bClip = true;
416
417 if (bInputProfile &&
IsSpacePCS(SrcspaceSig)) {
422
423 if (srcEncoding == icEncodeFloat)
424 bClip = false;
425 }
426
427
430
431
432 char SrcNameBuf[256], DestNameBuf[256];
433 CIccPixelBuf SrcPixel(nSrcSamples+16), DestPixel(nDestSamples+16), Pixel(
icIntMax(nSrcSamples, nDestSamples)+16);
434
436
437 outData.
m_space = DestspaceSig;
438
441 destEncoding = icEncodeValue;
443
445
447 srcEncoding = icEncodeValue;
449
450
451 for (
auto dataIter = cfgData.
m_data.begin(); dataIter != cfgData.
m_data.end(); dataIter++) {
453
454 int i;
455
456 if (!pData)
457 continue;
458
459 if (pDebugger)
461
463
464 out->m_srcName = pData->
m_name;
466
467
469
472
475 else
476 tint = 1.0;
477
478 switch(namedCmm.GetInterface()) {
479 case icApplyNamed2Pixel:
480 {
481
482 if(namedCmm.Apply(DestPixel,
szName, tint)) {
483 printf("Profile application failed.\n");
484 return -1;
485 }
486
487 if(CIccCmm::FromInternalEncoding(DestspaceSig, destEncoding, DestPixel, DestPixel, destEncoding!=icEncodeFloat)) {
488 printf("Invalid final data encoding\n");
489 return -1;
490 }
491
492 for(i = 0; i<nDestSamples; i++) {
493 out->m_values.push_back(DestPixel[i]);
494 }
495 break;
496 }
497 case icApplyNamed2Named:
498 {
499 if(namedCmm.Apply(DestNameBuf, SrcNameBuf, tint)) {
500 printf("Profile application failed.\n");
501 return -1;
502 }
503
504 out->m_name = DestNameBuf;
505 break;
506 }
507 case icApplyPixel2Pixel:
508 case icApplyPixel2Named:
509 default:
510 printf("Incorrect interface.\n");
511 return -1;
512 }
513 }
514 else {
515 for (i = 0; i < nSrcSamples && i < pData->
m_values.size(); i++) {
517 }
518
520
521 if(CIccCmm::ToInternalEncoding(SrcspaceSig, srcEncoding, SrcPixel, Pixel, bClip)) {
522 printf("Invalid source data encoding\n");
523 return -1;
524 }
525
526 switch(namedCmm.GetInterface()) {
527 case icApplyPixel2Pixel:
528 {
529 if (pMruCmm) {
530 if (pMruCmm->Apply(DestPixel, SrcPixel)) {
531 printf("Profile application failed.\n");
532 return -1;
533 }
534 }
535 else if(namedCmm.Apply(DestPixel, SrcPixel)) {
536 printf("Profile application failed.\n");
537 return -1;
538 }
539 if(CIccCmm::FromInternalEncoding(DestspaceSig, destEncoding, DestPixel, DestPixel)) {
540 printf("Invalid final data encoding\n");
541 return -1;
542 }
543
544 for(i = 0; i<nDestSamples; i++) {
545 out->m_values.push_back(DestPixel[i]);
546 }
547 break;
548 }
549 case icApplyPixel2Named:
550 {
551 if(namedCmm.Apply(DestNameBuf, SrcPixel)) {
552 printf("Profile application failed.\n");
553 return -1;
554 }
555 out->m_name = DestNameBuf;
556 break;
557 }
558 case icApplyNamed2Pixel:
559 case icApplyNamed2Named:
560 default:
561 printf("Incorrect interface.\n");
562 return -1;
563 }
564 }
565
566 if (pDebugger)
567 out->m_debugInfo = pDebugger->m_log;
568
569 outData.
m_data.push_back(out);
570 }
571
572
573
574
575
576
577
580 }
582 json out;
583 json seq;
585 if (seq.is_object())
586 out["appliedProfileSequence"] = seq;
587
588 json data;
590 if (data.is_object())
591 out["colorData"] = data;
592
593 if (out.is_object())
595 }
598 }
599 else {
600 printf("Unsupported output format\n");
601 delete pMruCmm;
602
603 return -1;
604 }
605
606 if (pMruCmm)
607 delete pMruCmm;
608
609 return 0;
610}
icStatusCMM
CMM return status values.
std::shared_ptr< CIccCfgDataEntry > CIccCfgDataEntryPtr
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
#define icSigDevLabData
Additional convenience color space signatures to distinguish between device encoding and PCS encoding...
std::map< icSignature, icFloatNumber > icCmmEnvSigMap
bool loadJsonFrom(json &j, const char *szFname)
bool saveJsonAs(const json &j, const char *szFname, int indent)
CIccProfile * OpenIccProfile(const icChar *szFilename, bool bUseSubProfile)
Name: OpenIccProfile.
icUInt32Number icGetSpaceSamples(icColorSpaceSignature sig)
icUInt32Number icIntMax(icUInt32Number v1, icUInt32Number v2)
bool fromLegacy(const char *filename, bool bReset=false)
icFloatColorEncoding m_srcEncoding
bool toIt8(const char *filename, icUInt8Number nDigits, icUInt8Number nPrecision)
icColorSpaceSignature m_srcSpace
bool fromJson(json obj, bool bReset=false)
void toJson(json &obj) const
icFloatColorEncoding m_encoding
CIccCfgDataEntryList m_data
icColorSpaceSignature m_space
bool toLegacy(const char *filename, CIccCfgProfileSequence *pProfiles, icUInt8Number nDigits, icUInt8Number nPrecision, bool bShowDebug=false)
bool fromJson(json obj, bool bReset=false)
icUInt8Number m_dstPrecision
int fromArgs(const char **args, int nArg, bool bReset=false)
icUInt8Number m_dstDigits
icFloatColorEncoding m_dstEncoding
std::vector< icFloatNumber > m_srcValues
std::vector< icFloatNumber > m_values
icCmmEnvSigMap m_pccEnvVars
icCmmEnvSigMap m_iccEnvVars
bool m_adjustPcsLuminance
CIccCfgProfileArray m_profiles
int fromArgs(const char **args, int nArg, bool bReset=false)
bool fromJson(json obj, bool bReset=false)
void toJson(json &obj) const
static void SetDebugger(IIccCalcDebugger *pDebugger)
std::list< CIccProfile * > IccProfilePtrList
std::shared_ptr< CIccLogDebugger > LogDebuggerPtr