// The main sink int main(int argc, char *argv[]) { cmsUInt16Number Output[cmsMAXCHANNELS]; cmsFloat64Number OutputFloat[cmsMAXCHANNELS]; cmsFloat64Number InputFloat[cmsMAXCHANNELS]; int nPatch = 0; fprintf(stderr, "LittleCMS ColorSpace conversion calculator - 4.3 [LittleCMS %2.2f]\n", LCMS_VERSION / 1000.0); InitUtils("transicc"); Verbose = 1; if (argc == 1) { Help(); return 0; } HandleSwitches(argc, argv); // Open profiles, create transforms if (!OpenTransforms()) return 1; // Open CGATS input if specified OpenCGATSFiles(argc, argv); // Main loop: read all values and convert them for(;;) { if (hIT8in != NULL) { if (nPatch >= nMaxPatches) break; TakeCGATSValues(nPatch++, InputFloat); } else { if (feof(stdin)) break; TakeFloatValues(InputFloat); } if (lIsFloat) cmsDoTransform(hTrans, InputFloat, OutputFloat, 1); else cmsDoTransform(hTrans, InputFloat, Output, 1); if (hIT8out != NULL) { PutCGATSValues(OutputFloat); } else { if (lIsFloat) { PrintFloatResults(OutputFloat); PrintPCSFloat(InputFloat); } else { PrintEncodedResults(Output); PrintPCSEncoded(InputFloat); } } } // Cleanup CloseTransforms(); if (hIT8in) cmsIT8Free(hIT8in); if (hIT8out) { cmsIT8SaveToFile(hIT8out, CGATSoutFilename); cmsIT8Free(hIT8out); } // All is ok return 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; }