Skip to main content

Module texture_decode

Module texture_decode 

Source
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Β§

LibrawHandle πŸ”’
MemImage πŸ”’

EnumsΒ§

MarkerKind πŸ”’
TextureDecoder πŸ”’
TiffEndian πŸ”’

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 flip orientation to a Pixbuf.
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 Pixbuf to a gdk4::Texture (same logic as decode_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_orientation silently 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 None if 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 πŸ”’