IndexedFormat<P>.bits32 constructor

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

Creates an 32-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.bits32(
  Iterable<P> palette, {
  required PixelFormat<P, void> format,
  String? name,
  int? zero,
  int? max,
}) {
  // This, if each value is a 32-bit integer, is 16 GiB, and likely to OOM.
  if (palette.length > 4294967296) {
    throw ArgumentError.value(
      palette.length,
      'palette.length',
      'Must be less than or equal to 4294967296 for 32-bit indexed format.',
    );
  }
  return IndexedFormat._(
    List.of(palette),
    format,
    zero: zero ?? 0,
    max: max ?? palette.length - 1,
    bytesPerPixel: 4,
    name: name ?? 'INDEXED_${format.name}_${palette.length}',
  );
}