Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
imageio_core.c File Reference
#include "colorprofiles/colorspaces.h"
#include "common/image.h"
#include "system/macros.h"
#include "system/openmp.h"
#include "system/target_clones.h"
#include "system/mem_alloc.h"
#include "system/simd.h"
#include "common/logging.h"
#include "common/times.h"
#include "common/paths.h"
#include "caches/pixelpipe_cache_alloc.h"
#include "common/xmp_sidecar.h"
#include "metadata/exif.h"
#include "caches/image_cache.h"
#include "history/history.h"
#include "common/image_extensions.h"
#include "imageio/imageio_core.h"
#include "imageio/imageio_module.h"
#include "imageio/imageio_gm.h"
#include "imageio/imageio_im.h"
#include "imageio/imageio_magick_abort_guard.h"
#include "imageio/imageio_jpeg.h"
#include "imageio/imageio_pfm.h"
#include "imageio/imageio_png.h"
#include "imageio/imageio_pnm.h"
#include "imageio/imageio_rawspeed.h"
#include "imageio/imageio_libraw.h"
#include "imageio/imageio_rgbe.h"
#include "imageio/imageio_tiff.h"
#include "caches/mipmap_cache.h"
#include "common/styles.h"
#include "common/conf.h"
#include "control/user_message.h"
#include "develop/develop.h"
#include "develop/imageop.h"
#include <assert.h>
#include <glib/gstdio.h>
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "imageio/imageio_profile.h"
#include "control/signal.h"
+ Include dependency graph for imageio_core.c:

Go to the source code of this file.

Functions

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)
 Map Exiv2 preview MIME types to decoder format identifiers.
 
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.
 
gboolean dt_imageio_has_mono_preview (const char *filename)
 
__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 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)
 
dt_imageio_retval_t dt_imageio_open_hdr (dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
 
gboolean dt_imageio_is_raster (const char *filename)
 
gboolean dt_imageio_is_raw (const char *filename)
 
int dt_imageio_is_hdr (const char *filename)
 
static gboolean _is_in_list (char *elem, char *list)
 
gboolean dt_imageio_is_handled_by_libraw (dt_image_t *img, const char *filename)
 
dt_imageio_retval_t dt_imageio_open_raster (dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
 
dt_imageio_retval_t dt_imageio_open_raw (dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
 
void dt_imageio_to_fractional (float in, uint32_t *num, uint32_t *den)
 
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 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)
 
gboolean _apply_style_before_export (dt_develop_t *dev, dt_imageio_module_data_t *format_params, const int32_t imgid)
 
void _print_export_debug (dt_dev_pixelpipe_t *pipe, dt_imageio_module_data_t *format_params, const gboolean use_style)
 
void _filter_pipeline (const char *filter, dt_dev_pixelpipe_t *pipe)
 
gboolean _get_export_size (dt_develop_t *dev, dt_dev_pixelpipe_t *pipe, const dt_imageio_module_data_t *format_params, const gboolean is_scaling, double *scale, int width, int height, int *processed_width, int *processed_height)
 
void _clamp_float_to_uint8 (const float *const inbuf, uint8_t *const outbuf, const size_t processed_width, const size_t processed_height)
 
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)
 
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)
 
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, gboolean is_scaling, 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_retval_t dt_imageio_open_exotic (dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
 
dt_imageio_retval_t dt_imageio_open (dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
 
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.
 
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 open failed.
 
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)
 

Function Documentation

◆ _apply_style_before_export()

◆ _clamp_float_to_uint8()

void _clamp_float_to_uint8 ( const float *const  inbuf,
uint8_t *const  outbuf,
const size_t  processed_width,
const size_t  processed_height 
)

Definition at line 889 of file imageio_core.c.

References __OMP_PARALLEL_FOR__, CLAMPF, for_four_channels, k, and L.

Referenced by dt_imageio_export_with_flags().

◆ _export_final_buffer_to_uint16()

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 
)

Definition at line 913 of file imageio_core.c.

References __OMP_PARALLEL_FOR__, for_four_channels, k, and L.

Referenced by dt_imageio_export_with_flags().

◆ _filter_pipeline()

void _filter_pipeline ( const char *  filter,
dt_dev_pixelpipe_t pipe 
)

◆ _get_export_size()

gboolean _get_export_size ( dt_develop_t dev,
dt_dev_pixelpipe_t pipe,
const dt_imageio_module_data_t format_params,
const gboolean  is_scaling,
double scale,
int  width,
int  height,
int *  processed_width,
int *  processed_height 
)

◆ _is_in_list()

static gboolean _is_in_list ( char *  elem,
char *  list 
)
static

Definition at line 584 of file imageio_core.c.

References FALSE, IS_NULL_PTR, and L.

Referenced by dt_imageio_is_handled_by_libraw().

◆ _print_export_debug()

void _print_export_debug ( dt_dev_pixelpipe_t pipe,
dt_imageio_module_data_t format_params,
const gboolean  use_style 
)

◆ _swap_byteorder_float_to_uint8()

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 
)

Definition at line 899 of file imageio_core.c.

References __OMP_PARALLEL_FOR__, CLAMPF, k, and L.

Referenced by dt_imageio_export_with_flags().

◆ dt_imageio_close_standalone()

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 open failed.

Definition at line 1278 of file imageio_core.c.

References dt_mipmap_buffer_t::buf, dt_mipmap_buffer_t::cache_entry, dt_cache_entry_free_detached(), IS_NULL_PTR, and L.

Referenced by _import_get_thumbnail(), and dt_imageio_open_standalone().

◆ dt_imageio_crop_thumbnail()

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.

Cameras that record selected framing (DNG DefaultUserCrop) still render their embedded previews from the full default-crop rectangle, so a preview taken straight out of the raw shows more than the photographer framed. This trims it back.

The box must be expressed in the buffer's own orientation. For previews read from a raw that is the un-oriented sensor frame (dt_image_get_usercrop()), because Ansel applies the EXIF rotation afterwards, when downscaling.

Only ever apply this to a preview embedded in the raw itself: a companion/sidecar JPEG is written by the camera at the framing it displayed and is already cropped.

Parameters
boxnormalized (top, left, bottom, right); an identity box is a no-op
buffer8-bit RGBA pixels, compacted in place
widthin/out buffer width, updated to the cropped width
heightin/out buffer height, updated to the cropped height
Returns
TRUE if the buffer was cropped, FALSE if it was left untouched

Definition at line 358 of file imageio_core.c.

References FALSE, height, IS_NULL_PTR, L, top, TRUE, and width.

Referenced by _import_get_thumbnail(), and _init_8().

◆ dt_imageio_export()

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 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 
)

Definition at line 727 of file imageio_core.c.

References dt_conf_is_equal(), dt_imageio_export_with_flags(), FALSE, L, and TRUE.

Referenced by store(), and store().

◆ dt_imageio_export_with_flags()

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,
gboolean  is_scaling,
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 
)

Definition at line 923 of file imageio_core.c.

References __OMP_PARALLEL_FOR__, _apply_style_before_export(), _clamp_float_to_uint8(), _export_final_buffer_to_uint16(), _filter_pipeline(), _get_export_size(), _print_export_debug(), _swap_byteorder_float_to_uint8(), dt_dev_pixelpipe_t::backbuf, bpp, dt_mipmap_buffer_t::buf, dt_pixel_cache_entry_t::data, DT_COLORSPACE_SRGB, dt_colorspaces_get_output_profile(), dt_control_signal_get_global(), DT_DEBUG_CONTROL_SIGNAL_RAISE, DT_DEBUG_IMAGEIO, dt_dev_backbuf_get_hash(), dt_dev_cleanup(), dt_dev_init(), dt_dev_load_image(), dt_dev_pixelpipe_cache_rdlock_entry(), dt_dev_pixelpipe_cache_ref_count_entry(), dt_dev_pixelpipe_cache_ref_entry_by_hash(), dt_dev_pixelpipe_cleanup(), dt_dev_pixelpipe_create_nodes(), dt_dev_pixelpipe_get_roi_out(), dt_dev_pixelpipe_init_export(), dt_dev_pixelpipe_init_thumbnail(), dt_dev_pixelpipe_process(), dt_dev_pixelpipe_propagate_formats(), dt_dev_pixelpipe_set_icc(), dt_dev_pixelpipe_set_input(), dt_dev_pixelpipe_synch_all, dt_exif_read_blob(), dt_exif_xmp_attach_export(), dt_free, dt_get_times(), dt_image_full_path(), dt_ioppr_resync_modules_order(), DT_MIPMAP_BLOCKING, dt_mipmap_cache_get, dt_mipmap_cache_release, DT_MIPMAP_FULL, dt_pixelpipe_cache_alloc_align_cache, dt_pixelpipe_cache_free_align, dt_print(), dt_show_times(), DT_SIGNAL_IMAGE_EXPORT_TMPFILE, error(), FALSE, FORMAT_FLAGS_NO_TMPFILE, FORMAT_FLAGS_SUPPORT_XMP, height, dt_mipmap_buffer_t::height, dt_backbuf_t::height, dt_dev_pixelpipe_t::iheight, IS_NULL_PTR, dt_mipmap_buffer_t::iscale, dt_dev_pixelpipe_t::iwidth, k, L, MAX, PATH_MAX, dt_dev_pixelpipe_t::processed_height, dt_dev_pixelpipe_t::processed_width, dt_dev_pixelpipe_t::shutdown_ext, size, sRGB, TRUE, width, dt_mipmap_buffer_t::width, and dt_backbuf_t::width.

Referenced by _export_image(), _export_pre_module_fullres_to_tiff(), _init_8(), dt_control_merge_hdr_job_run(), and dt_imageio_export().

◆ dt_imageio_flip_buffers()

__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 
)

◆ dt_imageio_flip_buffers_ui8_to_float()

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 
)

◆ dt_imageio_has_mono_preview()

gboolean dt_imageio_has_mono_preview ( const char *  filename)

◆ dt_imageio_is_handled_by_libraw()

gboolean dt_imageio_is_handled_by_libraw ( dt_image_t img,
const char *  filename 
)

◆ dt_imageio_is_hdr()

int dt_imageio_is_hdr ( const char *  filename)

Definition at line 576 of file imageio_core.c.

References dt_image_ext_is_hdr(), FALSE, and L.

Referenced by dt_imageio_open().

◆ dt_imageio_is_raster()

gboolean dt_imageio_is_raster ( const char *  filename)

Definition at line 560 of file imageio_core.c.

References dt_image_ext_is_ldr(), FALSE, and L.

Referenced by dt_imageio_open().

◆ dt_imageio_is_raw()

gboolean dt_imageio_is_raw ( const char *  filename)

Definition at line 568 of file imageio_core.c.

References dt_image_ext_is_raw(), FALSE, and L.

Referenced by dt_imageio_open().

◆ dt_imageio_large_thumbnail()

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 
)

Map Exiv2 preview MIME types to decoder format identifiers.

Load the thumbnail embedded into a RAW file having at least the size MAX(width, height) x MAX(width, height)

Embedded previews are handed to GraphicsMagick/ImageMagick as anonymous blobs. Some camera vendors store TIFF/PNG-style previews whose blob headers are not sufficient for GraphicsMagick to infer the format on its own, which yields the "Unrecognized image format ()" path seen in issue #711. When EXIF already gave us the preview MIME type, pass that format hint explicitly to the blob decoder instead of relying on autodetection.

Parameters
mime_typeMIME type returned by Exiv2 for the embedded preview.
Returns
Decoder format identifier, or NULL when we have no useful hint.
Todo:
: check if the embedded thumbs have a color space set! currently we assume that it's always sRGB

Definition at line 169 of file imageio_core.c.

References color_space, DT_COLORSPACE_SRGB, dt_exif_get_thumbnail(), dt_free, dt_imageio_jpeg_decompress(), dt_imageio_jpeg_decompress_header(), dt_pixelpipe_cache_alloc_align_cache, dt_pixelpipe_cache_free_align, error(), height, IS_NULL_PTR, L, MAX, row, width, and dt_imageio_jpeg_t::width.

Referenced by _get_image_buffer(), _import_get_thumbnail(), _init_8(), and dt_imageio_has_mono_preview().

◆ dt_imageio_lookup_makermodel()

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_open()

◆ dt_imageio_open_exotic()

◆ dt_imageio_open_hdr()

◆ dt_imageio_open_raster()

◆ dt_imageio_open_raw()

◆ dt_imageio_open_standalone()

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.

dt_imageio_open() writes into a dt_mipmap_buffer_t whose cache_entry the mipmap cache supplies and owns. A caller that just wants one image decoded once – the import dialog's preview, say – has no cache entry to give it, and used to fabricate a zeroed dt_cache_entry_t on its own stack, hand over its address, and free cache_entry.data itself. That is a caller assembling the cache's internal bookkeeping by hand in order to borrow the decoder, and it is why gui/import.c had to include the cache's substrate header.

This pair owns that bookkeeping instead. Nothing outside src/caches needs to know what a dt_cache_entry_t is.

Parameters
imgimage metadata, filled by the decoder as with dt_imageio_open().
filenamefile to decode.
bufreceives the decoded image. Zeroed first; release with dt_imageio_close_standalone() whether this succeeds or fails.
Returns
DT_IMAGEIO_OK on success, otherwise whatever the decoder reported.

Definition at line 1260 of file imageio_core.c.

References dt_mipmap_buffer_t::cache_entry, dt_cache_entry_new_detached(), DT_IMAGEIO_CACHE_FULL, dt_imageio_close_standalone(), DT_IMAGEIO_LOAD_FAILED, DT_IMAGEIO_OK, dt_imageio_open(), DT_MIPMAP_FULL, IS_NULL_PTR, L, and dt_mipmap_buffer_t::size.

Referenced by _import_get_thumbnail().

◆ dt_imageio_to_fractional()

void dt_imageio_to_fractional ( float  in,
uint32_t *  num,
uint32_t *  den 
)

Definition at line 711 of file imageio_core.c.

References L.