using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; namespace AForge.Imaging; public class UnmanagedImage : IDisposable { private IntPtr imageData; private int width; private int height; private int stride; private PixelFormat pixelFormat; private bool mustBeDisposed; public IntPtr ImageData => imageData; public int Width => width; public int Height => height; public int Stride => stride; public PixelFormat PixelFormat => pixelFormat; public UnmanagedImage(IntPtr imageData, int width, int height, int stride, PixelFormat pixelFormat) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) this.imageData = imageData; this.width = width; this.height = height; this.stride = stride; this.pixelFormat = pixelFormat; } public UnmanagedImage(BitmapData bitmapData) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) imageData = bitmapData.Scan0; width = bitmapData.Width; height = bitmapData.Height; stride = bitmapData.Stride; pixelFormat = bitmapData.PixelFormat; } ~UnmanagedImage() { Dispose(disposing: false); } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (mustBeDisposed && imageData != IntPtr.Zero) { Marshal.FreeHGlobal(imageData); GC.RemoveMemoryPressure(stride * height); imageData = IntPtr.Zero; } } public UnmanagedImage Clone() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) IntPtr dst = Marshal.AllocHGlobal(stride * height); GC.AddMemoryPressure(stride * height); UnmanagedImage unmanagedImage = new UnmanagedImage(dst, width, height, stride, pixelFormat); unmanagedImage.mustBeDisposed = true; SystemTools.CopyUnmanagedMemory(dst, imageData, stride * height); return unmanagedImage; } public unsafe void Copy(UnmanagedImage destImage) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (width != destImage.width || height != destImage.height || pixelFormat != destImage.pixelFormat) { throw new InvalidImagePropertiesException("Destination image has different size or pixel format."); } if (stride == destImage.stride) { SystemTools.CopyUnmanagedMemory(destImage.imageData, imageData, stride * height); return; } int num = destImage.stride; int count = ((stride < num) ? stride : num); byte* ptr = (byte*)imageData.ToPointer(); byte* ptr2 = (byte*)destImage.imageData.ToPointer(); for (int i = 0; i < height; i++) { SystemTools.CopyUnmanagedMemory(ptr2, ptr, count); ptr2 += num; ptr += stride; } } public static UnmanagedImage Create(int width, int height, PixelFormat pixelFormat) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Invalid comparison between Unknown and I4 //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Invalid comparison between Unknown and I4 //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Invalid comparison between Unknown and I4 //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Invalid comparison between Unknown and I4 //IL_00e1: Unknown result type (might be due to invalid IL or missing references) int num = 0; if ((int)pixelFormat <= 925707) { if ((int)pixelFormat <= 139273) { if ((int)pixelFormat != 137224) { if ((int)pixelFormat == 139273) { goto IL_0085; } goto IL_0091; } num = 3; } else { if ((int)pixelFormat != 198659) { if ((int)pixelFormat == 925707) { goto IL_0085; } goto IL_0091; } num = 1; } } else if ((int)pixelFormat <= 1060876) { if ((int)pixelFormat != 1052676) { if ((int)pixelFormat != 1060876) { goto IL_0091; } num = 6; } else { num = 2; } } else { if ((int)pixelFormat != 1851406) { if ((int)pixelFormat == 2498570) { goto IL_0085; } if ((int)pixelFormat != 3424269) { goto IL_0091; } } num = 8; } goto IL_009c; IL_0085: num = 4; goto IL_009c; IL_0091: throw new UnsupportedImageFormatException("Can not create image with specified pixel format."); IL_009c: if (width <= 0 || height <= 0) { throw new InvalidImagePropertiesException("Invalid image size specified."); } int num2 = width * num; if (num2 % 4 != 0) { num2 += 4 - num2 % 4; } IntPtr dst = Marshal.AllocHGlobal(num2 * height); SystemTools.SetUnmanagedMemory(dst, 0, num2 * height); GC.AddMemoryPressure(num2 * height); UnmanagedImage unmanagedImage = new UnmanagedImage(dst, width, height, num2, pixelFormat); unmanagedImage.mustBeDisposed = true; return unmanagedImage; } public Bitmap ToManagedImage() { return ToManagedImage(makeCopy: true); } public unsafe Bitmap ToManagedImage(bool makeCopy) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Invalid comparison between Unknown and I4 //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) Bitmap val = null; try { if (!makeCopy) { val = new Bitmap(width, height, stride, pixelFormat, imageData); if ((int)pixelFormat == 198659) { Image.SetGrayscalePalette(val); } } else { val = (Bitmap)(((int)pixelFormat == 198659) ? ((object)Image.CreateGrayscaleImage(width, height)) : ((object)new Bitmap(width, height, pixelFormat))); BitmapData val2 = val.LockBits(new Rectangle(0, 0, width, height), (ImageLockMode)3, pixelFormat); int num = val2.Stride; int count = System.Math.Min(stride, num); byte* ptr = (byte*)val2.Scan0.ToPointer(); byte* ptr2 = (byte*)imageData.ToPointer(); if (stride != num) { for (int i = 0; i < height; i++) { SystemTools.CopyUnmanagedMemory(ptr, ptr2, count); ptr += num; ptr2 += stride; } } else { SystemTools.CopyUnmanagedMemory(ptr, ptr2, stride * height); } val.UnlockBits(val2); } return val; } catch (Exception) { if (val != null) { ((Image)val).Dispose(); } throw new InvalidImagePropertiesException("The unmanaged image has some invalid properties, which results in failure of converting it to managed image."); } } public static UnmanagedImage FromManagedImage(Bitmap image) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) UnmanagedImage unmanagedImage = null; BitmapData val = image.LockBits(new Rectangle(0, 0, ((Image)image).Width, ((Image)image).Height), (ImageLockMode)1, ((Image)image).PixelFormat); try { return FromManagedImage(val); } finally { image.UnlockBits(val); } } public static UnmanagedImage FromManagedImage(BitmapData imageData) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Invalid comparison between Unknown and I4 //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Invalid comparison between Unknown and I4 //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Invalid comparison between Unknown and I4 //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Invalid comparison between Unknown and I4 PixelFormat val = imageData.PixelFormat; if ((int)val != 198659 && (int)val != 1052676 && (int)val != 137224 && (int)val != 139273 && (int)val != 2498570 && (int)val != 925707 && (int)val != 1060876 && (int)val != 3424269 && (int)val != 1851406) { throw new UnsupportedImageFormatException("Unsupported pixel format of the source image."); } IntPtr dst = Marshal.AllocHGlobal(imageData.Stride * imageData.Height); GC.AddMemoryPressure(imageData.Stride * imageData.Height); UnmanagedImage unmanagedImage = new UnmanagedImage(dst, imageData.Width, imageData.Height, imageData.Stride, val); SystemTools.CopyUnmanagedMemory(dst, imageData.Scan0, imageData.Stride * imageData.Height); unmanagedImage.mustBeDisposed = true; return unmanagedImage; } public unsafe byte[] Collect8bppPixelValues(List points) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Invalid comparison between Unknown and I4 int num = Image.GetPixelFormatSize(pixelFormat) / 8; if ((int)pixelFormat == 1052676 || num > 4) { throw new UnsupportedImageFormatException("Unsupported pixel format of the source image. Use Collect16bppPixelValues() method for it."); } byte[] array = new byte[points.Count * (((int)pixelFormat == 198659) ? 1 : 3)]; byte* ptr = (byte*)imageData.ToPointer(); if ((int)pixelFormat == 198659) { int num2 = 0; foreach (IntPoint point in points) { byte* ptr2 = ptr + (nint)stride * (nint)point.Y + point.X; array[num2++] = *ptr2; } } else { int num3 = 0; foreach (IntPoint point2 in points) { byte* ptr2 = ptr + (nint)stride * (nint)point2.Y + (nint)point2.X * (nint)num; array[num3++] = ptr2[2]; array[num3++] = ptr2[1]; array[num3++] = *ptr2; } } return array; } public List CollectActivePixels() { return CollectActivePixels(new Rectangle(0, 0, width, height)); } public unsafe List CollectActivePixels(Rectangle rect) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Invalid comparison between Unknown and I4 List list = new List(); int num = Image.GetPixelFormatSize(pixelFormat) / 8; rect.Intersect(new Rectangle(0, 0, width, height)); int x = rect.X; int y = rect.Y; int right = rect.Right; int bottom = rect.Bottom; byte* ptr = (byte*)imageData.ToPointer(); if ((int)pixelFormat == 1052676 || num > 4) { int num2 = num >> 1; for (int i = y; i < bottom; i++) { ushort* ptr2 = (ushort*)(ptr + (nint)i * (nint)stride + (nint)x * (nint)num); if (num2 == 1) { int num3 = x; while (num3 < right) { if (*ptr2 != 0) { list.Add(new IntPoint(num3, i)); } num3++; ptr2++; } continue; } int num4 = x; while (num4 < right) { if (ptr2[2] != 0 || ptr2[1] != 0 || *ptr2 != 0) { list.Add(new IntPoint(num4, i)); } num4++; ptr2 += num2; } } } else { for (int j = y; j < bottom; j++) { byte* ptr3 = ptr + (nint)j * (nint)stride + (nint)x * (nint)num; if (num == 1) { int num5 = x; while (num5 < right) { if (*ptr3 != 0) { list.Add(new IntPoint(num5, j)); } num5++; ptr3++; } continue; } int num6 = x; while (num6 < right) { if (ptr3[2] != 0 || ptr3[1] != 0 || *ptr3 != 0) { list.Add(new IntPoint(num6, j)); } num6++; ptr3 += num; } } } return list; } public unsafe void SetPixels(List coordinates, Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Invalid comparison between Unknown and I4 //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Invalid comparison between Unknown and I4 //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Invalid comparison between Unknown and I4 //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Invalid comparison between Unknown and I4 //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Invalid comparison between Unknown and I4 //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Invalid comparison between Unknown and I4 //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Invalid comparison between Unknown and I4 //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Invalid comparison between Unknown and I4 //IL_049e: Unknown result type (might be due to invalid IL or missing references) int num = Image.GetPixelFormatSize(pixelFormat) / 8; byte* ptr = (byte*)imageData.ToPointer(); byte r = color.R; byte g = color.G; byte b = color.B; byte a = color.A; PixelFormat val = pixelFormat; if ((int)val <= 198659) { if ((int)val == 137224 || (int)val == 139273) { foreach (IntPoint coordinate in coordinates) { if (coordinate.X >= 0 && coordinate.Y >= 0 && coordinate.X < width && coordinate.Y < height) { byte* ptr2 = ptr + (nint)coordinate.Y * (nint)stride + (nint)coordinate.X * (nint)num; ptr2[2] = r; ptr2[1] = g; *ptr2 = b; } } return; } if ((int)val == 198659) { byte b2 = (byte)(0.2125 * (double)(int)r + 0.7154 * (double)(int)g + 0.0721 * (double)(int)b); { foreach (IntPoint coordinate2 in coordinates) { if (coordinate2.X >= 0 && coordinate2.Y >= 0 && coordinate2.X < width && coordinate2.Y < height) { byte* ptr3 = ptr + (nint)coordinate2.Y * (nint)stride + coordinate2.X; *ptr3 = b2; } } return; } } } else if ((int)val <= 1060876) { if ((int)val == 1052676) { ushort num2 = (ushort)((ushort)(0.2125 * (double)(int)r + 0.7154 * (double)(int)g + 0.0721 * (double)(int)b) << 8); { foreach (IntPoint coordinate3 in coordinates) { if (coordinate3.X >= 0 && coordinate3.Y >= 0 && coordinate3.X < width && coordinate3.Y < height) { ushort* ptr4 = (ushort*)(ptr + (nint)coordinate3.Y * (nint)stride) + coordinate3.X; *ptr4 = num2; } } return; } } if ((int)val == 1060876) { ushort num3 = (ushort)(r << 8); ushort num4 = (ushort)(g << 8); ushort num5 = (ushort)(b << 8); { foreach (IntPoint coordinate4 in coordinates) { if (coordinate4.X >= 0 && coordinate4.Y >= 0 && coordinate4.X < width && coordinate4.Y < height) { ushort* ptr5 = (ushort*)(ptr + (nint)coordinate4.Y * (nint)stride + (nint)coordinate4.X * (nint)num); ptr5[2] = num3; ptr5[1] = num4; *ptr5 = num5; } } return; } } } else { if ((int)val == 2498570) { { foreach (IntPoint coordinate5 in coordinates) { if (coordinate5.X >= 0 && coordinate5.Y >= 0 && coordinate5.X < width && coordinate5.Y < height) { byte* ptr6 = ptr + (nint)coordinate5.Y * (nint)stride + (nint)coordinate5.X * (nint)num; ptr6[2] = r; ptr6[1] = g; *ptr6 = b; ptr6[3] = a; } } return; } } if ((int)val == 3424269) { ushort num6 = (ushort)(r << 8); ushort num7 = (ushort)(g << 8); ushort num8 = (ushort)(b << 8); ushort num9 = (ushort)(a << 8); { foreach (IntPoint coordinate6 in coordinates) { if (coordinate6.X >= 0 && coordinate6.Y >= 0 && coordinate6.X < width && coordinate6.Y < height) { ushort* ptr7 = (ushort*)(ptr + (nint)coordinate6.Y * (nint)stride + (nint)coordinate6.X * (nint)num); ptr7[2] = num6; ptr7[1] = num7; *ptr7 = num8; ptr7[3] = num9; } } return; } } } throw new UnsupportedImageFormatException("The pixel format is not supported: " + pixelFormat); } public void SetPixel(IntPoint point, Color color) { SetPixel(point.X, point.Y, color); } public void SetPixel(int x, int y, Color color) { SetPixel(x, y, color.R, color.G, color.B, color.A); } public void SetPixel(int x, int y, byte value) { SetPixel(x, y, value, value, value, byte.MaxValue); } private unsafe void SetPixel(int x, int y, byte r, byte g, byte b, byte a) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Invalid comparison between Unknown and I4 //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Invalid comparison between Unknown and I4 //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Invalid comparison between Unknown and I4 //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Invalid comparison between Unknown and I4 //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Invalid comparison between Unknown and I4 //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Invalid comparison between Unknown and I4 //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Invalid comparison between Unknown and I4 //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Invalid comparison between Unknown and I4 //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Invalid comparison between Unknown and I4 //IL_0181: Unknown result type (might be due to invalid IL or missing references) if (x < 0 || y < 0 || x >= width || y >= height) { return; } int num = Image.GetPixelFormatSize(pixelFormat) / 8; byte* ptr = (byte*)imageData.ToPointer() + (nint)y * (nint)stride + (nint)x * (nint)num; ushort* ptr2 = (ushort*)ptr; PixelFormat val = pixelFormat; if ((int)val <= 198659) { if ((int)val == 137224 || (int)val == 139273) { ptr[2] = r; ptr[1] = g; *ptr = b; return; } if ((int)val == 198659) { *ptr = (byte)(0.2125 * (double)(int)r + 0.7154 * (double)(int)g + 0.0721 * (double)(int)b); return; } } else if ((int)val <= 1060876) { if ((int)val == 1052676) { *ptr2 = (ushort)((ushort)(0.2125 * (double)(int)r + 0.7154 * (double)(int)g + 0.0721 * (double)(int)b) << 8); return; } if ((int)val == 1060876) { ptr2[2] = (ushort)(r << 8); ptr2[1] = (ushort)(g << 8); *ptr2 = (ushort)(b << 8); return; } } else { if ((int)val == 2498570) { ptr[2] = r; ptr[1] = g; *ptr = b; ptr[3] = a; return; } if ((int)val == 3424269) { ptr2[2] = (ushort)(r << 8); ptr2[1] = (ushort)(g << 8); *ptr2 = (ushort)(b << 8); ptr2[3] = (ushort)(a << 8); return; } } throw new UnsupportedImageFormatException("The pixel format is not supported: " + pixelFormat); } public Color GetPixel(IntPoint point) { return GetPixel(point.X, point.Y); } public unsafe Color GetPixel(int x, int y) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Invalid comparison between Unknown and I4 //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Invalid comparison between Unknown and I4 //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Invalid comparison between Unknown and I4 //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Invalid comparison between Unknown and I4 //IL_00df: Unknown result type (might be due to invalid IL or missing references) if (x < 0 || y < 0) { throw new ArgumentOutOfRangeException("x", "The specified pixel coordinate is out of image's bounds."); } if (x >= width || y >= height) { throw new ArgumentOutOfRangeException("y", "The specified pixel coordinate is out of image's bounds."); } Color color = default(Color); int num = Image.GetPixelFormatSize(pixelFormat) / 8; byte* ptr = (byte*)imageData.ToPointer() + (nint)y * (nint)stride + (nint)x * (nint)num; PixelFormat val = pixelFormat; if ((int)val <= 139273) { if ((int)val == 137224 || (int)val == 139273) { return Color.FromArgb(ptr[2], ptr[1], *ptr); } } else { if ((int)val == 198659) { return Color.FromArgb(*ptr, *ptr, *ptr); } if ((int)val == 2498570) { return Color.FromArgb(ptr[3], ptr[2], ptr[1], *ptr); } } throw new UnsupportedImageFormatException("The pixel format is not supported: " + pixelFormat); } public unsafe ushort[] Collect16bppPixelValues(List points) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Invalid comparison between Unknown and I4 int num = Image.GetPixelFormatSize(pixelFormat) / 8; if ((int)pixelFormat == 198659 || num == 3 || num == 4) { throw new UnsupportedImageFormatException("Unsupported pixel format of the source image. Use Collect8bppPixelValues() method for it."); } ushort[] array = new ushort[points.Count * (((int)pixelFormat == 1052676) ? 1 : 3)]; byte* ptr = (byte*)imageData.ToPointer(); if ((int)pixelFormat == 1052676) { int num2 = 0; foreach (IntPoint point in points) { ushort* ptr2 = (ushort*)(ptr + (nint)stride * (nint)point.Y + (nint)point.X * (nint)num); array[num2++] = *ptr2; } } else { int num3 = 0; foreach (IntPoint point2 in points) { ushort* ptr2 = (ushort*)(ptr + (nint)stride * (nint)point2.Y + (nint)point2.X * (nint)num); array[num3++] = ptr2[2]; array[num3++] = ptr2[1]; array[num3++] = *ptr2; } } return array; } }