Files
SuperVPN/output/Libraries/AForge.Imaging/AForge/Imaging/VerticalIntensityStatistics.cs
2025-10-09 09:57:24 +09:00

261 lines
8.4 KiB
C#

using System.Drawing;
using System.Drawing.Imaging;
using AForge.Math;
namespace AForge.Imaging;
public class VerticalIntensityStatistics
{
private Histogram red;
private Histogram green;
private Histogram blue;
private Histogram gray;
public Histogram Red
{
get
{
if (red == null)
{
throw new InvalidImagePropertiesException("Cannot access color histogram since the last processed image was grayscale.");
}
return red;
}
}
public Histogram Green
{
get
{
if (green == null)
{
throw new InvalidImagePropertiesException("Cannot access color histogram since the last processed image was grayscale.");
}
return green;
}
}
public Histogram Blue
{
get
{
if (blue == null)
{
throw new InvalidImagePropertiesException("Cannot access color histogram since the last processed image was grayscale.");
}
return blue;
}
}
public Histogram Gray
{
get
{
if (gray == null)
{
throw new InvalidImagePropertiesException("Cannot access gray histogram since the last processed image was color.");
}
return gray;
}
}
public bool IsGrayscale => gray != null;
public VerticalIntensityStatistics(Bitmap image)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Invalid comparison between Unknown and I4
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Invalid comparison between Unknown and I4
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Invalid comparison between Unknown and I4
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Invalid comparison between Unknown and I4
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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
if ((int)((Image)image).PixelFormat != 198659 && (int)((Image)image).PixelFormat != 1052676 && (int)((Image)image).PixelFormat != 137224 && (int)((Image)image).PixelFormat != 139273 && (int)((Image)image).PixelFormat != 2498570 && (int)((Image)image).PixelFormat != 1060876 && (int)((Image)image).PixelFormat != 3424269)
{
throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
}
BitmapData val = image.LockBits(new Rectangle(0, 0, ((Image)image).Width, ((Image)image).Height), (ImageLockMode)1, ((Image)image).PixelFormat);
try
{
ProcessImage(new UnmanagedImage(val));
}
finally
{
image.UnlockBits(val);
}
}
public VerticalIntensityStatistics(BitmapData imageData)
: this(new UnmanagedImage(imageData))
{
}
public VerticalIntensityStatistics(UnmanagedImage image)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Invalid comparison between Unknown and I4
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Invalid comparison between Unknown and I4
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Invalid comparison between Unknown and I4
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Invalid comparison between Unknown and I4
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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
if ((int)image.PixelFormat != 198659 && (int)image.PixelFormat != 1052676 && (int)image.PixelFormat != 137224 && (int)image.PixelFormat != 139273 && (int)image.PixelFormat != 2498570 && (int)image.PixelFormat != 1060876 && (int)image.PixelFormat != 3424269)
{
throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
}
ProcessImage(image);
}
private unsafe void ProcessImage(UnmanagedImage image)
{
//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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Invalid comparison between Unknown and I4
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Invalid comparison between Unknown and I4
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Invalid comparison between Unknown and I4
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Invalid comparison between Unknown and I4
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Invalid comparison between Unknown and I4
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Invalid comparison between Unknown and I4
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Invalid comparison between Unknown and I4
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Invalid comparison between Unknown and I4
PixelFormat pixelFormat = image.PixelFormat;
int width = image.Width;
int height = image.Height;
red = (green = (blue = (gray = null)));
if ((int)pixelFormat == 198659)
{
byte* ptr = (byte*)image.ImageData.ToPointer();
int num = image.Stride - width;
int[] array = new int[height];
for (int i = 0; i < height; i++)
{
int num2 = 0;
int num3 = 0;
while (num3 < width)
{
num2 += *ptr;
num3++;
ptr++;
}
array[i] = num2;
ptr += num;
}
gray = new Histogram(array);
}
else if ((int)pixelFormat == 1052676)
{
byte* ptr2 = (byte*)image.ImageData.ToPointer();
int stride = image.Stride;
int[] array2 = new int[height];
for (int j = 0; j < height; j++)
{
ushort* ptr3 = (ushort*)(ptr2 + (nint)stride * (nint)j);
int num4 = 0;
int num5 = 0;
while (num5 < width)
{
num4 += *ptr3;
num5++;
ptr3++;
}
array2[j] = num4;
}
gray = new Histogram(array2);
}
else if ((int)pixelFormat == 137224 || (int)pixelFormat == 139273 || (int)pixelFormat == 2498570)
{
byte* ptr4 = (byte*)image.ImageData.ToPointer();
int num6 = (((int)pixelFormat == 137224) ? 3 : 4);
int num7 = image.Stride - width * num6;
int[] array3 = new int[height];
int[] array4 = new int[height];
int[] array5 = new int[height];
for (int k = 0; k < height; k++)
{
int num8 = 0;
int num9 = 0;
int num10 = 0;
int num11 = 0;
while (num11 < width)
{
num8 += ptr4[2];
num9 += ptr4[1];
num10 += *ptr4;
num11++;
ptr4 += num6;
}
array3[k] = num8;
array4[k] = num9;
array5[k] = num10;
ptr4 += num7;
}
red = new Histogram(array3);
green = new Histogram(array4);
blue = new Histogram(array5);
}
else
{
if ((int)pixelFormat != 1060876 && (int)pixelFormat != 3424269)
{
return;
}
byte* ptr5 = (byte*)image.ImageData.ToPointer();
int stride2 = image.Stride;
int num12 = (((int)pixelFormat == 1060876) ? 3 : 4);
int[] array6 = new int[height];
int[] array7 = new int[height];
int[] array8 = new int[height];
for (int l = 0; l < height; l++)
{
ushort* ptr6 = (ushort*)(ptr5 + (nint)stride2 * (nint)l);
int num13 = 0;
int num14 = 0;
int num15 = 0;
int num16 = 0;
while (num16 < width)
{
num13 += ptr6[2];
num14 += ptr6[1];
num15 += *ptr6;
num16++;
ptr6 += num12;
}
array6[l] = num13;
array7[l] = num14;
array8[l] = num15;
}
red = new Histogram(array6);
green = new Histogram(array7);
blue = new Histogram(array8);
}
}
}