Expand description
Image decoding pipeline β codec dispatch, RAW/HEIF/JXL/JPEG2K/SVG/PSD/WebP decoders, embedded-preview extraction, EXIF orientation, and decode-cache management.
This module was extracted from library/mod.rs to keep the main module
focused on window construction and navigation.
ModulesΒ§
- codecs π
StructsΒ§
- Libraw
Handle π - MemImage π
EnumsΒ§
- Marker
Kind π - Texture
Decoder π - Tiff
Endian π
ConstantsΒ§
- MIN_
EMBEDDED_ πJPEG_ SIZE - Minimum size for an embedded preview to be considered β tiny thumbnails (EXIF 160x120 stubs) are almost always useless and should be skipped in favour of the full-resolution preview or the libraw fallback.
StaticsΒ§
- RAW_
CACHE_ πENABLED - Runtime flag controlling the on-disk RAW decode cache. Initialised from config at startup; toggled live from the settings UI.
- RAW_
FULL_ πDECODE - Runtime flag: true = full demosaic, false = extract embedded JPEG preview.
FunctionsΒ§
- apply_
exif_ πorientation - Apply EXIF orientation (1..=8) to a Pixbuf via rotate + optional flip.
- apply_
libraw_ πflip - Apply libraw
fliporientation to aPixbuf. - choose_
best_ πembedded_ jpeg - classify_
jpeg_ πmarker - configure_
libraw_ π βfull_ decode - decode_
full_ πraw_ texture - decode_
heif_ πtexture - decode_
image_ πtexture - decode_
jpeg_ πtexture - decode_
libraw_ πbitmap_ thumb - Decode a bitmap (uncompressed RGB) thumbnail extracted by libraw.
- decode_
libraw_ πjpeg_ thumb - Decode a JPEG thumbnail extracted by libraw.
- decode_
libraw_ πtexture - Decode a RAW via vendored libraw with camera white balance + AHD demosaic at full resolution. Output goes through a disk cache keyed by (path, mtime, size) so a re-open hits the cache instead of re-demosaicing.
- decode_
libraw_ πuncached - decode_
pixbuf_ πtexture - decode_
psd_ πtexture - decode_
raw_ πpreview_ or_ fallback - decode_
raw_ πtexture - decode_
raw_ πthumbnail_ texture - Thumbnail-targeted RAW decode: embedded JPEG first, full demosaic only as
last resort. Ignores
RAW_FULL_DECODE(which is for lightbox quality, not 256-px grid tiles β full sensor data would just be scaled away). - decode_
webp_ πtexture - decode_
with_ πfallbacks - decode_
with_ πroute - dynamic_
image_ πtexture - extract_
largest_ πembedded_ jpeg - Return the largest renderable JPEG embedded in the file, or None.
Uses structure-aware marker walking; skips lossless SOF3 payloads
(compressed Bayer data) and payloads below
MIN_EMBEDDED_JPEG_SIZE. - extract_
libraw_ πthumb - Embedded RAW preview: SOI-scan for the largest JPEG (primary), fall back to librawβs bitmap/JPEG thumbnail for files that store the preview as TIFF strips (Samsung DNG, OnePlus DNG, etc.). Full demosaic path untouched.
- extract_
primary_ πembedded_ jpeg - find_
jpeg_ πend - Walk the JPEG marker structure starting at the SOI at
bytes[start]and return the byte offset just past the EOI (or the end of the buffer if the file omits the trailing EOI). - has_
jpeg_ πsoi - init_
libraw π β - is_
embedded_ πjpeg_ start - is_
exif_ πsegment - is_
lossless_ πjpeg - True if the JPEG at
bytes[start..end]uses SOF3 (lossless JPEG). RAW files wrap compressed Bayer data in SOF3 containers β these are never renderable and should be skipped by the preview scanner. - is_
standalone_ πjpeg_ marker - is_
thumbnail_ πprerotated - Check whether a thumbnail has already been rotated to display orientation by the camera firmware. Compares the thumbnailβs aspect ratio to the raw sensorβs: if a 90-degree flip is needed (flip=5 or flip=6) but the thumbnail is already in the rotated aspect (portrait when sensor is landscape, or vice versa), the thumbnail is pre-rotated.
- jpeg_
bytes_ πto_ oriented_ texture - Decode JPEG bytes to a texture, applying EXIF orientation or libraw flip.
- jpeg_
segment π - libraw_
image_ π βto_ texture - libraw_
step π β - load_
texture_ πblocking - log_
decode_ πresult - make_
libraw_ π βimage - memory_
texture π - parse_
tiff_ πorientation - Parse TIFF IFD0 starting at the TIFF header, return orientation if present.
- pixbuf_
to_ πtexture - Convert a
Pixbufto agdk4::Texture(same logic asdecode_pixbuf_texture). - raw_
decode_ πcache_ dir - Return the directory used for the on-disk RAW decode cache.
- raw_
decode_ πcache_ key - Build a stable cache filename for a RAW file based on its canonical path, last-modified timestamp (seconds), and byte length. Any change to the file on disk produces a different key so stale pixels are never served.
- read_
jpeg_ πexif_ orientation - Read EXIF orientation (tag 0x0112) from JPEG bytes. Returns 1..=8 or None.
Hand-rolled because
Pixbuf::apply_embedded_orientationsilently drops EXIF on some RAW-embedded JPEGs (truncated/oversize APP1 segments). - read_
raw_ πdecode_ cache - Attempt to load a previously cached demosaiced texture from disk.
Returns
Noneif the cache entry is absent, stale, or unreadable. - run_
libraw_ π βfull_ decode - scan_
sos_ πentropy - Read a SOS header, then scan through entropy-coded data until the next real marker. Returns the position of that marker, or None on truncation.
- seek_
marker π - Advance past non-marker bytes and padding 0xFF fills, returning the position of the next real marker prefix.
- set_
raw_ cache_ enabled - Update the runtime RAW cache flag (called from settings and startup).
- set_
raw_ full_ decode - Update the runtime RAW full-decode flag (called from settings and startup).
- skip_
or_ πaccept - Skip a variable-length JPEG segment, or return None when the segment is malformed (signals the caller to accept the whole remaining buffer).
- skip_
segment π - Read and skip a variable-length JPEG segment. Returns the position after the segment, or None if the segment is malformed.
- texture_
decoder_ πfor_ path - unpack_
libraw_ π βfallback_ thumb - Unpack and decode the libraw fallback thumbnail (JPEG or bitmap).
- write_
raw_ πdecode_ cache - Persist a successfully demosaiced RAW texture to the disk cache so future opens can skip the expensive libraw pipeline entirely.
- write_
raw_ πdecode_ cache_ async