150int main(
int argc,
const char** argv)
153 if (argc < minargs) {
161 if (argc > 2 && !
stricmp(argv[1],
"-cfg")) {
164 printf(
"Unable to read configuration from '%s'\n", argv[2]);
168 if (cfg.find(
"imageFiles") == cfg.end() || !cfgApply.
fromJson(cfg[
"imageFiles"])) {
169 printf(
"Unable to parse imageFiles configuration from '%s'\n", argv[2]);
173 if (cfg.find(
"profileSequence") == cfg.end() || !cfgProfiles.
fromJson(cfg[
"profileSequence"])) {
174 printf(
"Unable to parse profileSequence configuration from '%s'\n", argv[2]);
182 int nArg = cfgApply.
fromArgs(&argv[0], argc);
184 printf(
"Unable to parse configuration arguments\n");
191 nArg = cfgProfiles.
fromArgs(&argv[0], argc);
193 printf(
"Unable to parse profile sequence arguments\n");
200 unsigned int sn, sphoto, photo, bps, dbps;
202 unsigned char *sptr, *dptr;
203 bool bSuccess =
true;
204 bool bConvert =
false;
205 const char *last_path = NULL;
209 printf(
"\nFile [%s] cannot be opened.\n", cfgApply.
m_srcImgFile.c_str());
217 icFloatColorEncoding srcEncoding, destEncoding;
220 srcEncoding = icEncode8Bit;
223 srcEncoding = icEncode16Bit;
226 srcEncoding = icEncodeFloat;
229 printf(
"Source bit depth / color data encoding not supported.\n");
234 destEncoding = srcEncoding;
239 switch (destEncoding) {
250 printf(
"Source color data encoding not recognized.\n");
254 unsigned char* pSrcProfile;
255 unsigned int nSrcProfileLen;
256 bool bHasSrcProfile = SrcImg.
GetIccProfile(pSrcProfile, nSrcProfileLen);
278 for (
auto pProfIter = cfgProfiles.
m_profiles.begin(); pProfIter != cfgProfiles.
m_profiles.end(); bFirst=
false, pProfIter++) {
282 printf(
"Invalid Profile configuration!\n");
286 CIccProfile* pPccProfile = NULL;
289 CIccCreateXformHintManager Hint;
294 Hint.AddHint(
new CIccLuminanceMatchingHint());
300 printf(
"Unable to open Profile Connections Conditions from '%s'\n", pProfCfg->
m_pccFile.c_str());
304 pccList.push_back(pPccProfile);
317 if (bFirst && !pProfCfg->
m_iccFile.size()) {
318 if (bHasSrcProfile) {
327 printf(
"Invalid embedded profile in [%s]!\n", cfgApply.
m_srcImgFile.c_str());
332 printf(
"Source image doesn't have embedded profile!\n");
339 if (theCmm.AddXform(pProfCfg->
m_iccFile.c_str(),
347 printf(
"Invalid Profile: %s\n", pProfCfg->
m_iccFile.c_str());
355 if((stat=theCmm.Begin())) {
356 printf(
"Error %d - Unable to begin profile application - Possibly invalid or incompatible profiles\n", stat);
361 IccProfilePtrList::iterator pcc;
362 for (pcc=pccList.begin(); pcc!=pccList.end(); pcc++) {
363 CIccProfile *pPccProfile = *pcc;
372 if (nSrcSamples != (
int)sn) {
373 printf(
"Number of samples %d in image[%s] doesn't match device samples %d in first profile\n", sn, cfgApply.
m_srcImgFile.c_str(), nSrcSamples);
381 switch (DestspaceSig) {
409 unsigned long sbpp = (nSrcSamples * bps + 7) / 8;
410 unsigned long dbpp = (nDestSamples * dbps + 7)/ 8;
414 printf(
"Unable to create Tiff file - '%s'\n", cfgApply.
m_dstImgFile.c_str());
419 if (bEmbed && last_path) {
420 unsigned long length = 0;
424 if (io.
Open(last_path,
"r")) {
428 io.
Read8(pDestProfile, length);
437 unsigned char *pSBuf = (
unsigned char *)malloc(SrcImg.
GetBytesPerLine());
439 printf(
"Out of Memory!\n");
444 unsigned char *pDBuf = (
unsigned char *)malloc(DstImg.
GetBytesPerLine());
446 printf(
"Out of Memory!\n");
452 CIccPixelBuf SrcPixel(nSrcSamples+16), DestPixel(nDestSamples+16), Pixel(
icIntMax(nSrcSamples, nDestSamples)+16);
457 for (i=0; i<(int)SrcImg.
GetHeight(); i++) {
462 for (sptr=pSBuf, dptr=pDBuf, j=0; j<(int)SrcImg.
GetWidth(); j++, sptr+=sbpp, dptr+=dbpp) {
468 unsigned char *pSPixel = sptr;
475 unsigned char *pSPixel = sptr;
477 for (k=0; k<nSrcSamples; k++) {
485 unsigned short *pSPixel = (
unsigned short*)sptr;
492 unsigned short *pSPixel = (
unsigned short*)sptr;
494 for (k=0; k<nSrcSamples; k++) {
503 memcpy(SrcPixel.get(), sptr, sbpp);
508 for (k=0; k<nSrcSamples; k++) {
520 printf(
"Invalid source bit depth\n");
530 theCmm.Apply(DestPixel, SrcPixel);
541 unsigned char *pDPixel = dptr;
550 for (k=0; k<nDestSamples; k++) {
558 unsigned short *pDPixel = (
unsigned short*)dptr;
567 for (k=0; k<nDestSamples; k++) {
580 memcpy(dptr, DestPixel.get(), dbpp);
585 for (k=0; k<nDestSamples; k++) {
593 printf(
"Invalid source bit depth\n");
605 curper = (int)((
float)(i+1)*100.0f/(
float)SrcImg.
GetHeight());
606 if (curper !=lastPer) {
607 printf(
"\r%d%%", curper);
unsigned int icUInt32Number
bool Create(const char *szFname, unsigned int nWidth, unsigned int nHeight, unsigned int nBPS, unsigned int nPhoto, unsigned int nSamples, float fXRes, float fYRes, bool bCompress=true, bool bSep=false)