|
|
|
@ -265,6 +265,12 @@ public class ScriptElement(ScriptGraphicsElement scriptElement, ILogger logger) |
|
|
|
int offset = shortBytes.Length; |
|
|
|
int offset = shortBytes.Length; |
|
|
|
using (SKPixmap pixmap = _canvasBitmap.PeekPixels()) |
|
|
|
using (SKPixmap pixmap = _canvasBitmap.PeekPixels()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
int canvasWidth = pixmap.Width; |
|
|
|
|
|
|
|
int canvasHeight = pixmap.Height; |
|
|
|
|
|
|
|
const int BYTES_PER_PIXEL = 4; |
|
|
|
|
|
|
|
int destRowBytes = pixmap.RowBytes; |
|
|
|
|
|
|
|
Span<byte> canvasSpan = pixmap.GetPixelSpan(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rectangleCount; i++) |
|
|
|
for (int i = 0; i < rectangleCount; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
buffer.Slice(offset, 2).CopyTo(shortBytes); |
|
|
|
buffer.Slice(offset, 2).CopyTo(shortBytes); |
|
|
|
@ -283,27 +289,20 @@ public class ScriptElement(ScriptGraphicsElement scriptElement, ILogger logger) |
|
|
|
offset += 2; |
|
|
|
offset += 2; |
|
|
|
int h = BinaryPrimitives.ReadUInt16BigEndian(shortBytes); |
|
|
|
int h = BinaryPrimitives.ReadUInt16BigEndian(shortBytes); |
|
|
|
|
|
|
|
|
|
|
|
int canvasWidth = pixmap.Width; |
|
|
|
int effectiveW = Math.Max(0, Math.Min(w, canvasWidth - x)); |
|
|
|
int canvasHeight = pixmap.Height; |
|
|
|
int effectiveH = Math.Max(0, Math.Min(h, canvasHeight - y)); |
|
|
|
|
|
|
|
|
|
|
|
int effectiveW = Math.Min(w, canvasWidth); |
|
|
|
|
|
|
|
int effectiveH = Math.Min(h, canvasHeight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (effectiveW > 0 && effectiveH > 0) |
|
|
|
if (effectiveW > 0 && effectiveH > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int bytesPerPixel = 4; |
|
|
|
int sourceRowBytes = w * BYTES_PER_PIXEL; |
|
|
|
int sourceRowBytes = w * bytesPerPixel; |
|
|
|
|
|
|
|
int destRowBytes = pixmap.RowBytes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Span<byte> canvasSpan = pixmap.GetPixelSpan(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < effectiveH; row++) |
|
|
|
for (int row = 0; row < effectiveH; row++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int sourceIndex = offset + (row * sourceRowBytes); |
|
|
|
int sourceIndex = offset + (row * sourceRowBytes); |
|
|
|
int destIndex = ((y + row) * destRowBytes) + (x * bytesPerPixel); |
|
|
|
int destIndex = ((y + row) * destRowBytes) + (x * BYTES_PER_PIXEL); |
|
|
|
|
|
|
|
|
|
|
|
buffer.Slice(sourceIndex, effectiveW * bytesPerPixel) |
|
|
|
buffer.Slice(sourceIndex, effectiveW * BYTES_PER_PIXEL) |
|
|
|
.CopyTo(canvasSpan.Slice(destIndex, effectiveW * bytesPerPixel)); |
|
|
|
.CopyTo(canvasSpan.Slice(destIndex, effectiveW * BYTES_PER_PIXEL)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|