/// <summary> /// Causes a portion of the layer surface to be invalidated. /// </summary> /// <param name="roi">The region of interest to be invalidated.</param> public void Invalidate(PdnRegion roi) { foreach (Rectangle rect in roi.GetRegionScansReadOnlyInt()) { Invalidate(rect); } }
public static PdnGraphicsPath FromRegion(PdnRegion region) { Rectangle bounds = region.GetBoundsInt(); Rectangle[] scans = region.GetRegionScansReadOnlyInt(); 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); }
public void Set(PdnRegion region, bool newValue) { foreach (Rectangle rect in region.GetRegionScansReadOnlyInt()) { Set(rect, newValue); } }
public void Invert(PdnRegion region) { foreach (Rectangle rect in region.GetRegionScansReadOnlyInt()) { Invert(rect); } }
public void UpdateHistogram(Surface surface, PdnRegion roi) { Clear(); foreach (Rectangle rect in roi.GetRegionScansReadOnlyInt()) { AddSurfaceRectangleToHistogram(surface, rect); } OnHistogramUpdated(); }
/// <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); }
/// <summary> /// Constructs an IrregularSurface 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 IrregularSurface(Surface source, PdnRegion roi) { PdnRegion roiClipped = (PdnRegion)roi.Clone(); roiClipped.Intersect(source.Bounds); Rectangle[] rects = roiClipped.GetRegionScansReadOnlyInt(); this.placedSurfaces = new ArrayList(rects.Length); foreach (Rectangle rect in rects) { this.placedSurfaces.Add(new PlacedSurface(source, rect)); } this.region = roiClipped; }
protected override void OnPaint(PaintEventArgs e) { if (this.surface != null) { PdnRegion clipRegion = null; Rectangle[] rects = this.realUpdateRects; if (rects == null) { clipRegion = new PdnRegion(e.Graphics.Clip, true); clipRegion.Intersect(e.ClipRectangle); rects = clipRegion.GetRegionScansReadOnlyInt(); } if (this.justPaintWhite > 0) { PdnGraphics.FillRectangles(e.Graphics, Color.White, rects); Invalidate(); } else { foreach (Rectangle rect in rects) { if (e.Graphics.IsVisible(rect)) { PaintEventArgs2 e2 = new PaintEventArgs2(e.Graphics, rect); OnPaintImpl(e2); } } } if (clipRegion != null) { clipRegion.Dispose(); clipRegion = null; } } if (this.justPaintWhite > 0) { --this.justPaintWhite; } base.OnPaint(e); }
/// <summary> /// Copies a region of the given surface to this surface. /// </summary> /// <param name="source">The surface to copy pixels from.</param> /// <param name="region">The region to clip copying to.</param> /// <remarks> /// The upper left corner of the source surface will be mapped to the upper left of this /// surface, and only those pixels that are defined by the region will be copied. /// The source surface does not need to have the same dimensions as this surface. Clipping /// will be handled automatically. No resizing will be done. /// </remarks> public void CopySurface(Surface source, PdnRegion region) { if (disposed) { throw new ObjectDisposedException("Surface"); } Rectangle[] scans = region.GetRegionScansReadOnlyInt(); for (int i = 0; i < scans.Length; ++i) { Rectangle rect = scans[i]; rect.Intersect(this.Bounds); rect.Intersect(source.Bounds); if (rect.Width == 0 || rect.Height == 0) { continue; } unsafe { for (int y = rect.Top; y < rect.Bottom; ++y) { ColorBgra *dst = this.GetPointAddressUnchecked(rect.Left, y); ColorBgra *src = source.GetPointAddressUnchecked(rect.Left, y); Memory.Copy(dst, src, (ulong)rect.Width * (ulong)ColorBgra.SizeOf); } } } }
/// <summary> /// Invalidates a portion of the document. The given region is then tagged /// for rerendering during the next call to Update. /// </summary> /// <param name="roi">The region of interest to be invalidated.</param> public void Invalidate(PdnRegion roi) { Dirty = true; foreach (Rectangle rect in roi.GetRegionScansReadOnlyInt()) { rect.Intersect(this.Bounds); updateRegion.Add(rect); if (!rect.IsEmpty) { InvalidateEventArgs iea = new InvalidateEventArgs(rect); OnInvalidated(iea); } } }
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); }
public void Apply(Surface surface, PdnRegion roi) { Apply(surface, roi.GetRegionScansReadOnlyInt()); }
public void Clear(PdnRegion region, ColorBgra color) { foreach (Rectangle rect in region.GetRegionScansReadOnlyInt()) { Clear(rect, color); } }
protected override void OnPaint(PaintEventArgs e) { if (this.surface != null) { PdnRegion clipRegion = null; Rectangle[] rects = this.realUpdateRects; if (rects == null) { clipRegion = new PdnRegion(e.Graphics.Clip, true); clipRegion.Intersect(e.ClipRectangle); rects = clipRegion.GetRegionScansReadOnlyInt(); } if (this.justPaintWhite > 0) { PdnGraphics.FillRectangles(e.Graphics, Color.White, rects); } else { foreach (Rectangle rect in rects) { if (e.Graphics.IsVisible(rect)) { PaintEventArgs2 e2 = new PaintEventArgs2(e.Graphics, rect); OnPaintImpl(e2); } } } if (clipRegion != null) { clipRegion.Dispose(); clipRegion = null; } } if (this.justPaintWhite > 0) { --this.justPaintWhite; } base.OnPaint(e); }
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; } }
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; }
private void RenderGradient(Surface surface, PdnRegion clipRegion, CompositingMode compositingMode, PointF startPointF, ColorBgra startColor, PointF endPointF, ColorBgra endColor) { GradientRenderer gr = AppEnvironment.GradientInfo.CreateGradientRenderer(); gr.StartColor = startColor; gr.EndColor = endColor; gr.StartPoint = startPointF; gr.EndPoint = endPointF; gr.AlphaBlending = (compositingMode == CompositingMode.SourceOver); gr.BeforeRender(); Rectangle[] oldRois = clipRegion.GetRegionScansReadOnlyInt(); Rectangle[] newRois; if (oldRois.Length == 1) { newRois = new Rectangle[Processor.LogicalCpuCount]; Utility.SplitRectangle(oldRois[0], newRois); } else { newRois = oldRois; } RenderContext rc = new RenderContext(); rc.surface = surface; rc.rois = newRois; rc.renderer = gr; WaitCallback wc = new WaitCallback(rc.Render); for (int i = 0; i < Processor.LogicalCpuCount; ++i) { if (i == Processor.LogicalCpuCount - 1) { wc(BoxedConstants.GetInt32(i)); } else { PaintDotNet.Threading.ThreadPool.Global.QueueUserWorkItem(wc, BoxedConstants.GetInt32(i)); } } PaintDotNet.Threading.ThreadPool.Global.Drain(); }