38
38
#include <inttypes.h>
39
39
#include <lcms2.h>
40
40
41
- // In some environments ERROR is already defined, ie: WIN32
42
- #if defined(ERROR )
43
- #undef ERROR
44
- #endif // defined (ERROR)
45
-
46
41
#define ERROR \
47
42
{ \
48
43
lineno = __LINE__; \
@@ -99,7 +94,7 @@ static void _dt_color_checker_patch_copy(dt_color_checker_patch *dest, const dt_
99
94
dest -> Lab [2 ] = src -> Lab [2 ];
100
95
}
101
96
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 )
103
98
{
104
99
if (!dest || !src ) return ;
105
100
@@ -324,10 +319,9 @@ static inline const char *_remove_leading_zeros(const char *in)
324
319
* @param cht_patch The structure containing the patch information.
325
320
* @param chart The structure to populate with patches.
326
321
* @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.
328
322
* @return gboolean Returns TRUE if the operation was successful, FALSE otherwise.
329
323
*/
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 )
331
325
{
332
326
gboolean result = FALSE;
333
327
int lineno = 0 ;
@@ -394,11 +388,11 @@ static gboolean _dt_cht_generate_patch_list(const cht_box_t *cht_patch, dt_color
394
388
patch -> name = g_strdup (label );
395
389
if (!patch -> name ) ERROR
396
390
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
399
393
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
402
396
403
397
// Add to the list
404
398
chart -> patches = g_slist_append (chart -> patches , patch );
@@ -489,6 +483,7 @@ static GList *_parse_cht(const char *filename)
489
483
}
490
484
if (!g_strcmp0 (line_tokens [0 ], "BOX_SHRINK" ) && last_block < BLOCK_BOX_SHRINK )
491
485
{
486
+ skip_block = 1 ;
492
487
break ; // we don't care about blocks comming after, just skip them.
493
488
}
494
489
@@ -523,14 +518,12 @@ static gboolean _dispatch_cht_data(GList **boxes, dt_colorchecker_chart_spec_t *
523
518
524
519
float chart_radius = -1.f ;
525
520
526
- float mark_size [2 ] = { 0 }; // width, height
527
-
528
521
for (GList * lines = * boxes ; lines ; lines = g_list_next (lines ))
529
522
{
530
523
const char * * tokens = (const char * * )lines -> data ;
531
524
if (!tokens ) ERROR
532
525
533
- const char * letter = tokens [0 ][0 ];
526
+ const char letter = tokens [0 ][0 ];
534
527
if (letter == 'F' )
535
528
{
536
529
F_box = _dt_cht_extract_F (tokens );
@@ -558,8 +551,8 @@ static gboolean _dispatch_cht_data(GList **boxes, dt_colorchecker_chart_spec_t *
558
551
if (box -> key_letter == 'D' )
559
552
{
560
553
// 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 ;
563
556
}
564
557
565
558
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 *
568
561
chart_spec -> patch_height = MIN (chart_spec -> patch_height , box -> height );
569
562
fprintf (stdout , "patch_width: %f, patch_height: %f\n" , chart_spec -> patch_width , chart_spec -> patch_height );
570
563
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 ))
572
565
{
573
566
free (box -> label_x_start );
574
567
free (box -> label_x_end );
@@ -714,7 +707,7 @@ static gboolean _dt_CGATS_is_supported(const cmsHANDLE *hIT8)
714
707
goto end ;
715
708
}
716
709
else
717
- {
710
+ {
718
711
const char * CGATS_type = cmsIT8GetProperty (* hIT8 , "CGATS" );
719
712
// Check if the data type can be found in our supported list of CGATS types
720
713
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
1069
1062
fprintf (stderr , "error: patch %lu not found in chart specification.\n" , patch_iter );
1070
1063
goto error ;
1071
1064
}
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 );
1075
1066
}
1076
1067
else
1077
1068
{
@@ -1187,14 +1178,6 @@ dt_color_checker_t *dt_colorchecker_user_ref_create(const char *filename, const
1187
1178
}
1188
1179
}
1189
1180
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
-
1198
1181
// Check if the CGATS file contains the expected number of patches
1199
1182
const int num_patches_it8 = (const int )cmsIT8GetPropertyDbl (hIT8 , "NUMBER_OF_SETS" );
1200
1183
@@ -1206,7 +1189,6 @@ dt_color_checker_t *dt_colorchecker_user_ref_create(const char *filename, const
1206
1189
1207
1190
// Limit the number of patches to the minimum between the CGATS file and the chart specification to avoid overflow.
1208
1191
const int num_patches = MIN (num_patches_it8 , chart_spec -> num_patches );
1209
- fprintf (stdout , "\tFinal number of patches: %i\n" , num_patches );
1210
1192
1211
1193
checker = dt_colorchecker_init ();
1212
1194
if (!checker )
@@ -1347,14 +1329,18 @@ int dt_colorchecker_find_CGAT_reference_files(GList **ref_colorcheckers_files)
1347
1329
const char * filename ;
1348
1330
while ((filename = g_dir_read_name (dir )) != NULL )
1349
1331
{
1332
+ const char * dot = g_strrstr (filename , "." );
1333
+ if (g_ascii_strcasecmp (dot , ".cht" ) == 0 )
1334
+ continue ; // skip .cht files
1335
+
1350
1336
dt_colorchecker_label_t * CGATS_label = _dt_colorchecker_user_ref_add_label (filename , user_it8_dir );
1351
1337
if (CGATS_label )
1352
1338
{
1353
1339
* ref_colorcheckers_files = g_list_append (* ref_colorcheckers_files , CGATS_label );
1354
1340
nb ++ ;
1355
1341
}
1356
1342
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 );
1358
1344
}
1359
1345
g_dir_close (dir );
1360
1346
}
0 commit comments