Пример #1
0
        public unsafe void OpeningErodedProcessing(BitmapCustomImage sourceData, BitmapCustomImage destinationData, Rectangle rect)
        {
            PixelFormat pixelFormat = sourceData.PixelFormat;

            int startX = rect.Left;
            int startY = rect.Top;
            int stopX = startX + rect.Width;
            int stopY = startY + rect.Height;
            int r = OpeningFilter.Size >> 1;
            bool isFound;

            if (pixelFormat == PixelFormat.Format8bppIndexed)
            {
                int dstStride = destinationData.Stride;
                int srcStride = sourceData.Stride;

                byte* baseSrc = (byte*)sourceData.ImageData.ToPointer();
                byte* baseDst = (byte*)destinationData.ImageData.ToPointer();

                for (int y = startY; y < stopY; y++)
                {
                    byte* src = baseSrc + y * srcStride;
                    byte* dst = baseDst + y * dstStride;
                    byte min, v;
                    int t, ir, jr, i, j;

                    for (int x = startX; x < stopX; x++, src++, dst++)
                    {
                        min = 255; isFound = false;
                        for (i = 0; i < OpeningFilter.Size; i++)
                        {
                            ir = i - r; t = y + ir;

                            if (t < startY) continue;
                            if (t >= stopY) break;
                            for (j = 0; j < OpeningFilter.Size; j++)
                            {
                                jr = j - r; t = x + jr;
                                if (t < startX) continue;
                                if (t < stopX)
                                {
                                    isFound = true;
                                    v = src[ir * srcStride + jr];
                                    if (v < min) min = v;
                                }
                            }
                        }
                        *dst = (isFound) ? min : *src;
                    }
                }
            }
        }
Пример #2
0
        protected unsafe void Convert60sImage(BitmapCustomImage sourceData, BitmapCustomImage destinationData)
        {
            int width = sourceData.Width;
            int height = sourceData.Height;
            PixelFormat srcPixelFormat = sourceData.PixelFormat;

            if ((srcPixelFormat == PixelFormat.Format24bppRgb) || (srcPixelFormat == PixelFormat.Format32bppRgb) || (srcPixelFormat == PixelFormat.Format32bppArgb))
            {
                int pixelSize = (srcPixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
                int srcOffset = sourceData.Stride - width * pixelSize;
                int dstOffset = destinationData.Stride - width;

                int rc = (int)(0x10000 * cr);
                int gc = (int)(0x10000 * cg);
                int bc = (int)(0x10000 * cb);

                while (rc + gc + bc < 0x10000)
                {
                    bc++;
                }

                byte* src = (byte*)sourceData.ImageData.ToPointer();
                byte* dst = (byte*)destinationData.ImageData.ToPointer();

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, src += pixelSize, dst++)
                    {
                        *dst = (byte)((rc * src[2] + gc * src[1] + bc * src[0]) >> 16);
                    }
                    src += srcOffset;
                    dst += dstOffset;
                }
            }
        }
Пример #3
0
        protected unsafe void ProcessFilterTowards(BitmapCustomImage image, Bitmap tmpImage)
        {
            if (tmpImage != null)
            {
                int stepSize = 1;
                BitmapData tmpData = tmpImage.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
                BitmapCustomImage tmplay = new BitmapCustomImage(tmpData);

                try
                {
                    PixelFormat pixelFormat = image.PixelFormat;
                    int width = image.Width;
                    int height = image.Height;
                    int v;

                    if ((pixelFormat == PixelFormat.Format8bppIndexed))
                    {
                        int srcOffset = image.Stride - width;
                        int ovrOffset = tmplay.Stride - width;

                        byte* ptr = (byte*)image.ImageData.ToPointer();
                        byte* ovr = (byte*)tmplay.ImageData.ToPointer();

                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++, ptr++, ovr++)
                            {
                                v = (int)*ovr - *ptr;
                                if (v > 0)
                                    *ptr += (byte)((stepSize < v) ? stepSize : v);
                                else if (v < 0)
                                {
                                    v = -v;
                                    *ptr -= (byte)((stepSize < v) ? stepSize : v);
                                }
                            }
                            ptr += srcOffset;
                            ovr += ovrOffset;
                        }
                    }
                }
                finally
                {
                    tmpImage.UnlockBits(tmpData);
                }
            }
        }
Пример #4
0
        protected unsafe void ProcessFilter(BitmapCustomImage image, Rectangle rect)
        {
            int startX = rect.Left;
            int startY = rect.Top;
            int stopX = startX + rect.Width;
            int stopY = startY + rect.Height;

            if (image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                int offset = image.Stride - rect.Width;
                byte* ptr = (byte*)image.ImageData.ToPointer();
                ptr += (startY * image.Stride + startX);

                for (int y = startY; y < stopY; y++)
                {
                    for (int x = startX; x < stopX; x++, ptr++)
                        *ptr = (byte)((*ptr >= threshold) ? 255 : 0);
                    ptr += offset;
                }
            }
            else
            {
                byte* basePtr = (byte*)image.ImageData.ToPointer() + startX * 2;
                int stride = image.Stride;

                for (int y = startY; y < stopY; y++)
                {
                    ushort* ptr = (ushort*)(basePtr + stride * y);
                    for (int x = startX; x < stopX; x++, ptr++)
                        *ptr = (ushort)((*ptr >= threshold) ? 65535 : 0);
                }
            }
        }
Пример #5
0
        protected unsafe void ProcessFilter(BitmapCustomImage image, BitmapCustomImage overlay)
        {
            int width = image.Width;
            int height = image.Height;
            int v;

            if ((image.PixelFormat == PixelFormat.Format8bppIndexed))
            {
                int srcOffset = image.Stride - width;
                int ovrOffset = overlay.Stride - width;

                byte* ptr = (byte*)image.ImageData.ToPointer();
                byte* ovr = (byte*)overlay.ImageData.ToPointer();

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, ptr++, ovr++)
                    {
                        v = (int)*ptr - (int)*ovr;
                        *ptr = (v < 0) ? (byte)-v : (byte)v;
                    }
                    ptr += srcOffset;
                    ovr += ovrOffset;
                }
            }
        }
Пример #6
0
 protected unsafe void ProcessFilter(BitmapCustomImage image)
 {
     if (referenceImage != null)
     {
         BitmapData ovrData = referenceImage.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
         try
         {
             ProcessFilter(image, new BitmapCustomImage(ovrData));
         }
         finally
         {
             referenceImage.UnlockBits(ovrData);
         }
     }
 }