170 FILE *fp = g_fopen(filename,
"rb");
173 fprintf(stderr,
"error opening `%s'\n", filename);
183 unsigned int n_boxes;
188 float x_min = FLT_MAX, x_max = FLT_MIN, y_min = FLT_MAX, y_max = FLT_MIN;
193 if(line[0] ==
'\0' || line[0] ==
'\n')
198 if(skip_block)
continue;
202 ssize_t len = strlen(line);
205 if(!g_strcmp0(keyword,
"BOXES") && last_block <
BLOCK_BOXES)
208 if(c - line >= len)
ERROR;
214 if(line[0] ==
'\0' || line[0] ==
'\n')
break;
217 ssize_t len = strlen(line);
218 while(*c ==
' ') c++;
221 float x0, y0, x1, y1, x2, y2, x3, y3;
226 while(*c ==
' ') c++;
227 if(*c++ !=
'_')
ERROR;
228 while(*c ==
' ') c++;
229 if(*c++ !=
'_')
ERROR;
230 while(*c ==
' ') c++;
231 if(c - line >= len)
ERROR;
233 if(c - line >= len)
ERROR;
235 if(c - line >= len)
ERROR;
237 if(c - line >= len)
ERROR;
239 if(c - line >= len)
ERROR;
241 if(c - line >= len)
ERROR;
243 if(c - line >= len)
ERROR;
245 if(c - line >= len)
ERROR;
248 x_min =
MIN(x_min, x0);
249 x_min =
MIN(x_min, x1);
250 x_min =
MIN(x_min, x2);
251 x_min =
MIN(x_min, x3);
253 y_min =
MIN(y_min, y0);
254 y_min =
MIN(y_min, y1);
255 y_min =
MIN(y_min, y2);
256 y_min =
MIN(y_min, y3);
258 x_max =
MAX(x_max, x0);
259 x_max =
MAX(x_max, x1);
260 x_max =
MAX(x_max, x2);
261 x_max =
MAX(x_max, x3);
263 y_max =
MAX(y_max, y0);
264 y_max =
MAX(y_max, y1);
265 y_max =
MAX(y_max, y2);
266 y_max =
MAX(y_max, y3);
282 else if((*c ==
'D') || (*c ==
'X') || (*c ==
'Y'))
284 char kl, *lxs, *lxe, *lys, *lye;
285 float w, h, xo, yo, xi, yi;
289 if(c - line >= len)
ERROR;
291 if(c - line >= len)
ERROR;
293 if(c - line >= len)
ERROR;
295 if(c - line >= len)
ERROR;
298 if(c - line >= len)
ERROR;
300 if(c - line >= len)
ERROR;
302 if(c - line >= len)
ERROR;
304 if(c - line >= len)
ERROR;
306 if(c - line >= len)
ERROR;
308 if(c - line >= len)
ERROR;
311 x_min =
MIN(x_min, xo);
312 y_min =
MIN(y_min, yo);
315 size_t lxs_len = strlen(lxs), lxe_len = strlen(lxe), lys_len = strlen(lys), lye_len = strlen(lye);
316 if(lxs_len > lxe_len || lys_len > lye_len)
ERROR;
319 const size_t x_label_size = lxe_len + 1;
320 const size_t y_label_size = lye_len + 1;
322 char *x_label = malloc(x_label_size);
323 char *y_label = malloc(y_label_size);
325 char *first_label = NULL, *last_label = NULL;
326 GList *labels = NULL;
329 memcpy(y_label, lys, lys_len + 1);
333 memcpy(x_label, lxs, lxs_len + 1);
338 if(!g_strcmp0(x_label,
"_"))
339 label = g_strdup(y_label);
340 else if(!g_strcmp0(y_label,
"_"))
341 label = g_strdup(x_label);
345 label = g_strconcat(y_label, x_label, NULL);
347 label = g_strconcat(x_label, y_label, NULL);
362 g_hash_table_insert(result->
d_table, label, box);
364 g_hash_table_insert(result->
box_table, label, box);
365 if(kl ==
'X' || kl ==
'Y') labels = g_list_append(labels, g_strdup(label));
368 if(!g_strcmp0(x_label, lxe))
break;
370 if(!
strinc(x_label, x_label_size))
377 x_max =
MAX(x_max,
x + w);
379 if(!g_strcmp0(y_label, lye))
break;
382 if(!
strinc(y_label, y_label_size))
389 y_max =
MAX(y_max, y + h);
390 if((kl ==
'X' || kl ==
'Y') && first_label && last_label)
391 g_hash_table_insert(result->
patch_sets, g_strdup_printf(
"%s .. %s", first_label, last_label), labels);
407 result->
bb_w = x_max - x_min;
408 result->
bb_h = y_max - y_min;
410#define SCALE_X(x) x = (x - x_min) / result->bb_w
411#define SCALE_Y(y) y = (y - y_min) / result->bb_h
413 for(GList *iter = result->
f_list; iter; iter = g_list_next(iter))
416 for(
int i = 0;
i < 4;
i++)
423 GHashTableIter table_iter;
426 g_hash_table_iter_init(&table_iter, result->
d_table);
427 while(g_hash_table_iter_next(&table_iter, &
key, &
value))
432 box->
w /= result->
bb_w;
433 box->
h /= result->
bb_h;
436 g_hash_table_iter_init(&table_iter, result->
box_table);
437 while(g_hash_table_iter_next(&table_iter, &
key, &
value))
442 box->
w /= result->
bb_w;
443 box->
h /= result->
bb_h;
452 if(c - line >= len)
ERROR;
458 if(c - line >= len)
ERROR;
461 else if(!g_strcmp0(keyword,
"XLIST") && last_block <
BLOCK_XLIST)
467 else if(!g_strcmp0(keyword,
"YLIST") && last_block <
BLOCK_YLIST)
473 else if(!g_strcmp0(keyword,
"EXPECTED") && last_block <
BLOCK_EXPECTED)
477 if(c - line >= len)
ERROR;
479 if(c - line >= len)
ERROR;
482 if(!g_strcmp0(cs,
"XYZ"))
484 else if(!g_strcmp0(cs,
"LAB"))
495 if(line[0] ==
'\0' || line[0] ==
'\n')
break;
497 ssize_t len = strlen(line);
504 if(c - line >= len)
ERROR;
506 if(c - line >= len)
ERROR;
508 if(c - line >= len)
ERROR;
512 if(n_colors != 0)
ERROR;
516 fprintf(stderr,
"unknown keyword `%s'\n", keyword);
521 fprintf(stderr,
"cht `%s' done\n", filename);
525 fprintf(stderr,
"error parsing CHT file, (%s:%d)\n", __FUNCTION__, lineno);
538 cmsHANDLE hIT8 = cmsIT8LoadFromFile(NULL, filename);
541 fprintf(stderr,
"error loading IT8 file `%s'\n", filename);
545 if(cmsIT8TableCount(hIT8) != 1)
547 fprintf(stderr,
"error with the IT8 file, we only support files with one table at the moment\n");
552 int column_SAMPLE_ID = -1, column_X = -1, column_Y = -1, column_Z = -1, column_L = -1, column_a = -1,
554 char **sample_names = NULL;
555 int n_columns = cmsIT8EnumDataFormat(hIT8, &sample_names);
559 fprintf(stderr,
"error with the IT8 file, can't get column types\n");
563 for(
int i = 0;
i < n_columns;
i++)
565 if(!g_strcmp0(sample_names[
i],
"SAMPLE_ID"))
566 column_SAMPLE_ID =
i;
567 else if(!g_strcmp0(sample_names[
i],
"XYZ_X"))
569 else if(!g_strcmp0(sample_names[
i],
"XYZ_Y"))
571 else if(!g_strcmp0(sample_names[
i],
"XYZ_Z"))
573 else if(!g_strcmp0(sample_names[
i],
"LAB_L"))
575 else if(!g_strcmp0(sample_names[
i],
"LAB_A"))
577 else if(!g_strcmp0(sample_names[
i],
"LAB_B"))
581 if(column_SAMPLE_ID == -1)
583 fprintf(stderr,
"error with the IT8 file, can't find the SAMPLE_ID column\n");
587 char *columns[3] = { 0 };
588 if(column_X != -1 && column_Y != -1 && column_Z != -1)
591 columns[0] =
"XYZ_X";
592 columns[1] =
"XYZ_Y";
593 columns[2] =
"XYZ_Z";
595 else if(column_L != -1 && column_a != -1 && column_b != -1)
598 columns[0] =
"LAB_L";
599 columns[1] =
"LAB_A";
600 columns[2] =
"LAB_B";
604 fprintf(stderr,
"error with the IT8 file, can't find XYZ or Lab columns\n");
608 GHashTableIter table_iter;
611 g_hash_table_iter_init(&table_iter, chart->
box_table);
612 while(g_hash_table_iter_next(&table_iter, &
key, &
value))
616 if(cmsIT8GetData(hIT8,
key,
"SAMPLE_ID") == NULL)
618 fprintf(stderr,
"error with the IT8 file, can't find sample `%s'\n", (
char *)
key);
623 cmsIT8GetDataDbl(hIT8,
key, columns[2]));
626 fprintf(stderr,
"it8 `%s' done\n", filename);
632 if(hIT8) cmsIT8Free(hIT8);