![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
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. | |
TIFF sidecar I/O implementation for drawlayer layers.
| typedef struct drawlayer_tiff_export_params_t drawlayer_tiff_export_params_t |
| typedef union dt_drawlayer_io_fp32_t dt_drawlayer_io_fp32_t |
|
inlinestatic |
|
inlinestatic |
Clear uint16 RGBA row/buffer to transparent black.
Referenced by _write_page().
|
static |
References drawlayer_tiff_export_params_t::bpp, drawlayer_tiff_export_params_t::compress, drawlayer_tiff_export_params_t::compresslevel, DT_COLORSPACE_NONE, dt_imageio_export_with_flags(), dt_imageio_get_format_by_name(), DT_INTENT_PERCEPTUAL, FALSE, dt_imageio_module_data_t::height, dt_imageio_module_data_t::max_height, dt_imageio_module_data_t::max_width, drawlayer_tiff_export_params_t::shortfile, dt_imageio_module_data_t::style, TRUE, and dt_imageio_module_data_t::width.
Referenced by dt_drawlayer_io_background_layer_job_run().
|
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().
|
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().
|
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().
|
static |
References DT_DRAWLAYER_IO_NAME_SIZE, FALSE, and name.
Referenced by dt_drawlayer_io_background_layer_job_run().
|
inlinestatic |
Load one half-float RGBA texel to float RGBA.
References _half_to_float().
Referenced by dt_drawlayer_io_load_layer().
|
static |
Overlay one clipped float patch span into a half-float TIFF row.
References _float_to_half(), dt_drawlayer_io_patch_t::height, MAX, MIN, dt_drawlayer_io_patch_t::pixels, width, dt_drawlayer_io_patch_t::width, dt_drawlayer_io_patch_t::x, and dt_drawlayer_io_patch_t::y.
Referenced by _write_page().
|
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().
|
static |
Rewrite sidecar with optional update/insert/delete of one target layer.
References _scan_directories(), _write_page(), dt_drawlayer_io_layer_info_t::count, dt_free, FALSE, dt_drawlayer_io_layer_info_t::found, dt_drawlayer_io_layer_info_t::index, and TRUE.
Referenced by dt_drawlayer_io_insert_layer(), and dt_drawlayer_io_store_layer().
|
static |
Normalize/sanitize requested layer name with fallback handling.
References name.
Referenced by dt_drawlayer_io_make_unique_name().
|
static |
Scan TIFF directories and resolve best match for name/order target.
References dt_drawlayer_io_layer_info_t::count, FALSE, dt_drawlayer_io_layer_info_t::found, height, dt_drawlayer_io_layer_info_t::height, dt_drawlayer_io_layer_info_t::index, dt_drawlayer_io_layer_info_t::name, TRUE, width, dt_drawlayer_io_layer_info_t::width, and dt_drawlayer_io_layer_info_t::work_profile.
Referenced by _rewrite_sidecar(), dt_drawlayer_io_find_layer(), and dt_drawlayer_io_load_layer().
|
static |
|
static |
Referenced by dt_drawlayer_io_background_layer_job_run().
|
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().
|
static |
| int32_t dt_drawlayer_io_background_layer_job_run | ( | dt_job_t * | job | ) |
Worker entrypoint for async "create background from input" sidecar jobs.
References _export_pre_module_fullres_to_tiff(), _layer_name_non_empty(), _sidecar_timestamp_from_path(), dt_drawlayer_io_background_job_result_t::created_bg_name, dt_control_job_get_params(), dt_drawlayer_cache_alloc_temp_buffer(), dt_drawlayer_cache_clear_transparent_float(), dt_drawlayer_cache_free_temp_buffer(), dt_drawlayer_io_find_layer(), dt_drawlayer_io_insert_layer(), dt_drawlayer_io_load_flat_rgba(), dt_drawlayer_io_make_unique_name_plain(), DT_DRAWLAYER_IO_NAME_SIZE, dt_free, dt_drawlayer_io_patch_t::height, dt_drawlayer_io_background_job_result_t::imgid, dt_drawlayer_io_background_job_result_t::initiator_layer_name, dt_drawlayer_io_background_job_result_t::initiator_layer_order, MAX, dt_drawlayer_io_background_job_result_t::message, MIN, dt_drawlayer_io_patch_t::pixels, dt_drawlayer_io_background_job_result_t::sidecar_timestamp, dt_drawlayer_io_background_job_result_t::success, TRUE, dt_drawlayer_io_patch_t::width, dt_drawlayer_io_patch_t::x, and dt_drawlayer_io_patch_t::y.
Referenced by _create_background_layer_from_input().
| 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.
Lookup layer by name/order and return directory metadata.
References _scan_directories(), FALSE, and dt_drawlayer_io_layer_info_t::found.
Referenced by _create_background_layer_from_input(), _current_layer_missing_in_sidecar(), _delete_current_layer(), _refresh_piece_base_cache(), _rename_current_layer_from_gui(), dt_drawlayer_ensure_layer_cache(), and dt_drawlayer_io_background_layer_job_run().
| 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.
Referenced by _populate_layer_list().
| 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().
| 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.
Referenced by _rename_current_layer_from_gui(), dt_drawlayer_io_make_unique_name(), and dt_drawlayer_io_make_unique_name_plain().
| 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().
| 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().
| 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.
Load one layer from TIFF sidecar into float RGBA patch.
References _load_half_pixel_rgba(), _read_scanline_rgba(), _scan_directories(), dt_drawlayer_cache_clear_transparent_float(), dt_free, FALSE, dt_drawlayer_io_layer_info_t::found, dt_drawlayer_io_patch_t::height, dt_drawlayer_io_layer_info_t::height, dt_drawlayer_io_layer_info_t::index, dt_drawlayer_io_patch_t::pixels, row, TRUE, dt_drawlayer_io_patch_t::width, dt_drawlayer_io_layer_info_t::width, dt_drawlayer_io_patch_t::x, and dt_drawlayer_io_patch_t::y.
Referenced by _refresh_piece_base_cache(), and dt_drawlayer_ensure_layer_cache().
| 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().
| 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().
| gboolean dt_drawlayer_io_sidecar_path | ( | const int32_t | imgid, |
| char * | path, | ||
| const size_t | path_size | ||
| ) |
Build absolute sidecar path from image id.
Build absolute sidecar TIFF path from image id.
References dt_image_full_path(), FALSE, and TRUE.
Referenced by _create_background_layer_from_input(), _current_layer_missing_in_sidecar(), _delete_current_layer(), _populate_layer_list(), _refresh_piece_base_cache(), _rename_current_layer_from_gui(), dt_drawlayer_ensure_layer_cache(), and dt_drawlayer_flush_layer_cache().
| 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().