IndexedFormat<P> class
final
Pixel Formats
A pixel format that uses a predefined palette to index colors.
Given a linear list of colors, an indexed pixel format uses a single integer value to represent a color in the palette. This is useful for reducing the memory footprint of images, especially when the number of unique colors is small.
Example
// Creating a simple system palette with 8 colors.
final palette = [
abgr8888.create(red: 0xFF, green: 0x00, blue: 0x00),
abgr8888.create(red: 0x00, green: 0xFF, blue: 0x00),
abgr8888.create(red: 0x00, green: 0x00, blue: 0xFF),
abgr8888.create(red: 0xFF, green: 0xFF, blue: 0x00),
abgr8888.create(red: 0xFF, green: 0x00, blue: 0xFF),
abgr8888.create(red: 0x00, green: 0xFF, blue: 0xFF),
abgr8888.create(red: 0xFF, green: 0xFF, blue: 0xFF),
abgr8888.create(red: 0x00, green: 0x00, blue: 0x00),
];
// Creating an 8-bit indexed pixel format with the palette.
final indexed = IndexedFormat.bits8(palette, format: abgr8888);
// Converting a color to an index.
final index = indexed.fromAbgr8888(abgr8888.create(red: 0xFF, green: 0x00, blue: 0x00));
// Converting an index to a color.
final color = indexed.toAbgr8888(index);
See system8 for a predefined palette of common RGB colors.
- Inheritance
-
- Object
- PixelFormat<
int, void> - IndexedFormat
Constructors
-
IndexedFormat.bits16(Iterable<
P> palette, {required PixelFormat<P, void> format, String? name, int? zero, int? max}) -
Creates an 16-bit indexed pixel format with the given
palette
.factory -
IndexedFormat.bits32(Iterable<
P> palette, {required PixelFormat<P, void> format, String? name, int? zero, int? max}) -
Creates an 32-bit indexed pixel format with the given
palette
.factory -
IndexedFormat.bits8(Iterable<
P> palette, {required PixelFormat<P, void> format, String? name, int? zero, int? max}) -
Creates an 8-bit indexed pixel format with the given
palette
.factory
Properties
- bytesPerPixel → int
-
Number of bytes required to store a single pixel in memory.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
Length of the palette.
no setter
- max → int
-
The maximum value for the pixel format.
final
- name → String
-
Human-readable name or description of the pixel format.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- zero → int
-
The zero, or minimum, value for the pixel format.
final
Methods
-
clamp(
int pixel) → int -
Clamps a
pixel
to the valid range of values for the pixel format.override -
compare(
int a, int b) → double -
Compares two pixels in the pixel format.
override
-
convert<
R> (R pixel, {required PixelFormat< R, void> from}) → int -
Converts a pixel
from
one another format tothis
format.inherited -
copyWith(
int pixel) → int -
Returns a copy of the
pixel
.override -
copyWithNormalized(
int pixel) → int -
Returns a copy of the
pixel
with normalized values.override -
describe(
int pixel) → String -
Returns a human-readable description of the pixel.
inherited
-
distance(
int a, int b) → double -
Returns the distance between two pixels in the pixel format.
override
-
fromAbgr8888(
int pixel) → int -
Converts a pixel in the abgr8888 pixel format to
this
pixel format.override -
fromFloatRgba(
Float32x4 pixel) → int -
Converts a pixel in the floatRgba pixel format to
this
pixel format.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toAbgr8888(
int pixel) → int -
Converts a pixel in
this
pixel format to the abgr8888 pixel format.override -
toFloatRgba(
int pixel) → Float32x4 -
Converts a pixel in
this
pixel format to the floatRgba pixel format.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
int index) → P -
Returns the color in the palette at the given
index
.