30
30
*/
31
31
32
32
#include "colorchecker.h"
33
- //#include "colorspaces.h"
34
33
#include "common/colorspaces_inline_conversions.h"
35
34
#include "darktable.h"
36
35
#include "file_location.h"
@@ -54,7 +53,7 @@ static inline dt_colorchecker_CGATS_types _dt_CGATS_get_type_val(const char *typ
54
53
return t ;
55
54
}
56
55
57
- const dt_colorchecker_CGATS_spec_t * _dt_get_CGATS_spec (const char * type )
56
+ const dt_colorchecker_CGATS_spec_t _dt_get_CGATS_spec (const char * type )
58
57
{
59
58
if (type )
60
59
{
@@ -63,16 +62,16 @@ const dt_colorchecker_CGATS_spec_t *_dt_get_CGATS_spec(const char *type)
63
62
switch (t )
64
63
{
65
64
case CGATS_TYPE_IT8_7_1 :
66
- return & IT8_7_1 ;
65
+ return IT8_7_1 ;
67
66
case CGATS_TYPE_CGATS_17 :
68
- return & CGATS_17 ;
67
+ return CGATS_17 ;
69
68
case CGATS_TYPE_LAST :
70
69
fprintf (stderr , "Unknown CGATS type: %s\n" , type );
71
- return & IT8_7_1 ;
70
+ return IT8_7_1 ;
72
71
}
73
72
}
74
73
75
- return & IT8_7_1 ;
74
+ return IT8_7_1 ;
76
75
}
77
76
78
77
/**
@@ -198,6 +197,19 @@ static inline const char *_dt_CGATS_get_manufacturer(const cmsHANDLE *hIT8)
198
197
return manufacturer ? manufacturer : "Unknown Manufacturer" ;
199
198
}
200
199
200
+ /**
201
+ * @brief Get the name of a built-in color checker.
202
+ *
203
+ * @param target_type The type of colorchecker
204
+ * @return char* The name of the colorchecker
205
+ */
206
+ static inline const char * dt_get_builtin_colorchecker_name (const dt_color_checker_targets target_type )
207
+ {
208
+ const dt_color_checker_t * color_checker = dt_get_color_checker (target_type , NULL );
209
+ const char * name = color_checker -> name ;
210
+ fprintf (stdout , "dt_get_builtin_colorchecker_name: %s\n" , name );
211
+ return name ;
212
+ }
201
213
202
214
/**
203
215
* @brief build a name for the colorchecker.
@@ -307,7 +319,7 @@ static inline void _dt_CGATS_find_whitest_blackest_greyest(const dt_color_checke
307
319
* @param bwg the float* [3] that will get the blackest, whitest and greyest patches to be found
308
320
* @return NULL if error, dt_color_checker_patch* with the colors otherwise.
309
321
*/
310
- int _dt_colorchecker_CGATS_fill_patch_values (cmsHANDLE hIT8 , dt_color_checker_patch * values , size_t * bwg )
322
+ int dt_colorchecker_CGATS_fill_patch_values (cmsHANDLE hIT8 , dt_color_checker_patch * values , size_t * bwg )
311
323
{
312
324
int error = 0 ;
313
325
if (!values ) error = 1 ;
@@ -323,7 +335,7 @@ int _dt_colorchecker_CGATS_fill_patch_values(cmsHANDLE hIT8, dt_color_checker_pa
323
335
int n_columns = cmsIT8EnumDataFormat (hIT8 , & sample_names );
324
336
size_t num_patches = (size_t )cmsIT8GetPropertyDbl (hIT8 , "NUMBER_OF_SETS" );
325
337
const char * CGATS_type = cmsIT8GetSheetType (hIT8 );
326
- const dt_colorchecker_CGATS_spec_t * CGATS_spec = _dt_get_CGATS_spec (CGATS_type );
338
+ const dt_colorchecker_CGATS_spec_t CGATS_spec = _dt_get_CGATS_spec (CGATS_type );
327
339
328
340
gboolean use_XYZ = FALSE;
329
341
if (n_columns == -1 )
@@ -378,15 +390,15 @@ int _dt_colorchecker_CGATS_fill_patch_values(cmsHANDLE hIT8, dt_color_checker_pa
378
390
}
379
391
380
392
// IT8 chart dimensions
381
- const int cols = CGATS_spec -> colums ;
382
- const int rows = CGATS_spec -> rows ;
393
+ const int cols = CGATS_spec . colums ;
394
+ const int rows = CGATS_spec . rows ;
383
395
// Patch size in ratio of the chart size
384
- const float patch_size_x = CGATS_spec -> patch_width ;
385
- const float patch_size_y = CGATS_spec -> patch_height ;
396
+ const float patch_size_x = CGATS_spec . patch_width ;
397
+ const float patch_size_y = CGATS_spec . patch_height ;
386
398
387
399
// Offset ratio of the center of the patch from the border of the chart
388
- const float patch_offset_x = CGATS_spec -> patch_offset_x ;
389
- const float patch_offset_y = CGATS_spec -> patch_offset_y ;
400
+ const float patch_offset_x = CGATS_spec . patch_offset_x ;
401
+ const float patch_offset_y = CGATS_spec . patch_offset_y ;
390
402
391
403
#ifdef OPENMP
392
404
#pragma omp parallel for
@@ -457,8 +469,7 @@ int _dt_colorchecker_CGATS_fill_patch_values(cmsHANDLE hIT8, dt_color_checker_pa
457
469
return error ;
458
470
}
459
471
460
-
461
- dt_color_checker_t * _dt_colorchecker_user_ref_create (const char * filename )
472
+ dt_color_checker_t * dt_colorchecker_user_ref_create (const char * filename )
462
473
{
463
474
int error = 0 ;
464
475
cmsHANDLE hIT8 = cmsIT8LoadFromFile (NULL , filename );
@@ -471,11 +482,12 @@ dt_color_checker_t *_dt_colorchecker_user_ref_create(const char *filename)
471
482
}
472
483
473
484
const char * type = cmsIT8GetSheetType (hIT8 );
474
- const dt_colorchecker_CGATS_spec_t * CGATS_spec = _dt_get_CGATS_spec (type );
485
+ const dt_colorchecker_CGATS_spec_t CGATS_spec = _dt_get_CGATS_spec (type );
475
486
size_t num_patches = (size_t )cmsIT8GetPropertyDbl (hIT8 , "NUMBER_OF_SETS" );
476
487
size_t total_size = sizeof (dt_color_checker_t ) + num_patches * sizeof (dt_color_checker_patch );
477
488
478
- dt_color_checker_t * checker = malloc (total_size );
489
+ dt_color_checker_t * checker = dt_colorchecker_init (total_size );
490
+
479
491
if (!checker )
480
492
{
481
493
fprintf (stderr , "Error: can't allocate memory for the color checker from IT8 chart\n" );
@@ -488,19 +500,18 @@ dt_color_checker_t *_dt_colorchecker_user_ref_create(const char *filename)
488
500
checker -> date = g_strdup (_dt_CGATS_get_date (& hIT8 ));
489
501
checker -> manufacturer = g_strdup (_dt_CGATS_get_manufacturer (& hIT8 ));
490
502
checker -> type = COLOR_CHECKER_USER_REF ;
491
- checker -> radius = CGATS_spec -> radius ;
492
- checker -> ratio = CGATS_spec -> ratio ;
503
+ checker -> radius = CGATS_spec . radius ;
504
+ checker -> ratio = CGATS_spec . ratio ;
493
505
checker -> patches = num_patches ;
494
- checker -> size [0 ] = CGATS_spec -> size [0 ];
495
- checker -> size [1 ] = CGATS_spec -> size [1 ];
496
- checker -> middle_grey = CGATS_spec -> middle_grey ;
497
- checker -> white = CGATS_spec -> white ;
498
- checker -> black = CGATS_spec -> black ;
506
+ checker -> size [0 ] = CGATS_spec . size [0 ];
507
+ checker -> size [1 ] = CGATS_spec . size [1 ];
508
+ checker -> middle_grey = CGATS_spec . middle_grey ;
509
+ checker -> white = CGATS_spec . white ;
510
+ checker -> black = CGATS_spec . black ;
499
511
500
512
// blackest, whitest and greyest patches will be found while filling the color values
501
513
size_t bwg [3 ] = { 0 , 0 , 0 };
502
-
503
- _dt_colorchecker_CGATS_fill_patch_values (hIT8 , checker -> values , bwg );
514
+ dt_colorchecker_CGATS_fill_patch_values (hIT8 , checker -> values , bwg );
504
515
505
516
checker -> black = bwg [0 ];
506
517
checker -> white = bwg [1 ];
@@ -511,7 +522,13 @@ dt_color_checker_t *_dt_colorchecker_user_ref_create(const char *filename)
511
522
512
523
end :
513
524
if (hIT8 ) cmsIT8Free (hIT8 );
514
- return error ? NULL : checker ;
525
+ if (error )
526
+ {
527
+ free (checker );
528
+ return NULL ;
529
+ }
530
+ else
531
+ return checker ;
515
532
}
516
533
517
534
static dt_colorchecker_label_t * _dt_colorchecker_user_ref_add_label (const gchar * filename , const gchar * user_it8_dir )
@@ -526,25 +543,46 @@ static dt_colorchecker_label_t *_dt_colorchecker_user_ref_add_label(const gchar
526
543
if (hIT8 && _dt_CGATS_is_valid (& hIT8 ))
527
544
{
528
545
gchar * label = _dt_CGATS_get_name (& hIT8 , filename );
529
- size_t label_size = safe_strlen (label ) + safe_strlen (filepath ) + sizeof (dt_color_checker_targets );
530
- dt_colorchecker_label_t * CGATS_label = malloc (label_size );
531
-
532
- CGATS_label -> label = g_strdup (label );
533
- CGATS_label -> path = g_strdup (filepath );
534
- CGATS_label -> type = COLOR_CHECKER_USER_REF ;
535
-
546
+ dt_colorchecker_label_t * CGATS_label = dt_colorchecker_label_init (label , COLOR_CHECKER_USER_REF , filepath );
547
+
536
548
g_free (label );
537
549
result = CGATS_label ;
550
+ if (!result ) goto error ;
538
551
}
539
552
cmsIT8Free (hIT8 );
540
553
}
541
554
g_free (filepath );
542
555
543
556
return result ;
557
+
558
+ error :
559
+ free (result );
560
+ return NULL ;
544
561
}
545
562
563
+ int dt_colorchecker_find_builtin (GList * * colorcheckers_label )
564
+ {
565
+ int nb = 0 ;
566
+ for (int k = 0 ; k < COLOR_CHECKER_USER_REF ; k ++ )
567
+ {
568
+ const char * name = dt_get_builtin_colorchecker_name (k );
569
+ dt_colorchecker_label_t * builtin_label = dt_colorchecker_label_init (name , k , NULL );
570
+
571
+ if (!builtin_label )
572
+ {
573
+ fprintf (stderr , "dt_colorchecker_find: failed to allocate memory for builtin colorchecker label %d\n" , k );
574
+ continue ;
575
+ }
576
+ else
577
+ {
578
+ * colorcheckers_label = g_list_append (* colorcheckers_label , builtin_label );
579
+ nb ++ ;
580
+ }
581
+ }
582
+ return nb ;
583
+ }
546
584
547
- int _dt_colorchecker_find_CGAT_reference_files (GList * * ref_colorcheckers_files )
585
+ int dt_colorchecker_find_CGAT_reference_files (GList * * ref_colorcheckers_files )
548
586
{
549
587
int nb = 0 ;
550
588
char confdir [PATH_MAX ] = { 0 };
@@ -563,6 +601,9 @@ int _dt_colorchecker_find_CGAT_reference_files(GList **ref_colorcheckers_files)
563
601
* ref_colorcheckers_files = g_list_append (* ref_colorcheckers_files , CGATS_label );
564
602
nb ++ ;
565
603
}
604
+ else
605
+ fprintf (stderr , "Error: failed to load CGATS file '%s' in %s\n" , filename , user_it8_dir );
606
+
566
607
}
567
608
g_dir_close (dir );
568
609
}
0 commit comments