mapIndexed method
- T convert(
- Pos,
- T
Returns a lazy buffer that converts pixels with the given function.
The function is called with the position of the pixel in the buffer.
It is expected that the function does not change the representation of the pixel data, only the values. For example a function that inverts the red channel of an RGB pixel would be acceptable, but a function that converts an RGB pixel to an RGBA pixel would not; for that use mapConvert instead.
Example
final buffer = IntPixels(2, 2, data: Uint32List.fromList([
abgr8888.red, abgr8888.green,
abgr8888.blue, abgr8888.alpha,
]));
// Invert pixels in the top row.
final converted = buffer.mapIndexed((pos, pixel) {
if (pos.y == 0) return pixel ^ 0xFFFFFFFF;
return pixel;
});
print(converted.data); // [0xFF00FFFF, 0xFF00FF00, 0xFF0000FF, 0xFF000000]
Implementation
Buffer<T> mapIndexed(T Function(Pos, T) convert) {
return _MapIndexedBuffer(this, convert);
}