Skip to content

Commit d0b672b

Browse files
committed
CGATS file : skip on .cht
1 parent 8b8e98a commit d0b672b

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

src/common/colorchecker.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
#include <inttypes.h>
3939
#include <lcms2.h>
4040

41-
// In some environments ERROR is already defined, ie: WIN32
42-
#if defined(ERROR)
43-
#undef ERROR
44-
#endif // defined (ERROR)
45-
4641
#define ERROR \
4742
{ \
4843
lineno = __LINE__; \
@@ -99,7 +94,7 @@ static void _dt_color_checker_patch_copy(dt_color_checker_patch *dest, const dt_
9994
dest->Lab[2] = src->Lab[2];
10095
}
10196

102-
static void dt_color_checker_copy(dt_color_checker_t *dest, const dt_color_checker_t *src)
97+
void dt_color_checker_copy(dt_color_checker_t *dest, const dt_color_checker_t *src)
10398
{
10499
if(!dest || !src) return;
105100

@@ -324,10 +319,9 @@ static inline const char *_remove_leading_zeros(const char *in)
324319
* @param cht_patch The structure containing the patch information.
325320
* @param chart The structure to populate with patches.
326321
* @param F_box The cht_box_F_t structure containing the frame values.
327-
* @param mark_size The sizes of the chart frame's marks.
328322
* @return gboolean Returns TRUE if the operation was successful, FALSE otherwise.
329323
*/
330-
static gboolean _dt_cht_generate_patch_list(const cht_box_t *cht_patch, dt_colorchecker_chart_spec_t *chart, const cht_box_F_t *F_box, const float mark_size[2])
324+
static gboolean _dt_cht_generate_patch_list(const cht_box_t *cht_patch, dt_colorchecker_chart_spec_t *chart, const cht_box_F_t *F_box)
331325
{
332326
gboolean result = FALSE;
333327
int lineno = 0;
@@ -394,11 +388,11 @@ static gboolean _dt_cht_generate_patch_list(const cht_box_t *cht_patch, dt_color
394388
patch->name = g_strdup(label);
395389
if(!patch->name) ERROR
396390

397-
patch->x = cht_patch->x_origin - (mark_size[0] / 2) + patch_w + cht_patch->x_increment * index_x;
398-
patch->x /= MAX(F_box->bx, F_box->cx) - mark_size[0]; // normalize to chart factor
391+
patch->x = cht_patch->x_origin - (chart->guide_size[0] / 2) + patch_w + cht_patch->x_increment * index_x;
392+
patch->x /= MAX(F_box->bx, F_box->cx) - chart->guide_size[0]; // normalize to chart factor
399393

400-
patch->y = cht_patch->y_origin - (mark_size[1] / 2) + patch_h + cht_patch->y_increment * index_y;
401-
patch->y /= MAX(F_box->cy, F_box->dy) - mark_size[1]; // normalize to chart factor
394+
patch->y = cht_patch->y_origin - (chart->guide_size[1] / 2) + patch_h + cht_patch->y_increment * index_y;
395+
patch->y /= MAX(F_box->cy, F_box->dy) - chart->guide_size[1]; // normalize to chart factor
402396

403397
// Add to the list
404398
chart->patches = g_slist_append(chart->patches, patch);
@@ -489,6 +483,7 @@ static GList *_parse_cht(const char *filename)
489483
}
490484
if(!g_strcmp0(line_tokens[0], "BOX_SHRINK") && last_block < BLOCK_BOX_SHRINK)
491485
{
486+
skip_block = 1;
492487
break; // we don't care about blocks comming after, just skip them.
493488
}
494489

@@ -523,14 +518,12 @@ static gboolean _dispatch_cht_data(GList **boxes, dt_colorchecker_chart_spec_t *
523518

524519
float chart_radius = -1.f;
525520

526-
float mark_size[2] = { 0 }; // width, height
527-
528521
for(GList *lines = *boxes; lines; lines = g_list_next(lines))
529522
{
530523
const char **tokens = (const char **)lines->data;
531524
if(!tokens) ERROR
532525

533-
const char *letter = tokens[0][0];
526+
const char letter = tokens[0][0];
534527
if(letter == 'F')
535528
{
536529
F_box = _dt_cht_extract_F(tokens);
@@ -558,8 +551,8 @@ static gboolean _dispatch_cht_data(GList **boxes, dt_colorchecker_chart_spec_t *
558551
if(box->key_letter == 'D')
559552
{
560553
// Save the corner sizes when they are specified, to changes the patches area size in consequence.
561-
if(!g_strcmp0(box->label_x_start,"MARK")) mark_size[0] = box->width - box->x_origin;
562-
if(!g_strcmp0(box->label_x_start,"MARK")) mark_size[1] = box->height - box->y_origin;
554+
if(!g_strcmp0(box->label_x_start,"MARK")) chart_spec->guide_size[0] = box->width - box->x_origin;
555+
if(!g_strcmp0(box->label_x_start,"MARK")) chart_spec->guide_size[1] = box->height - box->y_origin;
563556
}
564557

565558
else if(box->key_letter == 'X' || box->key_letter == 'Y')
@@ -568,7 +561,7 @@ static gboolean _dispatch_cht_data(GList **boxes, dt_colorchecker_chart_spec_t *
568561
chart_spec->patch_height = MIN(chart_spec->patch_height, box->height);
569562
fprintf(stdout, "patch_width: %f, patch_height: %f\n", chart_spec->patch_width, chart_spec->patch_height);
570563

571-
if(!_dt_cht_generate_patch_list(box, chart_spec, F_box, mark_size))
564+
if(!_dt_cht_generate_patch_list(box, chart_spec, F_box))
572565
{
573566
free(box->label_x_start);
574567
free(box->label_x_end);
@@ -714,7 +707,7 @@ static gboolean _dt_CGATS_is_supported(const cmsHANDLE *hIT8)
714707
goto end;
715708
}
716709
else
717-
{
710+
{
718711
const char *CGATS_type = cmsIT8GetProperty(*hIT8, "CGATS");
719712
// Check if the data type can be found in our supported list of CGATS types
720713
if(_dt_CGATS_get_type_value(CGATS_type) == CGATS_TYPE_UNKOWN)
@@ -1069,9 +1062,7 @@ static dt_color_checker_patch *_dt_colorchecker_CGATS_fill_patch_values(cmsHANDL
10691062
fprintf(stderr, "error: patch %lu not found in chart specification.\n", patch_iter);
10701063
goto error;
10711064
}
1072-
_dt_color_checker_patch_copy(&values[patch_iter], p);
1073-
fprintf(stdout, "Fill patch KEY: %s (%.5f, %.5f)\n", values[patch_iter].name, values[patch_iter].x, values[patch_iter].y);
1074-
1065+
_dt_color_checker_patch_copy(&values[patch_iter], p);
10751066
}
10761067
else
10771068
{
@@ -1187,14 +1178,6 @@ dt_color_checker_t *dt_colorchecker_user_ref_create(const char *filename, const
11871178
}
11881179
}
11891180

1190-
fprintf(stdout, "CHART:\ttype: %s, radius: %f, ratio: %f, size: [%zu, %zu]\n"
1191-
"\tpatches: %i, colums: %i, rows: %i\n"
1192-
"\tpatch_width: %f, patch_height: %f, patch_offset_x: %f, patch_offset_y: %f\n",
1193-
chart_spec->type, chart_spec->radius, chart_spec->ratio, chart_spec->size[0], chart_spec->size[1],
1194-
chart_spec->num_patches, chart_spec->colums, chart_spec->rows,
1195-
chart_spec->patch_width, chart_spec->patch_height, chart_spec->patch_offset_x, chart_spec->patch_offset_y);
1196-
1197-
11981181
// Check if the CGATS file contains the expected number of patches
11991182
const int num_patches_it8 = (const int)cmsIT8GetPropertyDbl(hIT8, "NUMBER_OF_SETS");
12001183

@@ -1206,7 +1189,6 @@ dt_color_checker_t *dt_colorchecker_user_ref_create(const char *filename, const
12061189

12071190
// Limit the number of patches to the minimum between the CGATS file and the chart specification to avoid overflow.
12081191
const int num_patches = MIN(num_patches_it8, chart_spec->num_patches);
1209-
fprintf(stdout, "\tFinal number of patches: %i\n", num_patches);
12101192

12111193
checker = dt_colorchecker_init();
12121194
if(!checker)
@@ -1347,14 +1329,18 @@ int dt_colorchecker_find_CGAT_reference_files(GList **ref_colorcheckers_files)
13471329
const char *filename;
13481330
while((filename = g_dir_read_name(dir)) != NULL)
13491331
{
1332+
const char *dot = g_strrstr(filename, ".");
1333+
if(g_ascii_strcasecmp(dot, ".cht") == 0)
1334+
continue; // skip .cht files
1335+
13501336
dt_colorchecker_label_t *CGATS_label = _dt_colorchecker_user_ref_add_label(filename, user_it8_dir);
13511337
if(CGATS_label)
13521338
{
13531339
*ref_colorcheckers_files = g_list_append(*ref_colorcheckers_files, CGATS_label);
13541340
nb++;
13551341
}
13561342
else
1357-
fprintf(stderr, "Error: failed to load CGATS file '%s' in %s\n", filename, user_it8_dir);
1343+
fprintf(stderr, "Warning: failed to load CGATS file '%s' in %s\n", filename, user_it8_dir);
13581344
}
13591345
g_dir_close(dir);
13601346
}

src/common/colorchecker.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef enum dt_color_checker_targets
3939
// helper to deal with patch color
4040
typedef struct dt_color_checker_patch
4141
{
42-
const char *name; // mnemonic name for the patch
42+
char *name; // mnemonic name for the patch
4343
dt_aligned_pixel_t Lab; // reference color in CIE Lab
4444

4545
// (x, y) position of the patch center, relatively to the guides (white dots)
@@ -431,6 +431,7 @@ typedef struct dt_colorchecker_chart_spec_t
431431
float radius; // radius of a patch in ratio of the checker diagonal
432432
float ratio; // format ratio of the chart, guide to guide (white dots)
433433
size_t size[2]; // number of patch along x, y axes
434+
float guide_size[2];// size of the guide area, specified by "MARK" data in cht files
434435
size_t middle_grey;
435436
size_t white;
436437
size_t black;
@@ -456,6 +457,7 @@ dt_colorchecker_chart_spec_t IT8_7 = {
456457
.radius = 0.0189f,
457458
.ratio = 6.f / 11.f,
458459
.size = { 22, 13 },
460+
.guide_size = { 0, 0 },
459461
.middle_grey = 273, // GS09
460462
.white = 263, // Dmin or GS00
461463
.black = 287, // Dmax or GS23
@@ -499,7 +501,6 @@ dt_color_checker_patch *dt_color_checker_patch_array_init(const size_t num_patch
499501
patches[i].Lab[1] = 0.0f;
500502
patches[i].Lab[2] = 0.0f;
501503
}
502-
503504
return patches;
504505
}
505506

@@ -574,7 +575,7 @@ void dt_colorchecker_label_list_cleanup(GList **colorcheckers)
574575
*colorcheckers = NULL;
575576
}
576577

577-
void dt_colorchecker_def_list_cleanup(GList **cht)
578+
void dt_colorchecker_cht_list_cleanup(GList **cht)
578579
{
579580
if(!cht) return;
580581

@@ -609,6 +610,12 @@ int dt_colorchecker_find_CGAT_reference_files(GList **ref_colorcheckers_files);
609610

610611
int dt_colorchecker_find_builtin(GList **colorcheckers_label);
611612

613+
/**
614+
* @brief Copy the content of a color checker from source to destination.
615+
*
616+
* @param dest A pointer to the destination color checker.
617+
* @param src A pointer to the source color checker.
618+
*/
612619
void dt_color_checker_copy(dt_color_checker_t *dest, const dt_color_checker_t *src);
613620

614621

@@ -643,7 +650,7 @@ static dt_color_checker_t *dt_get_color_checker(const dt_color_checker_targets t
643650
dt_color_checker_copy(checker_dest, &xrite_24_2014);
644651
break;
645652
case COLOR_CHECKER_SPYDER_24:
646-
dt_color_checker_copy(checker_dest,&spyder_24);
653+
dt_color_checker_copy(checker_dest, &spyder_24);
647654
break;
648655
case COLOR_CHECKER_SPYDER_24_V2:
649656
dt_color_checker_copy(checker_dest, &spyder_24_v2);
@@ -729,19 +736,25 @@ int dt_colorchecker_find(GList **colorcheckers_label)
729736
int total = dt_colorchecker_find_builtin(colorcheckers_label);
730737
dt_print(DT_DEBUG_VERBOSE, _("dt_colorchecker_find: found %d builtin colorcheckers\n"), total);
731738
int b_nb = total;
739+
732740
total += dt_colorchecker_find_CGAT_reference_files(colorcheckers_label);
733741
if (total) dt_print(DT_DEBUG_VERBOSE, _("dt_colorchecker_find: found %d CGAT references files\n"), total - b_nb);
734742
return total;
735743
}
736744

745+
/**
746+
* @brief Find all .cht files in the user it8 directory.
747+
*
748+
* @param cht A NULL GList that will be populated with found .cht files.
749+
* @return int The number of found .cht files.
750+
*/
737751
int dt_colorchecker_find_cht(GList **cht)
738752
{
739753
if(!cht) return 0;
740754

741-
// Find CGATS files
742755
const int total = dt_colorchecker_find_cht_files(cht);
743756

744-
if (total) dt_print(DT_DEBUG_VERBOSE, _("dt_colorchecker_find_cht: found %d .cht files\n"), total);
757+
if(total) dt_print(DT_DEBUG_VERBOSE, _("dt_colorchecker_find_cht: found %d .cht files\n"), total);
745758

746759
return total;
747760
}

src/iop/channelmixerrgb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3416,7 +3416,7 @@ void update_colorchecker_cht_list(dt_iop_module_t *self)
34163416
if(!g) return;
34173417

34183418
// clear and refill the chart definition list
3419-
dt_colorchecker_def_list_cleanup(&(g->colorcheckers_cht));
3419+
dt_colorchecker_cht_list_cleanup(&(g->colorcheckers_cht));
34203420

34213421
g->n_cht = 0;
34223422
int pos = -1;

0 commit comments

Comments
 (0)