public unsafe Bitmap Apply(Bitmap srcImg)
        {
            Bitmap bitmap;

            this.width  = srcImg.Width;
            this.height = srcImg.Height;
            if (srcImg.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                bitmap = GodLesZ.Library.Imaging.Image.Clone(srcImg);
            }
            else
            {
                IFilter filter = new GrayscaleRMY();
                bitmap = filter.Apply(srcImg);
            }
            BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, this.width, this.height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            Bitmap     bitmap2    = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(this.width, this.height);
            BitmapData data2      = bitmap2.LockBits(new Rectangle(0, 0, this.width, this.height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

            this.stride   = data2.Stride;
            this.widthM1  = this.width - 1;
            this.heightM1 = this.height - 1;
            int   num     = this.stride - this.width;
            byte *ptr     = (byte *)bitmapdata.Scan0.ToPointer();
            byte *numPtr2 = (byte *)data2.Scan0.ToPointer();

            this.y = 0;
            while (this.y < this.height)
            {
                this.x = 0;
                while (this.x < this.width)
                {
                    int num3;
                    int num2 = ptr[0];
                    if (num2 < 0x80)
                    {
                        numPtr2[0] = 0;
                        num3       = num2;
                    }
                    else
                    {
                        numPtr2[0] = 0xff;
                        num3       = num2 - 0xff;
                    }
                    this.Diffuse(num3, ptr);
                    this.x++;
                    ptr++;
                    numPtr2++;
                }
                ptr     += num;
                numPtr2 += num;
                this.y++;
            }
            bitmap2.UnlockBits(data2);
            bitmap.UnlockBits(bitmapdata);
            bitmap.Dispose();
            return(bitmap2);
        }
 public unsafe Bitmap Apply(Bitmap srcImg)
 {
     Bitmap bitmap;
     this.width = srcImg.Width;
     this.height = srcImg.Height;
     if (srcImg.PixelFormat == PixelFormat.Format8bppIndexed)
     {
         bitmap = GodLesZ.Library.Imaging.Image.Clone(srcImg);
     }
     else
     {
         IFilter filter = new GrayscaleRMY();
         bitmap = filter.Apply(srcImg);
     }
     BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, this.width, this.height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
     Bitmap bitmap2 = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(this.width, this.height);
     BitmapData data2 = bitmap2.LockBits(new Rectangle(0, 0, this.width, this.height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
     this.stride = data2.Stride;
     this.widthM1 = this.width - 1;
     this.heightM1 = this.height - 1;
     int num = this.stride - this.width;
     byte* ptr = (byte*) bitmapdata.Scan0.ToPointer();
     byte* numPtr2 = (byte*) data2.Scan0.ToPointer();
     this.y = 0;
     while (this.y < this.height)
     {
         this.x = 0;
         while (this.x < this.width)
         {
             int num3;
             int num2 = ptr[0];
             if (num2 < 0x80)
             {
                 numPtr2[0] = 0;
                 num3 = num2;
             }
             else
             {
                 numPtr2[0] = 0xff;
                 num3 = num2 - 0xff;
             }
             this.Diffuse(num3, ptr);
             this.x++;
             ptr++;
             numPtr2++;
         }
         ptr += num;
         numPtr2 += num;
         this.y++;
     }
     bitmap2.UnlockBits(data2);
     bitmap.UnlockBits(bitmapdata);
     bitmap.Dispose();
     return bitmap2;
 }
Example #3
0
		public unsafe Bitmap Apply(Bitmap srcImg) {
			int width = srcImg.Width;
			int height = srcImg.Height;
			bool flag = false;
			if (srcImg.PixelFormat != PixelFormat.Format8bppIndexed) {
				flag = true;
				IFilter filter = new GrayscaleRMY();
				srcImg = filter.Apply(srcImg);
			}
			BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
			Bitmap bitmap = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(width, height);
			BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
			int stride = bitmapdata.Stride;
			int num4 = stride - width;
			int num5 = width - 1;
			int num6 = height - 1;
			double num10 = 0.0;
			double num11 = 0.0;
			byte* numPtr = (byte*)((byte*)bitmapdata.Scan0.ToPointer() + stride);
			byte* numPtr2 = (byte*)data2.Scan0.ToPointer();
			for (int i = 1; i < num6; i++) {
				numPtr++;
				int num13 = 1;
				while (num13 < num5) {
					double num7 = numPtr[1] - numPtr[-1];
					double num8 = numPtr[stride] - numPtr[-stride];
					double num9 = (num7 > num8) ? num7 : num8;
					num10 += num9;
					num11 += num9 * numPtr[0];
					num13++;
					numPtr++;
				}
				numPtr += num4 + 1;
			}
			this.threshold = (num10 == 0.0) ? ((byte)0) : ((byte)(num11 / num10));
			numPtr = (byte*)bitmapdata.Scan0.ToPointer();
			for (int j = 0; j < height; j++) {
				int num15 = 0;
				while (num15 < width) {
					numPtr2[0] = (numPtr[0] <= this.threshold) ? ((byte)0) : ((byte)0xff);
					num15++;
					numPtr++;
					numPtr2++;
				}
				numPtr += num4;
				numPtr2 += num4;
			}
			bitmap.UnlockBits(data2);
			srcImg.UnlockBits(bitmapdata);
			if (flag) {
				srcImg.Dispose();
			}
			return bitmap;
		}
 public unsafe Bitmap Apply(Bitmap srcImg)
 {
     int width = srcImg.Width;
     int height = srcImg.Height;
     bool flag = false;
     if (srcImg.PixelFormat != PixelFormat.Format8bppIndexed)
     {
         flag = true;
         IFilter filter = new GrayscaleRMY();
         srcImg = filter.Apply(srcImg);
     }
     BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
     Bitmap bitmap = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(width, height);
     BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
     int stride = bitmapdata.Stride;
     int num4 = stride - width;
     int num5 = width - 1;
     int num6 = height - 1;
     byte* numPtr = (byte*) bitmapdata.Scan0.ToPointer();
     byte* numPtr2 = (byte*) data2.Scan0.ToPointer();
     numPtr += stride;
     numPtr2 += stride;
     for (int i = 1; i < num6; i++)
     {
         numPtr++;
         numPtr2++;
         int num10 = 1;
         while (num10 < num5)
         {
             int num8 = 0;
             int num7 = numPtr[-stride - 1] - numPtr[stride + 1];
             if (num7 < 0)
             {
                 num7 = -num7;
             }
             if (num7 > num8)
             {
                 num8 = num7;
             }
             num7 = numPtr[-stride + 1] - numPtr[stride - 1];
             if (num7 < 0)
             {
                 num7 = -num7;
             }
             if (num7 > num8)
             {
                 num8 = num7;
             }
             num7 = numPtr[-stride] - numPtr[stride];
             if (num7 < 0)
             {
                 num7 = -num7;
             }
             if (num7 > num8)
             {
                 num8 = num7;
             }
             num7 = numPtr[-1] - numPtr[1];
             if (num7 < 0)
             {
                 num7 = -num7;
             }
             if (num7 > num8)
             {
                 num8 = num7;
             }
             numPtr2[0] = (byte) num8;
             num10++;
             numPtr++;
             numPtr2++;
         }
         numPtr += num4 + 1;
         numPtr2 += num4 + 1;
     }
     bitmap.UnlockBits(data2);
     srcImg.UnlockBits(bitmapdata);
     if (flag)
     {
         srcImg.Dispose();
     }
     return bitmap;
 }
Example #5
0
        public unsafe Bitmap Apply(Bitmap srcImg)
        {
            int  width  = srcImg.Width;
            int  height = srcImg.Height;
            bool flag   = false;

            if (srcImg.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                flag = true;
                IFilter filter = new GrayscaleRMY();
                srcImg = filter.Apply(srcImg);
            }
            BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            Bitmap     bitmap     = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(width, height);
            BitmapData data2      = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            int        stride     = bitmapdata.Stride;
            int        num4       = stride - width;
            int        num5       = width - 1;
            int        num6       = height - 1;
            double     num14      = 0.0;
            byte *     numPtr     = (byte *)((byte *)bitmapdata.Scan0.ToPointer() + stride);
            byte *     numPtr2    = (byte *)((byte *)data2.Scan0.ToPointer() + stride);

            for (int i = 1; i < num6; i++)
            {
                numPtr++;
                numPtr2++;
                int num16 = 1;
                while (num16 < num5)
                {
                    double num12;
                    double num11 = num12 = 0.0;
                    for (int j = 0; j < 3; j++)
                    {
                        int num9 = j - 1;
                        for (int k = 0; k < 3; k++)
                        {
                            double num10 = numPtr[((num9 * stride) + k) - 1];
                            num11 += num10 * xKernel[j, k];
                            num12 += num10 * yKernel[j, k];
                        }
                    }
                    double num13 = Math.Min((double)(Math.Abs(num11) + Math.Abs(num12)), (double)255.0);
                    if (num13 > num14)
                    {
                        num14 = num13;
                    }
                    numPtr2[0] = (byte)num13;
                    num16++;
                    numPtr++;
                    numPtr2++;
                }
                numPtr  += num4 + 1;
                numPtr2 += num4 + 1;
            }
            if (this.scaleIntensity && (num14 != 255.0))
            {
                double num17 = 255.0 / num14;
                numPtr2 = (byte *)((byte *)data2.Scan0.ToPointer() + stride);
                for (int m = 1; m < num6; m++)
                {
                    numPtr2++;
                    int num19 = 1;
                    while (num19 < num5)
                    {
                        numPtr2[0] = (byte)(num17 * numPtr2[0]);
                        num19++;
                        numPtr2++;
                    }
                    numPtr2 += num4 + 1;
                }
            }
            bitmap.UnlockBits(data2);
            srcImg.UnlockBits(bitmapdata);
            if (flag)
            {
                srcImg.Dispose();
            }
            return(bitmap);
        }
Example #6
0
        public unsafe Bitmap Apply(Bitmap srcImg)
        {
            int  width  = srcImg.Width;
            int  height = srcImg.Height;
            bool flag   = false;

            if (srcImg.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                flag = true;
                IFilter filter = new GrayscaleRMY();
                srcImg = filter.Apply(srcImg);
            }
            BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            Bitmap     bitmap     = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(width, height);
            BitmapData data2      = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            int        stride     = bitmapdata.Stride;
            int        num4       = stride - width;
            int        num5       = width - 1;
            int        num6       = height - 1;
            byte *     numPtr     = (byte *)bitmapdata.Scan0.ToPointer();
            byte *     numPtr2    = (byte *)data2.Scan0.ToPointer();

            numPtr  += stride;
            numPtr2 += stride;
            for (int i = 1; i < num6; i++)
            {
                numPtr++;
                numPtr2++;
                int num11 = 1;
                while (num11 < num5)
                {
                    int num8 = 0;
                    int num9 = numPtr[0];
                    int num7 = num9 - numPtr[-stride - 1];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[-stride];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[-stride + 1];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[-1];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[1];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[stride - 1];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[stride];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    num7 = num9 - numPtr[stride + 1];
                    if (num7 < 0)
                    {
                        num7 = -num7;
                    }
                    if (num7 > num8)
                    {
                        num8 = num7;
                    }
                    numPtr2[0] = (byte)num8;
                    num11++;
                    numPtr++;
                    numPtr2++;
                }
                numPtr  += num4 + 1;
                numPtr2 += num4 + 1;
            }
            bitmap.UnlockBits(data2);
            srcImg.UnlockBits(bitmapdata);
            if (flag)
            {
                srcImg.Dispose();
            }
            return(bitmap);
        }
Example #7
0
        public unsafe Bitmap Apply(Bitmap srcImg)
        {
            int  width  = srcImg.Width;
            int  height = srcImg.Height;
            bool flag   = false;

            if (srcImg.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                flag = true;
                IFilter filter = new GrayscaleRMY();
                srcImg = filter.Apply(srcImg);
            }
            BitmapData bitmapdata = srcImg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            Bitmap     bitmap     = GodLesZ.Library.Imaging.Image.CreateGrayscaleImage(width, height);
            BitmapData data2      = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            int        stride     = bitmapdata.Stride;
            int        num4       = stride - width;
            int        num5       = width - 1;
            int        num6       = height - 1;
            double     num10      = 0.0;
            double     num11      = 0.0;
            byte *     numPtr     = (byte *)((byte *)bitmapdata.Scan0.ToPointer() + stride);
            byte *     numPtr2    = (byte *)data2.Scan0.ToPointer();

            for (int i = 1; i < num6; i++)
            {
                numPtr++;
                int num13 = 1;
                while (num13 < num5)
                {
                    double num7 = numPtr[1] - numPtr[-1];
                    double num8 = numPtr[stride] - numPtr[-stride];
                    double num9 = (num7 > num8) ? num7 : num8;
                    num10 += num9;
                    num11 += num9 * numPtr[0];
                    num13++;
                    numPtr++;
                }
                numPtr += num4 + 1;
            }
            this.threshold = (num10 == 0.0) ? ((byte)0) : ((byte)(num11 / num10));
            numPtr         = (byte *)bitmapdata.Scan0.ToPointer();
            for (int j = 0; j < height; j++)
            {
                int num15 = 0;
                while (num15 < width)
                {
                    numPtr2[0] = (numPtr[0] <= this.threshold) ? ((byte)0) : ((byte)0xff);
                    num15++;
                    numPtr++;
                    numPtr2++;
                }
                numPtr  += num4;
                numPtr2 += num4;
            }
            bitmap.UnlockBits(data2);
            srcImg.UnlockBits(bitmapdata);
            if (flag)
            {
                srcImg.Dispose();
            }
            return(bitmap);
        }