Skip to main content

raw_image_reader 0.0.2 copy "raw_image_reader: ^0.0.2" to clipboard
raw_image_reader: ^0.0.2 copied to clipboard

Read camera RAW data using Dart, Rust rawloader, or Windows WIC codecs.

raw_image_reader #

A Dart library for reading raw sensor samples and metadata from camera RAW files. It includes a pure-Dart TIFF subset, an optional Rust rawloader backend, and a Windows-only backend that uses installed Windows Imaging Component (WIC) codecs.

Note/Warning #

This library has been entirely generated using AI (Copilot)

Format support #

This table distinguishes the pure-Dart decoder from the optional Rust backend. Neither backend guarantees every camera model, firmware, or compression variant.

Format Pure-Dart decoder Rust rawloader FFI backend Windows WIC backend
Classic TIFF raw Strip-based, single-sample unsigned data from 1–16 bits/sample Upstream-dependent Built-in WIC codec
DNG Partial TIFF subset and selected metadata Upstream “good parts” Depends on installed codecs
Canon CR2 Partial; synthetic layouts only Supported for upstream camera entries Supported when an installed codec recognizes the camera
Canon CR3 Container metadata only; no CRX pixels Not supported by rawloader 0.37.2 Supported by the installed Raw Image Extension; sample verified
Canon CRW Unsupported Supported by upstream Depends on installed codecs
Other camera RAW formats Unsupported See upstream format list below Many are supported by Raw Image Extension; not all

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 native backend uses upstream rawloader 0.37.2. Its README lists support for these formats, subject to its camera database and implementation limits:

  • 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, decodeRawRgbBytes, and decodeRawRgbBytesAsync use the pure-Dart TIFF subset. The opt-in decodeRawloaderBytes, decodeRawloaderFile, and decodeRawloaderRgbBytes functions call the Rust crate through FFI. Build the native library first:

cargo build --manifest-path native/rawloader_ffi/Cargo.toml --release

The Dart FFI loader searches for the built library under native/rawloader_ffi/target from the current directory and its parents. Set RAW_IMAGE_READER_NATIVE_LIBRARY to an explicit shared-library path when using another build location. The Rust library must be built for the host OS and architecture. The FFI backend is unavailable on web; existing pure-Dart byte APIs remain usable there.

Android #

Android applications can use the Rust FFI backend through the bundled native asset. The package includes prebuilt libraries for arm64-v8a, armeabi-v7a, x86_64, and x86, so consuming apps do not need Rust or the NDK installed. The Android build uses the librawloader_ffi.so matching the application ABI. The libraries target Android API 21 or later. If rebuilding them from source, install Rust with the four Android targets and the Android NDK, then run:

.\native\rawloader_ffi\build_android.ps1

Set ANDROID_NDK_HOME to the NDK directory or pass -NdkPath if it is not under ANDROID_HOME. The build hook packages the matching shared library in Flutter apps. The four libraries were cross-compiled and checked for their expected ELF architectures; a Flutter APK build confirmed packaging for armeabi-v7a, arm64-v8a, and x86_64. Android runtime decoding could not be exercised without a connected device or emulator. This backend uses rawloader, which does not support CR3; the Windows-only WIC fallback is not available on Android.

On Windows, decodeWindowsRawRgbBytes and decodeWindowsRawRgbFile use WIC, the same extensible codec framework used by Windows image applications. RAW support depends on codecs installed on that Windows system. The Microsoft Raw Image Extension supplies codecs for a long list of camera models, including CR3, but does not support every RAW format (for example, its listing excludes GPR). Install the extension from the Microsoft Store if needed. WIC returns rendered RGB pixels rather than a camera's original Bayer samples; the API marks these results as RawRgbEncoding.platformRendered.

The WIC backend was run against the included CR3 sample on a Windows system with Raw Image Extension 2.5.42.0 installed. It produced 16-bit RGB output at 6022 x 4024 and read the camera make/model from WIC metadata. The dimensions and rendering can vary by codec version and camera.

The native decoder returns the rawloader sensor samples and metadata. decodeRawloaderRgbBytes applies the Dart bilinear demosaicer to single-sample CFA images or converts images with at least three samples per pixel to interleaved RGB. RGB values are linear camera RGB; white balance and camera color conversion are not applied.

The pure-Dart byte APIs can be used wherever Dart runs. Path-based APIs use conditional imports and report UnsupportedError on platforms without dart:io; browser callers should use the byte APIs.

Canon format notes and validation limits #

CR2 is TIFF-based, but real Canon raw IFDs may be sparse and rely on Canon's slice tag (0xC640) and multi-component lossless JPEG. The pure-Dart decoder does not implement these structures. The optional native backend was validated with a CC0 EOS 5D Mark III sample (5G4A9396.CR2); rawloader decoded its 2880 x 1920 sensor data and Canon camera/CFA metadata. This is a sample-level check, not a guarantee of every CR2 model.

The upstream rawloader README documents CR2 and CRW but does not list CR3, so rawloader cannot decode CR3. The included CR3 sample validates the pure-Dart container parser and, on Windows with a compatible WIC codec, the rendered RGB backend.

The Rust rawloader dependency and the bundled Android libraries are licensed under LGPL-2.1. Its license text is included at native/rawloader_ffi/RAWLOADER-LICENSE; review the license terms when distributing the compiled native library.

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;

final decodedBytes = decodeRawRgbBytes(fileBytes);

// Requires the Rust cdylib to be built for the current platform.
final nativeImage = decodeRawloaderBytes(fileBytes);
final nativeRgb = decodeRawloaderRgbBytes(fileBytes);

// Windows only; requires an installed WIC RAW codec.
final windowsRgb = decodeWindowsRawRgbBytes(fileBytes);

rgbData stores three interleaved 16-bit values per pixel in R, G, B order. The current pure-Dart decoder returns linear camera RGB.

Command line #

dart run bin/raw_image_reader.dart image.dng
dart run bin/raw_image_reader.dart --rawloader image.CR2
dart run bin/raw_image_reader.dart --windows-wic image.CR3

--rawloader selects the Rust backend. --windows-wic selects installed Windows codecs and returns rendered RGB; it is useful for formats such as CR3 that upstream rawloader does not decode.

0
likes
125
points
150
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Read camera RAW data using Dart, Rust rawloader, or Windows WIC codecs.

License

MIT (license)

Dependencies

code_assets, ffi, hooks, path, zcodec

More

Packages that depend on raw_image_reader