public static FromRGB ( |
||
rgb | Source color in RGB color space. | |
return |
private unsafe void ProcessImage(UnmanagedImage image) { this.CheckSourceFormat(image.PixelFormat); int width = image.Width; int height = image.Height; this.pixels = this.pixelsWithoutBlack = 0; int[] numArray = new int[0x100]; int[] numArray2 = new int[0x100]; int[] numArray3 = new int[0x100]; int[] numArray4 = new int[0x100]; RGB rgb = new RGB(); HSL hsl = new HSL(); int num3 = (image.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4; int num4 = image.Stride - (width * num3); byte *numPtr = (byte *)image.ImageData.ToPointer(); for (int i = 0; i < height; i++) { int num6 = 0; while (num6 < width) { rgb.Red = numPtr[2]; rgb.Green = numPtr[1]; rgb.Blue = numPtr[0]; HSL.FromRGB(rgb, hsl); numArray[(int)(hsl.Saturation * 255.0)]++; numArray2[(int)(hsl.Luminance * 255.0)]++; this.pixels++; if (hsl.Luminance != 0.0) { numArray3[(int)(hsl.Saturation * 255.0)]++; numArray4[(int)(hsl.Luminance * 255.0)]++; this.pixelsWithoutBlack++; } num6++; numPtr += num3; } numPtr += num4; } this.saturation = new ContinuousHistogram(numArray, new DoubleRange(0.0, 1.0)); this.luminance = new ContinuousHistogram(numArray2, new DoubleRange(0.0, 1.0)); this.saturationWithoutBlack = new ContinuousHistogram(numArray3, new DoubleRange(0.0, 1.0)); this.luminanceWithoutBlack = new ContinuousHistogram(numArray4, new DoubleRange(0.0, 1.0)); }
private unsafe void ProcessImage(UnmanagedImage image, byte *mask, int maskLineSize) { int width = image.Width; int height = image.Height; pixels = (pixelsWithoutBlack = 0); int[] array = new int[256]; int[] array2 = new int[256]; int[] array3 = new int[256]; int[] array4 = new int[256]; RGB rGB = new RGB(); HSL hSL = new HSL(); int num = (image.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4; int num2 = image.Stride - width * num; int num3 = maskLineSize - width; byte *ptr = (byte *)image.ImageData.ToPointer(); if (mask == null) { for (int i = 0; i < height; i++) { int num4 = 0; while (num4 < width) { rGB.Red = ptr[2]; rGB.Green = ptr[1]; rGB.Blue = *ptr; HSL.FromRGB(rGB, hSL); array[(int)(hSL.Saturation * 255f)]++; array2[(int)(hSL.Luminance * 255f)]++; pixels++; if ((double)hSL.Luminance != 0.0) { array3[(int)(hSL.Saturation * 255f)]++; array4[(int)(hSL.Luminance * 255f)]++; pixelsWithoutBlack++; } num4++; ptr += num; } ptr += num2; } } else { for (int j = 0; j < height; j++) { int num5 = 0; while (num5 < width) { if (*mask != 0) { rGB.Red = ptr[2]; rGB.Green = ptr[1]; rGB.Blue = *ptr; HSL.FromRGB(rGB, hSL); array[(int)(hSL.Saturation * 255f)]++; array2[(int)(hSL.Luminance * 255f)]++; pixels++; if ((double)hSL.Luminance != 0.0) { array3[(int)(hSL.Saturation * 255f)]++; array4[(int)(hSL.Luminance * 255f)]++; pixelsWithoutBlack++; } } num5++; ptr += num; mask++; } ptr += num2; mask += num3; } } saturation = new ContinuousHistogram(array, new Range(0f, 1f)); luminance = new ContinuousHistogram(array2, new Range(0f, 1f)); saturationWithoutBlack = new ContinuousHistogram(array3, new Range(0f, 1f)); luminanceWithoutBlack = new ContinuousHistogram(array4, new Range(0f, 1f)); }