Example #1
0
 public RectD(RectInt intRect)
 {
     Left = intRect.Left;
     Bottom = intRect.Bottom;
     Right = intRect.Right;
     Top = intRect.Top;
 }
 public VectorClipper(CellAARasterizer ras)
 {
     this.ras = ras;
     clipBox = new RectInt(0, 0, 0, 0);
     m_x1 = m_y1 = m_f1 = 0;
     m_clipping = false;
 }
Example #3
0
 public void ExpandToInclude(RectInt rectToInclude)
 {
     if (Right < rectToInclude.Right) Right = rectToInclude.Right;
     if (Top < rectToInclude.Top) Top = rectToInclude.Top;
     if (Left > rectToInclude.Left) Left = rectToInclude.Left;
     if (Bottom > rectToInclude.Bottom) Bottom = rectToInclude.Bottom;
 }
Example #4
0
 public bool Clip(RectInt r)
 {
     if (Right > r.Right) Right = r.Right;
     if (Top > r.Top) Top = r.Top;
     if (Left < r.Left) Left = r.Left;
     if (Bottom < r.Bottom) Bottom = r.Bottom;
     return Left <= Right && Bottom <= Top;
 }
        SmoothingMode _smoothingMode; //smoothing mode of this  painter
        public GLCanvasPainterBase(CanvasGL2d canvas, int w, int h)
        {
            _canvas = canvas;
            _width = w;
            _height = h;
            _rectInt = new RectInt(0, 0, w, h);
            arcTool = new Arc();
            CurrentFont = new RequestFont("tahoma", 14);

        }
Example #6
0
        public ImageGraphics2D(ActualImage destImage)
        {
            //create from actual image
            this.destImage = destImage;

            this.destActualImage = destImage;
            this.destImageReaderWriter = new MyImageReaderWriter();
            destImageReaderWriter.ReloadImage(destImage);
            this.sclineRas = new ScanlineRasterizer();
            this.sclineRasToBmp = new ScanlineRasToDestBitmapRenderer();
            this.destWidth = destImage.Width;
            this.destHeight = destImage.Height;
            this.clipBox = new RectInt(0, 0, destImage.Width, destImage.Height);
            this.sclineRas.SetClipBox(this.clipBox);
            this.sclinePack8 = new ScanlinePacked8();
            this.currentBlender = this.pixBlenderRGBA32 = new PixelBlenderBGRA();
        }
Example #7
0
        public bool IntersectRectangles(RectInt rectToCopy, RectInt rectToIntersectWith)
        {
            Left = rectToCopy.Left;
            Bottom = rectToCopy.Bottom;
            Right = rectToCopy.Right;
            Top = rectToCopy.Top;
            if (Left < rectToIntersectWith.Left) Left = rectToIntersectWith.Left;
            if (Bottom < rectToIntersectWith.Bottom) Bottom = rectToIntersectWith.Bottom;
            if (Right > rectToIntersectWith.Right) Right = rectToIntersectWith.Right;
            if (Top > rectToIntersectWith.Top) Top = rectToIntersectWith.Top;
            if (Left < Right && Bottom < Top)
            {
                return true;
            }

            return false;
        }
 public override void DoFilterBlurRecursive(RectInt area, int r)
 {
     ChildImage img = new ChildImage(this.gx.DestImage, gx.PixelBlender,
         area.Left, area.Bottom, area.Right, area.Top);
     filterMan.DoRecursiveBlur(img, r);
 }
        void CopyFromNoClipping(IImageReaderWriter sourceImage, RectInt clippedSourceImageRect, int destXOffset, int destYOffset)
        {
            if (BytesBetweenPixelsInclusive != BitDepth / 8
                || sourceImage.BytesBetweenPixelsInclusive != sourceImage.BitDepth / 8)
            {
                throw new Exception("WIP we only support packed pixel formats at this time.");
            }

            if (BitDepth == sourceImage.BitDepth)
            {
                int lengthInBytes = clippedSourceImageRect.Width * BytesBetweenPixelsInclusive;
                int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);
                byte[] sourceBuffer = sourceImage.GetBuffer();
                byte[] destBuffer = GetBuffer();
                int destOffset = GetBufferOffsetXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset);
                for (int i = 0; i < clippedSourceImageRect.Height; i++)
                {
                    AggMemMx.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
                    sourceOffset += sourceImage.Stride;
                    destOffset += Stride;
                }
            }
            else
            {
                bool haveConversion = true;
                switch (sourceImage.BitDepth)
                {
                    case 24:
                        switch (BitDepth)
                        {
                            case 32:
                                {
                                    int numPixelsToCopy = clippedSourceImageRect.Width;
                                    for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
                                    {
                                        int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);
                                        byte[] sourceBuffer = sourceImage.GetBuffer();
                                        byte[] destBuffer = GetBuffer();
                                        int destOffset = GetBufferOffsetXY(clippedSourceImageRect.Left + destXOffset,
                                            clippedSourceImageRect.Bottom + i + destYOffset);
                                        for (int x = 0; x < numPixelsToCopy; x++)
                                        {
                                            destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                            destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                            destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                            destBuffer[destOffset++] = 255;
                                        }
                                    }
                                }
                                break;
                            default:
                                haveConversion = false;
                                break;
                        }
                        break;
                    default:
                        haveConversion = false;
                        break;
                }

                if (!haveConversion)
                {
                    throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
                }
            }
        }
Example #10
0
 public abstract void DoFilterBlurRecursive(RectInt area, int r);
 public void SetClipBox(int x1, int y1, int x2, int y2)
 {
     clipBox = new RectInt(x1, y1, x2, y2);
     clipBox.Normalize();
     m_clipping = true;
 }
        public override void DoFilterBlurStack(RectInt area, int r)
        {
            //since area is Windows coord
            //so we need to invert it 
            //System.Drawing.Bitmap backupBmp = this._gfxBmp;
            //int bmpW = backupBmp.Width;
            //int bmpH = backupBmp.Height;
            //System.Drawing.Imaging.BitmapData bmpdata = backupBmp.LockBits(
            //    new System.Drawing.Rectangle(0, 0, bmpW, bmpH),
            //    System.Drawing.Imaging.ImageLockMode.ReadWrite,
            //     backupBmp.PixelFormat);
            ////copy sub buffer to int32 array
            ////this version bmpdata must be 32 argb 
            //int a_top = area.Top;
            //int a_bottom = area.Bottom;
            //int a_width = area.Width;
            //int a_stride = bmpdata.Stride;
            //int a_height = Math.Abs(area.Height);
            //int[] src_buffer = new int[(a_stride / 4) * a_height];
            //int[] destBuffer = new int[src_buffer.Length];
            //int a_lineOffset = area.Left * 4;
            //unsafe
            //{
            //    IntPtr scan0 = bmpdata.Scan0;
            //    byte* src = (byte*)scan0;
            //    if (a_top > a_bottom)
            //    {
            //        int tmp_a_bottom = a_top;
            //        a_top = a_bottom;
            //        a_bottom = tmp_a_bottom;
            //    }

            //    //skip  to start line
            //    src += ((a_stride * a_top) + a_lineOffset);
            //    int index_start = 0;
            //    for (int y = a_top; y < a_bottom; ++y)
            //    {
            //        //then copy to int32 buffer 
            //        System.Runtime.InteropServices.Marshal.Copy(new IntPtr(src), src_buffer, index_start, a_width);
            //        index_start += a_width;
            //        src += (a_stride + a_lineOffset);
            //    }
            //    PixelFarm.Agg.Imaging.StackBlurARGB.FastBlur32ARGB(src_buffer, destBuffer, a_width, a_height, r);
            //    //then copy back to bmp
            //    index_start = 0;
            //    src = (byte*)scan0;
            //    src += ((a_stride * a_top) + a_lineOffset);
            //    for (int y = a_top; y < a_bottom; ++y)
            //    {
            //        //then copy to int32 buffer 
            //        System.Runtime.InteropServices.Marshal.Copy(destBuffer, index_start, new IntPtr(src), a_width);
            //        index_start += a_width;
            //        src += (a_stride + a_lineOffset);
            //    }
            //}
            ////--------------------------------
            //backupBmp.UnlockBits(bmpdata);
        }
Example #13
0
 public abstract void DoFilterBlurStack(RectInt area, int r);
Example #14
0
        public override void Clear(Color color)
        {
            RectInt clippingRectInt = GetClippingRect();
            var     destImage       = this.DestImage;
            int     width           = destImage.Width;
            int     height          = destImage.Height;

            byte[] buffer = destImage.GetBuffer();
            switch (destImage.BitDepth)
            {
            case 8:
            {
                //int bytesBetweenPixels = destImage.BytesBetweenPixelsInclusive;
                //byte byteColor = color.Red0To255;
                //int clipRectLeft = clippingRectInt.Left;

                //for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; ++y)
                //{
                //    int bufferOffset = destImage.GetBufferOffsetXY(clipRectLeft, y);
                //    for (int x = 0; x < clippingRectInt.Width; ++x)
                //    {
                //        buffer[bufferOffset] = color.blue;
                //        bufferOffset += bytesBetweenPixels;
                //    }
                //}
                throw new NotSupportedException("temp");
            }

            case 24:
            {
                //int bytesBetweenPixels = destImage.BytesBetweenPixelsInclusive;
                //int clipRectLeft = clippingRectInt.Left;
                //for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; y++)
                //{
                //    int bufferOffset = destImage.GetBufferOffsetXY(clipRectLeft, y);
                //    for (int x = 0; x < clippingRectInt.Width; ++x)
                //    {
                //        buffer[bufferOffset + 0] = color.blue;
                //        buffer[bufferOffset + 1] = color.green;
                //        buffer[bufferOffset + 2] = color.red;
                //        bufferOffset += bytesBetweenPixels;
                //    }
                //}
                throw new NotSupportedException("temp");
            }
            break;

            case 32:
            {
                //------------------------------
                //fast clear buffer
                //skip clipping ****
                //TODO: reimplement clipping***
                //------------------------------
                if (color == Color.White)
                {
                    //fast cleat with white color
                    int n = buffer.Length / 4;
                    unsafe
                    {
                        fixed(void *head = &buffer[0])
                        {
                            uint *head_i32 = (uint *)head;

                            for (int i = n - 1; i >= 0; --i)
                            {
                                *head_i32 = 0xffffffff;         //white (ARGB)
                                head_i32++;
                            }
                        }
                    }
                }
                else if (color == Color.Black)
                {
                    //fast cleat with black color
                    int n = buffer.Length / 4;
                    unsafe
                    {
                        fixed(void *head = &buffer[0])
                        {
                            uint *head_i32 = (uint *)head;

                            for (int i = n - 1; i >= 0; --i)
                            {
                                *head_i32 = 0xff000000;         //black (ARGB)
                                head_i32++;
                            }
                        }
                    }
                }
                else
                {
                    //other color
#if WIN
                    uint colorARGB = (uint)((color.alpha << 24) | ((color.red << 16) | (color.green << 8) | color.blue));
#else
                    uint colorARGB = (uint)((color.alpha << 24) | ((color.blue << 16) | (color.green << 8) | color.red));
#endif
                    int n = buffer.Length / 4;
                    unsafe
                    {
                        fixed(void *head = &buffer[0])
                        {
                            uint *head_i32 = (uint *)head;

                            for (int i = n - 1; i >= 0; --i)
                            {
                                *head_i32 = colorARGB;
                                head_i32++;
                            }
                        }
                    }
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
Example #15
0
        //***************************************************************************************************************************************************
        public static bool ClipRect(RectInt pBoundingRect, ref RectInt pDestRect)
        {
            // clip off the top so we don't write into random memory
            if (pDestRect.Top < pBoundingRect.Top)
            {
                pDestRect.Top = pBoundingRect.Top;
                if (pDestRect.Top >= pDestRect.Bottom)
                {
                    return false;
                }
            }
            // clip off the bottom
            if (pDestRect.Bottom > pBoundingRect.Bottom)
            {
                pDestRect.Bottom = pBoundingRect.Bottom;
                if (pDestRect.Bottom <= pDestRect.Top)
                {
                    return false;
                }
            }

            // clip off the left
            if (pDestRect.Left < pBoundingRect.Left)
            {
                pDestRect.Left = pBoundingRect.Left;
                if (pDestRect.Left >= pDestRect.Right)
                {
                    return false;
                }
            }

            // clip off the right
            if (pDestRect.Right > pBoundingRect.Right)
            {
                pDestRect.Right = pBoundingRect.Right;
                if (pDestRect.Right <= pDestRect.Left)
                {
                    return false;
                }
            }

            return true;
        }
 public void SetClipBox(int x1, int y1, int x2, int y2)
 {
     userModeClipBox = new RectInt(x1, y1, x2, y2);
     Reset();
     m_vectorClipper.SetClipBox(
                         upscale(x1), upscale(y1),
                         upscale(x2), upscale(y2));
 }
Example #17
0
 //---------------------------------------------------------unite_rectangles
 public void unite_rectangles(RectInt r1, RectInt r2)
 {
     Left = r1.Left;
     Bottom = r1.Bottom;
     Right = r1.Right;
     Right = r1.Top;
     if (Right < r2.Right) Right = r2.Right;
     if (Top < r2.Top) Top = r2.Top;
     if (Left > r2.Left) Left = r2.Left;
     if (Bottom > r2.Bottom) Bottom = r2.Bottom;
 }
Example #18
0
        public static bool ClipRects(RectInt pBoundingRect, ref RectInt pSourceRect, ref RectInt pDestRect)
        {
            // clip off the top so we don't write into random memory
            if (pDestRect.Top < pBoundingRect.Top)
            {
                // This type of clipping only works when we aren't scaling an image...
                // If we are scaling an image, the source and dest sizes won't match
                if (pSourceRect.Height != pDestRect.Height)
                {
                    throw new Exception("source and dest rects must have the same height");
                }

                pSourceRect.Top += pBoundingRect.Top - pDestRect.Top;
                pDestRect.Top = pBoundingRect.Top;
                if (pDestRect.Top >= pDestRect.Bottom)
                {
                    return false;
                }
            }
            // clip off the bottom
            if (pDestRect.Bottom > pBoundingRect.Bottom)
            {
                // This type of clipping only works when we arenst scaling an image...
                // If we are scaling an image, the source and desst sizes won't match
                if (pSourceRect.Height != pDestRect.Height)
                {
                    throw new Exception("source and dest rects must have the same height");
                }

                pSourceRect.Bottom -= pDestRect.Bottom - pBoundingRect.Bottom;
                pDestRect.Bottom = pBoundingRect.Bottom;
                if (pDestRect.Bottom <= pDestRect.Top)
                {
                    return false;
                }
            }

            // clip off the left
            if (pDestRect.Left < pBoundingRect.Left)
            {
                // This type of clipping only works when we aren't scaling an image...
                // If we are scaling an image, the source and dest sizes won't match
                if (pSourceRect.Width != pDestRect.Width)
                {
                    throw new Exception("source and dest rects must have the same width");
                }

                pSourceRect.Left += pBoundingRect.Left - pDestRect.Left;
                pDestRect.Left = pBoundingRect.Left;
                if (pDestRect.Left >= pDestRect.Right)
                {
                    return false;
                }
            }
            // clip off the right
            if (pDestRect.Right > pBoundingRect.Right)
            {
                // This type of clipping only works when we aren't scaling an image...
                // If we are scaling an image, the source and dest sizes won't match
                if (pSourceRect.Width != pDestRect.Width)
                {
                    throw new Exception("source and dest rects must have the same width");
                }

                pSourceRect.Right -= pDestRect.Right - pBoundingRect.Right;
                pDestRect.Right = pBoundingRect.Right;
                if (pDestRect.Right <= pDestRect.Left)
                {
                    return false;
                }
            }

            return true;
        }
Example #19
0
        public static bool DoIntersect(RectInt rect1, RectInt rect2)
        {
            int x1 = rect1.Left;
            int y1 = rect1.Bottom;
            int x2 = rect1.Right;
            int y2 = rect1.Top;
            if (x1 < rect2.Left) x1 = rect2.Left;
            if (y1 < rect2.Bottom) y1 = rect2.Bottom;
            if (x2 > rect2.Right) x2 = rect2.Right;
            if (y2 > rect2.Top) y2 = rect2.Top;
            if (x1 < x2 && y1 < y2)
            {
                return true;
            }

            return false;
        }
 public static void FillRectangle(this Graphics2D gx, RectInt rect, Color fillColor)
 {
     gx.FillRectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, fillColor);
 }
 public static void Rectangle(this Graphics2D gx, RectInt rect, Color color)
 {
     gx.Rectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, color);
 }
Example #22
0
 public override void SetClippingRect(RectInt rect)
 {
     ScanlineRasterizer.SetClipBox(rect);
 }
Example #23
0
 public static void FillRectangle(this Graphics2D gx, RectInt rect, ColorRGBA fillColor)
 {
     gx.FillRectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, fillColor);
 }
 public void SetClipBox(int x1, int y1, int x2, int y2)
 {
     clipBox = new RectInt(x1, y1, x2, y2);
     clipBox.Normalize();
     m_clipping = true;
 }
Example #25
0
        public static bool ClipRects(RectInt pBoundingRect, ref RectInt pSourceRect, ref RectInt pDestRect)
        {
            // clip off the top so we don't write into random memory
            if (pDestRect.Top < pBoundingRect.Top)
            {
                // This type of clipping only works when we aren't scaling an image...
                // If we are scaling an image, the source and dest sizes won't match
                if (pSourceRect.Height != pDestRect.Height)
                {
                    throw new Exception("source and dest rects must have the same height");
                }

                pSourceRect.Top += pBoundingRect.Top - pDestRect.Top;
                pDestRect.Top    = pBoundingRect.Top;
                if (pDestRect.Top >= pDestRect.Bottom)
                {
                    return(false);
                }
            }
            // clip off the bottom
            if (pDestRect.Bottom > pBoundingRect.Bottom)
            {
                // This type of clipping only works when we arenst scaling an image...
                // If we are scaling an image, the source and desst sizes won't match
                if (pSourceRect.Height != pDestRect.Height)
                {
                    throw new Exception("source and dest rects must have the same height");
                }

                pSourceRect.Bottom -= pDestRect.Bottom - pBoundingRect.Bottom;
                pDestRect.Bottom    = pBoundingRect.Bottom;
                if (pDestRect.Bottom <= pDestRect.Top)
                {
                    return(false);
                }
            }

            // clip off the left
            if (pDestRect.Left < pBoundingRect.Left)
            {
                // This type of clipping only works when we aren't scaling an image...
                // If we are scaling an image, the source and dest sizes won't match
                if (pSourceRect.Width != pDestRect.Width)
                {
                    throw new Exception("source and dest rects must have the same width");
                }

                pSourceRect.Left += pBoundingRect.Left - pDestRect.Left;
                pDestRect.Left    = pBoundingRect.Left;
                if (pDestRect.Left >= pDestRect.Right)
                {
                    return(false);
                }
            }
            // clip off the right
            if (pDestRect.Right > pBoundingRect.Right)
            {
                // This type of clipping only works when we aren't scaling an image...
                // If we are scaling an image, the source and dest sizes won't match
                if (pSourceRect.Width != pDestRect.Width)
                {
                    throw new Exception("source and dest rects must have the same width");
                }

                pSourceRect.Right -= pDestRect.Right - pBoundingRect.Right;
                pDestRect.Right    = pBoundingRect.Right;
                if (pDestRect.Right <= pDestRect.Left)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #26
0
 public abstract void DoFilterBlurRecursive(RectInt area, int r);
        void CopyFromNoClipping(IImageReaderWriter sourceImage, RectInt clippedSourceImageRect, int destXOffset, int destYOffset)
        {
            if (BytesBetweenPixelsInclusive != BitDepth / 8 ||
                sourceImage.BytesBetweenPixelsInclusive != sourceImage.BitDepth / 8)
            {
                throw new Exception("WIP we only support packed pixel formats at this time.");
            }

            if (BitDepth == sourceImage.BitDepth)
            {
                int lengthInBytes = clippedSourceImageRect.Width * BytesBetweenPixelsInclusive;

                int    sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);
                byte[] sourceBuffer = sourceImage.GetBuffer();


                byte[] destBuffer = GetBuffer();
                int    destOffset = GetBufferOffsetXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset);


                for (int i = 0; i < clippedSourceImageRect.Height; i++)
                {
                    AggMemMx.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
                    sourceOffset += sourceImage.Stride;
                    destOffset   += Stride;
                }
            }
            else
            {
                bool haveConversion = true;
                switch (sourceImage.BitDepth)
                {
                case 24:
                    switch (BitDepth)
                    {
                    case 32:
                    {
                        int numPixelsToCopy = clippedSourceImageRect.Width;
                        for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
                        {
                            int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);

                            byte[] sourceBuffer = sourceImage.GetBuffer();



                            byte[] destBuffer = GetBuffer();
                            int    destOffset = GetBufferOffsetXY(clippedSourceImageRect.Left + destXOffset,
                                                                  clippedSourceImageRect.Bottom + i + destYOffset);

                            for (int x = 0; x < numPixelsToCopy; x++)
                            {
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = 255;
                            }
                        }
                    }
                    break;

                    default:
                        haveConversion = false;
                        break;
                    }
                    break;

                default:
                    haveConversion = false;
                    break;
                }

                if (!haveConversion)
                {
                    throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
                }
            }
        }
Example #28
0
 public override void SetClippingRect(RectInt rect)
 {
     ScanlineRasterizer.SetClipBox(rect);
 }
        //--------------------------

        internal void SetClipBox(RectInt clippingRect)
        {
            SetClipBox(clippingRect.Left, clippingRect.Bottom, clippingRect.Right, clippingRect.Top);
        }
 public override void DoFilterBlurRecursive(RectInt area, int r)
 {
     //TODO: implement this
 }
 public override void DoFilterBlurStack(RectInt area, int r)
 {
 }
Example #32
0
 public static void Rectangle(this Graphics2D gx, RectInt rect, ColorRGBA color)
 {
     gx.Rectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, color);
 }
 public void CopyFrom(IImageReaderWriter sourceImage, RectInt sourceImageRect, int destXOffset, int destYOffset)
 {
     RectInt sourceImageBounds = sourceImage.GetBounds();
     RectInt clippedSourceImageRect = new RectInt();
     if (clippedSourceImageRect.IntersectRectangles(sourceImageRect, sourceImageBounds))
     {
         RectInt destImageRect = clippedSourceImageRect;
         destImageRect.Offset(destXOffset, destYOffset);
         RectInt destImageBounds = GetBounds();
         RectInt clippedDestImageRect = new RectInt();
         if (clippedDestImageRect.IntersectRectangles(destImageRect, destImageBounds))
         {
             // we need to make sure the source is also clipped to the dest. So, we'll copy this back to source and offset it.
             clippedSourceImageRect = clippedDestImageRect;
             clippedSourceImageRect.Offset(-destXOffset, -destYOffset);
             CopyFromNoClipping(sourceImage, clippedSourceImageRect, destXOffset, destYOffset);
         }
     }
 }
        public void Render(IImageReaderWriter source, double destX, double destY)
        {
            int inScaleX     = 1;
            int inScaleY     = 1;
            int angleRadians = 0;
            // exit early if the dest and source bounds don't touch.
            // TODO: <BUG> make this do rotation and scalling
            RectInt sourceBounds = source.GetBounds();

            sourceBounds.Offset((int)destX, (int)destY);

            RectInt destBounds = this.destImageReaderWriter.GetBounds();

            if (!RectInt.DoIntersect(sourceBounds, destBounds))
            {
                //if (inScaleX != 1 || inScaleY != 1 || angleRadians != 0)
                //{
                //    throw new NotImplementedException();
                //}
                return;
            }

            double scaleX            = inScaleX;
            double scaleY            = inScaleY;
            Affine graphicsTransform = this.CurrentTransformMatrix;

            if (!graphicsTransform.IsIdentity())
            {
                if (scaleX != 1 || scaleY != 1 || angleRadians != 0)
                {
                    throw new NotImplementedException();
                }
                graphicsTransform.Transform(ref destX, ref destY);
            }


#if false // this is an optomization that eliminates the drawing of images that have their alpha set to all 0 (happens with generated images like explosions).
            MaxAlphaFrameProperty maxAlphaFrameProperty = MaxAlphaFrameProperty::GetMaxAlphaFrameProperty(source);

            if ((maxAlphaFrameProperty.GetMaxAlpha() * color.A_Byte) / 256 <= ALPHA_CHANNEL_BITS_DIVISOR)
            {
                m_OutFinalBlitBounds.SetRect(0, 0, 0, 0);
            }
#endif
            bool isScale   = (scaleX != 1 || scaleY != 1);
            bool isRotated = false;
            if (angleRadians != 0 && Math.Abs(angleRadians) >= (0.1 * MathHelper.Tau / 360))
            {
                isRotated = true;
            }
            else
            {
                angleRadians = 0;//reset very small angle to 0
            }


            //bool IsMipped = false;
            //double ox, oy;
            //source.GetOriginOffset(out ox, out oy);

            bool canUseMipMaps = isScale;
            if (scaleX > 0.5 || scaleY > 0.5)
            {
                canUseMipMaps = false;
            }

            bool needSourceResampling = isScale || isRotated || destX != (int)destX || destY != (int)destY;



            VectorToolBox.GetFreeVxs(out VertexStore imgBoundsPath);
            // this is the fast drawing path
            if (needSourceResampling)
            {
#if false // if the scalling is small enough the results can be improved by using mip maps
                if (CanUseMipMaps)
                {
                    CMipMapFrameProperty *pMipMapFrameProperty = CMipMapFrameProperty::GetMipMapFrameProperty(source);
                    double OldScaleX = scaleX;
                    double OldScaleY = scaleY;
                    const CFrameInterface *pMippedFrame = pMipMapFrameProperty.GetMipMapFrame(ref scaleX, ref scaleY);
                    if (pMippedFrame != source)
                    {
                        IsMipped             = true;
                        source               = pMippedFrame;
                        sourceOriginOffsetX *= (OldScaleX / scaleX);
                        sourceOriginOffsetY *= (OldScaleY / scaleY);
                    }

                    HotspotOffsetX *= (inScaleX / scaleX);
                    HotspotOffsetY *= (inScaleY / scaleY);
                }
#endif


                Affine destRectTransform = BuildImageBoundsPath(source.Width, source.Height,
                                                                destX, destY, ox, oy, scaleX, scaleY, angleRadians, imgBoundsPath);
                // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004]
                Affine sourceRectTransform = destRectTransform.CreateInvert();
                var    imgSpanGen          = new ImgSpanGenRGBA_BilinearClip(
                    source,
                    Drawing.Color.Black,
                    new SpanInterpolatorLinear(sourceRectTransform));

                VectorToolBox.GetFreeVxs(out VertexStore v1);
                destRectTransform.TransformToVxs(imgBoundsPath, v1);
                Render(v1, imgSpanGen);
                VectorToolBox.ReleaseVxs(ref v1);
#if false // this is some debug you can enable to visualize the dest bounding box
                LineFloat(BoundingRect.left, BoundingRect.top, BoundingRect.right, BoundingRect.top, WHITE);
                LineFloat(BoundingRect.right, BoundingRect.top, BoundingRect.right, BoundingRect.bottom, WHITE);
                LineFloat(BoundingRect.right, BoundingRect.bottom, BoundingRect.left, BoundingRect.bottom, WHITE);
                LineFloat(BoundingRect.left, BoundingRect.bottom, BoundingRect.left, BoundingRect.top, WHITE);
#endif
            }
            else // TODO: this can be even faster if we do not use an intermediat buffer
            {
                Affine destRectTransform = BuildImageBoundsPath(source.Width, source.Height,
                                                                destX, destY, imgBoundsPath);
                // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004]
                Affine     sourceRectTransform = destRectTransform.CreateInvert();
                var        interpolator        = new SpanInterpolatorLinear(sourceRectTransform);
                ImgSpanGen imgSpanGen          = null;
                switch (source.BitDepth)
                {
                case 32:
                    imgSpanGen = new ImgSpanGenRGBA_NN_StepXBy1(source, interpolator);
                    break;

                //case 24:
                //    imgSpanGen = new ImgSpanGenRGB_NNStepXby1(source, interpolator);
                //    break;
                case 8:
                    imgSpanGen = new ImgSpanGenGray_NNStepXby1(source, interpolator);
                    break;

                default:
                    throw new NotImplementedException();
                }


                VectorToolBox.GetFreeVxs(out VertexStore v1);

                destRectTransform.TransformToVxs(imgBoundsPath, v1);
                Render(v1, imgSpanGen);

                VectorToolBox.ReleaseVxs(ref v1);
                unchecked { destImageChanged++; };
            }
            VectorToolBox.ReleaseVxs(ref imgBoundsPath);
        }
Example #35
0
 public static void Rectangle(this AggRenderSurface gx, RectInt rect, Color color)
 {
     gx.Rectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, color);
 }
        //--------------------------

        internal void SetClipBox(RectInt clippingRect)
        {
            SetClipBox(clippingRect.Left, clippingRect.Bottom, clippingRect.Right, clippingRect.Top);
        }
Example #37
0
 public static void FillRectangle(this AggRenderSurface gx, RectInt rect, Color fillColor)
 {
     gx.FillRectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, fillColor);
 }
Example #38
0
        //------------------------------------------------------------------------

        public abstract void SetClippingRect(RectInt rect);
Example #39
0
 public abstract void DoFilterBlurStack(RectInt area, int r);
Example #40
0
        //------------------------------------------------------------------------

        public abstract void SetClippingRect(RectInt rect);
 public override void DoFilterBlurRecursive(RectInt area, int r)
 {
     //filter with glsl
 }