blit<S> method
inherited
Blits, or copies with blending, the pixel data from a source buffer to
this
buffer.
If a source
rectangle is provided, only the pixels within that rectangle
are copied, and the rectangle will be clipped to the bounds of the source
buffer. If omitted, the entire source buffer will be copied.
If a target
position is provided, the top-left corner of the source
rectangle will be copied starting at that position. If omitted, the
top-left corner of the source rectangle will be copied to the top-left
corner of the this
buffer. If there is not sufficient space in the
target buffer, the source rectangle will be clipped to fit this
.
If a blend
mode is provided, the pixels will be blended using that mode.
Example
final src = IntPixels(2, 2, data: Uint32List.fromList([
0xFFFFFFFF, 0x00000000, //
0x00000000, 0xFFFFFFFF, //
]));
final dst = IntPixels(3, 3);
dst.blit(src);
dst.blit(src, source: Rect.fromLTWH(1, 0, 1, 2));
dst.blit(src, target: Pos(1, 1));
dst.blit(src, source: Rect.fromLTWH(1, 0, 1, 2), target: Pos(1, 1));
Implementation
@override
void blit<S>(
Buffer<S> from, {
Rect? source,
Pos? target,
BlendMode blend = BlendMode.srcOver,
}) {
if (source == null) {
if (target == null) {
return blitUnsafe(from, blend: blend);
}
source = from.bounds;
} else {
source = source.intersect(from.bounds);
}
target ??= Pos.zero;
final clipped = Rect.fromTLBR(
target,
target + source.size,
).intersect(bounds);
if (clipped.isEmpty) {
return;
}
source = Rect.fromLTWH(
source.left,
source.top,
clipped.width,
clipped.height,
);
return blitUnsafe(from, source: source, target: target, blend: blend);
}