Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
CIccCfgColorData Class Reference

#include <IccCmmConfig.h>

+ Collaboration diagram for CIccCfgColorData:

Public Member Functions

 CIccCfgColorData ()
 
bool fromIt8 (const char *filename, bool bReset=false)
 
bool fromJson (json obj, bool bReset=false)
 
bool fromLegacy (const char *filename, bool bReset=false)
 
void reset ()
 
bool toIt8 (const char *filename, icUInt8Number nDigits, icUInt8Number nPrecision)
 
void toJson (json &obj) const
 
bool toLegacy (const char *filename, CIccCfgProfileSequence *pProfiles, icUInt8Number nDigits, icUInt8Number nPrecision, bool bShowDebug=false)
 
virtual ~CIccCfgColorData ()
 

Public Attributes

CIccCfgDataEntryList m_data
 
icFloatColorEncoding m_encoding
 
icColorSpaceSignature m_space
 
icFloatColorEncoding m_srcEncoding
 
icColorSpaceSignature m_srcSpace
 

Protected Member Functions

void addFields (std::string &dataFormat, int &nFields, int &nSamples, icColorSpaceSignature sig, std::string prefix)
 
std::string spaceName (icColorSpaceSignature sig)
 

Detailed Description

Definition at line 163 of file IccCmmConfig.h.

Constructor & Destructor Documentation

◆ CIccCfgColorData()

CIccCfgColorData::CIccCfgColorData ( )

Definition at line 894 of file IccCmmConfig.cpp.

895{
896 reset();
897}

References reset().

+ Here is the call graph for this function:

◆ ~CIccCfgColorData()

virtual CIccCfgColorData::~CIccCfgColorData ( )
inlinevirtual

Definition at line 167 of file IccCmmConfig.h.

167{}

Member Function Documentation

◆ addFields()

void CIccCfgColorData::addFields ( std::string & dataFormat,
int & nFields,
int & nSamples,
icColorSpaceSignature sig,
std::string prefix )
protected

Definition at line 1520 of file IccCmmConfig.cpp.

1521{
1522 std::string tabStr = "\t";
1523 char buf[32];
1524
1525 switch (sig) {
1526 case icSigRgbData:
1527 nSamples = 3;
1528 if (nFields) dataFormat += tabStr;
1529 dataFormat += prefix + "RGB_R";
1530 dataFormat += tabStr + prefix + "RGB_G";
1531 dataFormat += tabStr + prefix + "RGB_B";
1532 nFields += nSamples;
1533 return;
1534 case icSigCmykData:
1535 nSamples = 4;
1536 if (nFields) dataFormat += tabStr;
1537 dataFormat += prefix + "CMYK_C";
1538 dataFormat += tabStr + prefix + "CMYK_M";
1539 dataFormat += tabStr + prefix + "CMYK_Y";
1540 dataFormat += tabStr + prefix + "CMYK_K";
1541 nFields += nSamples;
1542 return;
1543 case icSigDevLabData:
1544 case icSigLabData:
1545 nSamples += 3;
1546 if (nFields) dataFormat += tabStr;
1547 dataFormat += prefix + "LAB_L";
1548 dataFormat += tabStr + prefix + "LAB_A";
1549 dataFormat += tabStr + prefix + "LAB_B";
1550 nFields += nSamples;
1551 return;
1552 case icSigDevXYZData:
1553 case icSigXYZData:
1554 nSamples += 3;
1555 if (nFields) dataFormat += tabStr;
1556 dataFormat += prefix + "XYZ_X";
1557 dataFormat += tabStr + prefix + "XYZ_Y";
1558 dataFormat += tabStr + prefix + "XYZ_Z";
1559 nFields += 3;
1560 return;
1561 case icSigNamedData:
1562 nSamples += 1;
1563 if (nFields) dataFormat += tabStr;
1564 dataFormat += prefix + "TINT";
1565 nFields += nSamples;
1566 return;
1567 default:
1568 nSamples = icGetSpaceSamples(sig);
1569 if (nFields) dataFormat += tabStr;
1570 for (int i = 0; i < nSamples; i++) {
1571 sprintf(buf, "%dCOLOR_%d", nSamples, i + 1);
1572 if (i)
1573 dataFormat += tabStr;
1574 dataFormat += buf;
1575 }
1576 nFields += nSamples;
1577 return;
1578 }
1579}
icArraySignature sig
#define icSigDevXYZData
Definition IccDefs.h:92
#define icSigDevLabData
Additional convenience color space signatures to distinguish between device encoding and PCS encoding...
Definition IccDefs.h:91
icUInt32Number icGetSpaceSamples(icColorSpaceSignature sig)
Definition IccUtil.cpp:1303
@ icSigLabData
@ icSigXYZData
@ icSigNamedData
@ icSigCmykData
@ icSigRgbData

References icGetSpaceSamples(), icSigCmykData, icSigDevLabData, icSigDevXYZData, icSigLabData, icSigNamedData, icSigRgbData, icSigXYZData, and sig.

Referenced by toIt8().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromIt8()

bool CIccCfgColorData::fromIt8 ( const char * filename,
bool bReset = false )

Definition at line 1087 of file IccCmmConfig.cpp.

1088{
1089 if (bReset)
1090 reset();
1091
1092 CIccIt8Parser f;
1093
1094 if (!f.open(filename))
1095 return false;
1096
1097 std::vector<std::string> line;
1098 if (!f.findTokenLine(line, "CGATS.17"))
1099 return false;
1100 if (!f.findTokenLine(line, "NUBER_OF_FIELDS"))
1101 return false;
1102 int nFields = 0;
1103 if (line.size() >= 2) {
1104 nFields = atoi(line[1].c_str());
1105 }
1106 if (!f.findTokenLine(line, "BEGIN_DATA_FORMAT"))
1107 return false;
1108 if (!f.parseNextLine(line)) {
1109 return false;
1110 }
1111 if (line.size() != nFields)
1112 return false;
1113
1114 std::string lastSpace;
1115 std::vector<icValueVector> samples;
1116 std::vector<std::string> spaces;
1117 std::vector<icIndexName> names;
1118 int nSpace = 0;
1119 int nName = 0;
1120
1121 int nId = -1;
1122 int nLabel = -1;
1123
1124 int index = 0;
1125 for (auto fmt = line.begin(); fmt != line.end(); fmt++, index++) {
1126 if (*fmt == "SAMPLE_ID") {
1127 nId = index;
1128 }
1129 else if (*fmt == "SAMPLE_NAME") {
1130 nLabel = index;
1131 }
1132 else {
1133 std::string space;
1134 const char* szFmt = fmt->c_str();
1135 if (!strncmp(szFmt, "SRC_", 4)) {
1136 space += "SRC_";
1137 szFmt += 4;
1138 }
1139 if (!strcmp(szFmt, "NAME")) {
1140 space += "NAME";
1141 names.push_back(icIndexName(index, space));
1142 }
1143 else if (!strncmp(szFmt, "TINT", 4)) {
1144 space += "TINT";
1145 if (space != lastSpace) {
1146 icValueVector val(1);
1147 val[0].nIndex = index;
1148 val[0].space = icSigNamedData;
1149 samples.push_back(val);
1150 lastSpace = "";
1151 }
1152 }
1153 else if (!strncmp(szFmt, "RGB_", 4)) {
1154 space += "RGB";
1155 szFmt += 4;
1156 if (space != lastSpace) {
1157 lastSpace = space;
1158 icValueVector val(3);
1159 val[0].space = icSigRgbData;
1160 samples.push_back(val);
1161 spaces.push_back(space);
1162 }
1163 const char* szChannels[] = { "R", "G", "B" };
1164 setSampleIndex(samples, index, szFmt, &szChannels[0]);
1165 }
1166 else if (!strncmp(szFmt, "CMYK_", 5)) {
1167 space += "CMYK";
1168 szFmt += 5;
1169 if (space != lastSpace) {
1170 lastSpace = space;
1171 icValueVector val(4);
1172 val[0].space = icSigCmykData;
1173 spaces.push_back(space);
1174 }
1175 const char* szChannels[] = { "C", "M", "Y", "K" };
1176 setSampleIndex(samples, index, szFmt, &szChannels[0]);
1177 }
1178 else if (!strncmp(szFmt, "LAB_", 4)) {
1179 space += "LAB";
1180 szFmt += 4;
1181 if (space != lastSpace) {
1182 lastSpace = space;
1183 icValueVector val(4);
1184 val[0].space = icSigLabData;
1185 samples.push_back(val);
1186 spaces.push_back(space);
1187 }
1188 const char* szChannels[] = { "L", "A", "B" };
1189 setSampleIndex(samples, index, szFmt, &szChannels[0]);
1190 }
1191 else if (!strncmp(szFmt, "XYZ_", 4)) {
1192 space += "XYZ";
1193 szFmt += 4;
1194 if (space != lastSpace) {
1195 lastSpace = space;
1196 icValueVector val(4);
1197 val[0].space = icSigXYZData;
1198 samples.push_back(val);
1199 spaces.push_back(space);
1200 }
1201 const char* szChannels[] = { "X", "Y", "Z" };
1202 setSampleIndex(samples, index, szFmt, &szChannels[0]);
1203 }
1204 else {
1205 int nColor = -1;
1206 if (sscanf(szFmt, "%uCOLOR_", &nColor) && nColor >= 1) {
1207 char buf[30];
1208 sprintf(buf, "%uCOLOR", nColor);
1209 space += buf;
1210
1211 if (space != lastSpace) {
1212 lastSpace = space;
1213 icValueVector val(nColor);
1214 val[0].space = (icColorSpaceSignature)(icSigNChannelData + (nColor & 0xffff));
1215 samples.push_back(val);
1216 spaces.push_back(space);
1217 }
1218
1219 szFmt = strchr(szFmt, '_');
1220 if (szFmt) {
1221 szFmt++;
1222 int nChannel = atoi(szFmt);
1223 size_t last = samples.size() - 1;
1224 if (nChannel > 0 && samples[last].size() >= nChannel) {
1225 samples[samples.size() - 1][nChannel - 1].nIndex = index;
1226 }
1227 }
1228 }
1229 }
1230 }
1231 }
1232
1233 if (!f.findTokenLine(line, "END_DATA_FORMAT"))
1234 return false;
1235
1236 if (!f.findTokenLine(line, "NUMBER_OF_SETS"))
1237 return false;
1238
1239 int nSets = 0;
1240 if (line.size() > 1) {
1241 nSets = atoi(line[1].c_str());
1242 }
1243
1244 if (!f.findTokenLine(line, "BEGIN_DATA"))
1245 return false;
1246
1247 do {
1248 if (!f.parseNextLine(line) || line[0] == "END_DATA")
1249 break;
1251
1252 if (nId >= 0 && nId < line.size()) {
1253 pData->m_index = atoi(line[nId].c_str());
1254 }
1255 else if (nLabel >= 0 && nLabel < line.size()) {
1256 pData->m_label = line[nLabel];
1257 }
1258
1259 if (names.size() > 0) {
1260 if (names[0].second == "NAME") {
1261 if (names[0].first >= 0)
1262 pData->m_name = line[names[0].first];
1263 if (names.size() > 1) {
1264 if (names[1].first >= 0)
1265 pData->m_srcName = line[names[1].first];
1266 }
1267 }
1268 else if (names[0].second == "SRC_NAME") {
1269 if (names[0].first >= 0)
1270 pData->m_srcName = line[names[0].first];
1271 if (names.size() > 1) {
1272 if (names[1].first >= 0)
1273 pData->m_name = line[names[1].first];
1274 }
1275 }
1276 }
1277
1278 int nValueIdx;
1279 for (nValueIdx = 0; nValueIdx < samples.size(); nValueIdx++) {
1280 if (samples[nValueIdx][0].space == m_space)
1281 break;
1282 }
1283 if (nValueIdx != samples.size()) {
1284 for (int i = 0; i < samples[nValueIdx].size(); i++) {
1285 int nPos = samples[nValueIdx][i].nIndex;
1286 if (nPos < line.size()) {
1287 pData->m_values.push_back((icFloatNumber)atof(line[nPos].c_str()));
1288 }
1289 }
1290 }
1291 else {
1292 for (nValueIdx = 0; nValueIdx < spaces.size(); nValueIdx++) {
1293 if (strncmp(spaces[nValueIdx].c_str(), "SRC_", 4))
1294 break;
1295 }
1296 if (nValueIdx != spaces.size() && nValueIdx < samples.size()) {
1297 m_space = samples[nValueIdx][0].space;
1298 for (int j = 0; j < samples[nValueIdx].size(); j++) {
1299 int nPos = samples[nValueIdx][j].nIndex;
1300 if (nPos < line.size()) {
1301 pData->m_values.push_back((icFloatNumber)atof(line[nPos].c_str()));
1302 }
1303 }
1304 }
1305 }
1306
1307 int nSrcIndex;
1308 for (nSrcIndex = 0; nSrcIndex < samples.size(); nSrcIndex++) {
1309 if (samples[nSrcIndex][0].space == m_srcSpace)
1310 break;
1311 }
1312 if (nSrcIndex != samples.size() && nSrcIndex != nValueIdx) {
1313 for (int i = 0; i < samples[nSrcIndex].size(); i++) {
1314 int nPos = samples[nSrcIndex][i].nIndex;
1315 if (nPos < line.size()) {
1316 pData->m_values.push_back((icFloatNumber)atof(line[nPos].c_str()));
1317 }
1318 }
1319 }
1320 else {
1321 for (nSrcIndex = 0; nSrcIndex < spaces.size(); nSrcIndex++) {
1322 if (!strncmp(spaces[nValueIdx].c_str(), "SRC_", 4))
1323 break;
1324 }
1325 if (nSrcIndex != spaces.size() && nSrcIndex < samples.size()) {
1326 m_srcSpace = samples[nSrcIndex][0].space;
1327 for (int j = 0; j < samples[nValueIdx].size(); j++) {
1328 int nPos = samples[nValueIdx][j].nIndex;
1329 if (nPos < line.size()) {
1330 pData->m_srcValues.push_back((icFloatNumber)atof(line[nPos].c_str()));
1331 }
1332 }
1333 }
1334 else {
1335 for (nSrcIndex = 0; nSrcIndex < samples.size(); nSrcIndex++) {
1336 if (nSrcIndex != nValueIdx)
1337 break;
1338 }
1339 if (nSrcIndex < samples.size()) {
1340 m_srcSpace = samples[nSrcIndex][0].space;
1341 for (int j = 0; j < samples[nValueIdx].size(); j++) {
1342 int nPos = samples[nValueIdx][j].nIndex;
1343 if (nPos < line.size()) {
1344 pData->m_srcValues.push_back((icFloatNumber)atof(line[nPos].c_str()));
1345 }
1346 }
1347 }
1348 }
1349 }
1350
1351 if (pData->m_values.size() || pData->m_srcValues.size() || pData->m_name.size() || pData->m_srcName.size())
1352 m_data.push_back(pData);
1353 else
1354 pData.reset();
1355
1356 } while (!f.isEOF());
1357
1358 return m_data.size() == nSets;
1359}
std::pair< int, std::string > icIndexName
std::vector< CIccIndexValue > icValueVector
static void setSampleIndex(std::vector< icValueVector > &samples, int index, const char *szFmt, const char **szChannels)
std::shared_ptr< CIccCfgDataEntry > CIccCfgDataEntryPtr
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
Definition IccDefs.h:100
icColorSpaceSignature m_srcSpace
CIccCfgDataEntryList m_data
icColorSpaceSignature m_space
bool open(const char *szFilename)
bool findTokenLine(std::vector< std::string > &line, const char *szToken)
bool parseNextLine(std::vector< std::string > &line)
icColorSpaceSignature
Color Space Signatures.
@ icSigNChannelData

References CIccIt8Parser::findTokenLine(), icSigCmykData, icSigLabData, icSigNamedData, icSigNChannelData, icSigRgbData, icSigXYZData, CIccIt8Parser::isEOF(), m_data, m_space, m_srcSpace, CIccIt8Parser::open(), CIccIt8Parser::parseNextLine(), reset(), and setSampleIndex().

+ Here is the call graph for this function:

◆ fromJson()

bool CIccCfgColorData::fromJson ( json obj,
bool bReset = false )

Definition at line 1361 of file IccCmmConfig.cpp.

1362{
1363 if (!j.is_object())
1364 return false;
1365
1366 if (bReset)
1367 reset();
1368
1369 std::string str;
1370
1371 jsonToColorSpace(j["space"], m_space);
1372 if (jsonToValue(j["encoding"], str))
1373 m_encoding = icSetJsonColorEncoding(str.c_str());
1374
1375 jsonToColorSpace(j["srcSpace"], m_srcSpace);
1376 if (jsonToValue(j["srcEncoding"], str))
1378
1379 if (j.find("data")!=j.end()) {
1380 json data = j["data"];
1381 if (data.is_array()) {
1382 for (auto d = data.begin(); d != data.end(); d++) {
1383 if (d->is_object()) {
1385 if (entry->fromJson(*d)) {
1386 m_data.push_back(entry);
1387 }
1388 else
1389 entry.reset();
1390 }
1391 }
1392 }
1393 }
1394
1395 return true;
1396}
bool jsonToValue(const json &j, icFloatColorEncoding &v)
icFloatColorEncoding icSetJsonColorEncoding(const char *szEncode)
bool jsonToColorSpace(const json &j, icColorSpaceSignature &sig)
icFloatColorEncoding m_srcEncoding
icFloatColorEncoding m_encoding

References icSetJsonColorEncoding(), jsonToColorSpace(), jsonToValue(), m_data, m_encoding, m_space, m_srcEncoding, m_srcSpace, and reset().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromLegacy()

bool CIccCfgColorData::fromLegacy ( const char * filename,
bool bReset = false )

Definition at line 977 of file IccCmmConfig.cpp.

978{
979 if (bReset)
980 reset();
981
982 std::ifstream InputData(filename);
983
984 if (!InputData) {
985 return false;
986 }
987
988 icChar ColorSig[7], *tempBuf = new icChar[20000];
989 if (!tempBuf)
990 return false;
991 InputData.getline(tempBuf, sizeof(tempBuf));
992
993 int i;
994 for (i = 0; (i < 4 || tempBuf[i + 1] != '\'') && i < 6; i++) {
995 ColorSig[i] = tempBuf[i + 1];
996 }
997 for (; i < 7; i++)
998 ColorSig[i] = '\0';
999
1000 //Init source number of samples from color signature is source data file
1002 int nSamples = icGetSpaceSamples(m_srcSpace);
1003 if (m_srcSpace != icSigNamedData) {
1004 if (!nSamples) {
1005 delete[] tempBuf;
1006 return false;
1007 }
1008 }
1009
1010 InputData.getline(tempBuf, sizeof(tempBuf));
1011 sscanf(tempBuf, "%s", tempBuf);
1012
1013 //Setup source encoding
1014 m_encoding = CIccCmm::GetFloatColorEncoding(tempBuf);
1015 if (m_encoding == icEncodeUnknown) {
1016 delete[] tempBuf;
1017 return false;
1018 }
1019 char SrcNameBuf[256];
1020 int nSrcSamples = icGetSpaceSamples(m_srcSpace);
1021 CIccPixelBuf Pixel(nSrcSamples + 16);
1022
1023 while (!InputData.eof()) {
1025
1026 //Are names coming is as an input?
1027 if (m_srcSpace == icSigNamedData) {
1028 InputData.getline(tempBuf, sizeof(tempBuf));
1029 if (!ParseName(SrcNameBuf, tempBuf))
1030 continue;
1031
1032 data->m_name = SrcNameBuf;
1033
1034 icChar* numptr = strstr(tempBuf, "\" }");
1035 if (numptr)
1036 numptr += 3;
1037
1038 icFloatNumber tint;
1039 if (!ParseNextNumber(tint, &numptr))
1040 tint = 1.0;
1041 data->m_values.push_back(tint);
1042 }
1043 else { //pixel sample data coming in as input
1044
1045 InputData.getline(tempBuf, sizeof(tempBuf));
1046 if (!ParseNumbers(Pixel, tempBuf, nSamples))
1047 continue;
1048
1049 for (int n = 0; n < nSamples; n++) {
1050 data->m_values.push_back(Pixel[n]);
1051 }
1052 }
1053
1054 m_data.push_back(data);
1055 }
1056 delete[] tempBuf;
1057 return true;
1058}
static bool ParseNextNumber(icFloatNumber &num, icChar **text)
static bool ParseName(icChar *pName, icChar *pString)
static bool ParseNumbers(icFloatNumber *pData, icChar *pString, icUInt32Number nSamples)
char icChar
Definition IccDefs.h:109
icUInt32Number icGetSigVal(const icChar *pBuf)
Definition IccUtil.cpp:1258

References icGetSigVal(), icGetSpaceSamples(), icSigNamedData, m_data, m_encoding, m_srcSpace, ParseName(), ParseNextNumber(), ParseNumbers(), and reset().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

void CIccCfgColorData::reset ( )

Definition at line 899 of file IccCmmConfig.cpp.

900{
902 m_encoding = icEncodeValue;
903
905 m_srcEncoding = icEncodeValue;
906
907 m_data.clear();
908}
#define icSigUnknownData

References icSigUnknownData, m_data, m_encoding, m_space, m_srcEncoding, and m_srcSpace.

Referenced by CIccCfgColorData(), fromIt8(), fromJson(), and fromLegacy().

+ Here is the caller graph for this function:

◆ spaceName()

std::string CIccCfgColorData::spaceName ( icColorSpaceSignature sig)
protected

Definition at line 1495 of file IccCmmConfig.cpp.

1496{
1497 switch (sig) {
1498 case icSigRgbData:
1499 return "RGB";
1500 case icSigCmykData:
1501 return "CMYK";
1502 case icSigDevXYZData:
1503 case icSigXYZData:
1504 return "XYZ";
1505 case icSigDevLabData:
1506 case icSigLabData:
1507 return "LAB";
1508 case icSigNamedData:
1509 return "TINT";
1510 default:
1511 {
1512 int nSamples = icGetSpaceSamples(sig);
1513 char buf[32];
1514 sprintf(buf, "%dCOLOR", nSamples);
1515 return buf;
1516 }
1517 }
1518}

References icGetSpaceSamples(), icSigCmykData, icSigDevLabData, icSigDevXYZData, icSigLabData, icSigNamedData, icSigRgbData, icSigXYZData, and sig.

Referenced by toIt8().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toIt8()

bool CIccCfgColorData::toIt8 ( const char * filename,
icUInt8Number nDigits,
icUInt8Number nPrecision )

Definition at line 1581 of file IccCmmConfig.cpp.

1582{
1583 if (!m_data.size())
1584 return false;
1585
1586 FILE* f;
1587 char fmt[64];
1588 if (!nDigits)
1589 sprintf(fmt, " %%.%df", nPrecision);
1590 else
1591 sprintf(fmt, " %%%d.%df", nDigits, nPrecision);
1592
1593 auto first = m_data.begin();
1594 CIccCfgDataEntry* pEntry = first->get();
1595
1596 std::string dataFormat;
1597 int nFields = 0;
1598 bool bShowIndex = false;
1599 bool bShowLabel = false;
1600 bool bShowSrcName = false;
1601 bool bShowSrcValues = false;
1602 bool bShowName = false;
1603 bool bShowValues = false;
1604
1605 int nSrcSamples = 0, nDstSamples = 0;
1606
1607 if (pEntry->m_index >= 0) {
1608 dataFormat = "INDEX";
1609 nFields = 1;
1610 bShowIndex = true;
1611 }
1612
1613 if (pEntry->m_label.size()) {
1614 if (nFields) dataFormat+="\t";
1615 dataFormat += "SAMPLE_ID";
1616 nFields++;
1617 bShowLabel = true;
1618 }
1619
1620 bool bSameSpace = spaceName(m_space) == spaceName(m_srcSpace);
1621
1622 if (pEntry->m_name.size()) {
1623 if (nFields) dataFormat += "\t";
1624 dataFormat += "NAME";
1625 nFields++;
1626 bShowName = true;
1627 }
1628
1629 if (m_space != icSigUnknownData) {
1630 addFields(dataFormat, nFields, nDstSamples, m_space, "");
1631 if (nDstSamples)
1632 bShowValues = true;
1633 }
1634
1635 if (pEntry->m_srcName.size()) {
1636 if (nFields) dataFormat += "\t";
1637 if (bSameSpace)
1638 dataFormat += "SRC_";
1639 dataFormat += "NAME";
1640 nFields++;
1641 bShowSrcName = true;
1642 }
1643
1645 addFields(dataFormat, nFields, nSrcSamples, m_srcSpace, bSameSpace ? "SRC_" : "");
1646 if (nSrcSamples)
1647 bShowSrcValues = true;
1648 }
1649
1650 if (!nFields)
1651 return false;
1652
1653 if (!filename || !filename[0])
1654 f = stdout;
1655 else
1656 f = fopen(filename, "wt");
1657
1658 if (!f)
1659 return false;
1660
1661 fprintf(f, "CGATS.17\n");
1662 fprintf(f, "ORIGINATOR\t\"DemoIccMAX\"\n");
1663 fprintf(f, "FILE_DESCRIPTOR\t\"Color Data\"\n");
1664
1665 fprintf(f, "NUMBER_OF_FIELDS\t%d\n", nFields);
1666 fprintf(f, "BEGIN_DATA_FORMAT\n");
1667 fprintf(f, "%s\n", dataFormat.c_str());
1668 fprintf(f, "END_DATA_FORMAT\n");
1669 fprintf(f, "NUMBER_OF_SETS\t%u\n", (int)m_data.size());
1670
1671 CIccCfgDataEntry blank;
1672 char buf[256];
1673
1674 fprintf(f, "BEGIN_DATA\n");
1675 for (auto e = m_data.begin(); e != m_data.end(); e++) {
1676 std::string line;
1677
1678 CIccCfgDataEntry* pEntry = e->get();
1679 if (!pEntry)
1680 pEntry = &blank;
1681
1682 if (bShowIndex) {
1683 sprintf(buf, "%d", pEntry->m_index);
1684 line += buf;
1685 }
1686
1687 if (bShowLabel) {
1688 if (line.size()) line += "\t";
1689 if (!pEntry->m_label.size())
1690 line += "\"\"";
1691 else
1692 line += pEntry->m_label;
1693 }
1694
1695 if (bShowName) {
1696 if (line.size()) line += "\t";
1697 if (!pEntry->m_name.size())
1698 line += "\"\"";
1699 else
1700 line += pEntry->m_name;
1701 }
1702
1703 if (bShowValues) {
1704 if (line.size()) line += "\t";
1705 for (int i = 0; i < nDstSamples; i++) {
1706 icFloatNumber v = i >= pEntry->m_values.size() ? 0 : pEntry->m_values[i];
1707 sprintf(buf, fmt, v);
1708 if (i)
1709 line += "\t";
1710 line += buf;
1711 }
1712 }
1713
1714 if (bShowSrcName) {
1715 if (line.size()) line += "\t";
1716 if (!pEntry->m_srcName.size())
1717 line += "\"\"";
1718 else
1719 line += pEntry->m_srcName;
1720 }
1721
1722 if (bShowSrcValues) {
1723 if (line.size()) line += "\t";
1724 for (int i = 0; i < nSrcSamples; i++) {
1725 icFloatNumber v = i >= pEntry->m_srcValues.size() ? 0 : pEntry->m_srcValues[i];
1726 sprintf(buf, fmt, v);
1727 if (i)
1728 line += "\t";
1729 line += buf;
1730 }
1731 }
1732
1733 fprintf(f, "%s\n", line.c_str());
1734 }
1735 fprintf(f, "END_DATA\n");
1736
1737 if (f != stdout)
1738 fclose(f);
1739
1740 return true;
1741}
void addFields(std::string &dataFormat, int &nFields, int &nSamples, icColorSpaceSignature sig, std::string prefix)
std::string spaceName(icColorSpaceSignature sig)
std::vector< icFloatNumber > m_srcValues
std::string m_srcName
int m_index
std::string m_label
std::vector< icFloatNumber > m_values
std::string m_name

References addFields(), icSigUnknownData, m_data, CIccCfgDataEntry::m_index, CIccCfgDataEntry::m_label, CIccCfgDataEntry::m_name, m_space, CIccCfgDataEntry::m_srcName, m_srcSpace, CIccCfgDataEntry::m_srcValues, CIccCfgDataEntry::m_values, and spaceName().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toJson()

void CIccCfgColorData::toJson ( json & obj) const

Definition at line 1743 of file IccCmmConfig.cpp.

1744{
1745 char buf[32];
1746 obj["space"] = icGetColorSigStr(buf, m_space);
1747 obj["encoding"] = icGetJsonFloatColorEncoding(m_encoding);
1748 obj["srcSpace"] = icGetColorSigStr(buf, m_srcSpace);
1749 obj["srcEncoding"] = icGetJsonFloatColorEncoding(m_srcEncoding);
1750
1751 json data;
1752 for (auto e = m_data.begin(); e != m_data.end(); e++) {
1753 CIccCfgDataEntry *pData = e->get();
1754 if (!pData)
1755 continue;
1756
1757 json entry;
1758 pData->toJson(entry);
1759 if (entry.is_object())
1760 data.push_back(entry);
1761 }
1762 if (data.is_array() && data.size()) {
1763 obj["data"] = data;
1764 }
1765}
static const icChar * icGetJsonFloatColorEncoding(icFloatColorEncoding val)
const icChar * icGetColorSigStr(icChar *pBuf, icUInt32Number nSig)
Definition IccUtil.cpp:1139
void toJson(json &obj)

References icGetColorSigStr(), icGetJsonFloatColorEncoding(), m_data, m_encoding, m_space, m_srcEncoding, m_srcSpace, and CIccCfgDataEntry::toJson().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toLegacy()

bool CIccCfgColorData::toLegacy ( const char * filename,
CIccCfgProfileSequence * pProfiles,
icUInt8Number nDigits,
icUInt8Number nPrecision,
bool bShowDebug = false )

Definition at line 1398 of file IccCmmConfig.cpp.

1399{
1400 FILE* f;
1401 char tempBuf[256];
1402 char fmt[20];
1403 if (!nDigits)
1404 sprintf(fmt, " %%.%df", nPrecision);
1405 else
1406 sprintf(fmt, " %%%d.%df", nDigits, nPrecision);
1407
1408 if (!filename || !filename[0])
1409 f = stdout;
1410 else
1411 f = fopen(filename, "wt");
1412
1413 if (!f)
1414 return false;
1415
1416 std::string out;
1417 sprintf(tempBuf, "%s\t; ", icGetColorSig(tempBuf, m_space, false));
1418 out = tempBuf;
1419 out += "Data Format\n";
1420 fwrite(out.c_str(), out.size(), 1, f);
1421
1422 sprintf(tempBuf, "%s\t; ", CIccCmm::GetFloatColorEncoding(m_encoding));
1423 out = tempBuf;
1424 out += "Encoding\n\n";
1425 fwrite(out.c_str(), out.size(), 1, f);
1426
1427 out = ";Source Data Format: ";
1428 sprintf(tempBuf, "%s\n", icGetColorSig(tempBuf, m_srcSpace, false));
1429 out += tempBuf;
1430 fwrite(out.c_str(), out.size(), 1, f);
1431
1432 out = ";Source Data Encoding: ";
1433 sprintf(tempBuf, "%s\n", CIccCmm::GetFloatColorEncoding(m_srcEncoding));
1434 out += tempBuf;
1435 fwrite(out.c_str(), out.size(), 1, f);
1436
1437 fprintf(f, ";Source data is after semicolon\n");
1438 if (pProfiles) {
1439 fprintf(f, "\n;Profiles applied\n");
1440 for (auto pIter = pProfiles->m_profiles.begin(); pIter != pProfiles->m_profiles.end(); pIter++) {
1441 CIccCfgProfile* pProf = pIter->get();
1442 if (!pProf)
1443 continue;
1444 if (pProf->m_pccFile.size()) {
1445 fprintf(f, "; %s -PCC %s\n", pProf->m_iccFile.c_str(), pProf->m_pccFile.c_str());
1446 }
1447 else {
1448 fprintf(f, "; %s\n", pProf->m_iccFile.c_str());
1449 }
1450 }
1451 }
1452 fprintf(f, "\n");
1453
1454 for (auto dIter = m_data.begin(); dIter != m_data.end(); dIter++) {
1455 CIccCfgDataEntry* pData = dIter->get();
1456 if (!pData)
1457 continue;
1458
1459 if (bShowDebug && pData->m_debugInfo.size()) {
1460 for (auto l = pData->m_debugInfo.begin(); l != pData->m_debugInfo.end(); l++) {
1461 fprintf(f, "; %s\n", l->c_str());
1462 }
1463 }
1464
1465 if (pData->m_name.size()) {
1466 fprintf(f, "{ \"%s\" }\t;", pData->m_name.c_str());
1467 }
1468 else {
1469 for (int i = 0; i < pData->m_values.size(); i++) {
1470 fprintf(f, fmt, pData->m_values[i]);
1471 }
1472 fprintf(f, "\t;");
1473 }
1474
1475 if (pData->m_srcName.size()) {
1476 fprintf(f,"{ \"%s\" }", pData->m_srcName.c_str());
1477 if (pData->m_srcValues.size() && pData->m_srcValues[0] != 1.0) {
1478 fprintf(f, fmt, pData->m_srcValues[0]);
1479 }
1480 }
1481 else {
1482 for (int i = 0; i < pData->m_srcValues.size(); i++) {
1483 fprintf(f, fmt, pData->m_srcValues[i]);
1484 }
1485 }
1486 fprintf(f, "\n");
1487 }
1488
1489 if (f != stdout)
1490 fclose(f);
1491
1492 return true;
1493}
const icChar * icGetColorSig(icChar *pBuf, icUInt32Number nSig, bool bGetHexVal)
Definition IccUtil.cpp:1088
std::list< std::string > m_debugInfo
std::string m_iccFile
std::string m_pccFile
CIccCfgProfileArray m_profiles

References icGetColorSig(), m_data, CIccCfgDataEntry::m_debugInfo, m_encoding, CIccCfgProfile::m_iccFile, CIccCfgDataEntry::m_name, CIccCfgProfile::m_pccFile, CIccCfgProfileSequence::m_profiles, m_space, m_srcEncoding, CIccCfgDataEntry::m_srcName, m_srcSpace, CIccCfgDataEntry::m_srcValues, and CIccCfgDataEntry::m_values.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_data

CIccCfgDataEntryList CIccCfgColorData::m_data

Definition at line 184 of file IccCmmConfig.h.

Referenced by fromIt8(), fromJson(), fromLegacy(), main(), reset(), toIt8(), toJson(), and toLegacy().

◆ m_encoding

icFloatColorEncoding CIccCfgColorData::m_encoding

Definition at line 179 of file IccCmmConfig.h.

Referenced by fromJson(), fromLegacy(), main(), reset(), toJson(), and toLegacy().

◆ m_space

icColorSpaceSignature CIccCfgColorData::m_space

Definition at line 178 of file IccCmmConfig.h.

Referenced by fromIt8(), fromJson(), main(), reset(), toIt8(), toJson(), and toLegacy().

◆ m_srcEncoding

icFloatColorEncoding CIccCfgColorData::m_srcEncoding

Definition at line 182 of file IccCmmConfig.h.

Referenced by fromJson(), main(), reset(), toJson(), and toLegacy().

◆ m_srcSpace

icColorSpaceSignature CIccCfgColorData::m_srcSpace

Definition at line 181 of file IccCmmConfig.h.

Referenced by fromIt8(), fromJson(), fromLegacy(), main(), reset(), toIt8(), toJson(), and toLegacy().


The documentation for this class was generated from the following files: