コード例 #1
0
        public MaskedSurface(Surface source, PdnGraphicsPath path)
        {
            RectangleF boundsF = path.GetBounds();
            Rectangle  bounds  = Utility.RoundRectangle(boundsF);

            Rectangle boundsClipped = Rectangle.Intersect(bounds, source.Bounds);
            Rectangle boundsRead;

            if (bounds != boundsClipped)
            {
                PdnRegion region = new PdnRegion(path);
                region.Intersect(source.Bounds);
                SetPathField(PdnGraphicsPath.FromRegion(region));
                this.region = region;
                boundsRead  = region.GetBoundsInt();
            }
            else
            {
                SetPathField(path.Clone());
                this.region = new PdnRegion(this.path);
                boundsRead  = boundsClipped;
            }

            if (boundsRead.Width > 0 && boundsRead.Height > 0)
            {
                this.surface = new Surface(boundsRead.Size);
                this.surface.CopySurface(source, boundsRead);
            }
            else
            {
                this.surface = null;
            }
        }
コード例 #2
0
        public SurfaceForClipboard(MaskedSurface maskedSurface)
        {
            using (PdnRegion region = maskedSurface.CreateRegion())
            {
                this.Bounds = region.GetBoundsInt();
            }

            this.MaskedSurface = maskedSurface;
        }
コード例 #3
0
        /// <summary>
        /// Causes the layer to render a given region of interest (roi) to the given destination surface.
        /// </summary>
        /// <param name="args">Contains information about which objects to use for rendering</param>
        /// <param name="roi">The region to be rendered.</param>
        public void Render(RenderArgs args, PdnRegion roi)
        {
            Rectangle roiBounds = roi.GetBoundsInt();

            if (!IsInBounds(roiBounds))
            {
                throw new ArgumentOutOfRangeException("roi");
            }

            Rectangle[] rects = roi.GetRegionScansReadOnlyInt();
            RenderImpl(args, rects);
        }
コード例 #4
0
        /// <summary>
        /// Constructs a MaskSurface by copying the given region-of-interest from an Image.
        /// </summary>
        /// <param name="source">The Surface to copy pixels from.</param>
        /// <param name="roi">Defines the Region from which to copy pixels from the Image.</param>
        public MaskedSurface(Surface source, PdnRegion roi)
        {
            PdnRegion roiClipped = (PdnRegion)roi.Clone();

            roiClipped.Intersect(source.Bounds);

            Rectangle boundsClipped = roiClipped.GetBoundsInt();

            this.surface = new Surface(boundsClipped.Size);
            this.surface.Clear(ColorBgra.FromUInt32(0x00ffffff));

            Rectangle rect      = boundsClipped;
            Point     dstOffset = new Point(rect.X - boundsClipped.X, rect.Y - boundsClipped.Y);

            this.surface.CopySurface(source, dstOffset, rect);

            this.region = roiClipped;
            // TODO: FromRegion() is a VERY expensive call for what we are doing!
            PdnGraphicsPath newPath = PdnGraphicsPath.FromRegion(this.region);

            SetPathField(newPath);
        }
コード例 #5
0
        public static PdnGraphicsPath FromRegion(PdnRegion region)
        {
            Rectangle[] scans = region.GetRegionScansReadOnlyInt();

            if (scans.Length == 1)
            {
                PdnGraphicsPath path = new PdnGraphicsPath();
                path.AddRectangle(scans[0]);
                path.CloseFigure();
                return(path);
            }
            else
            {
                Rectangle   bounds  = region.GetBoundsInt();
                BitVector2D stencil = new BitVector2D(bounds.Width, bounds.Height);

                for (int i = 0; i < scans.Length; ++i)
                {
                    Rectangle rect = scans[i];
                    rect.X -= bounds.X;
                    rect.Y -= bounds.Y;

                    stencil.SetUnchecked(rect, true);
                }

                PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height));

                using (Matrix matrix = new Matrix())
                {
                    matrix.Reset();
                    matrix.Translate(bounds.X, bounds.Y);
                    path.Transform(matrix);
                }

                return(path);
            }
        }
コード例 #6
0
        public void SaveRegion(PdnRegion saveMeRegion, Rectangle saveMeBounds)
        {
            BitmapLayer activeLayer = (BitmapLayer)ActiveLayer;

            if (savedTiles == null)
            {
                savedTiles = new BitVector2D(
                    (activeLayer.Width + saveTileGranularity - 1) / saveTileGranularity,
                    (activeLayer.Height + saveTileGranularity - 1) / saveTileGranularity);

                savedTiles.Clear(false);
            }

            Rectangle regionBounds;

            if (saveMeRegion == null)
            {
                regionBounds = saveMeBounds;
            }
            else
            {
                regionBounds = saveMeRegion.GetBoundsInt();
            }

            Rectangle bounds = Rectangle.Union(regionBounds, saveMeBounds);

            bounds.Intersect(activeLayer.Bounds);

            int leftTile   = bounds.Left / saveTileGranularity;
            int topTile    = bounds.Top / saveTileGranularity;
            int rightTile  = (bounds.Right - 1) / saveTileGranularity;
            int bottomTile = (bounds.Bottom - 1) / saveTileGranularity;

            for (int tileY = topTile; tileY <= bottomTile; ++tileY)
            {
                Rectangle rowAccumBounds = Rectangle.Empty;

                for (int tileX = leftTile; tileX <= rightTile; ++tileX)
                {
                    if (!savedTiles.Get(tileX, tileY))
                    {
                        Rectangle tileBounds = new Rectangle(tileX * saveTileGranularity, tileY * saveTileGranularity,
                                                             saveTileGranularity, saveTileGranularity);

                        tileBounds.Intersect(activeLayer.Bounds);

                        if (rowAccumBounds == Rectangle.Empty)
                        {
                            rowAccumBounds = tileBounds;
                        }
                        else
                        {
                            rowAccumBounds = Rectangle.Union(rowAccumBounds, tileBounds);
                        }

                        savedTiles.Set(tileX, tileY, true);
                    }
                    else
                    {
                        if (rowAccumBounds != Rectangle.Empty)
                        {
                            using (Surface dst = ScratchSurface.CreateWindow(rowAccumBounds),
                                   src = activeLayer.Surface.CreateWindow(rowAccumBounds))
                            {
                                dst.CopySurface(src);
                            }

                            rowAccumBounds = Rectangle.Empty;
                        }
                    }
                }

                if (rowAccumBounds != Rectangle.Empty)
                {
                    using (Surface dst = ScratchSurface.CreateWindow(rowAccumBounds),
                           src = activeLayer.Surface.CreateWindow(rowAccumBounds))
                    {
                        dst.CopySurface(src);
                    }

                    rowAccumBounds = Rectangle.Empty;
                }
            }

            if (this.saveRegion != null)
            {
                this.saveRegion.Dispose();
                this.saveRegion = null;
            }

            if (saveMeRegion != null)
            {
                this.saveRegion = saveMeRegion.Clone();
            }
        }
コード例 #7
0
        public static PdnGraphicsPath FromRegions(PdnRegion lhs, CombineMode combineMode, PdnRegion rhs)
        {
            Rectangle   lhsBounds = lhs.GetBoundsInt();
            Rectangle   rhsBounds = rhs.GetBoundsInt();
            int         left      = Math.Min(lhsBounds.Left, rhsBounds.Left);
            int         top       = Math.Min(lhsBounds.Top, rhsBounds.Top);
            int         right     = Math.Max(lhsBounds.Right, rhsBounds.Right);
            int         bottom    = Math.Max(lhsBounds.Bottom, rhsBounds.Bottom);
            Rectangle   bounds    = Rectangle.FromLTRB(left, top, right, bottom);
            BitVector2D stencil   = new BitVector2D(bounds.Width, bounds.Height);

            Rectangle[] lhsScans = lhs.GetRegionScansReadOnlyInt();
            Rectangle[] rhsScans = rhs.GetRegionScansReadOnlyInt();

            switch (combineMode)
            {
            case CombineMode.Complement:
            case CombineMode.Intersect:
            case CombineMode.Replace:
                throw new ArgumentException("combineMode can't be Complement, Intersect, or Replace");

            default:
                break;
            }

            for (int i = 0; i < lhsScans.Length; ++i)
            {
                Rectangle rect = lhsScans[i];
                rect.X -= bounds.X;
                rect.Y -= bounds.Y;

                stencil.SetUnchecked(rect, true);
            }

            for (int i = 0; i < rhsScans.Length; ++i)
            {
                Rectangle rect = rhsScans[i];
                rect.X -= bounds.X;
                rect.Y -= bounds.Y;

                switch (combineMode)
                {
                case CombineMode.Xor:
                    stencil.InvertUnchecked(rect);
                    break;

                case CombineMode.Union:
                    stencil.SetUnchecked(rect, true);
                    break;

                case CombineMode.Exclude:
                    stencil.SetUnchecked(rect, false);
                    break;
                }
            }

            PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height));

            using (Matrix matrix = new Matrix())
            {
                matrix.Reset();
                matrix.Translate(bounds.X, bounds.Y);
                path.Transform(matrix);
            }

            return(path);
        }