640{
641 int minargs = 10;
642 if(argc<minargs) {
644 return -1;
645 }
646
647 int nNumProfiles, temp;
648 temp = argc - minargs;
649
650
651 if(temp%2 != 0) {
652 printf("\nMissing arguments!\n");
654 return -1;
655 }
656
657 nNumProfiles = temp/2;
658
660 if (atoi(argv[2])) {
662 }
663 else {
665 }
666
667 if (!pLinkWriter) {
668 printf("Unable to allocate writer\n");
669 return -1;
670 }
671
673
674 pWriter->setFile(argv[1]);
675
676 int nLutSize = atoi(argv[3]);
677 pWriter->setLutSize(nLutSize);
678
679 pWriter->setOption(atoi(argv[4]));
680
681 pWriter->setTitle(argv[5]);
682
686 pWriter->setInputRange(loRange, hiRange);
687
688
689 bool bFirstTransform = atoi(argv[8]) != 0;
691
692 int nIntent, nType, nLuminance;
693
694
695
696
698
699
700
702
703 int i, nCount;
704 bool bUseD2BxB2DxTags;
707 bool bUseSubProfile;
708
709
710
711 for(i = 0, nCount=minargs; i<nNumProfiles; i++, nCount+=2) {
712#if defined(_WIN32) || defined(_WIN64)
713 if (!
strnicmp(argv[nCount],
"-ENV:", 5)) {
714#else
715 if (!strncasecmp(argv[nCount], "-ENV:", 5)) {
716#endif
719
721 }
722 else if (
stricmp(argv[nCount],
"-PCC")) {
723 bUseD2BxB2DxTags = true;
724 nIntent = atoi(argv[nCount+1]);
725 bUseSubProfile = (nIntent / 1000) > 0;
726 nIntent = nIntent % 1000;
727 nLuminance = nIntent / 100;
728 nIntent = nIntent % 100;
729 nType = abs(nIntent) / 10;
730 nIntent = nIntent % 10;
731 CIccProfile *pPccProfile = NULL;
732
733
734 CIccCreateXformHintManager Hint;
735 switch(nType) {
736 case 1:
737 nType = 0;
738 bUseD2BxB2DxTags = false;
739 break;
740 case 4:
741 nType = 0;
743 break;
744 }
745
746 if (nLuminance) {
747 Hint.AddHint(new CIccLuminanceMatchingHint());
748 }
749
750
751 if (i+1<nNumProfiles && !
stricmp(argv[nCount+2],
"-PCC")) {
753 if (!pPccProfile) {
754 printf("Unable to open Profile Connections Conditions from '%s'\n", argv[nCount+3]);
755 return -1;
756 }
757
758 pccList.push_back(pPccProfile);
759 }
760
761
762
763 if (sigMap.size()>0) {
765 }
766
767
768 CIccProfile* pXformProfile =
ReadIccProfile(argv[nCount], bUseSubProfile);
771 if (stat) {
772 printf("Invalid Profile(%d): %s\n", stat, argv[nCount]);
773 return -1;
774 }
775 sigMap.clear();
776
777 }
778 }
779
780
781 if((stat=theCmm.Begin())) {
782 printf("Error %d - Unable to begin profile application - Possibly invalid or incompatible profiles\n", stat);
783 return -1;
784 }
785
786 pWriter->setCmm(&theCmm);
787
788
789 IccProfilePtrList::iterator pcc;
790 for (pcc=pccList.begin(); pcc!=pccList.end(); pcc++) {
791 CIccProfile *pPccProfile = *pcc;
792 delete pPccProfile;
793 }
794 pccList.clear();
795
796 if (!pWriter->begin(theCmm.GetSourceSpace(), theCmm.GetDestSpace())) {
797 printf("Unable to begin writing LUT\n");
798 return -1;
799 }
800
801
804
805
808
809 int* idx = new int[nSrcSamples];
812
814
815 int curPer, lastPer = -1;
816
817
818 int lutCount = 1;
819 for (auto i = 0; i < nSrcSamples; i++) {
820 idx[i] = 0;
821 lutCount *= nLutSize;
822 }
823
824 int j = 0;
825 for (int c = 0; j >= 0; c++) {
826
827 for (auto i = 0; i < nSrcSamples; i++) {
828 srcPixel[i] = sizeRange * (
icFloatNumber)idx[i] / maxLut + loRange;
829 }
830
831
832 theCmm.Apply(dstPixel, srcPixel);
833
834 pWriter->setNextNode(dstPixel);
835
836 for (j = nSrcSamples - 1; j >= 0;) {
837 idx[j]++;
838 if (idx[j] >= nLutSize) {
839 idx[j] = 0;
840 j--;
841 }
842 else
843 break;
844 }
845
846
847 curPer = (int)((float)(c + 1) * 100.0f / (float)lutCount);
848 if (curPer != lastPer) {
849 printf("\r%d%%", curPer);
850 lastPer = curPer;
851 }
852 }
853
854 delete[] dstPixel;
855 delete[] srcPixel;
856 delete[] idx;
857
858 if (pWriter->finish()) {
859 printf("\nLUT successfully written to '%s'\n", argv[1]);
860 }
861 else {
862 printf("\nUnable to write LUT to '%s'\n", argv[1]);
863 }
864
865 return 0;
866}
icXformLutType
CMM Xform LUT types.
icXformInterp
CMM Interpolation types.
icStatusCMM
CMM return status values.
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
std::map< icSignature, icFloatNumber > icCmmEnvSigMap
CIccProfile * ReadIccProfile(const icChar *szFilename, bool bUseSubProfile)
Name: ReadIccProfile.
CIccProfile * OpenIccProfile(const icChar *szFilename, bool bUseSubProfile)
Name: OpenIccProfile.
icUInt32Number icGetSpaceSamples(icColorSpaceSignature sig)
icUInt32Number icGetSigVal(const icChar *pBuf)
unsigned int icUInt32Number
std::list< CIccProfile * > IccProfilePtrList
std::shared_ptr< ILinkWriter > LinkWriterPtr