Ejemplo n.º 1
0
        //private IntPtr _memDC;

        public PixelBufferManagedGraphics(PixelBuffer pixelBuffer)
            : base(pixelBuffer)
        {
            _bmp = new Bitmap(pixelBuffer.Width, pixelBuffer.Height);
            _gfx = Graphics.FromImage(_bmp);

            pixelBuffer.Renderer.RenderBegin += new PixelBufferRenderDelegate(Renderer_RenderBegin);
        }
        //private IntPtr _memDC;

        public PixelBufferManagedGraphics(PixelBuffer pixelBuffer)
            : base(pixelBuffer)
        {
            _bmp = new Bitmap(pixelBuffer.Width, pixelBuffer.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            _gfx = Graphics.FromImage(_bmp);

            pixelBuffer.Renderer.RenderBegin += new PixelBufferRenderDelegate(Renderer_RenderBegin);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
 public unsafe void BlendSubBuffer(PixelBuffer subBuffer, int x, int y)
 {
     BlendSubBuffer(subBuffer.InternalBuffer, x, y, subBuffer.Width, subBuffer.Height);
 }
Ejemplo n.º 6
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();

        }
Ejemplo n.º 7
0
        private unsafe PixelBuffer GetSubBufferOutside(int x, int y, int width, int height)
        {
            PixelBuffer retBuff = new PixelBuffer(width, height);

            int sx = x;
            int sy = y;
            int sw = width;
            int sh = height;

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

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

            if (sw <= 0 || sh <= 0)
            {
                return new PixelBuffer(width,height);
            }

            int defaultColor = 0;
            fixed (int* src = _buffer)
            {
                int index = this.GetPixelBytesIndex(sx, sy, _width);
                defaultColor = this.GetPixelColorByIndex(src, index);
            }

            fixed (int* dest = retBuff.InternalBuffer)
            {
                retBuff.SetBufferColor(dest, defaultColor);
            }

            using (PixelBuffer subBuff = this.GetSubBuffer(sx, sy, sw, sh))
            {
                int fx = 0;
                int fy = 0;
                if (x < 0) fx = -x;
                if (y < 0) fy = -y;

                retBuff.SetSubBuffer(subBuff, fx, fy);
            }

            return retBuff;
        }
Ejemplo n.º 8
0
 public unsafe void BlendSubBuffer(PixelBuffer subBuffer, int x, int y)
 {
     BlendSubBuffer(subBuffer.InternalBuffer, x, y, subBuffer.Width, subBuffer.Height);
 }
Ejemplo n.º 9
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();
 }
Ejemplo n.º 10
0
 protected PixelBufferRenderer(PixelBuffer pixelBuffer)
 {
     this.pixelBuffer = pixelBuffer;
     _useTransparentBackground = false;
     _backColor = Color.Black;
 }
Ejemplo n.º 11
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();
        }
 public PixelBufferManagedRenderer(PixelBuffer pixelBuffer)
     : base(pixelBuffer)
 {
     this.UseTransparentBackground = true;
     this.backColorBrush = new SolidBrush(Color.Black);
 }
Ejemplo n.º 13
0
 public PixelBufferGraphics(PixelBuffer pixelBuffer)
 {
     this.pixelBuffer = pixelBuffer;
 }
Ejemplo n.º 14
0
 private void UpdateControl()
 {
     if (_orientation == ColorSliderOrientation.Vertical)
     {
         _cursorRect = new Rectangle(0, 256 - 4, 20, 7);
     }
     else
     {
         _cursorRect = new Rectangle(-3, 0, 7, 20);
     }
     _pixBuffer = new PixelBuffer(this.Width, this.Height);
     FillBuffer();
 }
Ejemplo n.º 15
0
 public virtual void Dispose()
 {
     pixelBuffer = null;
 }
Ejemplo n.º 16
0
 public PixelBufferGraphics(PixelBuffer pixelBuffer)
 {
     this.pixelBuffer = pixelBuffer;
 }
Ejemplo n.º 17
0
 protected PixelBufferRenderer(PixelBuffer pixelBuffer)
 {
     this.pixelBuffer          = pixelBuffer;
     _useTransparentBackground = false;
     _backColor = Color.Black;
 }
Ejemplo n.º 18
0
 public PixelBufferManagedRenderer(PixelBuffer pixelBuffer)
     : base(pixelBuffer)
 {
     this.UseTransparentBackground = true;
     this.backColorBrush           = new SolidBrush(Color.Black);
 }
Ejemplo n.º 19
0
 public virtual void Dispose()
 {
     pixelBuffer = null;
 }
Ejemplo n.º 20
0
        private unsafe PixelBuffer GetSubBufferOutside(int x, int y, int width, int height)
        {
            PixelBuffer retBuff = new PixelBuffer(width, height);

            int sx = x;
            int sy = y;
            int sw = width;
            int sh = height;

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

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

            if (sw <= 0 || sh <= 0)
            {
                return(new PixelBuffer(width, height));
            }

            int defaultColor = 0;

            fixed(int *src = _buffer)
            {
                int index = this.GetPixelBytesIndex(sx, sy, _width);

                defaultColor = this.GetPixelColorByIndex(src, index);
            }

            fixed(int *dest = retBuff.InternalBuffer)
            {
                retBuff.SetBufferColor(dest, defaultColor);
            }

            using (PixelBuffer subBuff = this.GetSubBuffer(sx, sy, sw, sh))
            {
                int fx = 0;
                int fy = 0;
                if (x < 0)
                {
                    fx = -x;
                }
                if (y < 0)
                {
                    fy = -y;
                }

                retBuff.SetSubBuffer(subBuff, fx, fy);
            }

            return(retBuff);
        }