31#include <glib/gstdio.h>
60 out.
u = (h & 0x7fffu) << 13;
62 out.u += (127u - 15u) << 23;
65 out.u += (128u - 16u) << 23;
72 out.u |= (h & 0x8000u) << 16;
80 const uint32_t
sign = (in.
u >> 16) & 0x8000u;
81 const uint32_t
exponent = (in.
u >> 23) & 0xffu;
87 return (uint16_t)(
sign | 0x7c00u);
119 if(
half_exp >= 0x7c00u)
return (uint16_t)(
sign | 0x7c00u);
157 return tmp[0] !=
'\0';
165 if(
g_stat(path, &st) != 0)
return 0;
166 return (int64_t)st.st_mtime;
195 imgid, path, format,
format_params,
TRUE,
FALSE,
TRUE,
FALSE,
FALSE, (filter && filter[0]) ? filter :
NULL,
196 FALSE,
FALSE,
DT_COLORSPACE_NONE,
NULL,
DT_INTENT_PERCEPTUAL,
NULL,
NULL, 0, 0,
NULL,
NULL);
219 const char *filename =
sep1 + 1;
225 if(len == 0)
return FALSE;
243 const char *work_profile)
278 if(spp != 4)
return FALSE;
315 const int dst_x0 =
MAX(0, patch->
x - offset_x);
335 memset(info, 0,
sizeof(*info));
341 const gboolean
has_target_name = (target_name && target_name[0] !=
'\0');
486 for(uint32_t y = 0; y <
height; y++)
504 const int layer_y = (int)y + offset_y;
533 memset(&info, 0,
sizeof(info));
569 for(
int dir = 0; dir < info.
count && ok; dir++)
648 if(path[0] ==
'\0')
return FALSE;
664 return info && info->
found;
703 for(
int py = 0; py < patch->
height; py++)
715 for(
int px = 0; px < patch->
width; px++)
720 float *
dst = patch->
pixels + 4 * ((size_t)py * patch->
width + px);
733 if(pixels) *pixels =
NULL;
741 uint32_t w = 0, h = 0;
749 if(w == 0 || h == 0 || spp < 1)
773 for(uint32_t y = 0; y < h && ok; y++)
781 for(uint32_t
x = 0;
x < w;
x++)
783 float r = 0.0f,
g = 0.0f, b = 0.0f, a = 1.0f;
787 const float *src = (
const float *)
row + (
size_t)
x * spp;
798 if(spp >= 4) a = src[3];
802 const uint16_t *src = (
const uint16_t *)
row + (
size_t)
x * spp;
817 const uint16_t *src = (
const uint16_t *)
row + (
size_t)
x * spp;
820 r = src[0] / 65535.0f;
821 g = src[1] / 65535.0f;
822 b = src[2] / 65535.0f;
826 r =
g = b = src[0] / 65535.0f;
828 if(spp >= 4) a = src[3] / 65535.0f;
832 const uint8_t *src = (
const uint8_t *)
row + (
size_t)
x * spp;
841 r =
g = b = src[0] / 255.0f;
843 if(spp >= 4) a = src[3] / 255.0f;
851 float *
dst =
out + 4 * ((size_t)y * w +
x);
890 const int insert_order = (insert_after_order >= 0) ? (insert_after_order + 1) : -1;
919 if(!
IS_NULL_PTR(work_profile) && work_profile[0] !=
'\0')
946 if(
name[0] ==
'\0')
return;
981 *count = (int)
arr->len;
1001 const int n = (!
IS_NULL_PTR(count) && *count > 0) ? *count : 0;
1047 (
size_t)
params->layer_width *
params->layer_height * 4 *
sizeof(
float),
"drawlayer bg layer");
1061 for(
int y = 0; y <
copy_h; y++)
const dt_colorspaces_color_profile_t * dt_colorspaces_get_profile(dt_colorspaces_color_profile_type_t type, const char *filename, dt_colorspaces_profile_role_t role)
Resolve a profile identity to its registered entry.
The colour-profile module's API: which profiles exist, and how to apply one.
const dt_colormatrix_t dt_aligned_pixel_t out
void dt_image_full_path(const int32_t imgid, char *pathname, size_t pathname_len, gboolean *from_cache, const char *calling_func)
Get the full path of an image out of the database.
GHashTable * names
GtkWidget* -> the name the application knows it by.
int dt_imageio_export_with_flags(const int32_t imgid, const char *filename, dt_imageio_module_format_t *format, dt_imageio_module_data_t *format_params, const gboolean ignore_exif, const gboolean display_byteorder, const gboolean high_quality, const double scale_factor, const gboolean thumbnail_export, const char *filter, const gboolean copy_metadata, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, dt_iop_color_intent_t icc_intent, dt_imageio_module_storage_t *storage, dt_imageio_module_data_t *storage_params, int num, int total, dt_export_metadata_t *metadata, dt_atomic_int *shutdown)
dt_imageio_module_format_t * dt_imageio_get_format_by_name(const char *name)
int32_t dt_drawlayer_io_background_layer_job_run(dt_job_t *job)
Worker entrypoint for async "create background from input" sidecar jobs.
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.
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.
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.
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 float _clamp01(const float value)
Clamp scalar to [0,1].
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 layer_width, const int layer_height, int *final_order)
Insert a new layer after given order in sidecar TIFF.
gboolean dt_drawlayer_io_sidecar_path(const int32_t imgid, char *path, const size_t path_size)
Build absolute sidecar path from image id.
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 layer_width, const int layer_height, const gboolean delete_target, const int insert_order, int *final_order)
Rewrite sidecar with optional update/insert/delete of one target layer.
static void _load_half_pixel_rgba(const uint16_t *src, float rgba[4])
Load one half-float RGBA texel to float RGBA.
static int64_t dt_drawlayer_sidecar_timestamp_from_path(const char *path)
static float _half_to_float(const uint16_t h)
Convert IEEE-754 binary16 to float32.
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 dt_drawlayer_layer_name_non_empty(const char *name)
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 void _clear_transparent_half(uint16_t *pixels, const size_t pixel_count)
Clear uint16 RGBA row/buffer to transparent black.
gboolean dt_drawlayer_io_rename_layer(const char *path, const char *current_name, const char *new_name, const char *work_profile, const int layer_width, const int layer_height, dt_drawlayer_io_layer_info_t *info)
Rename one existing layer page while preserving its directory payload.
gboolean dt_drawlayer_io_list_layer_names(const char *path, char ***names, int *count)
List all TIFF layer page names.
gboolean dt_drawlayer_io_load_layer(const char *path, const char *target_name, const int target_order, const int layer_width, const int layer_height, dt_drawlayer_io_patch_t *patch)
Load one sidecar layer patch into float RGBA destination patch.
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.
gboolean dt_drawlayer_io_delete_layer(const char *path, const char *target_name, const int layer_width, const int layer_height)
Delete one existing layer page from the sidecar TIFF.
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.
static uint16_t _float_to_half(float value)
Convert float32 to IEEE-754 binary16 with rounding.
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.
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 layer_width, const int layer_height, const gboolean delete_target, int *final_order)
Store/update/delete one layer entry in sidecar TIFF.
static gboolean _export_pre_module_fullres_to_tiff(const int32_t imgid, const char *filter, const char *path)
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_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 layer_width, const int layer_height)
Write one output page, optionally copying from source and patch overlay.
void dt_drawlayer_io_free_layer_names(char ***names, int *count)
Free array returned by dt_drawlayer_io_list_layer_names.
TIFF sidecar I/O API for drawlayer layers.
#define DT_DRAWLAYER_IO_NAME_SIZE
Patch/cache helpers for drawlayer process and preview buffers.
void * dt_control_job_get_params(const _dt_job_t *job)
static const dt_iop_drawlayer_params_t * params
static const dt_dev_pixelpipe_t const dt_dev_pixelpipe_iop_t int int * layer_height
static const dt_dev_pixelpipe_t const dt_dev_pixelpipe_iop_t int * layer_width
_lib_location_type_t type
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
#define __OMP_FOR_SIMD__(...)
dt_colorspaces_color_profile_type_t
@ DT_COLORSPACE_NONE
No profile / "take it from the image settings". Never matches a list entry.
@ DT_PROFILE_ROLE_ANY
All four roles, in registration order.
static const dt_aligned_pixel_simd_t sign
static const dt_aligned_pixel_simd_t value
static const dt_aligned_pixel_simd_t exponent
void * dt_drawlayer_cache_alloc_temp_buffer(const size_t bytes, const char *name)
Allocate temporary aligned cache buffer.
void dt_drawlayer_cache_free_temp_buffer(void **buffer, const char *name)
Free temporary aligned cache buffer.
void dt_drawlayer_cache_clear_transparent_float(float *pixels, const size_t pixel_count)
Fill float RGBA buffer with transparent black.
dt_imageio_module_data_t global
One registered profile: its identity, its LCMS handle, and where it sits in each combo box.
cmsHPROFILE profile
the actual profile; NULL for the three category entries
Parameters owned by the async "create background from input" job.
Result posted back to the UI after background-layer creation.
int initiator_layer_order
char initiator_layer_name[64]
int64_t sidecar_timestamp
Metadata returned when probing one layer directory in sidecar TIFF.
Float RGBA patch used by drawlayer I/O routines.