Skip to main content

Module fuji_compressed

Module fuji_compressed 

Source
Expand description

Fujifilm compressed RAF codec (lossless and lossy, X-Trans and Bayer).

§Stream layout

The payload starts with a 16-byte big-endian header (signature IS), followed by one big-endian u32 byte size per vertical block (padded to 16 bytes), then — for lossy files only — one quantisation base per block and 6-row line (blocks × align16(lines) bytes), and finally the entropy-coded blocks back to back.

The image is split into vertical stripes of block_size (768) columns. Every stripe is an independent bit stream, which is what makes this codec embarrassingly parallel: FujiCompressed::decode decodes all stripes concurrently straight into the output buffer.

§Coding

A stripe is coded line by line, a line being six sensor rows. Samples of each colour are gathered into per-colour line buffers (3 red, 6 green, 3 blue per line, plus the two previous lines of each colour as context). Each sample is predicted from its neighbours (a median-edge-like rule that differs for even and odd positions), and the residual is coded with an adaptive Golomb-Rice-like code: a unary prefix (zero run) followed by k raw bits, k derived from running statistics selected by a quantised local gradient. Lossy files additionally quantise residuals with a per-line step 2 * q_base + 1. X-Trans streams leave some positions to pure interpolation (no bits are spent on them).

Decoding is bit-exact, including tolerance of a one-byte over-read at the end of a stripe.

Structs§

FujiCompressed
A parsed compressed payload, ready to decode.
FujiHeader
Parsed stream header.

Constants§

HEADER_SIZE
Size of the stream header in bytes.

Type Aliases§

ColorTile
Colour (0 = red, 1 = green, 2 = blue) of every position of a 6×6 tile anchored at the buffer origin. Bayer patterns are repeated to fill the tile.