예제 #1
0
        public unsafe void CopyTo(EditBitmap destinationBitmap, int top, int left, int height, int width)
        {
            lock (LockObject)
            {
                // Find smallest array
                //int size = (int)Math.Min(ByteLength, destinationBitmap.ByteLength) / destinationBitmap.BytesPerPixel;
                // Copy memory
                //CopyMemory(ImageData, destinationBitmap.ImageData, size);
                //Marshal.Copy(src, destinationBitmap.ImageData, 0, size);

                // First copy int64 as far as we can (faster than copying single bytes)
                Int64 *src64 = (Int64 *)ImageData;
                Int64 *dst64 = (Int64 *)destinationBitmap.ImageData;
                byte * src8  = (byte *)ImageData;
                byte * dst8  = (byte *)destinationBitmap.ImageData;

                int maxWidth  = Math.Min(Math.Min(Width - left, destinationBitmap.Width - left), width + top);
                int maxHeight = Math.Min(Math.Min(Height - top, destinationBitmap.Height - top), height + top);

                for (int x = top; x < maxHeight; x++)
                {
                    for (int y = left; y < maxWidth; y++)
                    {
                        int srcp = (x * Width) + y;
                        int dstp = (x * destinationBitmap.Width) + y;
                        dst8[dstp] = src8[srcp];
                    }
                }
            }
        }
예제 #2
0
        public EditBitmap Clone()
        {
            lock (LockObject)
            {
                // Create new bitmap
                EditBitmap bitmap = new EditBitmap(Width, Height, PixelFormat);
                // Copy data into new bitmap
                CopyTo(bitmap);

                return(bitmap);
            }
        }
예제 #3
0
        public unsafe void CopyTo(EditBitmap destinationBitmap)
        {
            lock (LockObject)
            {
                // Find smallest array
                //int size = (int)Math.Min(ByteLength, destinationBitmap.ByteLength) / destinationBitmap.BytesPerPixel;
                // Copy memory
                //CopyMemory(ImageData, destinationBitmap.ImageData, size);
                //Marshal.Copy(src, destinationBitmap.ImageData, 0, size);

                // First copy int64 as far as we can (faster than copying single bytes)
                int    copied = 0;
                Int64 *src64  = (Int64 *)ImageData;
                Int64 *dst64  = (Int64 *)destinationBitmap.ImageData;

                int srcHeight = Height * Width;
                int dstHeight = destinationBitmap.Height * destinationBitmap.Width;
                int maxLen    = Math.Min(srcHeight, dstHeight);

                int copyLength = maxLen - 8;
                int i          = 0;
                while (copied < copyLength)
                {
                    dst64[i] = src64[i];
                    i++;
                    copied += 8;
                }

                // Then copy single bytes until end of data
                byte *src8 = (byte *)ImageData;
                byte *dst8 = (byte *)destinationBitmap.ImageData;

                i *= 8;
                while (copied < ByteLength)
                {
                    dst8[i] = src8[i];
                    i++;
                    copied++;
                }
            }
        }
예제 #4
0
        public void Blur(int xBlur, int yBlur)
        {
            EditBitmap srcImage  = Clone();
            int *      srcIntPtr = srcImage.ImageIntPtr;
            int *      dstIntPtr = ImageIntPtr;

            int xfrom = (xBlur / 2) * -1;
            int xto   = xfrom + xBlur;
            int yfrom = (yBlur / 2) * -1;
            int yto   = yfrom + yBlur;

            for (int x = 0; x < Height; x++)
            {
                for (int y = 0; y < Width; y++)
                {
                    // Look around
                    long avg   = 0;
                    int  count = 0;
                    for (int xa = xfrom; xa < xto; xa++)
                    {
                        for (int ya = yfrom; ya < yto; ya++)
                        {
                            if (x + xa >= 0 && x + xa < Height &&
                                y + ya >= 0 && y + ya < Width)
                            {
                                int p = ((x + xa) * Width) + (y + ya);
                                avg += srcIntPtr[p];
                                count++;
                            }
                        }
                    }
                    int pd = (x * Width) + y;
                    dstIntPtr[pd] = (int)(avg / count);
                }
            }

            srcImage.Dispose();
        }