blitUnsafe<S> method

  1. @override
void blitUnsafe<S>(
  1. Buffer<S> from, {
  2. Rect? source,
  3. Pos? target,
  4. BlendMode blend = BlendMode.srcOver,
})
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. If the rectangle is outside the bounds of the source buffer, the behavior is undefined.

If a target position is provided, the top-left corner of the source rectangle will be copied starting at that position. If there is not sufficient space in the target buffer, the behavior is undefined.

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.blitUnsafe(src);
dst.blitUnsafe(src, source: Rect.fromLTWH(1, 0, 1, 2));
dst.blitUnsafe(src, target: Pos(1, 1));
dst.blitUnsafe(src, source: Rect.fromLTWH(1, 0, 1, 2), target: Pos(1, 1));

Implementation

@override
void blitUnsafe<S>(
  Buffer<S> from, {
  Rect? source,
  Pos? target,
  BlendMode blend = BlendMode.srcOver,
}) {
  target ??= Pos.zero;
  final sRect = source ?? from.bounds;
  final tRect = Rect.fromTLBR(
    target,
    target + sRect.size,
  ).intersect(bounds);
  if (tRect.isEmpty) {
    return;
  }
  source = Rect.fromLTWH(
    sRect.left,
    sRect.top,
    tRect.width,
    tRect.height,
  );
  final fn = blend.getBlend(from.format, format);
  if (from is _Pixels<S>) {
    _blitUnsafeFast(from, source: source, target: tRect, blend: fn);
  } else {
    _blitUnsafeSlow(from, source: source, target: tRect, blend: fn);
  }
}