234int main(
int argc,
const char* argv[])
237 if (argc < minargs) {
246 if (argc > 2 && !
stricmp(argv[1],
"-cfg")) {
249 printf(
"Unable to read configuration from '%s'\n", argv[2]);
253 if (cfg.find(
"dataFiles") == cfg.end() || !cfgApply.
fromJson(cfg[
"dataFiles"])) {
254 printf(
"Unable to parse dataFile configuration from '%s'\n", argv[2]);
258 if (cfg.find(
"profileSequence") == cfg.end() || !cfgProfiles.
fromJson(cfg[
"profileSequence"])) {
259 printf(
"Unable to parse profileSequence configuration from '%s'\n", argv[2]);
265 if (!cfgData.
fromJson(cfg[
"colorData"])) {
266 printf(
"Unable to parse colorData configuration from '%s'\n", argv[2]);
272 printf(
"Unable to load color data from '%s'\n", cfgApply.
m_srcFile.c_str());
282 if (argc > 1 && !
stricmp(argv[0],
"-debugcalc")) {
289 int nArg = cfgApply.
fromArgs(&argv[0], argc);
291 printf(
"Unable to parse configuration arguments\n");
297 nArg = cfgProfiles.
fromArgs(&argv[0], argc);
299 printf(
"Unable to parse profile sequence arguments\n");
304 printf(
"Unable to parse legacy data file '%s'\n", cfgApply.
m_srcFile.c_str());
315 char precisionStr[30];
318 icFloatColorEncoding srcEncoding, destEncoding;
326 bool bInputProfile = !
IsSpacePCS(SrcspaceSig);
327 if (!bInputProfile) {
331 bInputProfile =
true;
341 bool bUseSubProfile =
false;
343 for (
auto pProfIter = cfgProfiles.
m_profiles.begin(); pProfIter != cfgProfiles.
m_profiles.end(); pProfIter++) {
349 CIccProfile *pPccProfile = NULL;
352 CIccCreateXformHintManager Hint;
357 Hint.AddHint(
new CIccLuminanceMatchingHint());
363 printf(
"Unable to open Profile Connections Conditions from '%s'\n", pProfCfg->
m_pccFile.c_str());
367 pccList.push_back(pPccProfile);
380 if (namedCmm.AddXform(pProfCfg->
m_iccFile.c_str(),
388 printf(
"Invalid Profile: %s\n", pProfCfg->
m_iccFile.c_str());
396 if((stat=namedCmm.Begin())) {
397 printf(
"Error %d - Unable to begin profile application - Possibly invalid or incompatible profiles\n", stat);
401 CIccCmm *pMruCmm = NULL;
404 IccProfilePtrList::iterator pcc;
405 for (pcc=pccList.begin(); pcc!=pccList.end(); pcc++) {
406 CIccProfile *pPccProfile = *pcc;
412 SrcspaceSig = namedCmm.GetSourceSpace();
417 if (bInputProfile &&
IsSpacePCS(SrcspaceSig)) {
423 if (srcEncoding == icEncodeFloat)
432 char SrcNameBuf[256], DestNameBuf[256];
433 CIccPixelBuf SrcPixel(nSrcSamples+16), DestPixel(nDestSamples+16), Pixel(
icIntMax(nSrcSamples, nDestSamples)+16);
437 outData.
m_space = DestspaceSig;
441 destEncoding = icEncodeValue;
447 srcEncoding = icEncodeValue;
451 for (
auto dataIter = cfgData.
m_data.begin(); dataIter != cfgData.
m_data.end(); dataIter++) {
464 out->m_srcName = pData->
m_name;
478 switch(namedCmm.GetInterface()) {
479 case icApplyNamed2Pixel:
482 if(namedCmm.Apply(DestPixel,
szName, tint)) {
483 printf(
"Profile application failed.\n");
487 if(CIccCmm::FromInternalEncoding(DestspaceSig, destEncoding, DestPixel, DestPixel, destEncoding!=icEncodeFloat)) {
488 printf(
"Invalid final data encoding\n");
492 for(i = 0; i<nDestSamples; i++) {
493 out->m_values.push_back(DestPixel[i]);
497 case icApplyNamed2Named:
499 if(namedCmm.Apply(DestNameBuf, SrcNameBuf, tint)) {
500 printf(
"Profile application failed.\n");
504 out->m_name = DestNameBuf;
507 case icApplyPixel2Pixel:
508 case icApplyPixel2Named:
510 printf(
"Incorrect interface.\n");
515 for (i = 0; i < nSrcSamples && i < pData->
m_values.size(); i++) {
521 if(CIccCmm::ToInternalEncoding(SrcspaceSig, srcEncoding, SrcPixel, Pixel, bClip)) {
522 printf(
"Invalid source data encoding\n");
526 switch(namedCmm.GetInterface()) {
527 case icApplyPixel2Pixel:
530 if (pMruCmm->Apply(DestPixel, SrcPixel)) {
531 printf(
"Profile application failed.\n");
535 else if(namedCmm.Apply(DestPixel, SrcPixel)) {
536 printf(
"Profile application failed.\n");
539 if(CIccCmm::FromInternalEncoding(DestspaceSig, destEncoding, DestPixel, DestPixel)) {
540 printf(
"Invalid final data encoding\n");
544 for(i = 0; i<nDestSamples; i++) {
545 out->m_values.push_back(DestPixel[i]);
549 case icApplyPixel2Named:
551 if(namedCmm.Apply(DestNameBuf, SrcPixel)) {
552 printf(
"Profile application failed.\n");
555 out->m_name = DestNameBuf;
558 case icApplyNamed2Pixel:
559 case icApplyNamed2Named:
561 printf(
"Incorrect interface.\n");
567 out->m_debugInfo = pDebugger->m_log;
569 outData.
m_data.push_back(out);
586 out[
"appliedProfileSequence"] = seq;
590 if (data.is_object())
591 out[
"colorData"] = data;
600 printf(
"Unsupported output format\n");
std::vector< icFloatNumber > m_srcValues
std::vector< icFloatNumber > m_values