IndexedFormat<P>.bits8 constructor

IndexedFormat<P>.bits8(
  1. Iterable<P> palette, {
  2. required PixelFormat<P, void> format,
  3. String? name,
  4. int? zero,
  5. int? max,
})

Creates an 8-bit indexed pixel format with the given palette.

The format is used to convert between the palette colors and the indexed values.

The zero and max values are used to clamp the indexed values to the valid range of the palette; if omitted, they default to 0 and palette.length - 1 respectively.

Implementation

factory IndexedFormat.bits8(
  Iterable<P> palette, {
  required PixelFormat<P, void> format,
  String? name,
  int? zero,
  int? max,
}) {
  if (palette.length > 256) {
    throw ArgumentError.value(
      palette.length,
      'palette.length',
      'Must be less than or equal to 256 for 8-bit indexed format.',
    );
  }
  return IndexedFormat._(
    List.of(palette),
    format,
    zero: zero ?? 0,
    max: max ?? palette.length - 1,
    bytesPerPixel: 1,
    name: name ?? 'INDEXED_${format.name}_${palette.length}',
  );
}