Skip to content

High bit depth

image.bit_depth reports 8, 10, 12, or 16 significant bits per channel. Modes remain L, RGB, or RGBA. A 10-bit channel, for example, ranges from 0 to 1023. getpixel() returns full sample values; tobytes() packs depths above 8 bits as little-endian uint16 samples.

import numpy as np
from blanket import Image

samples = np.full((64, 64, 3), 713, dtype=np.uint16)
image = Image.fromarray(samples, bit_depth=10)
image.save("exact.png")
assert Image.open("exact.png").getpixel((0, 0)) == (713, 713, 713)
image.convert("RGB", bit_depth=8).save("preview.jpg")

fromarray() accepts uint16 arrays, including strided and big-endian arrays, and defaults to 16 bits unless bit_depth is specified. frombytes() accepts little-endian uint16 data. Values outside the selected depth are rejected.

Format Precision behavior
PNG Stores 16-bit channels with sBIT so Blanket recovers the original significant depth and exact samples.
TIFF and JPEG XL Use normalized 16-bit channels; convert back to the desired depth to recover the original range.
HEIF / HEIC Retains 8-, 10-, or 12-bit source depth.

Copy, conversion, pixel access, channel splitting, crop, transpose, and all six resize filters preserve sample precision. Other processing, JPEG and WebP saving, and to_pillow() require explicit conversion to 8 bits. This does not provide HDR tone mapping or retain HEIF HDR/ICC metadata.