madam.raw module

Raw camera image processor using rawpy (LibRaw).

The optional raw dependency group must be installed:

uv sync --extra raw
class madam.raw.RawImageProcessor(config: Mapping[str, Any] | None = None)[source]

Bases: Processor

Represents a processor that handles raw camera image formats (DNG, CR2, NEF, ARW, and any other format supported by LibRaw).

Reading and decoding require the rawpy package, which is a Python binding for LibRaw. Pillow is used to encode the decoded image into the requested output format.

Install the optional raw extra to get both dependencies:

pip install madam[raw]
__init__(config: Mapping[str, Any] | None = None) None[source]

Initializes a new RawImageProcessor.

Parameters:

config – Mapping with settings.

can_read(file: IO) bool[source]

Returns whether the specified MIME type is supported by this processor.

Parameters:

file (IO) – file-like object to be tested

Returns:

whether the data format of the specified file is supported or not

Return type:

bool

decode(asset: Asset, mime_type: str = 'image/png') Asset[source]

Demosaics a raw camera image and returns the result as a standard raster image asset.

Demosaicing is performed with LibRaw using automatic white balance. The result is encoded into the format specified by mime_type.

Parameters:
  • asset (Asset) – Raw image asset to demosaic

  • mime_type (str) – MIME type of the output image ('image/png', 'image/jpeg', or 'image/tiff')

Returns:

Decoded raster image asset

Return type:

Asset

Raises:

OperatorError – if mime_type is not supported

read(file: IO) Asset[source]

Reads a raw camera image file and returns an Asset.

The essence contains the original raw bytes unchanged. The width and height metadata attributes reflect the full sensor dimensions before demosaicing.

Parameters:

file (IO) – Readable binary file-like object containing raw image data

Returns:

Asset with mime_type='image/x-raw', width, and height

Return type:

Asset

property supported_mime_types: frozenset

MIME types this processor can handle (used to build the Madam index).