raw_image_reader

A Dart library for reading raw sensor samples and metadata from TIFF-based camera files. This is an independent implementation inspired by the feature scope of rawloader.

Note/Warning

This library has been entirely generated using AI (Copilot)

Format support

This table describes this Dart package, not the upstream Rust rawloader project or LibRaw. “Supported” means only the file structures and codecs listed below; it does not guarantee every camera model, firmware, or compression variant.

Format Status Current behavior
Classic TIFF raw Supported subset Reads strip-based, single-sample, unsigned integer data from 1–16 bits/sample.
DNG Partial Reads only the TIFF subset above and selected DNG metadata; it is not a complete DNG implementation.
Canon CR2 RGB decode supported through LibRaw decodeRawRgbFile and decodeRawRgbBytesAsync use RawKit/LibRaw to decode and render CR2 to 16-bit sRGB. The pure-Dart decodeRawFile path remains a limited TIFF/CR2 raw-IFD decoder.
Canon CR3 RGB decode supported through LibRaw decodeRawRgbFile and decodeRawRgbBytesAsync use RawKit/LibRaw to decode and render CRX sensor data to 16-bit sRGB. parseCr3File / parseCr3Bytes remain available for container, selected metadata, and embedded JPEG inspection.
Canon CRW Unsupported No CIFF/CRW parser.
Other camera RAW formats Unsupported See the list below.

Supported TIFF compression values are uncompressed (1), Deflate (8 and 32946), and lossless JPEG (6 and 7) when each JPEG strip is a complete, single-component lossless JPEG stream. BigTIFF, tiled images, multi-sample pixels, signed/floating-point samples, other JPEG modes, and other compression schemes are unsupported.

The upstream rawloader README lists these additional formats, which this Dart package does not currently decode:

  • Minolta MRW; Mamiya MEF; Olympus ORF; Samsung SRW; Epson ERF
  • Sony ARW, SRF, and SR2
  • Kodak KDC, DCS, and DCR
  • Panasonic RW2; Fujifilm RAF; Pentax PEF
  • Leaf IIQ and MOS; Hasselblad 3FR
  • Nikon NEF and NRW; ARRI ARI
  • Naked/raw-dump files

decodeRawRgbFile and decodeRawRgbBytesAsync return RawRgbImage for the supported TIFF subset and for Canon CR2/CR3. TIFF CFA data is bilinearly demosaiced to linear camera RGB, without white balance or camera color conversion. Canon files are decoded and developed by RawKit/LibRaw to interleaved 16-bit sRGB, using the camera white balance and LibRaw's default demosaicing. RawRgbImage.encoding identifies which output was returned. For Canon output, width and height match the returned RGB buffer; visibleWidth/visibleHeight and rawWidth/rawHeight retain the source dimensions reported by LibRaw. decodeRawRgbBytes remains the synchronous, pure-Dart API for TIFF-based inputs; use decodeRawRgbBytesAsync for Canon bytes.

Canon format notes and validation limits

Canon CR2/CR3 RGB decoding is delegated to the bundled LibRaw 0.22.2 backend through RawKit. CR2 raw sensor unpacking and CR3 CRX decoding are therefore no longer implemented by this package's pure-Dart TIFF/ISO-BMFF parsers. The CR3 container parser can still inspect metadata and embedded JPEG samples independently.

The upstream rawloader README documents CR2 and CRW but does not list CR3. LibRaw provides the codec implementation, but no decoder can guarantee every Canon model, firmware, or capture mode without representative test files. The included real CR3 sample is decoded end-to-end; this workspace contains no real CR2 fixture, so CR2 decoding is not yet verified by this package's tests. Add licensed CR2 samples from each required camera/mode to validate the specific compatibility target.

RawKit builds LibRaw as a native dependency on desktop/mobile and uses its WebAssembly build on the web. Desktop builds require the platform C/C++ toolchain; the package's distribution must also comply with LibRaw's LGPL license. See RawKit's third-party notices for details.

Research references:

Library usage

import 'package:raw_image_reader/raw_image_reader.dart';

Future<void> main() async {
  final image = await decodeRawFile('image.dng');
  print('${image.width} x ${image.height}, ${image.bitsPerSample}-bit');
  print(image.cfaPattern);
  // image.data contains one unsigned sample for each sensor pixel.
}

Use decodeRawBytes when the file is already in memory. Pixel data is retained in row-major order; TIFF orientation and crop metadata are reported rather than applied.

final decoded = await decodeRawRgbFile('image.dng');
final List<int> rgb = decoded.rgbData;
final metadata = decoded.metadata;

// For in-memory Canon CR2/CR3 files, use the asynchronous RawKit-backed API.
final canonImage = await decodeRawRgbBytesAsync(fileBytes);

rgbData stores three interleaved 16-bit values per pixel in R, G, B order. Check encoding to distinguish linear camera RGB from rendered sRGB.

Command line

dart run bin/raw_image_reader.dart image.dng

Libraries

raw_image_reader