Add some helpers to `BitmapBuffer`
This commit is contained in:
parent
d7e9668d50
commit
9a5a75e5bb
|
@ -34,6 +34,10 @@ namespace BizHawk.Bizware.Graphics
|
|||
private GCHandle CurrLockHandle;
|
||||
private BitmapData CurrLock;
|
||||
|
||||
/// <summary>same as <see cref="Pixels"/> (<see cref="PixelFormat.Format32bppArgb">A8R8G8B8</see>)</summary>
|
||||
public Span<int> AsSpan()
|
||||
=> Pixels;
|
||||
|
||||
/// <exception cref="InvalidOperationException">already locked</exception>
|
||||
/// <remarks>TODO add read/write semantic, for wraps</remarks>
|
||||
public BitmapData LockBits()
|
||||
|
@ -213,19 +217,24 @@ namespace BizHawk.Bizware.Graphics
|
|||
return new(0, 0);
|
||||
}
|
||||
|
||||
var w = maxx - minx + 1;
|
||||
var h = maxy - miny + 1;
|
||||
var bbRet = new BitmapBuffer(w, h);
|
||||
for (var y = 0; y < h; y++)
|
||||
{
|
||||
for (var x = 0; x < w; x++)
|
||||
{
|
||||
bbRet.SetPixel(x, y, GetPixel(x + minx, y + miny));
|
||||
}
|
||||
}
|
||||
|
||||
xofs = minx;
|
||||
yofs = miny;
|
||||
return Copy(region: new(x: minx, y: miny, width: maxx - minx + 1, height: maxy - miny + 1));
|
||||
}
|
||||
|
||||
public BitmapBuffer Copy()
|
||||
=> new(width: Width, height: Height, pixels: Pixels.AsSpan().ToArray());
|
||||
|
||||
/// <remarks>TODO surely there's a better implementation --yoshi</remarks>
|
||||
public BitmapBuffer Copy(Rectangle region)
|
||||
{
|
||||
BitmapBuffer bbRet = new(region.Size);
|
||||
var miny = region.Top;
|
||||
var minx = region.Left;
|
||||
for (int y = 0, h = region.Height; y < h; y++) for (int x = 0, w = region.Width; x < w; x++)
|
||||
{
|
||||
bbRet.SetPixel(x, y, GetPixel(x + minx, y + miny));
|
||||
}
|
||||
return bbRet;
|
||||
}
|
||||
|
||||
|
@ -535,6 +544,8 @@ namespace BizHawk.Bizware.Graphics
|
|||
return candidate;
|
||||
}
|
||||
|
||||
public bool SequenceEqual(BitmapBuffer other)
|
||||
=> Width == other.Width && Height == other.Height && AsSpan().SequenceEqual(other.AsSpan());
|
||||
|
||||
/// <summary>
|
||||
/// Dumps this BitmapBuffer to a new System.Drawing.Bitmap
|
||||
|
|
Loading…
Reference in New Issue