copyFromUnsafe method

  1. @override
void copyFromUnsafe(
  1. Buffer<Float32x4> from, {
  2. Rect? source,
  3. Pos? target,
})
inherited

Copies 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 provded, 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.

The pixels are copied as-is, without any conversion or blending; see blit for converting and blending pixel data.

Example

final src = IntPixels(2, 2, data: Uint32List.fromList([
  0xFFFFFFFF, 0x00000000, //
  0x00000000, 0xFFFFFFFF, //
]));

final dst = IntPixels(3, 3);
dst.copyFromUnsafe(src);
dst.copyFromUnsafe(src, source: Rect.fromLTWH(1, 0, 1, 2));
dst.copyFromUnsafe(src, target: Pos(1, 1));
dst.copyFromUnsafe(src, source: Rect.fromLTWH(1, 0, 1, 2), target: Pos(1, 1));

Implementation

@override
void copyFromUnsafe(
  Buffer<T> from, {
  Rect? source,
  Pos? target,
}) {
  final src = from;
  final dst = this;
  if (src is _Pixels<T>) {
    return lodim.copyRectLinear(
      src.data,
      dst.data,
      srcWidth: src.width,
      dstWidth: dst.width,
      source: source,
      target: target ?? Pos.zero,
    );
  }
  return lodim.copyRect(
    source ?? src.bounds,
    src.getUnsafe,
    dst.setUnsafe,
    target: target ?? Pos.zero,
  );
}