public unsafe void Render(ISurface <ColorAlpha8> dst, PointInt32 renderOffset)
        {
            int width     = dst.Width;
            int height    = dst.Height;
            int stride    = dst.Stride;
            int x         = renderOffset.X * 3;
            int y         = renderOffset.Y * 3;
            int dstWidth  = width * 3;
            int dstHeight = height * 3;
            IMaskFromScansRenderer source = this.source as IMaskFromScansRenderer;

            if (source != null)
            {
                ISurface <ColorAlpha8> surface = null;
                try
                {
                    int?nullable;
                    source.Render(alpha8Allocator, dstWidth, dstHeight, new PointInt32(x, y), ref surface, out nullable);
                    if (nullable.HasValue)
                    {
                        if (nullable.GetValueOrDefault() != 0)
                        {
                            if (nullable.GetValueOrDefault() != (dstWidth * dstHeight))
                            {
                                throw new UnreachableCodeException();
                            }
                            dst.Clear(ColorAlpha8.Opaque);
                        }
                        else
                        {
                            dst.Clear(ColorAlpha8.Transparent);
                        }
                    }
                    else
                    {
                        RenderingKernels.ResizeBoxFilterOneThirdAlpha8((byte *)dst.Scan0, width, height, stride, (byte *)surface.Scan0, dstWidth, dstHeight, surface.Stride);
                    }
                }
                finally
                {
                    DisposableUtil.Free <ISurface <ColorAlpha8> >(ref surface);
                }
            }
            else
            {
                using (ISurface <ColorAlpha8> surface2 = this.source.UseTileOrToSurface(new RectInt32(x, y, dstWidth, dstHeight)))
                {
                    RenderingKernels.ResizeBoxFilterOneThirdAlpha8((byte *)dst.Scan0, width, height, stride, (byte *)surface2.Scan0, dstWidth, dstHeight, surface2.Stride);
                }
            }
        }
Ejemplo n.º 2
0
        public void RenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
        {
            RectInt32 sourceRect = new RectInt32(renderOffset, dstMask.Size <ColorAlpha8>());

            if (Interlocked.Exchange(ref this.haveFetchedStamp, 1) == 0)
            {
                this.lazyStampMaskDevBitmap.EnsureEvaluated();
            }
            foreach (PointInt32 num2 in this.tileMathHelper.EnumerateTileOffsets(sourceRect))
            {
                TileData               tileData       = this.GetTileData(num2);
                RectInt32              tileSourceRect = this.tileMathHelper.GetTileSourceRect(num2);
                RectInt32              num4           = RectInt32.Intersect(tileSourceRect, sourceRect);
                PointInt32             num5           = new PointInt32(num4.X - tileSourceRect.X, num4.Y - tileSourceRect.Y);
                RectInt32              bounds         = new RectInt32(num4.X - sourceRect.X, num4.Y - sourceRect.Y, num4.Width, num4.Height);
                ISurface <ColorAlpha8> surface        = dstMask.CreateWindow <ColorAlpha8>(bounds);
                object sync = tileData.Sync;
                lock (sync)
                {
                    this.UpdateTileWhileLocked(tileData);
                    if (tileData.Mask == null)
                    {
                        surface.Clear();
                    }
                    else
                    {
                        tileData.Mask.Render(surface, num5);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Render(ISurface <TPixel> dst, PointInt32 renderOffset)
        {
            dst.Clear <TPixel>();
            SizeInt32  size     = dst.Size <TPixel>();
            RectInt32  num2     = new RectInt32(renderOffset, size);
            PointInt32 location = new PointInt32(renderOffset.X - this.offset.X, renderOffset.Y - this.offset.Y);
            RectInt32  a        = new RectInt32(location, size);
            RectInt32  num5     = RectInt32.Intersect(a, this.source.Bounds <TPixel>());

            if (num5.HasPositiveArea)
            {
                PointInt32 num6   = new PointInt32(num5.X - a.X, num5.Y - a.Y);
                RectInt32  bounds = new RectInt32(num6, num5.Size);
                if (bounds.Location.IsZero && (bounds.Size == size))
                {
                    this.source.Render(dst, location);
                }
                else
                {
                    using (ISurface <TPixel> surface = dst.CreateWindow <TPixel>(bounds))
                    {
                        this.source.Render(surface, num5.Location);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static ISurface <ColorAlpha8> UseTileOrToSurfaceWithEdgePadding(IRenderer <ColorAlpha8> source, RectInt32 bounds, ColorAlpha8 padding)
        {
            if (source.Bounds <ColorAlpha8>().Contains(bounds))
            {
                return(source.UseTileOrToSurface(bounds));
            }
            ISurface <ColorAlpha8> surface = SurfaceAllocator.Alpha8.Allocate <ColorAlpha8>(bounds.Size, AllocationOptions.ZeroFillNotRequired);

            surface.Clear(padding);
            RectInt32  num2     = RectInt32.Intersect(source.Bounds <ColorAlpha8>(), bounds);
            PointInt32 location = new PointInt32(num2.Location.X - bounds.Location.X, num2.Location.Y - bounds.Location.Y);
            RectInt32  num4     = new RectInt32(location, num2.Size);

            using (ISurfaceWindow <ColorAlpha8> window = surface.CreateWindow <ColorAlpha8>(num4))
            {
                source.Render(window, num2.Location);
            }
            return(surface);
        }
Ejemplo n.º 5
0
        public void RenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset, ICancellationToken cancelToken)
        {
            Validate.Begin().IsNotNull <ISurface <ColorAlpha8> >(dstMask, "dstMask").IsNotNull <ICancellationToken>(cancelToken, "cancelToken").Check();
            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            RectInt32 sourceRect = new RectInt32(renderOffset, dstMask.Size <ColorAlpha8>());

            if (Interlocked.Exchange(ref this.haveFetchedStamp, 1) == 0)
            {
                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                this.lazyStampMaskDevBitmap.EnsureEvaluated();
            }
            foreach (PointInt32 num2 in this.tileMathHelper.EnumerateTileOffsets(sourceRect))
            {
                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                TileData               tileData       = this.GetTileData(num2);
                RectInt32              tileSourceRect = this.tileMathHelper.GetTileSourceRect(num2);
                RectInt32              num4           = RectInt32.Intersect(tileSourceRect, sourceRect);
                PointInt32             num5           = new PointInt32(num4.X - tileSourceRect.X, num4.Y - tileSourceRect.Y);
                RectInt32              bounds         = new RectInt32(num4.X - sourceRect.X, num4.Y - sourceRect.Y, num4.Width, num4.Height);
                ISurface <ColorAlpha8> surface        = dstMask.CreateWindow <ColorAlpha8>(bounds);
                object sync = tileData.Sync;
                lock (sync)
                {
                    cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                    this.UpdateTileWhileLocked(tileData, cancelToken);
                    cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                    if (tileData.Mask == null)
                    {
                        surface.Clear();
                    }
                    else
                    {
                        tileData.Mask.Render(surface, num5);
                    }
                }
                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            }
        }
Ejemplo n.º 6
0
 private void RenderFlattenedDocument(Document input, ISurface <ColorBgra> dst)
 {
     dst.Clear(ColorBgra.Zero);
     input.CreateRenderer().Parallelize <ColorBgra>(TilingStrategy.HorizontalSlices, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(dst);
 }
Ejemplo n.º 7
0
 protected override void OnRenderContent(ISurface <ColorBgra> dstContent, PointInt32 renderOffset)
 {
     dstContent.Clear();
 }
Ejemplo n.º 8
0
        private void RenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
        {
            int       width     = dstMask.Width;
            int       height    = dstMask.Height;
            bool      flag      = false;
            SizeInt32 size      = new SizeInt32(width, height);
            RectInt32 rectangle = new RectInt32(renderOffset, size);

            if (!flag && this.matrix.HasInverse)
            {
                Matrix3x2Double inverse           = this.matrix.Inverse;
                PointDouble     pt                = inverse.Transform(rectangle.TopLeft);
                PointDouble     num7              = inverse.Transform(rectangle.TopRight);
                PointDouble     num8              = inverse.Transform(rectangle.BottomLeft);
                PointDouble     num9              = inverse.Transform(rectangle.BottomRight);
                RectDouble      srcCoverageBounds = this.srcCoverageBounds;
                if ((srcCoverageBounds.Contains(pt) && srcCoverageBounds.Contains(num7)) && (srcCoverageBounds.Contains(num8) && srcCoverageBounds.Contains(num9)))
                {
                    dstMask.Clear(ColorAlpha8.Opaque);
                    flag = true;
                }
            }
            if (!flag)
            {
                GeometryRelation relation;
                IDirect2DFactory perThread = Direct2DFactory.PerThread;
                using (IRectangleGeometry geometry = perThread.CreateRectangleGeometry(rectangle))
                {
                    base.ThrowIfCancellationRequested();
                    using (IRectangleGeometry geometry2 = perThread.CreateRectangleGeometry(this.srcCoverageBounds))
                    {
                        base.ThrowIfCancellationRequested();
                        relation = geometry.CompareWithGeometry(geometry2, new Matrix3x2Float?((Matrix3x2Float)this.matrix), null);
                        base.ThrowIfCancellationRequested();
                    }
                }
                switch (relation)
                {
                case GeometryRelation.IsContained:
                    dstMask.Clear(ColorAlpha8.Opaque);
                    flag = true;
                    break;

                case GeometryRelation.Disjoint:
                    dstMask.Clear(ColorAlpha8.Transparent);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                using (IDrawingContext context = DrawingContext.FromSurface(dstMask, FactorySource.PerThread))
                {
                    base.ThrowIfCancellationRequested();
                    context.Clear(null);
                    context.AntialiasMode = AntialiasMode.PerPrimitive;
                    using (context.UseTranslateTransform((float)-renderOffset.X, (float)-renderOffset.Y, MatrixMultiplyOrder.Prepend))
                    {
                        using (context.UseTransformMultiply((Matrix3x2Float)this.matrix, MatrixMultiplyOrder.Prepend))
                        {
                            context.FillRectangle(this.srcCoverageBounds, whiteBrush);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public unsafe void Render(ISurfaceAllocator <ColorAlpha8> allocator, int dstWidth, int dstHeight, PointInt32 renderOffset, ref ISurface <ColorAlpha8> dst, out int?fill255Count)
        {
            int stride;

            if ((allocator == null) && (dst == null))
            {
                throw new ArgumentException();
            }
            if (dst != null)
            {
                dst.Clear(ColorAlpha8.Transparent);
            }
            int       x               = renderOffset.X;
            int       y               = renderOffset.Y;
            int       right           = renderOffset.X + dstWidth;
            int       bottom          = renderOffset.Y + dstHeight;
            RectInt32 a               = RectInt32.FromEdges(x, y, right, bottom);
            int       count           = this.scans.Count;
            int       scansStartIndex = this.GetScansStartIndex(y, bottom);

Label_006C:
            stride = -1;
            byte *numPtr = null;

            if (dst != null)
            {
                stride = dst.Stride;
                numPtr = (byte *)dst.Scan0;
            }
            int num9 = 0;

            for (int i = scansStartIndex; i < count; i++)
            {
                RectInt32 scanAt = this.GetScanAt(i);
                if (scanAt.Y >= bottom)
                {
                    break;
                }
                int       left  = Math.Max(x, scanAt.X);
                int       top   = Math.Max(y, scanAt.Y);
                int       num14 = Math.Min(right, scanAt.X + scanAt.Width);
                int       num15 = Math.Min(bottom, scanAt.Y + scanAt.Height);
                RectInt32 b     = RectInt32.FromEdges(left, top, num14, num15);
                if (RectInt32.Intersect(a, b).HasPositiveArea)
                {
                    uint num18 = (uint)(num14 - left);
                    int  num19 = left - renderOffset.X;
                    int  num20 = num14 - renderOffset.X;
                    if (dst == null)
                    {
                        num9 += (int)((num15 - top) * num18);
                    }
                    else
                    {
                        byte *prgBuffer = numPtr + ((byte *)(((top - renderOffset.Y) * stride) + num19));
                        for (int j = top; j < num15; j++)
                        {
                            Memory.FillMemory(prgBuffer, 0xff, (ulong)num18);
                            prgBuffer += stride;
                        }
                    }
                }
            }
            if (((dst != null) || (num9 == 0)) || (num9 == (dstWidth * dstHeight)))
            {
                if (dst == null)
                {
                    fill255Count = new int?(num9);
                }
                else
                {
                    fill255Count = 0;
                }
            }
            else
            {
                dst = allocator.Allocate(dstWidth, dstHeight, AllocationOptions.Default);
                goto Label_006C;
            }
        }
Ejemplo n.º 10
0
 public static void Clear()
 {
     _surface.Clear();
 }