Exemple #1
0
        public unsafe void FlipBuffer(FlipMode flipMode)
        {
            PixelBuffer pb = new PixelBuffer(_width, _height);

            fixed(int *src = _buffer)
            {
                fixed(int *dest = pb.InternalBuffer)
                {
                    switch (flipMode)
                    {
                    default:
                    case FlipMode.FlipHorizontal:
                        FlipBufferHorizontal(src, dest);
                        break;

                    case FlipMode.FlipVertical:
                        FlipBufferVertical(src, dest);
                        break;

                    case FlipMode.FlipBoth:
                        FlipBufferBoth(src, dest);
                        break;
                    }
                }
            }

            fixed(int *src = pb.InternalBuffer)
            {
                fixed(int *dest = _buffer)
                {
                    CopyBuffer(dest, src, _pixelsCount);
                }
            }

            pb.Dispose();
        }
Exemple #2
0
        private unsafe void SetBufferRectBufferOutside(int[] srcBuffer, int x, int y, int width, int height)
        {
            int sx = 0;
            int sy = 0;
            int sw = width;
            int sh = height;

            if (x < 0)
            {
                sx = -x;
                sw += x;
            }
            else if ((x + width) > _width)
            {
                sx = 0;
                sw = _width - x;
            }

            if (y < 0)
            {
                sy = -y;
                sh += y;
            }
            else if ((y + height) > _height)
            {
                sy = 0;
                sh = _height - y;
            }

            if (sw <= 0 || sh <= 0)
            {
                return;
            }

            //TODO: problema con l'indice del pixel di un buffer senza istanza
            //
            //int[] blitBufferArray = new int[sw * sh];
            //fixed (int* src = srcBuffer)
            //{
            //    fixed (int* dest = blitBufferArray)
            //    {
            //        CopyBufferRect(dest, src, sx, sy, sw, sh);
            //    }
            //}
            PixelBuffer srcBufferHelper = new PixelBuffer(width, height, srcBuffer);
            PixelBuffer blitBufferArray = srcBufferHelper.GetSubBuffer(sx, sy, sw, sh);

            int fx = x;
            int fy = y;
            if (x < 0) fx = 0;
            if (y < 0) fy = 0;

            fixed (int* src = blitBufferArray.InternalBuffer)
            {
                fixed (int* dest = _buffer)
                {
                    SetBufferRectBuffer(dest, src, fx, fy, sw, sh);
                }
            }

            srcBufferHelper.Dispose();
            blitBufferArray.Dispose();
        }
Exemple #3
0
        public void ResizeBuffer(ResizePivot pivot, int width, int height, Color backColor)
        {
            if (width == _width && height == _height) return;

            PixelBuffer newBuffer = new PixelBuffer(width, height);
            newBuffer.ClearBuffer(backColor);

            int dataWidth = Math.Min(width, _width);
            int dataHeight = Math.Min(height, _height);

            int deltaX = Math.Abs(width - _width);
            int deltaY = Math.Abs(height - _height);
            int midDeltaX = (int)Math.Round(deltaX / 2f, MidpointRounding.AwayFromZero);
            int midDeltaY = (int)Math.Round(deltaY / 2f, MidpointRounding.AwayFromZero);

            bool inflateX = (width > _width);
            bool inflateY = (height > _height);

            int srcX = 0;
            int srcY = 0;
            int destX = 0;
            int destY = 0;

            int srcW = width;
            int srcH = height;

            switch (pivot)
            {
                case ResizePivot.TopLeft:
                    srcX = 0;
                    destX = 0;
                    srcY = 0;
                    destY = 0;
                    break;
                case ResizePivot.TopCenter:
                    if (inflateX)
                    {
                        srcX = 0;
                        destX = midDeltaX;
                    }
                    else
                    {
                        srcX = midDeltaX;
                        destX = 0;
                    }
                    srcY = 0;
                    destY = 0;
                    break;
                case ResizePivot.TopRight:
                    if (inflateX)
                    {
                        srcX = 0;
                        destX = deltaX;
                    }
                    else
                    {
                        srcX = deltaX;
                        destX = 0;
                    }
                    srcY = 0;
                    destY = 0;
                    break;
                case ResizePivot.MiddleLeft:
                    srcX = 0;
                    destX = 0;
                    if (inflateY)
                    {
                        srcY = 0;
                        destY = midDeltaY;
                    }
                    else
                    {
                        srcY = midDeltaY;
                        destY = 0;
                    }
                    break;
                case ResizePivot.MiddleCenter:
                    if (inflateX)
                    {
                        srcX = 0;
                        destX = midDeltaX;
                    }
                    else
                    {
                        srcX = midDeltaX;
                        destX = 0;
                    }
                    if (inflateY)
                    {
                        srcY = 0;
                        destY = midDeltaY;
                    }
                    else
                    {
                        srcY = midDeltaY;
                        destY = 0;
                    }
                    break;
                case ResizePivot.MiddleRight:
                    if (inflateX)
                    {
                        srcX = 0;
                        destX = deltaX;
                    }
                    else
                    {
                        srcX = deltaX;
                        destX = 0;
                    }
                    if (inflateY)
                    {
                        srcY = 0;
                        destY = midDeltaY;
                    }
                    else
                    {
                        srcY = midDeltaY;
                        destY = 0;
                    }
                    break;
                case ResizePivot.BottomLeft:
                    srcX = 0;
                    destX = 0;
                    if (inflateY)
                    {
                        srcY = 0;
                        destY = deltaY;
                    }
                    else
                    {
                        srcY = deltaY;
                        destY = 0;
                    }
                    break;
                case ResizePivot.BottomCenter:
                    if (inflateX)
                    {
                        srcX = 0;
                        destX = midDeltaX;
                    }
                    else
                    {
                        srcX = midDeltaX;
                        destX = 0;
                    }
                    if (inflateY)
                    {
                        srcY = 0;
                        destY = deltaY;
                    }
                    else
                    {
                        srcY = deltaY;
                        destY = 0;
                    }
                    break;
                case ResizePivot.BottomRight:
                    if (inflateX)
                    {
                        srcX = 0;
                        destX = deltaX;
                    }
                    else
                    {
                        srcX = deltaX;
                        destX = 0;
                    }
                    if (inflateY)
                    {
                        srcY = 0;
                        destY = deltaY;
                    }
                    else
                    {
                        srcY = deltaY;
                        destY = 0;
                    }
                    break;
            }

            if (inflateX && inflateY)
            {
                newBuffer.SetSubBuffer(_buffer, destX, destY, dataWidth, dataHeight);
            }
            else
            {
                PixelBuffer blitBuffer = this.GetSubBuffer(srcX, srcY, dataWidth, dataHeight);
                newBuffer.SetSubBuffer(blitBuffer, destX, destY);
            }

            this.Initialize(width, height);
            Array.Copy(newBuffer.InternalBuffer, _buffer, _buffer.Length);

            newBuffer.Dispose();

        }
Exemple #4
0
 public unsafe void FlipBuffer(FlipMode flipMode)
 {
     PixelBuffer pb = new PixelBuffer(_width, _height);
     fixed (int* src = _buffer)
     {
         fixed (int* dest = pb.InternalBuffer)
         {
             switch (flipMode)
             {
                 default:
                 case FlipMode.FlipHorizontal:
                     FlipBufferHorizontal(src, dest);
                     break;
                 case FlipMode.FlipVertical:
                     FlipBufferVertical(src, dest);
                     break;
                 case FlipMode.FlipBoth:
                     FlipBufferBoth(src, dest);
                     break;
             }
         }
     }
     fixed (int* src = pb.InternalBuffer)
     {
         fixed (int* dest = _buffer)
         {
             CopyBuffer(dest, src, _pixelsCount);
         }
     }
     pb.Dispose();
 }
Exemple #5
0
        private unsafe void SetBufferRectBufferOutside(int[] srcBuffer, int x, int y, int width, int height)
        {
            int sx = 0;
            int sy = 0;
            int sw = width;
            int sh = height;

            if (x < 0)
            {
                sx  = -x;
                sw += x;
            }
            else if ((x + width) > _width)
            {
                sx = 0;
                sw = _width - x;
            }

            if (y < 0)
            {
                sy  = -y;
                sh += y;
            }
            else if ((y + height) > _height)
            {
                sy = 0;
                sh = _height - y;
            }

            if (sw <= 0 || sh <= 0)
            {
                return;
            }

            //TODO: problema con l'indice del pixel di un buffer senza istanza
            //
            //int[] blitBufferArray = new int[sw * sh];
            //fixed (int* src = srcBuffer)
            //{
            //    fixed (int* dest = blitBufferArray)
            //    {
            //        CopyBufferRect(dest, src, sx, sy, sw, sh);
            //    }
            //}
            PixelBuffer srcBufferHelper = new PixelBuffer(width, height, srcBuffer);
            PixelBuffer blitBufferArray = srcBufferHelper.GetSubBuffer(sx, sy, sw, sh);

            int fx = x;
            int fy = y;

            if (x < 0)
            {
                fx = 0;
            }
            if (y < 0)
                fy = 0;

            fixed(int *src = blitBufferArray.InternalBuffer)
            {
                fixed(int *dest = _buffer)
                {
                    SetBufferRectBuffer(dest, src, fx, fy, sw, sh);
                }
            }

            srcBufferHelper.Dispose();
            blitBufferArray.Dispose();
        }