ImageMode

class toasty.image.ImageMode(value)[source]

Bases: Enum

Allowed image “modes”, describing their pixel data formats.

These align with PIL modes when possible, but we expect to need to support modes that aren’t present in PIL (namely, float64). There are also various obscure PIL modes that we do not support.

Attributes Summary

F16x3

48-bit color with three 16-bit floating-point channels for red, green, and blue.

F32

32-bit floating-point scalar data.

F64

64-bit floating-point scalar data.

RGB

24-bit color with three uint8 channels for red, green, and blue.

RGBA

32-bit color with four uint8 channels for red, green, blue, and alpha (transparency).

U8

Methods Summary

from_array_info(shape, dtype)

make_maskable_buffer(buf_height, buf_width)

Return a new, uninitialized buffer of the specified shape, with a mode compatible with this one but able to accept undefined values.

try_as_pil()

Attempt to convert this mode into a PIL image mode string.

Attributes Documentation

F16x3 = 'F16x3'

48-bit color with three 16-bit floating-point channels for red, green, and blue.

This mode is useful for high-dynamic-range image processing and can be stored in the OpenEXR file format.

F32 = 'F'

32-bit floating-point scalar data.

F64 = 'D'

64-bit floating-point scalar data.

RGB = 'RGB'

24-bit color with three uint8 channels for red, green, and blue.

RGBA = 'RGBA'

32-bit color with four uint8 channels for red, green, blue, and alpha (transparency).

U8 = 'U8'

Methods Documentation

classmethod from_array_info(shape, dtype)[source]
make_maskable_buffer(buf_height, buf_width)[source]

Return a new, uninitialized buffer of the specified shape, with a mode compatible with this one but able to accept undefined values.

Parameters:
buf_heightint

The height of the new buffer

buf_widthint

The width of the new buffer

Returns:
An uninitialized Image instance.

Notes

“Maskable” means that the buffer can accommodate undefined values. If the image is RGB or RGBA, that means that the buffer will have an alpha channel. If the image is scientific, that means that the buffer will be able to accept NaNs.

try_as_pil()[source]

Attempt to convert this mode into a PIL image mode string.

Returns:
A PIL image mode string, or None if there is no exact counterpart.