IccMAX 2.1.27
Color Profile Tools
Loading...
Searching...
No Matches
CIccCfgColorData Class Reference

#include <IccCmmConfig.h>

Public Member Functions

 CIccCfgColorData ()
 
virtual ~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)
 

Data Fields

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

Constructor & Destructor Documentation

◆ CIccCfgColorData()

CIccCfgColorData::CIccCfgColorData ( )
895{
896 reset();
897}
void reset()
Definition IccCmmConfig.cpp:899

References reset().

+ Here is the call graph for this function:

◆ ~CIccCfgColorData()

virtual CIccCfgColorData::~CIccCfgColorData ( )
inlinevirtual
171{}

Member Function Documentation

◆ addFields()

void CIccCfgColorData::addFields ( std::string &  dataFormat,
int &  nFields,
int &  nSamples,
icColorSpaceSignature  sig,
std::string  prefix 
)
protected
1524{
1525 std::string tabStr = "\t";
1526 char buf[32];
1527
1528 switch (sig) {
1529 case icSigRgbData:
1530 nSamples = 3;
1531 if (nFields) dataFormat += tabStr;
1532 dataFormat += prefix + "RGB_R";
1533 dataFormat += tabStr + prefix + "RGB_G";
1534 dataFormat += tabStr + prefix + "RGB_B";
1535 nFields += nSamples;
1536 return;
1537 case icSigCmyData:
1538 nSamples = 3;
1539 if (nFields) dataFormat += tabStr;
1540 dataFormat += prefix + "CMY_C";
1541 dataFormat += tabStr + prefix + "CMY_M";
1542 dataFormat += tabStr + prefix + "CMY_Y";
1543 nFields += nSamples;
1544 return;
1545 case icSigCmykData:
1546 nSamples = 4;
1547 if (nFields) dataFormat += tabStr;
1548 dataFormat += prefix + "CMYK_C";
1549 dataFormat += tabStr + prefix + "CMYK_M";
1550 dataFormat += tabStr + prefix + "CMYK_Y";
1551 dataFormat += tabStr + prefix + "CMYK_K";
1552 nFields += nSamples;
1553 return;
1554 case icSigDevLabData:
1555 case icSigLabData:
1556 nSamples += 3;
1557 if (nFields) dataFormat += tabStr;
1558 dataFormat += prefix + "LAB_L";
1559 dataFormat += tabStr + prefix + "LAB_A";
1560 dataFormat += tabStr + prefix + "LAB_B";
1561 nFields += nSamples;
1562 return;
1563 case icSigDevXYZData:
1564 case icSigXYZData:
1565 nSamples += 3;
1566 if (nFields) dataFormat += tabStr;
1567 dataFormat += prefix + "XYZ_X";
1568 dataFormat += tabStr + prefix + "XYZ_Y";
1569 dataFormat += tabStr + prefix + "XYZ_Z";
1570 nFields += 3;
1571 return;
1572 case icSigNamedData:
1573 nSamples += 1;
1574 if (nFields) dataFormat += tabStr;
1575 dataFormat += prefix + "TINT";
1576 nFields += nSamples;
1577 return;
1578 default:
1579 nSamples = icGetSpaceSamples(sig);
1580 if (nFields) dataFormat += tabStr;
1581 for (int i = 0; i < nSamples; i++) {
1582 sprintf(buf, "%dCOLOR_%d", nSamples, i + 1);
1583 if (i)
1584 dataFormat += tabStr;
1585 dataFormat += buf;
1586 }
1587 nFields += nSamples;
1588 return;
1589 }
1590}
@ icSigLabData
Definition icProfileHeader.h:847
@ icSigXYZData
Definition icProfileHeader.h:846
@ icSigNamedData
Definition icProfileHeader.h:873
@ icSigCmykData
Definition icProfileHeader.h:855
@ icSigRgbData
Definition icProfileHeader.h:851
@ icSigCmyData
Definition icProfileHeader.h:856
#define icSigDevXYZData
Definition IccDefs.h:92
#define icSigDevLabData
Definition IccDefs.h:91
ICCPROFLIB_API icUInt32Number icGetSpaceSamples(icColorSpaceSignature sig)
Definition IccUtil.cpp:1303

References icGetSpaceSamples(), icSigCmyData, icSigCmykData, icSigLabData, icSigNamedData, icSigRgbData, and icSigXYZData.

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

References CIccIt8Parser::findTokenLine(), icSigCmykData, icSigLabData, icSigNamedData, icSigNChannelData, icSigRgbData, icSigXYZData, CIccIt8Parser::isEOF(), m_data, CIccCfgDataEntry::m_index, CIccCfgDataEntry::m_label, CIccCfgDataEntry::m_name, m_space, CIccCfgDataEntry::m_srcName, m_srcSpace, CIccCfgDataEntry::m_srcValues, CIccCfgDataEntry::m_values, CIccIndexValue::nIndex, CIccIt8Parser::open(), CIccIt8Parser::parseNextLine(), reset(), setSampleIndex(), and CIccIndexValue::space.

+ Here is the call graph for this function:

◆ fromJson()

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

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

References CIccCfgDataEntry::CIccCfgDataEntry(), CIccPixelBuf::CIccPixelBuf(), icGetSigVal(), icGetSpaceSamples(), icSigNamedData, m_data, m_encoding, CIccCfgDataEntry::m_name, m_srcSpace, CIccCfgDataEntry::m_values, CIccPixelBuf::operator[](), 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 ( )
900{
902 m_encoding = icEncodeValue;
903
905 m_srcEncoding = icEncodeValue;
906
907 m_data.clear();
908}
#define icSigUnknownData
Definition icProfileHeader.h:903

References 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
1497{
1498 switch (sig) {
1499 case icSigRgbData:
1500 return "RGB";
1501 case icSigCmyData:
1502 return "CMY";
1503 case icSigCmykData:
1504 return "CMYK";
1505 case icSigDevXYZData:
1506 case icSigXYZData:
1507 return "XYZ";
1508 case icSigDevLabData:
1509 case icSigLabData:
1510 return "LAB";
1511 case icSigNamedData:
1512 return "TINT";
1513 default:
1514 {
1515 int nSamples = icGetSpaceSamples(sig);
1516 char buf[32];
1517 sprintf(buf, "%dCOLOR", nSamples);
1518 return buf;
1519 }
1520 }
1521}

References icGetSpaceSamples(), icSigCmyData, icSigCmykData, icSigLabData, icSigNamedData, icSigRgbData, and icSigXYZData.

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

References addFields(), 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
1755{
1756 char buf[32];
1757 obj["space"] = icGetColorSigStr(buf, m_space);
1758 obj["encoding"] = icGetJsonFloatColorEncoding(m_encoding);
1759 obj["srcSpace"] = icGetColorSigStr(buf, m_srcSpace);
1760 obj["srcEncoding"] = icGetJsonFloatColorEncoding(m_srcEncoding);
1761
1762 json data;
1763 for (auto e = m_data.begin(); e != m_data.end(); e++) {
1764 CIccCfgDataEntry *pData = e->get();
1765 if (!pData)
1766 continue;
1767
1768 json entry;
1769 pData->toJson(entry);
1770 if (entry.is_object())
1771 data.push_back(entry);
1772 }
1773 if (data.is_array() && data.size()) {
1774 obj["data"] = data;
1775 }
1776}
ICCPROFLIB_API const icChar * icGetColorSigStr(icChar *pBuf, icUInt32Number nSig)
Definition IccUtil.cpp:1139
static const icChar * icGetJsonFloatColorEncoding(icFloatColorEncoding val)
Definition IccCmmConfig.cpp:77
void toJson(json &obj)
Definition IccCmmConfig.cpp:1816

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

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:

Field Documentation

◆ m_data

CIccCfgDataEntryList CIccCfgColorData::m_data

◆ m_encoding

icFloatColorEncoding CIccCfgColorData::m_encoding

◆ m_space

icColorSpaceSignature CIccCfgColorData::m_space

◆ m_srcEncoding

icFloatColorEncoding CIccCfgColorData::m_srcEncoding

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

◆ m_srcSpace

icColorSpaceSignature CIccCfgColorData::m_srcSpace

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