Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
imageio_core.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2014 johannes hanika.
4 Copyright (C) 2010 Anton Blanchard.
5 Copyright (C) 2010-2012 Henrik Andersson.
6 Copyright (C) 2010 Kaminsky Andrey.
7 Copyright (C) 2010-2020 Tobias Ellinghaus.
8 Copyright (C) 2011 Bruce Guenter.
9 Copyright (C) 2011 Omari Stephens.
10 Copyright (C) 2011 Sergey Pavlov.
11 Copyright (C) 2011-2014, 2019 Ulrich Pegelow.
12 Copyright (C) 2012-2015 Jérémy Rosen.
13 Copyright (C) 2012-2014 Pascal de Bruijn.
14 Copyright (C) 2012-2015, 2018-2021 Pascal Obry.
15 Copyright (C) 2012 Richard Wonka.
16 Copyright (C) 2013 Simon Spannagel.
17 Copyright (C) 2014-2015 Pedro Côrte-Real.
18 Copyright (C) 2014-2018 Roman Lebedev.
19 Copyright (C) 2015 Edouard Gomez.
20 Copyright (C) 2016 Chris Hodapp.
21 Copyright (C) 2016, 2020 Matthieu Volat.
22 Copyright (C) 2017 Žilvinas Žaltiena.
23 Copyright (C) 2018-2019 Edgardo Hoszowski.
24 Copyright (C) 2018 Sören Witt.
25 Copyright (C) 2019, 2022 Aldric Renaudin.
26 Copyright (C) 2019 Andreas Schneider.
27 Copyright (C) 2019-2022 Hanno Schwalm.
28 Copyright (C) 2019-2021 Heiko Bauke.
29 Copyright (C) 2019 Philippe Weyland.
30 Copyright (C) 2020 a.
31 Copyright (C) 2020, 2022-2026 Aurélien PIERRE.
32 Copyright (C) 2020-2021 Hubert Kowalski.
33 Copyright (C) 2020 Miloš Komarčević.
34 Copyright (C) 2021 Daniel Vogelbacher.
35 Copyright (C) 2021 luzpaz.
36 Copyright (C) 2021 Ralf Brown.
37 Copyright (C) 2022 Martin Bařinka.
38 Copyright (C) 2022 parafin.
39 Copyright (C) 2022 Philipp Lutz.
40 Copyright (C) 2023-2024 Alynx Zhou.
41 Copyright (C) 2023 Ricky Moon.
42 Copyright (C) 2026 Guillaume Stutin.
43
44 darktable is free software: you can redistribute it and/or modify
45 it under the terms of the GNU General Public License as published by
46 the Free Software Foundation, either version 3 of the License, or
47 (at your option) any later version.
48
49 darktable is distributed in the hope that it will be useful,
50 but WITHOUT ANY WARRANTY; without even the implied warranty of
51 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 GNU General Public License for more details.
53
54 You should have received a copy of the GNU General Public License
55 along with darktable. If not, see <http://www.gnu.org/licenses/>.
56*/
58#include "common/image.h"
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62#include "system/macros.h"
63#include "system/openmp.h"
65#include "system/mem_alloc.h"
66#include "system/simd.h"
67#include "common/logging.h"
68#include "common/times.h"
69#include "common/paths.h"
71#include "common/xmp_sidecar.h"
72#include "metadata/exif.h"
73#include "caches/image_cache.h"
74#include "history/history.h"
78#ifdef HAVE_OPENEXR
79#include "imageio/imageio_exr.h"
80#endif
81#ifdef HAVE_OPENJPEG
82#include "imageio/imageio_j2k.h"
83#endif
85#include "imageio/imageio_pfm.h"
86#include "imageio/imageio_png.h"
87#include "imageio/imageio_pnm.h"
92#ifdef HAVE_LIBAVIF
94#endif
95#ifdef HAVE_LIBHEIF
97#endif
98#ifdef HAVE_WEBP
100#endif
102#include "caches/mipmap_cache.h"
103#include "common/styles.h"
104#include "common/conf.h"
105#include "control/user_message.h"
106#include "develop/develop.h"
107#include "develop/imageop.h"
108#include "develop/dev_history.h"
109
110
111#include <assert.h>
112#include <glib/gstdio.h>
113#include <inttypes.h>
114#include <math.h>
115#include <stdio.h>
116#include <stdlib.h>
117#include <string.h>
118#include <strings.h>
120#include "control/signal.h"
121
122
123// Best-effort image-type hint from the file extension. Returns DT_IMAGE_RAW / DT_IMAGE_LDR /
124// DT_IMAGE_HDR for the unambiguous extensions, or 0 ("unknown") for containers whose dynamic range
125// only the decoder can settle (TIFF, AVIF, HEIF/HEIC, DNG -- see dt_image_ext_is_ambiguous()).
126// Callers must treat 0 as "decode it"; dt_image_buffer_resolve_flags() sets the authoritative
127// LDR/HDR/MOSAIC flags once decoded.
128int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t *th_width, int32_t *th_height,
130{
131 int res = 1;
132
133 uint8_t *buf = NULL;
134 char *mime_type = NULL;
135 size_t bufsize;
136
137 if(dt_exif_get_thumbnail(filename, &buf, &bufsize, &mime_type, th_width, th_height, MAX(width, height)))
138 goto error;
139
140 // dt_exif_get_thumbnail() sets mime_type with strdup(), which returns NULL under memory
141 // pressure while still reporting success -- it checks its buffer allocation but not this
142 // one. Everything below reads it: two strcmp() calls and a "%s" in the error path.
143 if(IS_NULL_PTR(mime_type)) goto error;
144
145 if(strcmp(mime_type, "image/jpeg") == 0)
146 {
147 // Decompress the JPG into our own memory format
149 if(dt_imageio_jpeg_decompress_header(buf, bufsize, &jpg)) goto error;
150 *buffer = (uint8_t *)dt_pixelpipe_cache_alloc_align_cache(
151 sizeof(uint8_t) * 4 * jpg.width * jpg.height,
152 0);
153 if(!*buffer) goto error;
154
155 *th_width = jpg.width;
156 *th_height = jpg.height;
157 // TODO: check if the embedded thumbs have a color space set! currently we assume that it's always sRGB
159 if(dt_imageio_jpeg_decompress(&jpg, *buffer))
160 {
162 *buffer = NULL;
163 goto error;
164 }
165
166 res = 0;
167 }
168 else if(!strcmp(mime_type, "image/tiff") || !strcmp(mime_type, "image/x-tiff"))
169 {
170 // The only other preview format raw files actually use. See
171 // dt_imageio_tiff_decode_blob() for why libtiff rather than a generic decoder.
172 if(dt_imageio_tiff_decode_blob(buf, bufsize, buffer, th_width, th_height))
173 {
174 // TODO: check if the embedded thumbs have a color space set! currently we assume that it's always sRGB
176 res = 0;
177 }
178 }
179
180 if(res)
181 {
182 fprintf(
183 stderr,
184 "[dt_imageio_large_thumbnail] error: Not a supported thumbnail image format or broken thumbnail: %s\n",
185 IS_NULL_PTR(mime_type) ? "(none)" : mime_type);
186 goto error;
187 }
188
189error:
190 dt_free(mime_type);
191 dt_free(buf);
192 return res;
193}
194
195gboolean dt_imageio_crop_thumbnail(const dt_boundingbox_t box, uint8_t *const buffer,
196 int32_t *width, int32_t *height)
197{
198 if(IS_NULL_PTR(buffer) || IS_NULL_PTR(width) || IS_NULL_PTR(height)) return FALSE;
199
200 const int32_t in_width = *width;
201 const int32_t in_height = *height;
202 if(in_width < 1 || in_height < 1) return FALSE;
203
204 /* The box is normalized against the frame the camera renders its previews from, which is the
205 * same DefaultCropOrigin/DefaultCropSize rectangle the tag itself references -- so it maps
206 * onto the decoded preview directly, at whatever resolution that preview happens to be. */
207 const int32_t left = CLAMP((int32_t)roundf(box[1] * in_width), 0, in_width - 1);
208 const int32_t top = CLAMP((int32_t)roundf(box[0] * in_height), 0, in_height - 1);
209 const int32_t right = CLAMP((int32_t)roundf(box[3] * in_width), left + 1, in_width);
210 const int32_t bottom = CLAMP((int32_t)roundf(box[2] * in_height), top + 1, in_height);
211
212 const int32_t out_width = right - left;
213 const int32_t out_height = bottom - top;
214 if(out_width == in_width && out_height == in_height) return FALSE;
215
216 /* Compact in place, forward: destination row j starts at 4 * j * out_width, its source at
217 * 4 * ((j + top) * in_width + left). Since out_width <= in_width and top, left >= 0, the
218 * destination never runs ahead of the source, so no row is overwritten before it is read. */
219 for(int32_t j = 0; j < out_height; j++)
220 {
221 const uint8_t *const source = buffer + 4 * ((size_t)(j + top) * in_width + left);
222 uint8_t *const destination = buffer + 4 * (size_t)j * out_width;
223 memmove(destination, source, 4 * (size_t)out_width);
224 }
225
226 *width = out_width;
227 *height = out_height;
228 return TRUE;
229}
230
231gboolean dt_imageio_has_mono_preview(const char *filename)
232{
234 uint8_t *tmp = NULL;
235 int32_t thumb_width = 0, thumb_height = 0;
236 gboolean mono = FALSE;
237
238 if(dt_imageio_large_thumbnail(filename, &tmp, &thumb_width, &thumb_height, &color_space, -1, -1))
239 goto cleanup;
240 if((thumb_width < 32) || (thumb_height < 32) || (IS_NULL_PTR(tmp)))
241 goto cleanup;
242
243 mono = TRUE;
244 for(int y = 0; y < thumb_height; y++)
245 {
246 uint8_t *in = (uint8_t *)tmp + (size_t)4 * y * thumb_width;
247 for(int x = 0; x < thumb_width; x++, in += 4)
248 {
249 if((in[0] != in[1]) || (in[0] != in[2]) || (in[1] != in[2]))
250 {
251 mono = FALSE;
252 goto cleanup;
253 }
254 }
255 }
256
257 cleanup:
258
259 dt_print(DT_DEBUG_IMAGEIO,"[dt_imageio_has_mono_preview] testing `%s', yes/no %i, %ix%i\n", filename, mono, thumb_width, thumb_height);
261 return mono;
262}
263
265void dt_imageio_flip_buffers(char *out, const char *in, const size_t bpp, const int wd, const int ht,
266 const int fwd, const int fht, const int stride,
267 const dt_image_orientation_t orientation)
268{
269 if(!orientation)
270 {
272 for(int j = 0; j < ht; j++) memcpy(out + (size_t)j * bpp * wd, in + (size_t)j * stride, bpp * wd);
273 return;
274 }
275 int ii = 0, jj = 0;
276 int si = bpp, sj = wd * bpp;
277 if(orientation & ORIENTATION_SWAP_XY)
278 {
279 sj = bpp;
280 si = ht * bpp;
281 }
282 if(orientation & ORIENTATION_FLIP_Y)
283 {
284 jj = (int)fht - jj - 1;
285 sj = -sj;
286 }
287 if(orientation & ORIENTATION_FLIP_X)
288 {
289 ii = (int)fwd - ii - 1;
290 si = -si;
291 }
293 for(int j = 0; j < ht; j++)
294 {
295 char *out2 = out + (size_t)labs(sj) * jj + (size_t)labs(si) * ii + (size_t)sj * j;
296 const char *in2 = in + (size_t)stride * j;
297 for(int i = 0; i < wd; i++)
298 {
299 memcpy(out2, in2, bpp);
300 in2 += bpp;
301 out2 += si;
302 }
303 }
304}
305
306void dt_imageio_flip_buffers_ui8_to_float(float *out, const uint8_t *in, const float black, const float white,
307 const int ch, const int wd, const int ht, const int fwd,
308 const int fht, const int stride,
309 const dt_image_orientation_t orientation)
310{
311 const float scale = 1.0f / (white - black);
312 if(!orientation)
313 {
315 for(int j = 0; j < ht; j++)
316 for(int i = 0; i < wd; i++)
317 for(int k = 0; k < ch; k++)
318 out[4 * ((size_t)j * wd + i) + k] = (in[(size_t)j * stride + (size_t)ch * i + k] - black) * scale;
319 return;
320 }
321 int ii = 0, jj = 0;
322 int si = 4, sj = wd * 4;
323 if(orientation & ORIENTATION_SWAP_XY)
324 {
325 sj = 4;
326 si = ht * 4;
327 }
328 if(orientation & ORIENTATION_FLIP_Y)
329 {
330 jj = (int)fht - jj - 1;
331 sj = -sj;
332 }
333 if(orientation & ORIENTATION_FLIP_X)
334 {
335 ii = (int)fwd - ii - 1;
336 si = -si;
337 }
339 for(int j = 0; j < ht; j++)
340 {
341 float *out2 = out + (size_t)labs(sj) * jj + (size_t)labs(si) * ii + sj * j;
342 const uint8_t *in2 = in + (size_t)stride * j;
343 for(int i = 0; i < wd; i++)
344 {
345 for(int k = 0; k < ch; k++) out2[k] = (in2[k] - black) * scale;
346 in2 += ch;
347 out2 += si;
348 }
349 }
350}
351
352/* Every decoder answers DT_IMAGEIO_FILE_CORRUPTED to a file in another format, and rawspeed
353 * DT_IMAGEIO_UNSUPPORTED_FORMAT, so neither says anything once the whole cascade has failed. The
354 * failures kept here come from a decoder that recognised the file and says why it could not load
355 * it: the first one is the reason, and a later decoder turning the file down does not replace it. */
357{
358 if(reason != DT_IMAGEIO_FILE_CORRUPTED) return reason;
359
360 switch(ret)
361 {
366 return ret;
367 default:
368 return reason;
369 }
370}
371
373{
374 // if buf is NULL, don't proceed
375 if(IS_NULL_PTR(buf))
376 return DT_IMAGEIO_OK;
377
380
381#ifdef HAVE_OPENEXR
382 ret = dt_imageio_open_exr(img, filename, buf);
383 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
384 return ret;
385 reason = _decoder_reason(reason, ret);
386#endif
387
388 ret = dt_imageio_open_rgbe(img, filename, buf);
389 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
390 return ret;
391 reason = _decoder_reason(reason, ret);
392
393 ret = dt_imageio_open_pfm(img, filename, buf);
394 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
395 return ret;
396 reason = _decoder_reason(reason, ret);
397
398#ifdef HAVE_LIBAVIF
399 ret = dt_imageio_open_avif(img, filename, buf);
400 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
401 return ret;
402 reason = _decoder_reason(reason, ret);
403#endif
404
405#ifdef HAVE_LIBHEIF
406 ret = dt_imageio_open_heif(img, filename, buf);
407 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
408 return ret;
409 reason = _decoder_reason(reason, ret);
410#endif
411
412 return reason;
413}
414
415// Decoder routing: dt_image_ext_is_ldr() drives dt_imageio_open_raster(), the generic/
416// exotic-capable chain -- kept distinct from is_hdr() (dt_imageio_open_hdr(), the dedicated
417// OpenEXR/Radiance/PFM/AVIF/HEIF chain). See the comment on dt_image_ext_is_raw/_ldr/_hdr in
418// common/image_extensions.h for why these must never be combined for routing purposes.
419gboolean dt_imageio_is_raster(const char *filename)
420{
421 const char *c = filename + strlen(filename);
422 while(c > filename && *c != '.') c--;
423 if(*c != '.') return FALSE;
424 return dt_image_ext_is_ldr(c + 1);
425}
426
427gboolean dt_imageio_is_raw(const char *filename)
428{
429 const char *c = filename + strlen(filename);
430 while(c > filename && *c != '.') c--;
431 if(*c != '.') return FALSE;
432 return dt_image_ext_is_raw(c + 1);
433}
434
435int dt_imageio_is_hdr(const char *filename)
436{
437 const char *c = filename + strlen(filename);
438 while(c > filename && *c != '.') c--;
439 if(*c != '.') return FALSE;
440 return dt_image_ext_is_hdr(c + 1);
441}
442
458static gboolean _is_in_list(const char *elem, char *list)
459{
460 if(IS_NULL_PTR(elem) || IS_NULL_PTR(list)) return FALSE;
461
462 char *saveptr = NULL;
463 for(char *entry = strtok_r(list, ",", &saveptr); !IS_NULL_PTR(entry);
464 entry = strtok_r(NULL, ",", &saveptr))
465 {
466 if(!g_ascii_strcasecmp(entry, elem)) return TRUE;
467 }
468
469 return FALSE;
470}
471
472gboolean dt_imageio_is_handled_by_libraw(dt_image_t *img, const char *filename)
473{
474 // Allow users to define some extensions, makers and models that should be handled by Libraw
475 gboolean is_handled = FALSE;
476
477 // g_strrstr() returns NULL when the name has no dot at all, and NULL + 1 is undefined
478 // behaviour before _is_in_list() ever gets to dereference it. An extensionless file in an
479 // imported folder is enough to reach this.
480 const char *dot = g_strrstr(filename, ".");
481 const char *ext = IS_NULL_PTR(dot) ? NULL : dot + 1;
482
483 char *extensions = dt_conf_get_string("libraw/extensions");
484 char *makers = dt_conf_get_string("libraw/makers");
485 char *models = dt_conf_get_string("libraw/models");
486
487 // _is_in_list() tokenises its list argument in place; these are private copies from
488 // dt_conf_get_string(), so that is safe.
489 is_handled |= _is_in_list(ext, extensions);
490 is_handled |= _is_in_list(img->exif_maker, makers);
491 is_handled |= _is_in_list(img->exif_model, models);
492
493 dt_free(extensions);
494 dt_free(makers);
495 dt_free(models);
496
497 const char *iolib = (is_handled) ? "Libraw" : "Rawspeed";
498 dt_print(DT_DEBUG_IMAGEIO, "[image I/O] image `%s` from camera `%s` of maker `%s` loaded with %s\n", filename,
499 img->exif_model, img->exif_maker, iolib);
500
501 return is_handled;
502}
503
504// transparent read method to load ldr image to dt_raw_image_t with exif and so on.
506{
507 // if buf is NULL, don't proceed
508 if(IS_NULL_PTR(buf))
509 return DT_IMAGEIO_OK;
510
513
514 ret = dt_imageio_open_jpeg(img, filename, buf);
515 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
516 return ret;
517 reason = _decoder_reason(reason, ret);
518
519 ret = dt_imageio_open_tiff(img, filename, buf);
520 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
521 return ret;
522 reason = _decoder_reason(reason, ret);
523
524#ifdef HAVE_WEBP
525 ret = dt_imageio_open_webp(img, filename, buf);
526 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
527 return ret;
528 reason = _decoder_reason(reason, ret);
529#endif
530
531 ret = dt_imageio_open_png(img, filename, buf);
532 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
533 return ret;
534 reason = _decoder_reason(reason, ret);
535
536#ifdef HAVE_OPENJPEG
537 ret = dt_imageio_open_j2k(img, filename, buf);
538 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
539 return ret;
540 reason = _decoder_reason(reason, ret);
541#endif
542
543 ret = dt_imageio_open_pnm(img, filename, buf);
544 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
545 return ret;
546 reason = _decoder_reason(reason, ret);
547
548 return reason;
549}
550
552{
553 // if buf is NULL, don't proceed
554 if(IS_NULL_PTR(buf))
555 return DT_IMAGEIO_OK;
556
559
560 /* check if user wants to force processing through Libraw */
561 const gboolean force_libraw = dt_imageio_is_handled_by_libraw(img, filename);
562
563 /* use rawspeed to load the raw */
564 if(!force_libraw)
565 {
566 ret = dt_imageio_open_rawspeed(img, filename, buf);
567 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
568 return ret;
569 reason = _decoder_reason(reason, ret);
570 }
571
572#ifdef HAVE_LIBRAW
573 /* fallback that tries to open file via LibRAW to support Canon CR3 */
574 ret = dt_imageio_open_libraw(img, filename, buf);
575 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
576 return ret;
577 reason = _decoder_reason(reason, ret);
578#endif
579
580 /* try Rawspeed again in case Libraw was forced but failed */
581 if(force_libraw)
582 {
583 ret = dt_imageio_open_rawspeed(img, filename, buf);
584 if(ret == DT_IMAGEIO_OK || ret == DT_IMAGEIO_CACHE_FULL)
585 return ret;
586 reason = _decoder_reason(reason, ret);
587 }
588
589 return reason;
590}
591
592void dt_imageio_to_fractional(float in, uint32_t *num, uint32_t *den)
593{
594 if(!(in >= 0))
595 {
596 *num = *den = 0;
597 return;
598 }
599 *den = 1;
600 *num = (int)(in * *den + .5f);
601 while(fabsf(*num / (float)*den - in) > 0.001f)
602 {
603 *den *= 10;
604 *num = (int)(in * *den + .5f);
605 }
606}
607
608int dt_imageio_export(const int32_t imgid, const char *filename, dt_imageio_module_format_t *format,
609 dt_imageio_module_data_t *format_params, const double scale_factor, const gboolean high_quality,
610 const gboolean copy_metadata, const gboolean export_masks,
611 dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename,
613 dt_imageio_module_data_t *storage_params, int num, int total, dt_export_metadata_t *metadata)
614{
615 if(strcmp(format->mime(format_params), "x-copy") == 0)
616 /* This is a just a copy, skip process and just export */
617 return format->write_image(format_params, filename, NULL, icc_type, icc_filename, NULL, 0, imgid, num, total, NULL,
618 export_masks);
619 else
620 {
621 return dt_imageio_export_with_flags(imgid, filename, format, format_params, FALSE, FALSE, TRUE, scale_factor,
622 FALSE, FALSE, NULL, copy_metadata, export_masks, icc_type, icc_filename, icc_intent,
623 storage, storage_params, num, total, metadata, NULL);
624 }
625}
626
627gboolean _apply_style_before_export(dt_develop_t *dev, const dt_imageio_module_data_t *format_params, const int32_t imgid)
628{
629 GList *style_items = dt_styles_get_item_list(format_params->style, TRUE, -1);
630 if(IS_NULL_PTR(style_items))
631 {
632 dt_control_alert(_("Export failed"), _("cannot find the style to apply during export."),
633 format_params->style);
634 return TRUE;
635 }
636
637 dt_ioppr_check_iop_order(dev, imgid, "dt_imageio_export_with_flags");
640
641 for(GList *st_items = style_items; st_items; st_items = g_list_next(st_items))
642 {
643 dt_style_item_t *st_item = (dt_style_item_t *)st_items->data;
645 }
646
647 g_list_free_full(style_items, dt_style_item_free);
648 style_items = NULL;
649
650 return FALSE;
651}
652
653void _print_export_debug(dt_dev_pixelpipe_t *pipe, dt_imageio_module_data_t *format_params, const gboolean use_style)
654{
656 {
657 fprintf(stderr,"[dt_imageio_export_with_flags] ");
658 if(use_style)
659 {
660 fprintf(stderr,"appending style `%s'\n", format_params->style);
661 }
662 else fprintf(stderr,"\n");
663 int cnt = 0;
664 for(GList *nodes = pipe->nodes; nodes; nodes = g_list_next(nodes))
665 {
667 if(piece->enabled)
668 {
669 cnt++;
670 fprintf(stderr," %s", piece->module->op);
671 }
672 }
673 fprintf(stderr," (%i)\n", cnt);
674 }
675}
676
677
678void _filter_pipeline(const char *filter, dt_dev_pixelpipe_t *pipe)
679{
680 // Warning: can only filter prior to or past to a certain module, but not both !!!
681 if(filter)
682 {
683 if(!strncmp(filter, "pre:", 4)) dt_dev_pixelpipe_disable_after(pipe, filter + 4);
684 if(!strncmp(filter, "post:", 5)) dt_dev_pixelpipe_disable_before(pipe, filter + 5);
685 }
686}
687
688
689static gboolean _get_export_size(const dt_dev_pixelpipe_t *pipe, const double scale_factor, double *scale,
690 int width, int height, int *processed_width, int *processed_height)
691{
692 const double image_ratio = (double)pipe->processed_width / (double)pipe->processed_height;
693
694 if(scale_factor > 0.0)
695 {
696 *scale = fmin(scale_factor, 1.);
697 *processed_height = (int)roundf(pipe->processed_height * (*scale));
698 *processed_width = (int)roundf(pipe->processed_width * (*scale));
699 return 0;
700 }
701
702 // if width and height are both 0, we use the full resolution of the image
703 if(width == 0 && height == 0)
704 {
705 // original resolution
706 *processed_width = pipe->processed_width;
707 *processed_height = pipe->processed_height;
708 *scale = 1.;
709 return 0;
710 }
711
712 if(width > 0 && height > 0)
713 {
714 // fixed width and height : fit within a bounding box
715 *processed_width = MIN(pipe->processed_width, width);
716 *processed_height = MIN(pipe->processed_height, height);
717 double scale_x = (double)*processed_width / (double)pipe->processed_width;
718 double scale_y = (double)*processed_height / (double)pipe->processed_height;
719 *scale = fmin(scale_x, scale_y);
720
721 // Note : we handle each case separately to avoid rounding errors
722 if(image_ratio > 1.0)
723 {
724 // landscape image, width is the limiting factor
725 *processed_width = MIN((int)roundf(pipe->processed_width * (*scale)), pipe->processed_width);
726 *processed_height = MIN((int)roundf(*processed_width / image_ratio), pipe->processed_height);
727 }
728 else if(image_ratio < 1.0)
729 {
730 // portrait image, height is the limiting factor
731 *processed_height = MIN((int)roundf(pipe->processed_height * (*scale)), pipe->processed_height);
732 *processed_width = MIN((int)roundf(*processed_height * image_ratio), pipe->processed_width);
733 }
734 else
735 {
736 // square image, both width and height are the limiting factors
737 *processed_width = MIN((int)roundf(pipe->processed_width * (*scale)), pipe->processed_width);
738 *processed_height = MIN((int)roundf(pipe->processed_height * (*scale)), pipe->processed_height);
739 }
740 return 0;
741 }
742
743 if(width > 0)
744 {
745 // fluid height, fixed width
746 *processed_width = MIN(pipe->processed_width, width);
747 *processed_height = (int)roundf(*processed_width / image_ratio);
748 }
749 else if(height > 0)
750 {
751 // fluid width, fixed height
752 *processed_height = MIN(pipe->processed_height, height);
753 *processed_width = (int)roundf(*processed_height * image_ratio);
754 }
755
756 double scale_x = (double)*processed_width / (double)pipe->processed_width;
757 double scale_y = (double)*processed_height / (double)pipe->processed_height;
758 *scale = fmin(scale_x, scale_y);
759
760 return 0;
761}
762
763
764void _clamp_float_to_uint8(const float *const inbuf, uint8_t *const outbuf, const size_t processed_width,
765 const size_t processed_height)
766{
768 for(size_t k = 0; k < processed_width * processed_height; k++)
770 outbuf[4 * k + c] = (uint8_t)CLAMPF(roundf(inbuf[4 * k + c] * 255.f), 0.f, 255.f);
771}
772
773
774void _swap_byteorder_float_to_uint8(const float *const restrict inbuf, uint8_t *const outbuf,
775 const size_t processed_width, const size_t processed_height)
776{
778 for(size_t k = 0; k < processed_width * processed_height; k++)
779 {
780 outbuf[4 * k + 0] = (uint8_t)CLAMPF(roundf(inbuf[4 * k + 2] * 255.f), 0.f, 255.f);
781 outbuf[4 * k + 1] = (uint8_t)CLAMPF(roundf(inbuf[4 * k + 1] * 255.f), 0.f, 255.f);
782 outbuf[4 * k + 2] = (uint8_t)CLAMPF(roundf(inbuf[4 * k + 0] * 255.f), 0.f, 255.f);
783 outbuf[4 * k + 3] = (uint8_t)CLAMPF(roundf(inbuf[4 * k + 3] * 255.f), 0.f, 255.f);
784 }
785}
786
787
788void _export_final_buffer_to_uint16(const float *const restrict inbuf, uint16_t *const outbuf,
789 const size_t processed_width, const size_t processed_height)
790{
792 for(size_t k = 0; k < processed_width * processed_height; k++)
794 outbuf[4 * k + c] = (uint16_t)CLAMP(roundf(inbuf[4 * k + c] * 65535.f), 0.f, 65535.f);
795}
796
806static void _export_convert_output(const float *const data, void *const outbuf, const int bpp,
807 const size_t width, const size_t height,
808 const gboolean display_byteorder, const gboolean thumbnail_export)
809{
810 const size_t pixels = width * height * 4;
811 if(bpp == 8)
812 {
813 if(display_byteorder)
815 else
817
818 if(thumbnail_export)
819 {
820 uint8_t *thumbnail_buf = outbuf;
822 for(size_t k = 0; k < pixels / 4; k++) thumbnail_buf[4 * k + 3] = UINT8_MAX;
823 }
824 }
825 else if(bpp == 16)
826 {
828
829 if(thumbnail_export)
830 {
831 uint16_t *thumbnail_buf = outbuf;
833 for(size_t k = 0; k < pixels / 4; k++) thumbnail_buf[4 * k + 3] = UINT16_MAX;
834 }
835 }
836 else // output float, no further harm done to the pixels :)
837 {
838 memcpy(outbuf, data, sizeof(float_t) * pixels);
839
840 if(thumbnail_export)
841 {
842 float *thumbnail_buf = outbuf;
844 for(size_t k = 0; k < pixels / 4; k++) thumbnail_buf[4 * k + 3] = 1.0f;
845 }
846 }
847}
848
849// internal function: to avoid exif blob reading + 8-bit byteorder flag + high-quality override
850dt_imageio_retval_t dt_imageio_export_with_flags(const int32_t imgid, const char *filename,
852 const gboolean ignore_exif, const gboolean display_byteorder,
853 const gboolean high_quality, const double scale_factor, const gboolean thumbnail_export,
854 const gboolean ignore_history, const char *filter, const gboolean copy_metadata,
855 const gboolean export_masks,
856 dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename,
858 dt_imageio_module_data_t *storage_params, int num, int total,
859 dt_export_metadata_t *metadata, dt_atomic_int *shutdown)
860{
861 dt_times_t start;
862 dt_get_times(&start);
863
865 void *outbuf = NULL;
866 // set at every `goto error`, so the caller learns which step failed
868
869 // Get the history, aka sequence of editing changes
871 dt_dev_init(&dev, 0);
872 dt_dev_load_image(&dev, imgid);
874
875 // The pipe syncs its nodes from the history up to history_end only, so at 0 every node gets
876 // its module's defaults. The history read above stays, and with it the module instances.
877 if(ignore_history)
878 {
879 dt_pthread_rwlock_wrlock(&dev.history_mutex);
881 dt_pthread_rwlock_unlock(&dev.history_mutex);
882 dt_print(DT_DEBUG_IMAGEIO, "[dt_imageio_export] image %" PRId32 " rendered without its history\n", imgid);
883 }
884
885 // Get a pipeline, aka sequence of nodes. It is initialised before the first `goto error`, since
886 // the error path cleans it up: a cleanup run on what the stack held there walks and frees
887 // garbage pointers. The init reads no history, so the style below still reaches the nodes.
889 int res = thumbnail_export
891 : dt_dev_pixelpipe_init_export(&pipe, &dev, format->levels(format_params), export_masks);
892
893 if(!res)
894 {
896 goto error;
897 }
898
899 pipe.shutdown_ext = shutdown;
900
901 // Apply styles on top of current history
902 const gboolean use_style = !thumbnail_export && format_params->style[0] != '\0';
903 // If a style is to be applied during export, add the iop params into the history
904 if(use_style && _apply_style_before_export(&dev, format_params, imgid))
905 {
907 goto error;
908 }
909
910 int width = MAX(format_params->max_width, 0);
911 int height = MAX(format_params->max_height, 0);
912 double scale = 1.;
913
914 // The nodes are built from the history, so only once the style is in it
916
917 // Sync history with pipeline nodes
918 // Update the ICC type if DT_COLORSPACE_NONE is passed
919 dt_colorspaces_get_output_profile(imgid, &icc_type, icc_filename);
920 dt_dev_pixelpipe_set_icc(&pipe, icc_type, icc_filename, icc_intent);
921
922 // Find out what input size we want
924
925 // Take a local copy of the input buffer so we can release the mipmap cache lock immediately
926 dt_mipmap_cache_get(&buf, imgid, size, DT_MIPMAP_BLOCKING, 'r');
927
928 if(IS_NULL_PTR(buf.buf) || buf.width == 0 || buf.height == 0)
929 {
930 // the loader's own reason (unsupported camera, corrupted file...)
931 status = buf.status;
933 goto error;
934 }
935
936 const size_t buf_width = buf.width;
937 const size_t buf_height = buf.height;
939
940 // Update size with actual input and resync nodes
941 dt_dev_pixelpipe_set_input(&pipe, imgid, buf_width, buf_height, buf.iscale, size);
943
944 // Write debug info to stdout
945 _print_export_debug(&pipe, format_params, use_style);
946
947 // Remove modules past or prior a certain one.
948 // Useful for partial exports, for technical purposes (HDR merge)
949 _filter_pipeline(filter, &pipe);
950
951 // This export path drives the pipe directly instead of through dt_dev_pixelpipe_change(), so
952 // establish the buffer-format contract (and disable incompatible nodes) explicitly, after the
953 // optional filtering changed the node set and before ROI planning / global hashing.
955
956 // Get theoritical final size of image, taking distortions and croppings AND borders into account,
957 // considering full-size original input. Meaning we can enlarge or reduce the original image,
958 // even taking full-res input.
959 // Needs to be done after optional filtering, in case we filter out distortion modules
960 dt_dev_pixelpipe_get_roi_out(&pipe, pipe.iwidth, pipe.iheight, &pipe.processed_width,
961 &pipe.processed_height);
962
963 dt_show_times(&start, "[export] creating pixelpipe");
964
965 // Compute the actual final sizes that fit within the bounding box width*height
966 // while preserving original image ratio
967 int processed_width = 0;
968 int processed_height = 0;
970
972 "[dt_imageio_export] (direct) image input %ix%i, turned to output %ix%i, will be exported to fit %ix%i "
973 "--> final size is %ix%i\n",
974 pipe.iwidth, pipe.iheight, pipe.processed_width, pipe.processed_height, width, height, processed_width,
976
977
978 const int bpp = format->bpp(format_params);
979
981
982 dt_get_times(&start);
983 const uint32_t alloc_refusals = dt_pixelpipe_cache_get_alloc_refusals();
984 int err = dt_dev_pixelpipe_process(&pipe, roi);
985 dt_show_times(&start, thumbnail_export ? "[dev_process_thumbnail] pixel pipeline processing thread"
986 : "[dev_process_export] pixel pipeline processing thread");
987
988 if(dt_dev_backbuf_get_hash(&pipe.backbuf) == -1 || err)
989 {
990 dt_print(DT_DEBUG_IMAGEIO, "[dt_imageio_export_with_flags] no valid output buffer\n");
991 /* The pipe returns the same error for a kill-switch stop, a module that failed, and a buffer
992 * the pixelpipe cache refused it. The stop is the pipe's own state. The cache counts what it
993 * refuses to each thread, and the pipe ran on this one. Anything else stays a processing
994 * failure, including memory the modules allocate outside the cache. */
997 else if(dt_pixelpipe_cache_get_alloc_refusals() != alloc_refusals)
999 else
1001 goto error;
1002 }
1003
1004 // Initialised because the failure path below tests it. It is currently reached only after
1005 // dt_dev_pixelpipe_cache_ref_entry_by_hash() has written NULL into it on every early
1006 // return -- a callee-side contract propping up a caller-side assumption, on a path whose
1007 // failure mode is unreffing a garbage pointer.
1008 struct dt_pixel_cache_entry_t *cache_entry = NULL;
1009 void *data = NULL;
1010 /* Atomically look up the final pipeline output and increment its refcount under the cache
1011 * mutex. peek() + separate ref_count_entry() has a TOCTOU window: peek releases its
1012 * tryrdlock immediately and returns with no ownership, so a concurrent eviction thread
1013 * could see refcount==1 (backbuf keepalive only) and decrement it to 0 between peek()
1014 * returning and our ref_count_entry() call — leaving us with a dangling data pointer that
1015 * the OpenMP conversion threads then read → SIGSEGV. ref_entry_by_hash() closes that
1016 * window by holding cache->lock across both the lookup and the increment. */
1018 &data, &cache_entry)
1019 || IS_NULL_PTR(data))
1020 {
1021 if(!IS_NULL_PTR(cache_entry))
1024 goto error;
1025 }
1026
1027 /* Hold a read lock for the duration of the conversion so no writer can replace the buffer
1028 * while the OpenMP threads are reading it. */
1030
1031 // Down-conversion to low-precision formats: 8 and 16 bits, any other depth stays float
1032 size_t channel_size = sizeof(float_t);
1033 if(bpp == 8)
1034 channel_size = sizeof(uint8_t);
1035 else if(bpp == 16)
1036 channel_size = sizeof(uint16_t);
1037
1038 outbuf = dt_pixelpipe_cache_alloc_align_cache(channel_size * pipe.backbuf.width * pipe.backbuf.height * 4, 0);
1039 if(!IS_NULL_PTR(outbuf))
1040 _export_convert_output(data, outbuf, bpp, pipe.backbuf.width, pipe.backbuf.height, display_byteorder,
1041 thumbnail_export);
1042
1043 // Decrease ref count on the cache entry and release the read lock
1046
1047 if(IS_NULL_PTR(outbuf))
1048 {
1050 goto error;
1051 }
1052
1053 format_params->width = pipe.backbuf.width;
1054 format_params->height = pipe.backbuf.height;
1055
1056 // Exif data should be 65536 bytes max, but if original size is close to that,
1057 // adding new tags could make it go over that... so let it be and see what
1058 // happens when we write the image
1059 int length = 0;
1060 uint8_t *exif_profile = NULL;
1061
1062 if(!ignore_exif)
1063 {
1064 gboolean from_cache = TRUE;
1065 char pathname[DT_PATH_MAX] = { 0 };
1066 dt_image_full_path(imgid, pathname, sizeof(pathname), &from_cache, __FUNCTION__);
1067 // find output color profile for this image:
1068 int sRGB = (icc_type == DT_COLORSPACE_SRGB);
1069 // last param is dng mode, it's false here
1070 length = dt_exif_read_blob(&exif_profile, pathname, imgid, sRGB, pipe.backbuf.width, pipe.backbuf.height, 0);
1071 }
1072
1073 // Finally: write image buffer to target container
1074 res = format->write_image(format_params, filename, outbuf, icc_type, icc_filename, exif_profile, length, imgid,
1075 num, total, &pipe, export_masks);
1076
1077 dt_free(exif_profile);
1078 if(res)
1079 {
1081 goto error;
1082 }
1083
1086
1087 /* now write xmp into that container, if possible */
1088 if(copy_metadata && (format->flags(format_params) & FORMAT_FLAGS_SUPPORT_XMP))
1089 dt_exif_xmp_attach_export(imgid, filename, metadata);
1090
1091 if(!thumbnail_export && strcmp(format->mime(format_params), "memory")
1092 && !(format->flags(format_params) & FORMAT_FLAGS_NO_TMPFILE))
1093 {
1095 format_params, storage, storage_params);
1096 }
1097
1099 return DT_IMAGEIO_OK;
1100
1101error:
1105 return status;
1106}
1107
1108
1109
1110// =================================================
1111// combined reading
1112// =================================================
1113
1114dt_imageio_retval_t dt_imageio_open(dt_image_t *img, // non-const * means you hold a write lock!
1115 const char *filename, // full path
1116 dt_mipmap_buffer_t *buf)
1117{
1118 /* first of all, check if file exists, don't bother to test loading if not exists */
1119 if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
1120 return !DT_IMAGEIO_OK;
1121
1124 img->loader = LOADER_UNKNOWN;
1125
1126 // Start with the decoder(s) the extension routes to (fast path). Unlike before, a failure here
1127 // no longer aborts: an extension can route to more than one category (see
1128 // dt_image_ext_is_ambiguous() -- e.g. a linear DNG that a raw decoder can't demosaic, or a
1129 // renamed/mislabeled file), so let it cascade into the bruteforce section below instead of
1130 // reporting "corrupted" on a file a later attempt would have opened fine.
1131 if(dt_imageio_is_raster(filename))
1132 ret = dt_imageio_open_raster(img, filename, buf);
1133 reason = _decoder_reason(reason, ret);
1134
1135 if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL && dt_imageio_is_raw(filename))
1136 ret = dt_imageio_open_raw(img, filename, buf);
1137 reason = _decoder_reason(reason, ret);
1138
1139 if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL && dt_imageio_is_hdr(filename))
1140 ret = dt_imageio_open_hdr(img, filename, buf);
1141 reason = _decoder_reason(reason, ret);
1142
1143 // fallback: bruteforce everything hoping for a miracle
1144 // Most likely, it's a format we never heard of.
1145 if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL)
1146 ret = dt_imageio_open_raster(img, filename, buf);
1147 reason = _decoder_reason(reason, ret);
1148
1149 if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL)
1150 ret = dt_imageio_open_raw(img, filename, buf);
1151 reason = _decoder_reason(reason, ret);
1152
1153 if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL)
1154 ret = dt_imageio_open_hdr(img, filename, buf);
1155 reason = _decoder_reason(reason, ret);
1156
1157 // Final check and abort. CACHE_FULL stopped the cascade above: a decoder took the file, but could
1158 // not allocate the memory to decode it -- the full-size buffer (dt_mipmap_cache_alloc()), or one
1159 // of its own. Saying that no decoder supports the file would send the user looking elsewhere.
1160 if(ret == DT_IMAGEIO_CACHE_FULL)
1161 {
1162 dt_control_alert_once(_("Not enough memory"),
1163 _("Not enough memory to load the image at full size.\n"
1164 "Close other applications or add more RAM to your system."),
1165 filename);
1166 return ret;
1167 }
1168 if(ret != DT_IMAGEIO_OK)
1169 {
1170 fprintf(stderr, "[imageio] The file %s is supported by none of our decoders.\n", filename);
1171 dt_control_log(_("The file `%s` is supported by none of our decoders."), filename);
1172 return reason;
1173 }
1174
1175 img->p_width = img->width - img->crop_x - img->crop_width;
1176 img->p_height = img->height - img->crop_y - img->crop_height;
1177
1178 // The codec has now populated img->dsc: finalize the buffer-derived type flags
1179 // (DT_IMAGE_MOSAIC + DT_IMAGE_BUFFER_RESOLVED). This is the single point where the
1180 // decoded descriptor is mapped to the persisted classification.
1182
1183 return ret;
1184}
1185
1187 dt_mipmap_buffer_t *buf)
1188{
1189 if(IS_NULL_PTR(buf)) return DT_IMAGEIO_LOAD_FAILED;
1190
1191 memset(buf, 0, sizeof(*buf));
1192 buf->size = DT_MIPMAP_FULL;
1193
1194 /* The decoder allocates into the entry it is handed. Owning one here is what lets callers
1195 * decode a file without knowing that a cache entry exists -- see the header. */
1198
1199 const dt_imageio_retval_t ret = dt_imageio_open(img, filename, buf);
1201 return ret;
1202}
1203
1205{
1206 if(IS_NULL_PTR(buf) || IS_NULL_PTR(buf->cache_entry)) return;
1208 buf->cache_entry = NULL;
1209 buf->buf = NULL;
1210}
1211
1212gboolean dt_imageio_lookup_makermodel(const char *maker, const char *model,
1213 char *mk, int mk_len, char *md, int md_len,
1214 char *al, int al_len)
1215{
1216 // At this stage, we can't tell which loader is used to open the image.
1217 gboolean found = dt_rawspeed_lookup_makermodel(maker, model,
1218 mk, mk_len,
1219 md, md_len,
1220 al, al_len);
1221 if(found == FALSE)
1222 {
1223 // Special handling for CR3 raw files via libraw
1225 mk, mk_len,
1226 md, md_len,
1227 al, al_len);
1228 }
1229 return found;
1230}
1231
1232// clang-format off
1233// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
1234// vim: shiftwidth=2 expandtab tabstop=2 cindent
1235// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
1236// clang-format on
static void error(char *msg)
Definition ashift_lsd.c:202
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
atomic_int dt_atomic_int
Definition atomic.h:68
void cleanup(dt_imageio_module_format_t *self)
Definition avif.c:170
static const float x
The colour-profile module's API: which profiles exist, and how to apply one.
static dt_aligned_pixel_t sRGB
const dt_colormatrix_t dt_aligned_pixel_t out
const float top
gchar * dt_conf_get_string(const char *name)
Read the stored string for name as a private copy.
void dt_image_buffer_resolve_flags(dt_image_t *img)
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.
void dt_control_alert_once(const char *title, const char *message, const char *item)
dt_control_alert() for a failure that repeats as long as its cause lasts – memory running short,...
Definition control.c:893
void dt_control_alert(const char *title, const char *message, const char *item)
Tell the user something that must not go unseen: what it says stays true after a toast would have fad...
Definition control.c:888
void dt_control_log(const char *msg,...)
Definition control.c:844
void dt_dev_pop_history_items(dt_develop_t *dev)
Thread-safe wrapper around dt_dev_pop_history_items_ext(), then update GUI.
void dt_dev_set_history_end_ext(struct dt_develop_t *dev, const uint32_t index)
Set the history end index (GUI perspective).
Definition develop.c:1972
void dt_dev_pixelpipe_propagate_formats(dt_dev_pixelpipe_t *pipe)
void dt_dev_pixelpipe_get_roi_out(dt_dev_pixelpipe_t *pipe, const int width_in, const int height_in, int *width, int *height)
dt_atomic_set_uint64 & dev
void dt_dev_cleanup(dt_develop_t *dev)
Definition develop.c:240
dt_dev_image_storage_t dt_dev_load_image(dt_develop_t *dev, const int32_t imgid)
Definition develop.c:1054
void dt_dev_init(dt_develop_t *dev, int32_t gui_attached)
Definition develop.c:146
static int dt_pthread_rwlock_wrlock(dt_pthread_rwlock_t *rwlock) ACQUIRE(rwlock) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:299
static int dt_pthread_rwlock_unlock(dt_pthread_rwlock_t *rwlock) RELEASE_GENERIC(rwlock) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:217
const int res
Definition dtpthread.h:351
int dt_exif_get_thumbnail(const char *path, uint8_t **buffer, size_t *size, char **mime_type, int *width, int *height, int min_width)
Definition exif.cc:1929
What a photograph says about itself: the EXIF, IPTC and XMP tags a camera and a cataloguer write,...
int32_t processed_width
Definition geometry.c:71
int32_t processed_height
Definition geometry.c:71
memcpy(roundtrip, origin, sizeof(roundtrip))
void * data
Definition geometry.h:111
dt_iop_roi_t in
Definition geometry.h:117
float dt_boundingbox_t[4]
Definition image.h:83
dt_image_orientation_t
Definition image.h:225
@ ORIENTATION_SWAP_XY
Definition image.h:230
@ ORIENTATION_FLIP_Y
Definition image.h:228
@ ORIENTATION_FLIP_X
Definition image.h:229
dt_imageio_retval_t
Return value of image io functions: loading, exporting, and making a thumbnail.
Definition image.h:97
@ DT_IMAGEIO_LOAD_FAILED
Definition image.h:105
@ DT_IMAGEIO_ABORTED
Definition image.h:109
@ DT_IMAGEIO_OK
Definition image.h:98
@ DT_IMAGEIO_CACHE_FULL
Definition image.h:101
@ DT_IMAGEIO_UNSUPPORTED_FEATURE
Definition image.h:103
@ DT_IMAGEIO_FILE_CORRUPTED
Definition image.h:100
@ DT_IMAGEIO_PROCESSING_FAILED
Definition image.h:108
@ DT_IMAGEIO_IOERROR
Definition image.h:106
@ DT_IMAGEIO_UNSUPPORTED_CAMERA
Definition image.h:104
@ LOADER_UNKNOWN
Definition image.h:292
gboolean dt_image_ext_is_ldr(const char *ext)
gboolean dt_image_ext_is_raw(const char *ext)
gboolean dt_image_ext_is_hdr(const char *ext)
int bpp
dt_imageio_retval_t dt_imageio_open_avif(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
gboolean _apply_style_before_export(dt_develop_t *dev, const dt_imageio_module_data_t *format_params, const int32_t imgid)
void _clamp_float_to_uint8(const float *const inbuf, uint8_t *const outbuf, const size_t processed_width, const size_t processed_height)
void dt_imageio_flip_buffers_ui8_to_float(float *out, const uint8_t *in, const float black, const float white, const int ch, const int wd, const int ht, const int fwd, const int fht, const int stride, const dt_image_orientation_t orientation)
int dt_imageio_is_hdr(const char *filename)
dt_imageio_retval_t 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 gboolean ignore_history, 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)
gboolean dt_imageio_lookup_makermodel(const char *maker, const char *model, char *mk, int mk_len, char *md, int md_len, char *al, int al_len)
dt_imageio_retval_t dt_imageio_open(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
void dt_imageio_close_standalone(dt_mipmap_buffer_t *buf)
Release a buffer from dt_imageio_open_standalone(). NULL-safe, and safe to call on a buffer whose ope...
void _swap_byteorder_float_to_uint8(const float *const restrict inbuf, uint8_t *const outbuf, const size_t processed_width, const size_t processed_height)
dt_imageio_retval_t dt_imageio_open_raster(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
void _filter_pipeline(const char *filter, dt_dev_pixelpipe_t *pipe)
static gboolean _get_export_size(const dt_dev_pixelpipe_t *pipe, const double scale_factor, double *scale, int width, int height, int *processed_width, int *processed_height)
dt_imageio_retval_t dt_imageio_open_standalone(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
Decode a file into a buffer the CALLER owns, with no cache involvement.
gboolean dt_imageio_is_raster(const char *filename)
gboolean dt_imageio_has_mono_preview(const char *filename)
int dt_imageio_export(const int32_t imgid, const char *filename, dt_imageio_module_format_t *format, dt_imageio_module_data_t *format_params, const double scale_factor, const gboolean high_quality, 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)
void dt_imageio_to_fractional(float in, uint32_t *num, uint32_t *den)
gboolean dt_imageio_crop_thumbnail(const dt_boundingbox_t box, uint8_t *const buffer, int32_t *width, int32_t *height)
Crop an 8-bit RGBA preview buffer in place to a normalized bounding box.
static dt_imageio_retval_t _decoder_reason(const dt_imageio_retval_t reason, const dt_imageio_retval_t ret)
gboolean dt_imageio_is_handled_by_libraw(dt_image_t *img, const char *filename)
dt_imageio_retval_t dt_imageio_open_hdr(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
static void _export_convert_output(const float *const data, void *const outbuf, const int bpp, const size_t width, const size_t height, const gboolean display_byteorder, const gboolean thumbnail_export)
Convert the pipeline's float RGBA output into outbuf, at the depth the format writes: 8 bits (in disp...
dt_imageio_retval_t dt_imageio_open_raw(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
static gboolean _is_in_list(const char *elem, char *list)
Is elem one of the comma-separated entries of list?
gboolean dt_imageio_is_raw(const char *filename)
int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t *th_width, int32_t *th_height, dt_colorspaces_color_profile_type_t *color_space, const int width, const int height)
Load the thumbnail embedded into a RAW file having at least the size MAX(width, height) x MAX(width,...
void _print_export_debug(dt_dev_pixelpipe_t *pipe, dt_imageio_module_data_t *format_params, const gboolean use_style)
__DT_CLONE_TARGETS__ void dt_imageio_flip_buffers(char *out, const char *in, const size_t bpp, const int wd, const int ht, const int fwd, const int fht, const int stride, const dt_image_orientation_t orientation)
void _export_final_buffer_to_uint16(const float *const restrict inbuf, uint16_t *const outbuf, const size_t processed_width, const size_t processed_height)
dt_imageio_retval_t dt_imageio_open_exr(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
dt_imageio_retval_t dt_imageio_open_heif(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
int dt_imageio_jpeg_decompress_header(const void *in, size_t length, dt_imageio_jpeg_t *jpg)
dt_imageio_retval_t dt_imageio_open_jpeg(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
int dt_imageio_jpeg_decompress(dt_imageio_jpeg_t *jpg, uint8_t *out)
dt_imageio_retval_t dt_imageio_open_libraw(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
gboolean dt_libraw_lookup_makermodel(const char *maker, const char *model, char *mk, int mk_len, char *md, int md_len, char *al, int al_len)
@ FORMAT_FLAGS_SUPPORT_XMP
@ FORMAT_FLAGS_NO_TMPFILE
dt_imageio_retval_t dt_imageio_open_pfm(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
Definition imageio_pfm.c:42
dt_imageio_retval_t dt_imageio_open_png(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
dt_imageio_retval_t dt_imageio_open_pnm(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
const dt_colorspaces_color_profile_t * dt_colorspaces_get_output_profile(const int32_t imgid, dt_colorspaces_color_profile_type_t *over_type, const char *over_filename)
gboolean dt_rawspeed_lookup_makermodel(const char *maker, const char *model, char *mk, int mk_len, char *md, int md_len, char *al, int al_len)
dt_imageio_retval_t dt_imageio_open_rawspeed(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
dt_imageio_retval_t dt_imageio_open_rgbe(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
dt_imageio_retval_t dt_imageio_open_tiff(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
gboolean dt_imageio_tiff_decode_blob(const uint8_t *const blob, const size_t bufsize, uint8_t **out, int32_t *width, int32_t *height)
Decode a TIFF held in memory into 8-bit RGBx, for the previews raw files embed.
dt_imageio_retval_t dt_imageio_open_webp(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
const char * maker
const char * model
void dt_ioppr_resync_modules_order(dt_develop_t *dev)
Update dev->iop module order values from dev->iop_order_list.
Definition iop_order.c:1249
void dt_ioppr_update_for_style_items(dt_develop_t *dev, GList *st_items, gboolean append)
Update dev->iop_order_list with modules referenced by style items.
Definition iop_order.c:1721
int dt_ioppr_check_iop_order(dt_develop_t *dev, const int32_t imgid, const char *msg)
Debug helper to validate the current order for a develop context.
Definition iop_order.c:2351
static const dt_dev_pixelpipe_t * pipe
Definition layers.h:49
static const dt_dev_pixelpipe_t const dt_dev_pixelpipe_iop_t * piece
Definition layers.h:50
@ DT_DEBUG_IMAGEIO
Definition logging.h:68
int32_t dt_get_debug_flags(void)
Definition darktable.c:2094
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
float *const restrict const size_t k
float *const restrict const size_t const size_t ch
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
#define CLAMPF(a, mn, mx)
Definition math.h:91
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
uint32_t width
Definition mipmap_cache.c:0
dt_imageio_retval_t status
Definition mipmap_cache.c:8
uint32_t height
Definition mipmap_cache.c:1
size_t size
Definition mipmap_cache.c:3
dt_colorspaces_color_profile_type_t color_space
Definition mipmap_cache.c:5
@ DT_MIPMAP_BLOCKING
dt_mipmap_size_t
@ DT_MIPMAP_FULL
#define dt_mipmap_cache_get(B, C, D, E, F)
#define dt_mipmap_cache_release(B)
#define __OMP_PARALLEL_FOR__(...)
Definition openmp.h:95
#define DT_PATH_MAX
Buffer size for a filesystem path anywhere in Ansel.
Definition paths.h:57
void dt_dev_pixelpipe_cache_ref_count_entry(gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Take or release one reference on a cache line. A referenced line is never evicted,...
void dt_dev_pixelpipe_cache_rdlock_entry(gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Lock or release the read lock on the entry.
gboolean dt_dev_pixelpipe_cache_ref_entry_by_hash(const uint64_t hash, void **data, dt_pixel_cache_entry_t **entry)
Resolve and retain an existing cache entry by hash.
uint32_t dt_pixelpipe_cache_get_alloc_refusals(void)
Count the allocations the cache refused to the calling thread for lack of memory (thread-local).
#define dt_pixelpipe_cache_alloc_align_cache(size, id)
#define dt_pixelpipe_cache_free_align(mem)
void dt_dev_pixelpipe_set_input(dt_dev_pixelpipe_t *pipe, int32_t imgid, int width, int height, float iscale, dt_mipmap_size_t size)
void dt_dev_pixelpipe_disable_before(dt_dev_pixelpipe_t *pipe, const char *op)
void dt_dev_pixelpipe_disable_after(dt_dev_pixelpipe_t *pipe, const char *op)
void dt_dev_pixelpipe_set_icc(dt_dev_pixelpipe_t *pipe, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, dt_iop_color_intent_t icc_intent)
void dt_dev_pixelpipe_create_nodes(dt_dev_pixelpipe_t *pipe)
int dt_dev_pixelpipe_init_thumbnail(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev)
int dt_dev_pixelpipe_init_export(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev, int levels, gboolean store_masks)
void dt_dev_pixelpipe_cleanup(dt_dev_pixelpipe_t *pipe)
int dt_dev_pixelpipe_process(dt_dev_pixelpipe_t *pipe, dt_iop_roi_t roi)
#define dt_dev_pixelpipe_synch_all(pipe)
static uint64_t dt_dev_backbuf_get_hash(const dt_backbuf_t *backbuf)
static gboolean dt_dev_pixelpipe_has_shutdown(const dt_dev_pixelpipe_t *pipe)
dt_iop_color_intent_t
ICC rendering intent, as stored in iop params and in conf.
dt_colorspaces_color_profile_type_t
@ DT_COLORSPACE_SRGB
sRGB – registered TWICE, and the two entries are not interchangeable.
#define DT_DEBUG_CONTROL_SIGNAL_RAISE(ctlsig, signal,...)
Definition signal.h:390
struct dt_control_signal_t * dt_control_signal_get_global(void)
Definition darktable.c:619
@ DT_SIGNAL_IMAGE_EXPORT_TMPFILE
This signal is raised after an image has been exported to a file, but before it is sent to facebook/p...
Definition signal.h:265
#define for_four_channels(_var,...)
Definition simd.h:89
void dt_cache_entry_free_detached(dt_cache_entry_t *entry)
Release an entry from dt_cache_entry_new_detached(), and its data. NULL-safe.
dt_cache_entry_t * dt_cache_entry_new_detached(void)
Allocate a cache entry that belongs to NO cache, for a one-shot decode.
GList * dt_styles_get_item_list(const char *name, gboolean params, int32_t imgid)
void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item)
void dt_style_item_free(gpointer data)
int32_t height
Definition image.h:406
dt_image_loader_t loader
Definition image.h:426
int32_t crop_height
Definition image.h:407
int32_t width
Definition image.h:406
char exif_maker[64]
Definition image.h:383
int32_t crop_y
Definition image.h:407
int32_t crop_x
Definition image.h:407
int32_t p_height
Definition image.h:406
int32_t p_width
Definition image.h:406
char exif_model[64]
Definition image.h:384
int32_t crop_width
Definition image.h:407
int(* flags)(struct dt_imageio_module_data_t *data)
int(* write_image)(struct dt_imageio_module_data_t *data, const char *filename, const void *in, dt_colorspaces_color_profile_type_t over_type, const char *over_filename, void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe, const gboolean export_masks)
const char *(* mime)(struct dt_imageio_module_data_t *data)
int(* bpp)(struct dt_imageio_module_data_t *data)
int(* levels)(struct dt_imageio_module_data_t *data)
Region of interest passed through the pixelpipe.
Definition format.h:49
dt_cache_entry_t * cache_entry
NULL with a non-NULL buf when a blocking get could not allocate the thumbnail's entry: buf is then a ...
dt_mipmap_size_t size
dt_imageio_retval_t status
Why the entry holds no image: a thumbnail drawn as a skull, or a full-size input with no pixels....
#define __DT_CLONE_TARGETS__
typedef double((*spd)(unsigned long int wavelength, double TempK))
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29
void dt_show_times(const dt_times_t *start, const char *prefix)
Definition darktable.c:2147
static void dt_get_times(dt_times_t *t)
Definition times.h:50
Telling the user something happened.
int dt_exif_xmp_attach_export(const int32_t imgid, const char *filename, void *metadata)
int dt_exif_read_blob(uint8_t **buf, const char *path, const int32_t imgid, const int sRGB, const int out_width, const int out_height, const int dng_mode)
The XMP document that carries an image's development: history stack, mask shapes, module order,...