Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
io.c File Reference

TIFF sidecar I/O implementation for drawlayer layers. More...

#include "common/darktable.h"
#include "iop/drawlayer/io.h"
#include "common/colorspaces.h"
#include "common/image.h"
#include "common/imageio.h"
#include "common/imageio_module.h"
#include "control/jobs.h"
#include "iop/drawlayer/cache.h"
#include <glib/gstdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <tiffio.h>
+ Include dependency graph for io.c:

Data Structures

union  dt_drawlayer_io_fp32_t
 
struct  drawlayer_tiff_export_params_t
 

Typedefs

typedef union dt_drawlayer_io_fp32_t dt_drawlayer_io_fp32_t
 
typedef struct drawlayer_tiff_export_params_t drawlayer_tiff_export_params_t
 

Functions

static float _clamp01 (const float value)
 Clamp scalar to [0,1].
 
static float _half_to_float (const uint16_t h)
 Convert IEEE-754 binary16 to float32.
 
static uint16_t _float_to_half (float value)
 Convert float32 to IEEE-754 binary16 with rounding.
 
static void _clear_transparent_half (uint16_t *pixels, const size_t pixel_count)
 Clear uint16 RGBA row/buffer to transparent black.
 
static void _load_half_pixel_rgba (const uint16_t *src, float rgba[4])
 Load one half-float RGBA texel to float RGBA.
 
static gboolean _layer_name_non_empty (const char *name)
 
static int64_t _sidecar_timestamp_from_path (const char *path)
 
static gboolean _export_pre_module_fullres_to_tiff (const int32_t imgid, const char *filter, const char *path)
 
static gboolean _icc_blob_from_profile_key (const char *work_profile, uint8_t **icc_data, uint32_t *icc_len)
 Resolve embedded ICC blob from serialized work-profile key.
 
static gboolean _set_directory_tags (TIFF *tiff, const uint32_t width, const uint32_t height, const char *name, const char *work_profile)
 Write TIFF directory tags for one RGBA half-float page.
 
static gboolean _read_scanline_rgba (TIFF *tiff, const uint32_t width, const uint32_t row, uint16_t *out)
 Read one TIFF scanline into half-float RGBA buffer.
 
static gboolean _write_scanline_rgba (TIFF *tiff, const uint32_t row, const uint16_t *in)
 Write one half-float RGBA scanline into TIFF page.
 
static void _overlay_patch_row_rgba (uint16_t *dst_row, const uint32_t width, const int offset_x, const int raw_y, const dt_drawlayer_io_patch_t *patch)
 Overlay one clipped float patch span into a half-float TIFF row.
 
static void _scan_directories (TIFF *tiff, const char *target_name, const int target_order, dt_drawlayer_io_layer_info_t *info)
 Scan TIFF directories and resolve best match for name/order target.
 
static gboolean _write_page (TIFF *dst, TIFF *src, const int src_dir, const char *name, const char *work_profile, const dt_drawlayer_io_patch_t *patch, const int raw_width, const int raw_height)
 Write one output page, optionally copying from source and patch overlay.
 
static gboolean _rewrite_sidecar (const char *path, const char *target_name, const int target_order, const char *work_profile, const dt_drawlayer_io_patch_t *patch, const int raw_width, const int raw_height, const gboolean delete_target, const int insert_order, int *final_order)
 Rewrite sidecar with optional update/insert/delete of one target layer.
 
gboolean dt_drawlayer_io_layer_name_exists (const char *path, const char *candidate, const int ignore_index)
 Test if a layer name already exists in sidecar TIFF.
 
static void _sanitize_requested_layer_name (const char *requested, const char *fallback_name, char *name, const size_t name_size)
 Normalize/sanitize requested layer name with fallback handling.
 
gboolean dt_drawlayer_io_sidecar_path (const int32_t imgid, char *path, const size_t path_size)
 Build absolute sidecar path from image id.
 
gboolean dt_drawlayer_io_find_layer (const char *path, const char *target_name, const int target_order, dt_drawlayer_io_layer_info_t *info)
 Find target layer metadata in sidecar TIFF.
 
gboolean dt_drawlayer_io_load_layer (const char *path, const char *target_name, const int target_order, const int raw_width, const int raw_height, dt_drawlayer_io_patch_t *patch)
 Load one sidecar layer patch into float RGBA destination patch.
 
gboolean dt_drawlayer_io_load_flat_rgba (const char *path, float **pixels, int *width, int *height)
 Load first TIFF page as flat RGBA float image.
 
gboolean dt_drawlayer_io_store_layer (const char *path, const char *target_name, const int target_order, const char *work_profile, const dt_drawlayer_io_patch_t *patch, const int raw_width, const int raw_height, const gboolean delete_target, int *final_order)
 Store/update/delete one layer entry in sidecar TIFF.
 
gboolean dt_drawlayer_io_insert_layer (const char *path, const char *target_name, const int insert_after_order, const char *work_profile, const dt_drawlayer_io_patch_t *patch, const int raw_width, const int raw_height, int *final_order)
 Insert a new layer after given order in sidecar TIFF.
 
void dt_drawlayer_io_make_unique_name (const char *path, const char *requested, const char *fallback_name, char *name, const size_t name_size)
 Create unique layer name with fallback if requested name is empty.
 
void dt_drawlayer_io_make_unique_name_plain (const char *path, const char *requested, char *name, const size_t name_size)
 Create unique layer name without fallback source.
 
gboolean dt_drawlayer_io_list_layer_names (const char *path, char ***names, int *count)
 List all TIFF layer page names.
 
void dt_drawlayer_io_free_layer_names (char ***names, int *count)
 Free array returned by dt_drawlayer_io_list_layer_names.
 
int32_t dt_drawlayer_io_background_layer_job_run (dt_job_t *job)
 Worker entrypoint for async "create background from input" sidecar jobs.
 

Detailed Description

TIFF sidecar I/O implementation for drawlayer layers.

Typedef Documentation

◆ drawlayer_tiff_export_params_t

◆ dt_drawlayer_io_fp32_t

Function Documentation

◆ _clamp01()

static float _clamp01 ( const float  value)
inlinestatic

Clamp scalar to [0,1].

References value.

Referenced by dt_drawlayer_io_load_flat_rgba().

◆ _clear_transparent_half()

static void _clear_transparent_half ( uint16_t *  pixels,
const size_t  pixel_count 
)
inlinestatic

Clear uint16 RGBA row/buffer to transparent black.

Referenced by _write_page().

◆ _export_pre_module_fullres_to_tiff()

◆ _float_to_half()

static uint16_t _float_to_half ( float  value)
inlinestatic

Convert float32 to IEEE-754 binary16 with rounding.

References exponent, dt_drawlayer_io_fp32_t::f, sign, dt_drawlayer_io_fp32_t::u, and value.

Referenced by _overlay_patch_row_rgba().

◆ _half_to_float()

static float _half_to_float ( const uint16_t  h)
inlinestatic

Convert IEEE-754 binary16 to float32.

References dt_drawlayer_io_fp32_t::f, h, out, and dt_drawlayer_io_fp32_t::u.

Referenced by _load_half_pixel_rgba(), and dt_drawlayer_io_load_flat_rgba().

◆ _icc_blob_from_profile_key()

static gboolean _icc_blob_from_profile_key ( const char *  work_profile,
uint8_t **  icc_data,
uint32_t *  icc_len 
)
static

Resolve embedded ICC blob from serialized work-profile key.

References dt_colorspaces_get_profile(), dt_free, DT_PROFILE_DIRECTION_ANY, FALSE, dt_colorspaces_color_profile_t::profile, TRUE, and type.

Referenced by _write_page().

◆ _layer_name_non_empty()

static gboolean _layer_name_non_empty ( const char *  name)
static

◆ _load_half_pixel_rgba()

static void _load_half_pixel_rgba ( const uint16_t *  src,
float  rgba[4] 
)
inlinestatic

Load one half-float RGBA texel to float RGBA.

References _half_to_float().

Referenced by dt_drawlayer_io_load_layer().

◆ _overlay_patch_row_rgba()

static void _overlay_patch_row_rgba ( uint16_t *  dst_row,
const uint32_t  width,
const int  offset_x,
const int  raw_y,
const dt_drawlayer_io_patch_t patch 
)
static

◆ _read_scanline_rgba()

static gboolean _read_scanline_rgba ( TIFF *  tiff,
const uint32_t  width,
const uint32_t  row,
uint16_t *  out 
)
static

Read one TIFF scanline into half-float RGBA buffer.

References bpp, FALSE, out, row, TRUE, and width.

Referenced by _write_page(), and dt_drawlayer_io_load_layer().

◆ _rewrite_sidecar()

static gboolean _rewrite_sidecar ( const char *  path,
const char *  target_name,
const int  target_order,
const char *  work_profile,
const dt_drawlayer_io_patch_t patch,
const int  raw_width,
const int  raw_height,
const gboolean  delete_target,
const int  insert_order,
int *  final_order 
)
static

◆ _sanitize_requested_layer_name()

static void _sanitize_requested_layer_name ( const char *  requested,
const char *  fallback_name,
char *  name,
const size_t  name_size 
)
static

Normalize/sanitize requested layer name with fallback handling.

References name.

Referenced by dt_drawlayer_io_make_unique_name().

◆ _scan_directories()

◆ _set_directory_tags()

static gboolean _set_directory_tags ( TIFF *  tiff,
const uint32_t  width,
const uint32_t  height,
const char *  name,
const char *  work_profile 
)
static

Write TIFF directory tags for one RGBA half-float page.

References FALSE, height, name, TRUE, and width.

Referenced by _write_page().

◆ _sidecar_timestamp_from_path()

static int64_t _sidecar_timestamp_from_path ( const char *  path)
static

◆ _write_page()

static gboolean _write_page ( TIFF *  dst,
TIFF *  src,
const int  src_dir,
const char *  name,
const char *  work_profile,
const dt_drawlayer_io_patch_t patch,
const int  raw_width,
const int  raw_height 
)
static

Write one output page, optionally copying from source and patch overlay.

References _clear_transparent_half(), _icc_blob_from_profile_key(), _overlay_patch_row_rgba(), _read_scanline_rgba(), _set_directory_tags(), _write_scanline_rgba(), dt_free, FALSE, height, name, and width.

Referenced by _rewrite_sidecar().

◆ _write_scanline_rgba()

static gboolean _write_scanline_rgba ( TIFF *  tiff,
const uint32_t  row,
const uint16_t *  in 
)
static

Write one half-float RGBA scanline into TIFF page.

References row.

Referenced by _write_page().

◆ dt_drawlayer_io_background_layer_job_run()

◆ dt_drawlayer_io_find_layer()

gboolean dt_drawlayer_io_find_layer ( const char *  path,
const char *  target_name,
const int  target_order,
dt_drawlayer_io_layer_info_t info 
)

◆ dt_drawlayer_io_free_layer_names()

void dt_drawlayer_io_free_layer_names ( char ***  names,
int *  count 
)

Free array returned by dt_drawlayer_io_list_layer_names.

Free name list returned by dt_drawlayer_io_list_layer_names.

References dt_free, i, and n.

Referenced by _populate_layer_list().

◆ dt_drawlayer_io_insert_layer()

gboolean dt_drawlayer_io_insert_layer ( const char *  path,
const char *  target_name,
const int  insert_after_order,
const char *  work_profile,
const dt_drawlayer_io_patch_t patch,
const int  raw_width,
const int  raw_height,
int *  final_order 
)

Insert a new layer after given order in sidecar TIFF.

Insert new layer after target order in sidecar TIFF.

References _rewrite_sidecar(), and FALSE.

Referenced by dt_drawlayer_io_background_layer_job_run().

◆ dt_drawlayer_io_layer_name_exists()

gboolean dt_drawlayer_io_layer_name_exists ( const char *  path,
const char *  candidate,
const int  ignore_index 
)

Test if a layer name already exists in sidecar TIFF.

Check whether candidate layer name already exists.

References FALSE, and TRUE.

Referenced by _rename_current_layer_from_gui(), dt_drawlayer_io_make_unique_name(), and dt_drawlayer_io_make_unique_name_plain().

◆ dt_drawlayer_io_list_layer_names()

gboolean dt_drawlayer_io_list_layer_names ( const char *  path,
char ***  names,
int *  count 
)

List all TIFF layer page names.

List all layer names from sidecar TIFF.

References FALSE, i, out, and TRUE.

Referenced by _populate_layer_list().

◆ dt_drawlayer_io_load_flat_rgba()

gboolean dt_drawlayer_io_load_flat_rgba ( const char *  path,
float **  pixels,
int *  width,
int *  height 
)

Load first TIFF page as flat RGBA float image.

Load full TIFF page as flat RGBA float image.

References _clamp01(), _half_to_float(), a, b, bpp, dt_drawlayer_cache_clear_transparent_float(), dt_free, FALSE, g, h, height, out, r, row, TRUE, width, and x.

Referenced by dt_drawlayer_io_background_layer_job_run().

◆ dt_drawlayer_io_load_layer()

gboolean dt_drawlayer_io_load_layer ( const char *  path,
const char *  target_name,
const int  target_order,
const int  raw_width,
const int  raw_height,
dt_drawlayer_io_patch_t patch 
)

◆ dt_drawlayer_io_make_unique_name()

void dt_drawlayer_io_make_unique_name ( const char *  path,
const char *  requested,
const char *  fallback_name,
char *  name,
const size_t  name_size 
)

Create unique layer name with fallback if requested name is empty.

Build unique layer name with fallback and numeric suffixing.

References _sanitize_requested_layer_name(), dt_drawlayer_io_layer_name_exists(), DT_DRAWLAYER_IO_NAME_SIZE, MAX, and name.

Referenced by dt_drawlayer_ensure_layer_cache().

◆ dt_drawlayer_io_make_unique_name_plain()

void dt_drawlayer_io_make_unique_name_plain ( const char *  path,
const char *  requested,
char *  name,
const size_t  name_size 
)

Create unique layer name without fallback source.

Build unique layer name without fallback override.

References dt_drawlayer_io_layer_name_exists(), DT_DRAWLAYER_IO_NAME_SIZE, MAX, and name.

Referenced by dt_drawlayer_io_background_layer_job_run().

◆ dt_drawlayer_io_sidecar_path()

gboolean dt_drawlayer_io_sidecar_path ( const int32_t  imgid,
char *  path,
const size_t  path_size 
)

◆ dt_drawlayer_io_store_layer()

gboolean dt_drawlayer_io_store_layer ( const char *  path,
const char *  target_name,
const int  target_order,
const char *  work_profile,
const dt_drawlayer_io_patch_t patch,
const int  raw_width,
const int  raw_height,
const gboolean  delete_target,
int *  final_order 
)

Store/update/delete one layer entry in sidecar TIFF.

Store or replace one layer page in sidecar TIFF.

References _rewrite_sidecar(), and FALSE.

Referenced by _delete_current_layer(), _rename_current_layer_from_gui(), dt_drawlayer_ensure_layer_cache(), and dt_drawlayer_flush_layer_cache().