static void TakeCGATSValues(int nPatch, cmsFloat64Number Float[]) { // At first take the name if SAMPLE_ID is present if (cmsIT8GetPatchName(hIT8in, nPatch, CGATSPatch) == NULL) { FatalError("Sorry, I need 'SAMPLE_ID' on input CGATS to operate."); } // Special handling for named color profiles. // Lookup the name in the names database (the transform) if (InputNamedColor) { const cmsNAMEDCOLORLIST* NamedColorList; int index; NamedColorList = cmsGetNamedColorList(hTrans); if (NamedColorList == NULL) FatalError("Malformed named color profile"); index = cmsNamedColorIndex(NamedColorList, CGATSPatch); if (index < 0) FatalError("Named color '%s' not found in the profile", CGATSPatch); Float[0] = index; return; } // Color is not a spot color, proceed. switch (InputColorSpace) { // Encoding should follow CGATS specification. case cmsSigXYZData: Float[0] = cmsIT8GetDataDbl(hIT8in, CGATSPatch, "XYZ_X") / 100.0; Float[1] = cmsIT8GetDataDbl(hIT8in, CGATSPatch, "XYZ_Y") / 100.0; Float[2] = cmsIT8GetDataDbl(hIT8in, CGATSPatch, "XYZ_Z") / 100.0; break; case cmsSigLabData: Float[0] = cmsIT8GetDataDbl(hIT8in, CGATSPatch, "LAB_L"); Float[1] = cmsIT8GetDataDbl(hIT8in, CGATSPatch, "LAB_A"); Float[2] = cmsIT8GetDataDbl(hIT8in, CGATSPatch, "LAB_B"); break; case cmsSigRgbData: Float[0] = GetIT8Val("RGB_R", 255.0); Float[1] = GetIT8Val("RGB_G", 255.0); Float[2] = GetIT8Val("RGB_B", 255.0); break; case cmsSigGrayData: Float[0] = GetIT8Val("GRAY", 255.0); break; case cmsSigCmykData: Float[0] = GetIT8Val("CMYK_C", 1.0); Float[1] = GetIT8Val("CMYK_M", 1.0); Float[2] = GetIT8Val("CMYK_Y", 1.0); Float[3] = GetIT8Val("CMYK_K", 1.0); break; case cmsSigCmyData: Float[0] = GetIT8Val("CMY_C", 1.0); Float[1] = GetIT8Val("CMY_M", 1.0); Float[2] = GetIT8Val("CMY_Y", 1.0); break; case cmsSig1colorData: case cmsSig2colorData: case cmsSig3colorData: case cmsSig4colorData: case cmsSig5colorData: case cmsSig6colorData: case cmsSig7colorData: case cmsSig8colorData: case cmsSig9colorData: case cmsSig10colorData: case cmsSig11colorData: case cmsSig12colorData: case cmsSig13colorData: case cmsSig14colorData: case cmsSig15colorData: { cmsUInt32Number i, n; n = cmsChannelsOf(InputColorSpace); for (i=0; i < n; i++) { char Buffer[255]; sprintf(Buffer, "%uCLR_%u", n, i+1); Float[i] = GetIT8Val(Buffer, 100.0); } } break; default: { cmsUInt32Number i, n; n = cmsChannelsOf(InputColorSpace); for (i=0; i < n; i++) { char Buffer[255]; sprintf(Buffer, "CHAN_%u", i+1); Float[i] = GetIT8Val(Buffer, 1.0); } } } }
int parse_it8(const char *filename, chart_t *chart) { int result = 1; cmsHANDLE hIT8 = cmsIT8LoadFromFile(NULL, filename); if(!hIT8) { fprintf(stderr, "error loading IT8 file `%s'\n", filename); goto error; } if(cmsIT8TableCount(hIT8) != 1) { fprintf(stderr, "error with the IT8 file, we only support files with one table at the moment\n"); goto error; } dt_colorspaces_color_profile_type_t color_space = DT_COLORSPACE_NONE; int column_SAMPLE_ID = -1, column_X = -1, column_Y = -1, column_Z = -1, column_L = -1, column_a = -1, column_b = -1; char **sample_names = NULL; int n_columns = cmsIT8EnumDataFormat(hIT8, &sample_names); if(n_columns == -1) { fprintf(stderr, "error with the IT8 file, can't get column types\n"); goto error; } for(int i = 0; i < n_columns; i++) { if(!g_strcmp0(sample_names[i], "SAMPLE_ID")) column_SAMPLE_ID = i; else if(!g_strcmp0(sample_names[i], "XYZ_X")) column_X = i; else if(!g_strcmp0(sample_names[i], "XYZ_Y")) column_Y = i; else if(!g_strcmp0(sample_names[i], "XYZ_Z")) column_Z = i; else if(!g_strcmp0(sample_names[i], "LAB_L")) column_L = i; else if(!g_strcmp0(sample_names[i], "LAB_A")) column_a = i; else if(!g_strcmp0(sample_names[i], "LAB_B")) column_b = i; } if(column_SAMPLE_ID == -1) { fprintf(stderr, "error with the IT8 file, can't find the SAMPLE_ID column\n"); goto error; } char *columns[3] = { 0 }; if(column_X != -1 && column_Y != -1 && column_Z != -1) { color_space = DT_COLORSPACE_XYZ; columns[0] = "XYZ_X"; columns[1] = "XYZ_Y"; columns[2] = "XYZ_Z"; } else if(column_L != -1 && column_a != -1 && column_b != -1) { color_space = DT_COLORSPACE_LAB; columns[0] = "LAB_L"; columns[1] = "LAB_A"; columns[2] = "LAB_B"; } else { fprintf(stderr, "error with the IT8 file, can't find XYZ or Lab columns\n"); goto error; } GHashTableIter table_iter; gpointer key, value; g_hash_table_iter_init(&table_iter, chart->box_table); while(g_hash_table_iter_next(&table_iter, &key, &value)) { box_t *box = (box_t *)value; if(cmsIT8GetData(hIT8, key, "SAMPLE_ID") == NULL) { fprintf(stderr, "error with the IT8 file, can't find sample `%s'\n", (char *)key); goto error; } set_color(box, color_space, cmsIT8GetDataDbl(hIT8, key, columns[0]), cmsIT8GetDataDbl(hIT8, key, columns[1]), cmsIT8GetDataDbl(hIT8, key, columns[2])); } fprintf(stderr, "it8 `%s' done\n", filename); goto end; error: result = 0; end: if(hIT8) cmsIT8Free(hIT8); return result; }