Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
colorchecker.c File Reference
#include "colorchecker.h"
#include "common/colorspaces_inline_conversions.h"
#include "darktable.h"
#include "file_location.h"
#include <glib.h>
#include <inttypes.h>
#include <lcms2.h>
+ Include dependency graph for common/colorchecker.c:

Go to the source code of this file.

Data Structures

struct  cht_box_t
 
struct  cht_box_F_t
 

Macros

#define ERROR
 
#define TWO_SQRT2f   2.8284271247461900976f
 

Typedefs

typedef enum parser_state_t parser_state_t
 
typedef struct cht_box_t cht_box_t
 
typedef struct cht_box_F_t cht_box_F_t
 

Enumerations

enum  parser_state_t {
  BLOCK_NONE = 0 ,
  BLOCK_BOXES ,
  BLOCK_BOX_SHRINK ,
  BLOCK_REF_ROTATION ,
  BLOCK_XLIST ,
  BLOCK_YLIST ,
  BLOCK_EXPECTED
}
 

Functions

static void _dt_colorchecker_copy_patch (dt_color_checker_patch *dest, const dt_color_checker_patch *src)
 
void dt_colorchecker_copy (dt_color_checker_t *dest, const dt_color_checker_t *src)
 Copy the content of a color checker from source to destination.
 
static cht_box_F_t_dt_cht_extract_F (const char **tokens)
 Extracts the frame coordinates from the tokens, computes the width and height.
 
static dt_colorchecker_chart_spec_t_dt_colorchecker_chart_spec_init ()
 
static void _dt_colorchecker_chart_spec_cleanup (dt_colorchecker_chart_spec_t *chart_spec)
 
static dt_color_checker_patch_dt_colorchecker_patch_init ()
 
static void _dt_cht_box_cleanup (void *data)
 
static cht_box_t_dt_cht_box_extract (const char **tokens)
 
static char * _increment_string (const gchar *in)
 Increments a string alphanumerically.
 
static const char * _remove_leading_zeros (const char *in)
 Removes leading zeros from a string.
 
static gboolean _dt_cht_generate_patch_list (dt_colorchecker_chart_spec_t *chart, const cht_box_t *cht_patch, const cht_box_F_t *F_box)
 Generates a list of patches from the provided cht_patch structure. Patche's positions are calculated by iterating over the labels alphanumerically.
 
static GList * _parse_cht (const char *filename)
 Parses a CHT file and extracts the boxes data.
 
static gboolean _dispatch_cht_data (GList **boxes, dt_colorchecker_chart_spec_t *chart_spec)
 
static gboolean _dt_colorchecker_open_cht (const char *filename, dt_colorchecker_chart_spec_t *chart_spec)
 Opens a CHT file and parses its content to fill the chart_spec structure.
 
static dt_colorchecker_CGATS_types _dt_CGATS_get_type_value (const char *type)
 
static dt_colorchecker_material_types _dt_colorchecker_IT8_get_material_type (const cmsHANDLE *hIT8)
 
static const char * _dt_colorchecker_get_material_string (const dt_colorchecker_material_types material)
 Gets the string representation of the material type ("Transparent" or "Opaque") to be used in label name. The caller is responsible for freeing the returned string.
 
static gchar * _dt_colorchecker_get_standard_type (const char *type)
 Get the standard type name from a CGATS type.
 
static gboolean _dt_CGATS_is_supported (const cmsHANDLE *hIT8)
 Test if the file is a CGATS.17 file and if it contains one table of patch only.
 
static const char * _dt_CGATS_get_author (const cmsHANDLE *hIT8)
 
static const char * _dt_CGATS_get_date (const cmsHANDLE *hIT8)
 Get the production date of the CGATS file.
 
static const char * _dt_CGATS_get_manufacturer (const cmsHANDLE *hIT8)
 
static gchar * _dt_get_builtin_colorchecker_name (const dt_color_checker_targets target_type)
 Get the name of a built-in color checker.
 
static int _dt_get_builtin_colorchecker_patch_nb (const dt_color_checker_targets target_type)
 Get the number of patches in a built-in colorchecker.
 
static gchar * _dt_colorchecker_label_build_name (const dt_colorchecker_CGATS_label_make_name_t *label)
 build a name for the colorchecker. The returned string must be freed by the caller.
 
static char * _dt_CGATS_get_name (const cmsHANDLE *hIT8, const char *filename)
 Get the name of the colorchecker from the CGATS file. The resulting string must be freed by the caller.
 
static int _dt_colorchecker_cht_get_patch_nb (const char *filepath)
 Get the number of patches in a CHT file.
 
static float dE_1976 (const float a, const float b, const float c)
 
static void _dt_CGATS_find_whitest_blackest_greyest (const dt_color_checker_patch *const values, size_t *bwg, const size_t patch)
 
static dt_color_checker_patch_dt_colorchecker_CGATS_fill_patch_values (const cmsHANDLE hIT8, size_t *bwg, const dt_colorchecker_chart_spec_t *chart_spec, const size_t num_patches)
 fills the patch values from the CGATS file, converts to Lab if needed. The number of patches to be filled is given by the CGATS file.
 
dt_color_checker_tdt_colorchecker_user_ref_create (const char *color_filename, const char *cht_filename)
 Creates a color checker from a reference file (CGATS format).
 
static dt_colorchecker_label_t_dt_colorchecker_user_ref_make_label (const gchar *filename, const gchar *user_it8_dir)
 
static dt_colorchecker_label_t_dt_colorchecker_cht_make_label (const gchar *filename, const gchar *user_it8_dir)
 
int dt_colorchecker_find_builtin (GList **colorcheckers_label)
 Find all builtin colorcheckers.
 
int dt_colorchecker_find_CGATS_reference_files (GList **ref_colorcheckers_files)
 Find all CGAT files in the user config/color/it8 directory.
 
int dt_colorchecker_find_cht_files (GList **chts)
 Find all .cht files in the user config/color/it8 directory.
 

Macro Definition Documentation

◆ ERROR

#define ERROR
Value:
{ \
lineno = __LINE__; \
goto error; \
}
static void error(char *msg)
Definition ashift_lsd.c:202

ANSI CGATS.17 is THE standard text file format for exchanging color measurement data. This standard text format (the ASCII version is by far the most common) is the format accepted by most color measurement and profiling applications. They can be used with lcms2.

IT8 targets contain 288 patches in total. At the bottom of the chart, there is a grey scale consisting of 22 patches (labeled GS01 to GS22), flanked on each side by a Dmin and a Dmax patch, which are usually labeled as Dmin or GS0, and Dmax or GS23.

Definition at line 45 of file common/colorchecker.c.

◆ TWO_SQRT2f

#define TWO_SQRT2f   2.8284271247461900976f

Definition at line 88 of file common/colorchecker.c.

Typedef Documentation

◆ cht_box_F_t

typedef struct cht_box_F_t cht_box_F_t

◆ cht_box_t

typedef struct cht_box_t cht_box_t

◆ parser_state_t

Enumeration Type Documentation

◆ parser_state_t

Enumerator
BLOCK_NONE 
BLOCK_BOXES 
BLOCK_BOX_SHRINK 
BLOCK_REF_ROTATION 
BLOCK_XLIST 
BLOCK_YLIST 
BLOCK_EXPECTED 

Definition at line 51 of file common/colorchecker.c.

Function Documentation

◆ _dispatch_cht_data()

◆ _dt_CGATS_find_whitest_blackest_greyest()

static void _dt_CGATS_find_whitest_blackest_greyest ( const dt_color_checker_patch *const  values,
size_t *  bwg,
const size_t  patch 
)
inlinestatic

Definition at line 1153 of file common/colorchecker.c.

References dE_1976(), i, IS_NULL_PTR, and Lab.

Referenced by _dt_colorchecker_CGATS_fill_patch_values().

◆ _dt_CGATS_get_author()

static const char * _dt_CGATS_get_author ( const cmsHANDLE *  hIT8)
inlinestatic

Definition at line 923 of file common/colorchecker.c.

References IS_NULL_PTR.

Referenced by dt_colorchecker_user_ref_create().

◆ _dt_CGATS_get_date()

static const char * _dt_CGATS_get_date ( const cmsHANDLE *  hIT8)
inlinestatic

Get the production date of the CGATS file.

Parameters
hIT8the CGATS file handle
Returns
const char* a pointer to the date from the CGATS file

Definition at line 941 of file common/colorchecker.c.

References IS_NULL_PTR.

Referenced by dt_colorchecker_user_ref_create().

◆ _dt_CGATS_get_manufacturer()

static const char * _dt_CGATS_get_manufacturer ( const cmsHANDLE *  hIT8)
inlinestatic

Definition at line 955 of file common/colorchecker.c.

References IS_NULL_PTR.

Referenced by dt_colorchecker_user_ref_create().

◆ _dt_CGATS_get_name()

static char * _dt_CGATS_get_name ( const cmsHANDLE *  hIT8,
const char *  filename 
)
inlinestatic

Get the name of the colorchecker from the CGATS file. The resulting string must be freed by the caller.

Parameters
hIT8the CGATS file handle
filenamethe CGATS file name, used if the CGATS file does not contain a name.
Returns
char* String with the name of the colorchecker

Definition at line 1048 of file common/colorchecker.c.

References _dt_colorchecker_get_material_string(), _dt_colorchecker_get_standard_type(), _dt_colorchecker_IT8_get_material_type(), _dt_colorchecker_label_build_name(), description(), DT_DEBUG_VERBOSE, dt_free, dt_print(), IS_NULL_PTR, name, and dt_colorchecker_CGATS_label_make_name_t::type.

Referenced by _dt_colorchecker_user_ref_make_label(), and dt_colorchecker_user_ref_create().

◆ _dt_CGATS_get_type_value()

static dt_colorchecker_CGATS_types _dt_CGATS_get_type_value ( const char *  type)
inlinestatic

◆ _dt_CGATS_is_supported()

static gboolean _dt_CGATS_is_supported ( const cmsHANDLE *  hIT8)
static

Test if the file is a CGATS.17 file and if it contains one table of patch only.

Parameters
hIT8pointer to the cmsHANDLE
Returns
gboolean TRUE if the file is valid, FALSE otherwise.

Definition at line 846 of file common/colorchecker.c.

References _dt_CGATS_get_type_value(), CGATS_TYPE_UNKOWN, DT_DEBUG_VERBOSE, dt_print(), FALSE, i, IS_NULL_PTR, and TRUE.

Referenced by _dt_colorchecker_user_ref_make_label(), and dt_colorchecker_user_ref_create().

◆ _dt_cht_box_cleanup()

static void _dt_cht_box_cleanup ( void data)
static

◆ _dt_cht_box_extract()

◆ _dt_cht_extract_F()

static cht_box_F_t * _dt_cht_extract_F ( const char **  tokens)
static

Extracts the frame coordinates from the tokens, computes the width and height.

Parameters
tokensAn array of strings containing the data from a F box in a .cht file.
Returns
cht_box_F_t* A pointer to a cht_box_F_t structure containing the extracted coordinates and dimensions.

Definition at line 147 of file common/colorchecker.c.

References cht_box_F_t::ax, cht_box_F_t::ay, cht_box_F_t::bx, cht_box_F_t::by, cht_box_F_t::cx, cht_box_F_t::cy, cht_box_F_t::dx, cht_box_F_t::dy, cht_box_F_t::height, i, IS_NULL_PTR, and cht_box_F_t::width.

Referenced by _dispatch_cht_data().

◆ _dt_cht_generate_patch_list()

static gboolean _dt_cht_generate_patch_list ( dt_colorchecker_chart_spec_t chart,
const cht_box_t cht_patch,
const cht_box_F_t F_box 
)
static

Generates a list of patches from the provided cht_patch structure. Patche's positions are calculated by iterating over the labels alphanumerically.

Parameters
chartThe structure to populate with patches.
cht_patchThe structure containing the patch information.
F_boxThe cht_box_F_t structure containing the frame values.
Returns
gboolean Returns TRUE if the operation was successful, FALSE otherwise.

Definition at line 370 of file common/colorchecker.c.

References _dt_colorchecker_patch_init(), _increment_string(), _remove_leading_zeros(), cht_box_F_t::ax, cht_box_F_t::ay, dt_colorchecker_chart_spec_t::colums, dt_free, ERROR, error(), FALSE, dt_colorchecker_chart_spec_t::guide_size, cht_box_t::height, cht_box_F_t::height, IS_NULL_PTR, cht_box_t::key_letter, cht_box_t::label_x_end, cht_box_t::label_x_start, cht_box_t::label_y_end, cht_box_t::label_y_start, MAX, out, dt_colorchecker_chart_spec_t::patches, dt_colorchecker_chart_spec_t::rows, TRUE, cht_box_t::width, cht_box_F_t::width, cht_box_t::x_increment, cht_box_t::x_origin, cht_box_t::y_increment, and cht_box_t::y_origin.

Referenced by _dispatch_cht_data().

◆ _dt_colorchecker_CGATS_fill_patch_values()

static dt_color_checker_patch * _dt_colorchecker_CGATS_fill_patch_values ( const cmsHANDLE  hIT8,
size_t *  bwg,
const dt_colorchecker_chart_spec_t chart_spec,
const size_t  num_patches 
)
static

fills the patch values from the CGATS file, converts to Lab if needed. The number of patches to be filled is given by the CGATS file.

Parameters
hIT8the CGATS file handle
bwgthe array of indices for the black, white, and grey patches
chart_specthe color checker chart specification, used to get the number of patches and patch size
num_patchesthe number of patches to fill, should be the minimum between the CGATS file and the chart specification
Returns
dt_color_checker_patch* a pointer to the array of patches filled with values, or NULL on error.

Definition at line 1181 of file common/colorchecker.c.

References _dt_CGATS_find_whitest_blackest_greyest(), _dt_colorchecker_copy_patch(), dt_colorchecker_patch_array_init(), dt_colorchecker_patch_cleanup(), dt_free_align, dt_XYZ_to_Lab(), error(), FALSE, i, IS_NULL_PTR, Lab, name, p, dt_colorchecker_chart_spec_t::patches, and TRUE.

Referenced by dt_colorchecker_user_ref_create().

◆ _dt_colorchecker_chart_spec_cleanup()

◆ _dt_colorchecker_chart_spec_init()

◆ _dt_colorchecker_cht_get_patch_nb()

static int _dt_colorchecker_cht_get_patch_nb ( const char *  filepath)
static

Get the number of patches in a CHT file.

Parameters
filepaththe path to the CHT file
Returns
int the number of patches in the CHT file, or 0 if an error occurred.

Definition at line 1115 of file common/colorchecker.c.

References _dt_colorchecker_chart_spec_cleanup(), _dt_colorchecker_chart_spec_init(), _dt_colorchecker_open_cht(), IS_NULL_PTR, and dt_colorchecker_chart_spec_t::num_patches.

Referenced by _dt_colorchecker_cht_make_label().

◆ _dt_colorchecker_cht_make_label()

static dt_colorchecker_label_t * _dt_colorchecker_cht_make_label ( const gchar *  filename,
const gchar *  user_it8_dir 
)
static

◆ _dt_colorchecker_copy_patch()

◆ _dt_colorchecker_get_material_string()

static const char * _dt_colorchecker_get_material_string ( const dt_colorchecker_material_types  material)
inlinestatic

Gets the string representation of the material type ("Transparent" or "Opaque") to be used in label name. The caller is responsible for freeing the returned string.

Parameters
material(dt_colorchecker_material_types) the material type of the color checker
Returns
gchar* The string representation of the material type, or NULL if unknown.

Definition at line 778 of file common/colorchecker.c.

References COLOR_CHECKER_MATERIAL_TRANSPARENT, COLOR_CHECKER_MATERIAL_UNKNOWN, and colorchecker_material_types.

Referenced by _dt_CGATS_get_name().

◆ _dt_colorchecker_get_standard_type()

static gchar * _dt_colorchecker_get_standard_type ( const char *  type)
static

Get the standard type name from a CGATS type.

Parameters
typethe CGATS type (the first 7 characters of the CGATS file)
Returns
gchar* The standard type name, or "Unknown Type" if the type is invalid.

Definition at line 807 of file common/colorchecker.c.

References _dt_CGATS_get_type_value(), CGATS_TYPE_CTI3, CGATS_TYPE_IT8_7_1, CGATS_TYPE_IT8_7_2, DT_DEBUG_VERBOSE, dt_print(), IS_NULL_PTR, t, and type.

Referenced by _dt_CGATS_get_name().

◆ _dt_colorchecker_IT8_get_material_type()

◆ _dt_colorchecker_label_build_name()

static gchar * _dt_colorchecker_label_build_name ( const dt_colorchecker_CGATS_label_make_name_t label)
static

build a name for the colorchecker. The returned string must be freed by the caller.

Parameters
labelthe struct containing useful data to build a label
Returns
gchar* String with the name of the colorchecker.

Definition at line 1013 of file common/colorchecker.c.

References dt_colorchecker_CGATS_label_make_name_t::description, dt_free, IS_NULL_PTR, dt_colorchecker_CGATS_label_make_name_t::material, name, dt_colorchecker_CGATS_label_make_name_t::type, and type.

Referenced by _dt_CGATS_get_name().

◆ _dt_colorchecker_open_cht()

static gboolean _dt_colorchecker_open_cht ( const char *  filename,
dt_colorchecker_chart_spec_t chart_spec 
)
static

Opens a CHT file and parses its content to fill the chart_spec structure.

Parameters
filenameThe path to the CHT file.
chart_specThe initialized structure to fill with the parsed data.
Returns
gboolean TRUE if the file was successfully parsed and the chart_spec filled, FALSE otherwise.

Definition at line 713 of file common/colorchecker.c.

References _dispatch_cht_data(), _parse_cht(), FALSE, IS_NULL_PTR, TRUE, and dt_colorchecker_chart_spec_t::type.

Referenced by _dt_colorchecker_cht_get_patch_nb(), and dt_colorchecker_user_ref_create().

◆ _dt_colorchecker_patch_init()

◆ _dt_colorchecker_user_ref_make_label()

static dt_colorchecker_label_t * _dt_colorchecker_user_ref_make_label ( const gchar *  filename,
const gchar *  user_it8_dir 
)
static

◆ _dt_get_builtin_colorchecker_name()

static gchar * _dt_get_builtin_colorchecker_name ( const dt_color_checker_targets  target_type)
inlinestatic

Get the name of a built-in color checker.

Parameters
target_typeThe type of colorchecker
Returns
char* The name of the colorchecker

Definition at line 972 of file common/colorchecker.c.

References dt_colorchecker_cleanup(), dt_get_color_checker(), IS_NULL_PTR, dt_color_checker_t::name, and name.

Referenced by dt_colorchecker_find_builtin().

◆ _dt_get_builtin_colorchecker_patch_nb()

static int _dt_get_builtin_colorchecker_patch_nb ( const dt_color_checker_targets  target_type)
inlinestatic

Get the number of patches in a built-in colorchecker.

Parameters
target_typeThe type of colorchecker
Returns
int The number of patches in the colorchecker, or 0 if an error occurred.

Definition at line 992 of file common/colorchecker.c.

References dt_colorchecker_cleanup(), dt_get_color_checker(), IS_NULL_PTR, and dt_color_checker_t::patches.

Referenced by dt_colorchecker_find_builtin().

◆ _increment_string()

static char * _increment_string ( const gchar *  in)
static

Increments a string alphanumerically.

Parameters
inThe input string to increment.
Returns
char* A new string with the last character incremented. The caller is responsible for freeing the returned string.

Definition at line 297 of file common/colorchecker.c.

References dt_free, i, and IS_NULL_PTR.

Referenced by _dt_cht_generate_patch_list().

◆ _parse_cht()

static GList * _parse_cht ( const char *  filename)
static

Parses a CHT file and extracts the boxes data.

Parameters
filenameThe path to the CHT file to parse.
Returns
GList* A GList containing the parsed boxes data. Each element is a GList of strings representing a box.

Definition at line 525 of file common/colorchecker.c.

References BLOCK_BOX_SHRINK, BLOCK_BOXES, BLOCK_NONE, ERROR, error(), IS_NULL_PTR, and TRUE.

Referenced by _dt_colorchecker_open_cht().

◆ _remove_leading_zeros()

static const char * _remove_leading_zeros ( const char *  in)
inlinestatic

Removes leading zeros from a string.

Parameters
inThe input string.
Returns
char* A pointer to the first char following the leading zero.

Definition at line 352 of file common/colorchecker.c.

References IS_NULL_PTR.

Referenced by _dt_cht_generate_patch_list().

◆ dE_1976()

static float dE_1976 ( const float  a,
const float  b,
const float  c 
)
static

Definition at line 1148 of file common/colorchecker.c.

Referenced by _dt_CGATS_find_whitest_blackest_greyest().

◆ dt_colorchecker_copy()

◆ dt_colorchecker_find_builtin()

int dt_colorchecker_find_builtin ( GList **  colorcheckers_label)

Find all builtin colorcheckers.

Parameters
colorcheckers_labelNULL GList that will be populated with found colorcheckers.
Returns
int Number of found colorcheckers.

Definition at line 1506 of file common/colorchecker.c.

References _dt_get_builtin_colorchecker_name(), _dt_get_builtin_colorchecker_patch_nb(), COLOR_CHECKER_USER_REF, dt_colorchecker_label_init(), dt_free, IS_NULL_PTR, k, and name.

Referenced by dt_colorchecker_find().

◆ dt_colorchecker_find_CGATS_reference_files()

int dt_colorchecker_find_CGATS_reference_files ( GList **  ref_colorcheckers_files)

Find all CGAT files in the user config/color/it8 directory.

Parameters
ref_colorcheckers_filesNULL GList that will be populated with found IT8 files
Returns
int Number of found files

Definition at line 1536 of file common/colorchecker.c.

References _dt_colorchecker_user_ref_make_label(), DT_DEBUG_VERBOSE, dt_free, dt_loc_get_user_config_dir(), dt_print(), IS_NULL_PTR, and PATH_MAX.

Referenced by dt_colorchecker_find_color().

◆ dt_colorchecker_find_cht_files()

int dt_colorchecker_find_cht_files ( GList **  chts)

Find all .cht files in the user config/color/it8 directory.

Parameters
chtsNULL GList that will be populated with found IT8 files
Returns
int Number of found files

Definition at line 1569 of file common/colorchecker.c.

References _dt_colorchecker_cht_make_label(), dt_free, dt_loc_get_user_config_dir(), IS_NULL_PTR, and PATH_MAX.

Referenced by dt_colorchecker_find().

◆ dt_colorchecker_user_ref_create()

dt_color_checker_t * dt_colorchecker_user_ref_create ( const char *  color_filename,
const char *  cht_filename 
)