160 FILE *fp = g_fopen(filename,
"rb");
163 fprintf(stderr,
"error opening `%s'\n", filename);
173 unsigned int n_boxes;
178 float x_min = FLT_MAX, x_max = FLT_MIN, y_min = FLT_MAX, y_max = FLT_MIN;
183 if(line[0] ==
'\0' || line[0] ==
'\n')
188 if(skip_block)
continue;
192 ssize_t len = strlen(line);
195 if(!g_strcmp0(keyword,
"BOXES") && last_block <
BLOCK_BOXES)
198 if(c - line >= len)
ERROR;
204 if(line[0] ==
'\0' || line[0] ==
'\n')
break;
207 ssize_t len = strlen(line);
208 while(*c ==
' ') c++;
211 float x0, y0, x1, y1, x2, y2, x3, y3;
216 while(*c ==
' ') c++;
217 if(*c++ !=
'_')
ERROR;
218 while(*c ==
' ') c++;
219 if(*c++ !=
'_')
ERROR;
220 while(*c ==
' ') c++;
221 if(c - line >= len)
ERROR;
223 if(c - line >= len)
ERROR;
225 if(c - line >= len)
ERROR;
227 if(c - line >= len)
ERROR;
229 if(c - line >= len)
ERROR;
231 if(c - line >= len)
ERROR;
233 if(c - line >= len)
ERROR;
235 if(c - line >= len)
ERROR;
238 x_min =
MIN(x_min, x0);
239 x_min =
MIN(x_min, x1);
240 x_min =
MIN(x_min, x2);
241 x_min =
MIN(x_min, x3);
243 y_min =
MIN(y_min, y0);
244 y_min =
MIN(y_min, y1);
245 y_min =
MIN(y_min, y2);
246 y_min =
MIN(y_min, y3);
248 x_max =
MAX(x_max, x0);
249 x_max =
MAX(x_max, x1);
250 x_max =
MAX(x_max, x2);
251 x_max =
MAX(x_max, x3);
253 y_max =
MAX(y_max, y0);
254 y_max =
MAX(y_max, y1);
255 y_max =
MAX(y_max, y2);
256 y_max =
MAX(y_max, y3);
272 else if((*c ==
'D') || (*c ==
'X') || (*c ==
'Y'))
274 char kl, *lxs, *lxe, *lys, *lye;
275 float w, h, xo, yo, xi, yi;
279 if(c - line >= len)
ERROR;
281 if(c - line >= len)
ERROR;
283 if(c - line >= len)
ERROR;
285 if(c - line >= len)
ERROR;
288 if(c - line >= len)
ERROR;
290 if(c - line >= len)
ERROR;
292 if(c - line >= len)
ERROR;
294 if(c - line >= len)
ERROR;
296 if(c - line >= len)
ERROR;
298 if(c - line >= len)
ERROR;
301 x_min =
MIN(x_min, xo);
302 y_min =
MIN(y_min, yo);
305 size_t lxs_len = strlen(lxs), lxe_len = strlen(lxe), lys_len = strlen(lys), lye_len = strlen(lye);
306 if(lxs_len > lxe_len || lys_len > lye_len)
ERROR;
309 const size_t x_label_size = lxe_len + 1;
310 const size_t y_label_size = lye_len + 1;
312 char *x_label = malloc(x_label_size);
313 char *y_label = malloc(y_label_size);
315 char *first_label = NULL, *last_label = NULL;
316 GList *labels = NULL;
319 memcpy(y_label, lys, lys_len + 1);
323 memcpy(x_label, lxs, lxs_len + 1);
328 if(!g_strcmp0(x_label,
"_"))
329 label = g_strdup(y_label);
330 else if(!g_strcmp0(y_label,
"_"))
331 label = g_strdup(x_label);
335 label = g_strconcat(y_label, x_label, NULL);
337 label = g_strconcat(x_label, y_label, NULL);
352 g_hash_table_insert(result->
d_table, label, box);
354 g_hash_table_insert(result->
box_table, label, box);
355 if(kl ==
'X' || kl ==
'Y') labels = g_list_append(labels, g_strdup(label));
358 if(!g_strcmp0(x_label, lxe))
break;
360 if(!
strinc(x_label, x_label_size))
367 x_max =
MAX(x_max,
x + w);
369 if(!g_strcmp0(y_label, lye))
break;
372 if(!
strinc(y_label, y_label_size))
379 y_max =
MAX(y_max, y + h);
380 if((kl ==
'X' || kl ==
'Y') && first_label && last_label)
381 g_hash_table_insert(result->
patch_sets, g_strdup_printf(
"%s .. %s", first_label, last_label), labels);
397 result->
bb_w = x_max - x_min;
398 result->
bb_h = y_max - y_min;
400#define SCALE_X(x) x = (x - x_min) / result->bb_w
401#define SCALE_Y(y) y = (y - y_min) / result->bb_h
403 for(GList *iter = result->
f_list; iter; iter = g_list_next(iter))
406 for(
int i = 0;
i < 4;
i++)
413 GHashTableIter table_iter;
416 g_hash_table_iter_init(&table_iter, result->
d_table);
417 while(g_hash_table_iter_next(&table_iter, &
key, &
value))
422 box->
w /= result->
bb_w;
423 box->
h /= result->
bb_h;
426 g_hash_table_iter_init(&table_iter, result->
box_table);
427 while(g_hash_table_iter_next(&table_iter, &
key, &
value))
432 box->
w /= result->
bb_w;
433 box->
h /= result->
bb_h;
442 if(c - line >= len)
ERROR;
448 if(c - line >= len)
ERROR;
451 else if(!g_strcmp0(keyword,
"XLIST") && last_block <
BLOCK_XLIST)
457 else if(!g_strcmp0(keyword,
"YLIST") && last_block <
BLOCK_YLIST)
463 else if(!g_strcmp0(keyword,
"EXPECTED") && last_block <
BLOCK_EXPECTED)
467 if(c - line >= len)
ERROR;
469 if(c - line >= len)
ERROR;
472 if(!g_strcmp0(cs,
"XYZ"))
474 else if(!g_strcmp0(cs,
"LAB"))
485 if(line[0] ==
'\0' || line[0] ==
'\n')
break;
487 ssize_t len = strlen(line);
494 if(c - line >= len)
ERROR;
496 if(c - line >= len)
ERROR;
498 if(c - line >= len)
ERROR;
502 if(n_colors != 0)
ERROR;
506 fprintf(stderr,
"unknown keyword `%s'\n", keyword);
511 fprintf(stderr,
"cht `%s' done\n", filename);
515 fprintf(stderr,
"error parsing CHT file, (%s:%d)\n", __FUNCTION__, lineno);
528 cmsHANDLE hIT8 = cmsIT8LoadFromFile(NULL, filename);
531 fprintf(stderr,
"error loading IT8 file `%s'\n", filename);
535 if(cmsIT8TableCount(hIT8) != 1)
537 fprintf(stderr,
"error with the IT8 file, we only support files with one table at the moment\n");
542 int column_SAMPLE_ID = -1, column_X = -1, column_Y = -1, column_Z = -1, column_L = -1, column_a = -1,
544 char **sample_names = NULL;
545 int n_columns = cmsIT8EnumDataFormat(hIT8, &sample_names);
549 fprintf(stderr,
"error with the IT8 file, can't get column types\n");
553 for(
int i = 0;
i < n_columns;
i++)
555 if(!g_strcmp0(sample_names[
i],
"SAMPLE_ID"))
556 column_SAMPLE_ID =
i;
557 else if(!g_strcmp0(sample_names[
i],
"XYZ_X"))
559 else if(!g_strcmp0(sample_names[
i],
"XYZ_Y"))
561 else if(!g_strcmp0(sample_names[
i],
"XYZ_Z"))
563 else if(!g_strcmp0(sample_names[
i],
"LAB_L"))
565 else if(!g_strcmp0(sample_names[
i],
"LAB_A"))
567 else if(!g_strcmp0(sample_names[
i],
"LAB_B"))
571 if(column_SAMPLE_ID == -1)
573 fprintf(stderr,
"error with the IT8 file, can't find the SAMPLE_ID column\n");
577 char *columns[3] = { 0 };
578 if(column_X != -1 && column_Y != -1 && column_Z != -1)
581 columns[0] =
"XYZ_X";
582 columns[1] =
"XYZ_Y";
583 columns[2] =
"XYZ_Z";
585 else if(column_L != -1 && column_a != -1 && column_b != -1)
588 columns[0] =
"LAB_L";
589 columns[1] =
"LAB_A";
590 columns[2] =
"LAB_B";
594 fprintf(stderr,
"error with the IT8 file, can't find XYZ or Lab columns\n");
598 GHashTableIter table_iter;
601 g_hash_table_iter_init(&table_iter, chart->
box_table);
602 while(g_hash_table_iter_next(&table_iter, &
key, &
value))
606 if(cmsIT8GetData(hIT8,
key,
"SAMPLE_ID") == NULL)
608 fprintf(stderr,
"error with the IT8 file, can't find sample `%s'\n", (
char *)
key);
613 cmsIT8GetDataDbl(hIT8,
key, columns[2]));
616 fprintf(stderr,
"it8 `%s' done\n", filename);
622 if(hIT8) cmsIT8Free(hIT8);