decodeFrame method
Decode a single frame from the data stat was set with startDecode.
If frame
is out of the range of available frames, null is returned.
Non animated image files will only have frame
0. An AnimationFrame
is returned, which provides the image, and top-left coordinates of the
image, as animated frames may only occupy a subset of the canvas.
Implementation
@override
Image decodeFrame(int frame) {
_input.offset = _pixelDataOffset();
var rowStride = (info!.width * info!.bpp) >> 3;
if (rowStride % 4 != 0) {
rowStride += 4 - (rowStride % 4);
}
final image = Image(info!.width, info!.height);
for (var y = image.height - 1; y >= 0; --y) {
final line = info!.readBottomUp ? y : image.height - 1 - y;
final row = _input.readBytes(rowStride);
for (var x = 0; x < image.width;) {
info!.decodeRgba(row, (color) => image.setPixelSafe(x++, line, color));
}
}
return image;
}