DICOM RLE Lossless codec per PS3.5 Annex G.
Transfer Syntax UID: 1.2.840.10008.1.2.5
RLE Format
Each RLE-compressed frame consists of:
RLE Header (64 bytes):
uint32number of segments (1..15)- 15
uint32segment offsets (unused offsets are zero)
Segments: One per byte plane. For single-byte pixels (8-bit), there is one segment. For 16-bit pixels, segment 1 contains all high bytes and segment 2 all low bytes (byte-plane separation).
RLE Encoding (per segment):
nin 0..127: copy the nextn + 1bytes literallyn= -128 (0x80): no operation (skip)nin -127..-1: repeat the next byte1 - ntimes
All multi-byte integers in the header are little-endian unsigned 32-bit.
Reference: DICOM PS3.5 Annex G.
Summary
Functions
Decodes an RLE-compressed frame to raw pixel data.
Encodes raw pixel data to RLE-compressed form.
Functions
@spec decode(binary(), Dicom.Codec.metadata()) :: {:ok, binary()} | {:error, term()}
Decodes an RLE-compressed frame to raw pixel data.
Requires :bits_allocated and :samples_per_pixel in metadata
to determine the expected number of segments and output size.
Requires :rows and :columns to compute total pixel count.
@spec encode(binary(), Dicom.Codec.metadata()) :: {:ok, binary()} | {:error, term()}
Encodes raw pixel data to RLE-compressed form.
Requires :bits_allocated and :samples_per_pixel in metadata
to determine byte-plane segmentation.