Example #1
0
		public static void RGB2HSL(RGB rgb, HSL hsl) {
			double num = ((double)rgb.Red) / 255.0;
			double num2 = ((double)rgb.Green) / 255.0;
			double num3 = ((double)rgb.Blue) / 255.0;
			double num4 = Math.Min(Math.Min(num, num2), num3);
			double num5 = Math.Max(Math.Max(num, num2), num3);
			double num6 = num5 - num4;
			hsl.Luminance = (num5 + num4) / 2.0;
			if (num6 == 0.0) {
				hsl.Hue = 0;
				hsl.Saturation = 0.0;
			} else {
				double num10;
				hsl.Saturation = (hsl.Luminance < 0.5) ? (num6 / (num5 + num4)) : (num6 / ((2.0 - num5) - num4));
				double num7 = (((num5 - num) / 6.0) + (num6 / 2.0)) / num6;
				double num8 = (((num5 - num2) / 6.0) + (num6 / 2.0)) / num6;
				double num9 = (((num5 - num3) / 6.0) + (num6 / 2.0)) / num6;
				if (num == num5) {
					num10 = num9 - num8;
				} else if (num2 == num5) {
					num10 = (0.33333333333333331 + num7) - num9;
				} else {
					num10 = (0.66666666666666663 + num8) - num7;
				}
				if (num10 < 0.0) {
					num10++;
				}
				if (num10 > 1.0) {
					num10--;
				}
				hsl.Hue = (int)(num10 * 360.0);
			}
		}
Example #2
0
		public static void HSL2RGB(HSL hsl, RGB rgb) {
			if (hsl.Saturation == 0.0) {
				rgb.Red = rgb.Green = rgb.Blue = (byte)(hsl.Luminance * 255.0);
			} else {
				double vH = ((double)hsl.Hue) / 360.0;
				double num2 = (hsl.Luminance < 0.5) ? (hsl.Luminance * (1.0 + hsl.Saturation)) : ((hsl.Luminance + hsl.Saturation) - (hsl.Luminance * hsl.Saturation));
				double num = (2.0 * hsl.Luminance) - num2;
				rgb.Red = (byte)(255.0 * Hue2RGB(num, num2, vH + 0.33333333333333331));
				rgb.Green = (byte)(255.0 * Hue2RGB(num, num2, vH));
				rgb.Blue = (byte)(255.0 * Hue2RGB(num, num2, vH - 0.33333333333333331));
			}
		}
Example #3
0
 public unsafe Bitmap Apply(Bitmap srcImg)
 {
     if (srcImg.PixelFormat != PixelFormat.Format24bppRgb)
     {
         throw new ArgumentException();
     }
     int width = srcImg.Width;
     int height = srcImg.Height;
     BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
     Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
     BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
     RGB rgb = new RGB();
     HSL hsl = new HSL();
     int num3 = bitmapdata.Stride - (width * 3);
     byte* numPtr = (byte*) bitmapdata.Scan0.ToPointer();
     byte* numPtr2 = (byte*) data2.Scan0.ToPointer();
     for (int i = 0; i < height; i++)
     {
         int num5 = 0;
         while (num5 < width)
         {
             rgb.Red = numPtr[2];
             rgb.Green = numPtr[1];
             rgb.Blue = numPtr[0];
             GodLesZ.Library.Imaging.ColorConverter.RGB2HSL(rgb, hsl);
             hsl.Hue = this.hue;
             GodLesZ.Library.Imaging.ColorConverter.HSL2RGB(hsl, rgb);
             numPtr2[2] = rgb.Red;
             numPtr2[1] = rgb.Green;
             numPtr2[0] = rgb.Blue;
             num5++;
             numPtr += 3;
             numPtr2 += 3;
         }
         numPtr += num3;
         numPtr2 += num3;
     }
     bitmap.UnlockBits(data2);
     srcImg.UnlockBits(bitmapdata);
     return bitmap;
 }
Example #4
0
		public unsafe ImageStatistics(Bitmap image, bool collectHSL) {
			int width = image.Width;
			int height = image.Height;
			this.pixels = width * height;
			if (this.grayscale = image.PixelFormat == PixelFormat.Format8bppIndexed) {
				BitmapData bitmapdata = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
				int[] values = new int[0x100];
				int num3 = bitmapdata.Stride - width;
				byte* numPtr = (byte*)bitmapdata.Scan0.ToPointer();
				for (int i = 0; i < height; i++) {
					int num5 = 0;
					while (num5 < width) {
						values[numPtr[0]]++;
						num5++;
						numPtr++;
					}
					numPtr += num3;
				}
				image.UnlockBits(bitmapdata);
				this.gray = new Histogram(values);
			} else {
				BitmapData data2 = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
				int[] numArray2 = new int[0x100];
				int[] numArray3 = new int[0x100];
				int[] numArray4 = new int[0x100];
				int[] numArray5 = new int[0x100];
				int[] numArray6 = new int[0x100];
				RGB rgb = new RGB();
				HSL hsl = new HSL();
				int num6 = data2.Stride - (width * 3);
				byte* numPtr2 = (byte*)data2.Scan0.ToPointer();
				for (int j = 0; j < height; j++) {
					int num8 = 0;
					while (num8 < width) {
						numArray2[numPtr2[2]]++;
						numArray3[numPtr2[1]]++;
						numArray4[numPtr2[0]]++;
						if (collectHSL) {
							rgb.Red = numPtr2[2];
							rgb.Green = numPtr2[1];
							rgb.Blue = numPtr2[0];
							if (collectHSL) {
								GodLesZ.Library.Imaging.ColorConverter.RGB2HSL(rgb, hsl);
								numArray5[(int)(hsl.Saturation * 255.0)]++;
								numArray6[(int)(hsl.Luminance * 255.0)]++;
							}
						}
						num8++;
						numPtr2 += 3;
					}
					numPtr2 += num6;
				}
				image.UnlockBits(data2);
				this.red = new Histogram(numArray2);
				this.green = new Histogram(numArray3);
				this.blue = new Histogram(numArray4);
				if (collectHSL) {
					this.saturation = new HistogramD(numArray5, new RangeD(0.0, 1.0));
					this.luminance = new HistogramD(numArray6, new RangeD(0.0, 1.0));
				}
			}
		}
Example #5
0
 public unsafe Bitmap Apply(Bitmap srcImg)
 {
     if (srcImg.PixelFormat != PixelFormat.Format24bppRgb)
     {
         throw new ArgumentException();
     }
     int width = srcImg.Width;
     int height = srcImg.Height;
     BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
     Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
     BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
     RGB rgb = new RGB();
     HSL hsl = new HSL();
     int num3 = bitmapdata.Stride - (width * 3);
     double num4 = 0.0;
     double num5 = 0.0;
     double num6 = 0.0;
     double num7 = 0.0;
     if (this.inLuminance.Max != this.inLuminance.Min)
     {
         num4 = (this.outLuminance.Max - this.outLuminance.Min) / (this.inLuminance.Max - this.inLuminance.Min);
         num5 = this.outLuminance.Min - (num4 * this.inLuminance.Min);
     }
     if (this.inSaturation.Max != this.inSaturation.Min)
     {
         num6 = (this.outSaturation.Max - this.outSaturation.Min) / (this.inSaturation.Max - this.inSaturation.Min);
         num7 = this.outSaturation.Min - (num6 * this.inSaturation.Min);
     }
     byte* numPtr = (byte*) bitmapdata.Scan0.ToPointer();
     byte* numPtr2 = (byte*) data2.Scan0.ToPointer();
     for (int i = 0; i < height; i++)
     {
         int num9 = 0;
         while (num9 < width)
         {
             rgb.Red = numPtr[2];
             rgb.Green = numPtr[1];
             rgb.Blue = numPtr[0];
             GodLesZ.Library.Imaging.ColorConverter.RGB2HSL(rgb, hsl);
             if (hsl.Luminance >= this.inLuminance.Max)
             {
                 hsl.Luminance = this.outLuminance.Max;
             }
             else if (hsl.Luminance <= this.inLuminance.Min)
             {
                 hsl.Luminance = this.outLuminance.Min;
             }
             else
             {
                 hsl.Luminance = (num4 * hsl.Luminance) + num5;
             }
             if (hsl.Saturation >= this.inSaturation.Max)
             {
                 hsl.Saturation = this.outSaturation.Max;
             }
             else if (hsl.Saturation <= this.inSaturation.Min)
             {
                 hsl.Saturation = this.outSaturation.Min;
             }
             else
             {
                 hsl.Saturation = (num6 * hsl.Saturation) + num7;
             }
             GodLesZ.Library.Imaging.ColorConverter.HSL2RGB(hsl, rgb);
             numPtr2[2] = rgb.Red;
             numPtr2[1] = rgb.Green;
             numPtr2[0] = rgb.Blue;
             num9++;
             numPtr += 3;
             numPtr2 += 3;
         }
         numPtr += num3;
         numPtr2 += num3;
     }
     bitmap.UnlockBits(data2);
     srcImg.UnlockBits(bitmapdata);
     return bitmap;
 }
Example #6
0
        public unsafe ImageStatistics(Bitmap image, bool collectHSL)
        {
            int width  = image.Width;
            int height = image.Height;

            this.pixels = width * height;
            if (this.grayscale = image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                BitmapData bitmapdata = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
                int[]      values     = new int[0x100];
                int        num3       = bitmapdata.Stride - width;
                byte *     numPtr     = (byte *)bitmapdata.Scan0.ToPointer();
                for (int i = 0; i < height; i++)
                {
                    int num5 = 0;
                    while (num5 < width)
                    {
                        values[numPtr[0]]++;
                        num5++;
                        numPtr++;
                    }
                    numPtr += num3;
                }
                image.UnlockBits(bitmapdata);
                this.gray = new Histogram(values);
            }
            else
            {
                BitmapData data2     = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                int[]      numArray2 = new int[0x100];
                int[]      numArray3 = new int[0x100];
                int[]      numArray4 = new int[0x100];
                int[]      numArray5 = new int[0x100];
                int[]      numArray6 = new int[0x100];
                RGB        rgb       = new RGB();
                HSL        hsl       = new HSL();
                int        num6      = data2.Stride - (width * 3);
                byte *     numPtr2   = (byte *)data2.Scan0.ToPointer();
                for (int j = 0; j < height; j++)
                {
                    int num8 = 0;
                    while (num8 < width)
                    {
                        numArray2[numPtr2[2]]++;
                        numArray3[numPtr2[1]]++;
                        numArray4[numPtr2[0]]++;
                        if (collectHSL)
                        {
                            rgb.Red   = numPtr2[2];
                            rgb.Green = numPtr2[1];
                            rgb.Blue  = numPtr2[0];
                            if (collectHSL)
                            {
                                GodLesZ.Library.Imaging.ColorConverter.RGB2HSL(rgb, hsl);
                                numArray5[(int)(hsl.Saturation * 255.0)]++;
                                numArray6[(int)(hsl.Luminance * 255.0)]++;
                            }
                        }
                        num8++;
                        numPtr2 += 3;
                    }
                    numPtr2 += num6;
                }
                image.UnlockBits(data2);
                this.red   = new Histogram(numArray2);
                this.green = new Histogram(numArray3);
                this.blue  = new Histogram(numArray4);
                if (collectHSL)
                {
                    this.saturation = new HistogramD(numArray5, new RangeD(0.0, 1.0));
                    this.luminance  = new HistogramD(numArray6, new RangeD(0.0, 1.0));
                }
            }
        }
Example #7
0
 public unsafe Bitmap Apply(Bitmap srcImg)
 {
     if (srcImg.PixelFormat != PixelFormat.Format24bppRgb)
     {
         throw new ArgumentException();
     }
     int width = srcImg.Width;
     int height = srcImg.Height;
     BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
     Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
     BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
     RGB rgb = new RGB();
     HSL hsl = new HSL();
     int num3 = bitmapdata.Stride - (width * 3);
     byte* numPtr = (byte*) bitmapdata.Scan0.ToPointer();
     byte* numPtr2 = (byte*) data2.Scan0.ToPointer();
     for (int i = 0; i < height; i++)
     {
         int num5 = 0;
         while (num5 < width)
         {
             rgb.Red = numPtr[2];
             rgb.Green = numPtr[1];
             rgb.Blue = numPtr[0];
             GodLesZ.Library.Imaging.ColorConverter.RGB2HSL(rgb, hsl);
             if ((((hsl.Saturation >= this.saturation.Min) && (hsl.Saturation <= this.saturation.Max)) && ((hsl.Luminance >= this.luminance.Min) && (hsl.Luminance <= this.luminance.Max))) && ((((this.hue.Min < this.hue.Max) && (hsl.Hue >= this.hue.Min)) && (hsl.Hue <= this.hue.Max)) || ((this.hue.Min > this.hue.Max) && ((hsl.Hue >= this.hue.Min) || (hsl.Hue <= this.hue.Max)))))
             {
                 if (!this.fillOutsideRange)
                 {
                     if (this.updateH)
                     {
                         hsl.Hue = this.fillH;
                     }
                     if (this.updateS)
                     {
                         hsl.Saturation = this.fillS;
                     }
                     if (this.updateL)
                     {
                         hsl.Luminance = this.fillL;
                     }
                 }
             }
             else if (this.fillOutsideRange)
             {
                 if (this.updateH)
                 {
                     hsl.Hue = this.fillH;
                 }
                 if (this.updateS)
                 {
                     hsl.Saturation = this.fillS;
                 }
                 if (this.updateL)
                 {
                     hsl.Luminance = this.fillL;
                 }
             }
             GodLesZ.Library.Imaging.ColorConverter.HSL2RGB(hsl, rgb);
             numPtr2[2] = rgb.Red;
             numPtr2[1] = rgb.Green;
             numPtr2[0] = rgb.Blue;
             num5++;
             numPtr += 3;
             numPtr2 += 3;
         }
         numPtr += num3;
         numPtr2 += num3;
     }
     bitmap.UnlockBits(data2);
     srcImg.UnlockBits(bitmapdata);
     return bitmap;
 }