Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
imageio_tiff.c File Reference
#include "colorprofiles/colorspaces.h"
#include "imageio_tiff.h"
#include "system/macros.h"
#include "system/mem_alloc.h"
#include "common/logging.h"
#include "caches/pixelpipe_cache_alloc.h"
#include "metadata/exif.h"
#include "develop/develop.h"
#include <inttypes.h>
#include <memory.h>
#include <stdio.h>
#include <strings.h>
#include <tiffio.h>
+ Include dependency graph for imageio_tiff.c:

Go to the source code of this file.

Data Structures

struct  tiff_t
 
union  fp32_t
 
struct  _tiff_blob_t
 

Macros

#define LAB_CONVERSION_PROFILE   DT_COLORSPACE_LIN_REC2020
 

Typedefs

typedef struct tiff_t tiff_t
 
typedef union fp32_t fp32_t
 
typedef struct _tiff_blob_t _tiff_blob_t
 

Functions

static float _half_to_float (uint16_t h)
 
static int _read_chunky_8 (tiff_t *t)
 
static int _read_chunky_16 (tiff_t *t)
 
static int _read_chunky_h (tiff_t *t)
 
static int _read_chunky_f (tiff_t *t)
 
static int _read_chunky_8_Lab (tiff_t *t, uint16_t photometric)
 
static int _read_chunky_16_Lab (tiff_t *t, uint16_t photometric)
 
static void _warning_error_handler (const char *type, const char *module, const char *fmt, va_list ap)
 
static void _warning_handler (const char *module, const char *fmt, va_list ap)
 
static void _error_handler (const char *module, const char *fmt, va_list ap)
 
dt_imageio_retval_t dt_imageio_open_tiff (dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
 
int dt_imageio_tiff_read_profile (const char *filename, uint8_t **out)
 
static tmsize_t _blob_read (thandle_t handle, void *buffer, tmsize_t size)
 
static tmsize_t _blob_write (thandle_t handle, void *buffer, tmsize_t size)
 
static toff_t _blob_seek (thandle_t handle, toff_t offset, int whence)
 
static int _blob_close (thandle_t handle)
 
static toff_t _blob_size (thandle_t handle)
 
static int _blob_map (thandle_t handle, void **base, toff_t *size)
 
static void _blob_unmap (thandle_t handle, void *base, toff_t size)
 
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.
 

Macro Definition Documentation

◆ LAB_CONVERSION_PROFILE

#define LAB_CONVERSION_PROFILE   DT_COLORSPACE_LIN_REC2020

Definition at line 51 of file imageio_tiff.c.

Typedef Documentation

◆ _tiff_blob_t

typedef struct _tiff_blob_t _tiff_blob_t

◆ fp32_t

typedef union fp32_t fp32_t

◆ tiff_t

typedef struct tiff_t tiff_t

Function Documentation

◆ _blob_close()

static int _blob_close ( thandle_t  handle)
static

Definition at line 630 of file imageio_tiff.c.

Referenced by dt_imageio_tiff_decode_blob().

◆ _blob_map()

static int _blob_map ( thandle_t  handle,
void **  base,
toff_t *  size 
)
static

Definition at line 642 of file imageio_tiff.c.

Referenced by dt_imageio_tiff_decode_blob().

◆ _blob_read()

static tmsize_t _blob_read ( thandle_t  handle,
void buffer,
tmsize_t  size 
)
static

Definition at line 588 of file imageio_tiff.c.

References _tiff_blob_t::data, n, _tiff_blob_t::pos, size, and _tiff_blob_t::size.

Referenced by dt_imageio_tiff_decode_blob().

◆ _blob_seek()

static toff_t _blob_seek ( thandle_t  handle,
toff_t  offset,
int  whence 
)
static

Definition at line 608 of file imageio_tiff.c.

References _tiff_blob_t::pos, and _tiff_blob_t::size.

Referenced by dt_imageio_tiff_decode_blob().

◆ _blob_size()

static toff_t _blob_size ( thandle_t  handle)
static

Definition at line 635 of file imageio_tiff.c.

Referenced by dt_imageio_tiff_decode_blob().

◆ _blob_unmap()

static void _blob_unmap ( thandle_t  handle,
void base,
toff_t  size 
)
static

Definition at line 647 of file imageio_tiff.c.

Referenced by dt_imageio_tiff_decode_blob().

◆ _blob_write()

static tmsize_t _blob_write ( thandle_t  handle,
void buffer,
tmsize_t  size 
)
static

Definition at line 603 of file imageio_tiff.c.

Referenced by dt_imageio_tiff_decode_blob().

◆ _error_handler()

static void _error_handler ( const char *  module,
const char *  fmt,
va_list  ap 
)
static

Definition at line 349 of file imageio_tiff.c.

References _warning_error_handler().

Referenced by dt_imageio_open_tiff(), and dt_imageio_tiff_decode_blob().

◆ _half_to_float()

static float _half_to_float ( uint16_t  h)
inlinestatic
Todo:
: use intrinsics when possible

Definition at line 73 of file imageio_tiff.c.

References fp32_t::f, and fp32_t::u.

Referenced by _read_chunky_h().

◆ _read_chunky_16()

static int _read_chunky_16 ( tiff_t t)
inlinestatic

Definition at line 134 of file imageio_tiff.c.

References i, out, row, and t.

Referenced by dt_imageio_open_tiff().

◆ _read_chunky_16_Lab()

static int _read_chunky_16_Lab ( tiff_t t,
uint16_t  photometric 
)
inlinestatic

◆ _read_chunky_8()

static int _read_chunky_8 ( tiff_t t)
inlinestatic

Definition at line 102 of file imageio_tiff.c.

References i, out, row, and t.

Referenced by dt_imageio_open_tiff().

◆ _read_chunky_8_Lab()

static int _read_chunky_8_Lab ( tiff_t t,
uint16_t  photometric 
)
inlinestatic

◆ _read_chunky_f()

static int _read_chunky_f ( tiff_t t)
inlinestatic

Definition at line 196 of file imageio_tiff.c.

References i, out, row, and t.

Referenced by dt_imageio_open_tiff().

◆ _read_chunky_h()

static int _read_chunky_h ( tiff_t t)
inlinestatic

Definition at line 165 of file imageio_tiff.c.

References _half_to_float(), i, out, row, and t.

Referenced by dt_imageio_open_tiff().

◆ _warning_error_handler()

static void _warning_error_handler ( const char *  type,
const char *  module,
const char *  fmt,
va_list  ap 
)
static

Definition at line 334 of file imageio_tiff.c.

References type.

Referenced by _error_handler(), and _warning_handler().

◆ _warning_handler()

static void _warning_handler ( const char *  module,
const char *  fmt,
va_list  ap 
)
static

◆ dt_imageio_open_tiff()

◆ dt_imageio_tiff_decode_blob()

gboolean dt_imageio_tiff_decode_blob ( const uint8_t *  blob,
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.

Raws that do not embed a JPEG preview embed a TIFF one – every DNG written by Adobe's converter does, as do Phase One IIQ, Hasselblad 3FR and film scanners. This is the only decoder those previews need; libtiff reads a blob through TIFFClientOpen just as well as a file.

Parameters
blobEncoded TIFF bytes. Not retained.
bufsizeLength of blob.
outOn success, receives a freshly allocated buffer of 4 bytes per pixel, laid out R, G, B, unused – the layout the JPEG preview path also produces. The caller owns it and must release it with dt_pixelpipe_cache_free_align(). Untouched on failure.
widthReceives the decoded width. Untouched on failure.
heightReceives the decoded height. Untouched on failure.
Returns
TRUE on success, FALSE if the blob is not a readable TIFF or allocation failed.

Definition at line 651 of file imageio_tiff.c.

References _blob_close(), _blob_map(), _blob_read(), _blob_seek(), _blob_size(), _blob_unmap(), _blob_write(), _error_handler(), _warning_handler(), _tiff_blob_t::data, DT_DEBUG_IMAGEIO, dt_pixelpipe_cache_alloc_align_cache, dt_pixelpipe_cache_free_align, dt_print(), FALSE, height, i, IS_NULL_PTR, out, TRUE, and width.

Referenced by dt_imageio_large_thumbnail().

◆ dt_imageio_tiff_read_profile()

int dt_imageio_tiff_read_profile ( const char *  filename,
uint8_t **  out 
)