Esempio n. 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();
        }
Esempio n. 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();
        }