blit method
Copy a region of another Uint8List to this texture's buffer
srcRect
must contain the starting X and Y coordinates to copy from,
and the width and height of the entire image held by src
.
dstRect
if provided, gives a region of this texture's buffer to which
to copy the pixels.
Implementation
void blit(Uint8List src, Rect srcRect, Rect? dstRect) {
int srcX = srcRect.left.toInt();
int srcY = srcRect.top.toInt();
int srcW = srcRect.width.toInt();
int srcH = srcRect.height.toInt();
int dstX = dstRect?.left.toInt() ?? 0;
int dstY = dstRect?.top.toInt() ?? 0;
int dstW = dstRect?.width.toInt() ?? width;
int dstH = dstRect?.height.toInt() ?? height;
int rowSize = min(min(dstW, srcW - srcX), width - dstX);
int numRows = min(min(dstH, srcH - srcY), height - dstY);
for (int dy = 0; dy < numRows; dy++) {
for (int dx = 0; dx < rowSize; dx++) {
for (int k = 0; k < 4; k++) {
buffer[4 * ((dstY + dy) * width + dstX + dx) + k] =
src[4 * ((srcY + dy) * srcW + srcX + srcH) + k];
}
}
}
}