Esempio n. 1
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);
                    }
                }
            }
        }
Esempio n. 2
0
        private unsafe void RenderContent(ISurface <ColorBgra> dstContent, PointInt32 renderOffset)
        {
            int        width         = dstContent.Width;
            int        height        = dstContent.Height;
            int        stride        = dstContent.Stride;
            int        num4          = stride - (width * 4);
            RectInt32  num5          = RectInt32.Intersect(this.srcCoverageBounds, new RectInt32(0, 0, this.contentWidth, this.contentHeight));
            int        left          = num5.Left;
            int        top           = num5.Top;
            int        right         = num5.Right;
            int        bottom        = num5.Bottom;
            long       num10         = (this.srcOffsetOriginXFp + (renderOffset.X * this.srcOffsetDxDxFp)) + (renderOffset.Y * this.srcOffsetDxDyFp);
            long       num11         = (this.srcOffsetOriginYFp + (renderOffset.X * this.srcOffsetDyDxFp)) + (renderOffset.Y * this.srcOffsetDyDyFp);
            ColorBgra *bgraPtr       = this.contentScan0;
            int        contentStride = this.contentStride;
            ColorBgra *bgraPtr2      = (ColorBgra *)dstContent.Scan0;
            ColorBgra *bgraPtr3      = bgraPtr2 + width;

            for (int i = 0; i < height; i++)
            {
                uint num16;
                int  num17;
                base.ThrowIfCancellationRequested();
                long       num14    = num10;
                long       num15    = num11;
                ColorBgra *bgraPtr4 = bgraPtr3 - width;
                int        num18    = (int)((long)((bgraPtr3 - bgraPtr4) / sizeof(ColorBgra)));
                int        num19    = (int)(num14 >> 0x18);
                int        num20    = (int)(num15 >> 0x18);
                int        num21    = ((num19 >= left) && (num19 < right)) ? 1 : 0;
                int        num22    = ((num20 >= top) && (num20 < bottom)) ? 1 : 0;
                int        num23    = ((num19 >= (left - 1)) && (num19 < (right - 1))) ? 1 : 0;
                int        num24    = ((num20 >= (top - 1)) && (num20 < (bottom - 1))) ? 1 : 0;
                long       num25    = num14 + (this.srcOffsetDxDxFp * num18);
                long       num26    = num15 + (this.srcOffsetDyDxFp * num18);
                int        num27    = (int)(num25 >> 0x18);
                int        num28    = (int)(num26 >> 0x18);
                int        num29    = ((num27 >= left) && (num27 < right)) ? 1 : 0;
                int        num30    = ((num28 >= top) && (num28 < bottom)) ? 1 : 0;
                int        num31    = ((num27 >= (left - 1)) && (num27 < (right - 1))) ? 1 : 0;
                int        num32    = ((num28 >= (top - 1)) && (num28 < (bottom - 1))) ? 1 : 0;
                if ((((((((num21 + num22) + num23) + num24) + num29) + num30) + num31) + num32) == 8)
                {
                    num17 = num18;
                }
                else
                {
                    num17 = 0;
                }
                while ((bgraPtr4 < bgraPtr3) && (num17 > 0))
                {
                    num16 = 0;
                    int         num33 = (int)(num14 >> 0x18);
                    int         num34 = (int)(num15 >> 0x18);
                    int         num35 = 0x100 - (((int)(num14 & 0xffffffL)) >> 0x10);
                    int         num36 = 0x100 - (((int)(num15 & 0xffffffL)) >> 0x10);
                    int         num37 = (num35 * num36) >> 8;
                    int         num38 = ((0x100 - num35) * num36) >> 8;
                    int         num39 = (num35 * (0x100 - num36)) >> 8;
                    int         num40 = ((0x100 - num35) * (0x100 - num36)) >> 8;
                    int         num41 = num37;
                    int         num42 = num38;
                    int         num43 = num39;
                    int         num44 = num40;
                    ushort      d     = (ushort)(((num41 + num42) + num43) + num44);
                    long        num46 = (num34 * contentStride) + (num33 * 4);
                    ColorBgra32 bgra  = *((ColorBgra32 *)(bgraPtr + num46));
                    ColorBgra32 bgra2 = *((ColorBgra32 *)(bgraPtr + (num46 + 4L)));
                    ColorBgra32 bgra3 = *((ColorBgra32 *)(bgraPtr + (num46 + contentStride)));
                    ColorBgra32 bgra4 = *((ColorBgra32 *)(bgraPtr + ((num46 + contentStride) + 4L)));
                    int         num47 = bgra.A * num41;
                    int         num48 = bgra2.A * num42;
                    int         num49 = bgra3.A * num43;
                    int         num50 = bgra4.A * num44;
                    ushort      n     = (ushort)(((num47 + num48) + num49) + num50);
                    if (n != 0)
                    {
                        uint num52 = UInt32Util.FastDivideByUInt16(n, d);
                        uint num53 = UInt32Util.FastDivideByUInt16((uint)((((num47 * bgra.B) + (num48 * bgra2.B)) + (num49 * bgra3.B)) + (num50 * bgra4.B)), n);
                        uint num54 = UInt32Util.FastDivideByUInt16((uint)((((num47 * bgra.G) + (num48 * bgra2.G)) + (num49 * bgra3.G)) + (num50 * bgra4.G)), n);
                        uint num55 = UInt32Util.FastDivideByUInt16((uint)((((num47 * bgra.R) + (num48 * bgra2.R)) + (num49 * bgra3.R)) + (num50 * bgra4.R)), n);
                        num16 = ColorBgra.BgraToUInt32((byte)num53, (byte)num54, (byte)num55, (byte)num52);
                    }
                    bgraPtr4->Bgra = num16;
                    num14         += this.srcOffsetDxDxFp;
                    num15         += this.srcOffsetDyDxFp;
                    bgraPtr4++;
                    num17--;
                }
                while (bgraPtr4 < bgraPtr3)
                {
                    num16 = 0;
                    int num56 = (int)(num14 >> 0x18);
                    int num57 = (int)(num15 >> 0x18);
                    int num58 = ((num56 >= left) && (num56 < right)) ? 1 : 0;
                    int num59 = ((num57 >= top) && (num57 < bottom)) ? 1 : 0;
                    int num60 = ((num56 >= (left - 1)) && (num56 < (right - 1))) ? 1 : 0;
                    int num61 = ((num57 >= (top - 1)) && (num57 < (bottom - 1))) ? 1 : 0;
                    int num62 = num59 * num58;
                    int num63 = num59 * num60;
                    int num64 = num61 * num58;
                    int num65 = num61 * num60;
                    if ((((num62 + num63) + num64) + num65) != 0)
                    {
                        int         num67 = 0x100 - (((int)(num14 & 0xffffffL)) >> 0x10);
                        int         num68 = 0x100 - (((int)(num15 & 0xffffffL)) >> 0x10);
                        int         num69 = (num67 * num68) >> 8;
                        int         num70 = ((0x100 - num67) * num68) >> 8;
                        int         num71 = (num67 * (0x100 - num68)) >> 8;
                        int         num72 = ((0x100 - num67) * (0x100 - num68)) >> 8;
                        int         num73 = num62 * num69;
                        int         num74 = num63 * num70;
                        int         num75 = num64 * num71;
                        int         num76 = num65 * num72;
                        ushort      num77 = (ushort)(((num73 + num74) + num75) + num76);
                        long        num78 = (num57 * contentStride) + (num56 * 4);
                        ColorBgra32 bgra5 = *((ColorBgra32 *)(bgraPtr + (num78 * num62)));
                        ColorBgra32 bgra6 = *((ColorBgra32 *)(bgraPtr + ((num78 + 4L) * num63)));
                        ColorBgra32 bgra7 = *((ColorBgra32 *)(bgraPtr + ((num78 + contentStride) * num64)));
                        ColorBgra32 bgra8 = *((ColorBgra32 *)(bgraPtr + (((num78 + contentStride) + 4L) * num65)));
                        int         num79 = bgra5.A * num73;
                        int         num80 = bgra6.A * num74;
                        int         num81 = bgra7.A * num75;
                        int         num82 = bgra8.A * num76;
                        ushort      num83 = (ushort)(((num79 + num80) + num81) + num82);
                        if (num83 != 0)
                        {
                            uint num84 = UInt32Util.FastDivideByUInt16(num83, num77);
                            uint num85 = UInt32Util.FastDivideByUInt16((uint)((((num79 * bgra5.B) + (num80 * bgra6.B)) + (num81 * bgra7.B)) + (num82 * bgra8.B)), num83);
                            uint num86 = UInt32Util.FastDivideByUInt16((uint)((((num79 * bgra5.G) + (num80 * bgra6.G)) + (num81 * bgra7.G)) + (num82 * bgra8.G)), num83);
                            uint num87 = UInt32Util.FastDivideByUInt16((uint)((((num79 * bgra5.R) + (num80 * bgra6.R)) + (num81 * bgra7.R)) + (num82 * bgra8.R)), num83);
                            num16 = ColorBgra.BgraToUInt32((byte)num85, (byte)num86, (byte)num87, (byte)num84);
                        }
                    }
                    bgraPtr4->Bgra = num16;
                    num14         += this.srcOffsetDxDxFp;
                    num15         += this.srcOffsetDyDxFp;
                    bgraPtr4++;
                }
                num10    += this.srcOffsetDxDyFp;
                num11    += this.srcOffsetDyDyFp;
                bgraPtr3 += stride;
            }
        }
        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;
            }
        }