using System; namespace ScreenConnect; public abstract class BitmapData : CriticalFinalizerDisposableObject, IBitmapData, IBlittable { public PixelModel PixelModel { get; } public int Width { get; } public int Height { get; } public int Stride { get; } public IntPtr Scan0 { get; } public CoreSize Size => new CoreSize(Width, Height); protected BitmapData(PixelModel pixelModel, int width, int height, int stride, IntPtr scan0) { PixelModel = pixelModel; Width = width; Height = height; Stride = stride; Scan0 = scan0; } public BitmapSection AcquireBits(CoreRect bounds) { if (bounds.X < 0 || bounds.Y < 0 || bounds.X + bounds.Width > Width || bounds.Y + bounds.Height > Height) { throw new ArgumentOutOfRangeException(); } return new BitmapSection(PixelModel, bounds.Width, bounds.Height, Stride, OffsetScan0(Scan0, bounds.X, bounds.Y, Stride, PixelModel), this, bounds.X, bounds.Y); } IBitmapData IBlittable.AcquireBits(CoreRect bounds) { return AcquireBits(bounds); } public void ReleaseBits(IBitmapData bitmapData) { } protected static IntPtr OffsetScan0(IntPtr scan0, int offsetX, int offsetY, int stride, PixelModel pixelModel) { return new IntPtr(scan0.ToInt64() + offsetY * stride + offsetX * pixelModel.BytesPerPixel); } public unsafe void Clear() { int byteCount = Extensions.DivUp(Width * PixelModel.BitsPerPixel, 8); byte* ptr = (byte*)Scan0.ToPointer(); int num = 0; while (num < Height) { Extensions.ZeroMemory(ptr, byteCount); num++; ptr += Stride; } } }