Esempio n. 1
0
 private static unsafe void RenderWithClipMask(Effect effect, EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, IRenderer <ColorAlpha8> clipMaskRenderer)
 {
     effect.Render(token, dstArgs, srcArgs, rois);
     if (!effect.IsCancelRequested && (clipMaskRenderer != null))
     {
         RectInt32 bounds = RectangleUtil.Bounds(rois).ToRectInt32();
         if (bounds.HasPositiveArea)
         {
             using (ISurface <ColorAlpha8> surface = clipMaskRenderer.UseTileOrToSurface(bounds))
             {
                 int        width        = bounds.Width;
                 int        height       = bounds.Height;
                 int        left         = bounds.Left;
                 int        top          = bounds.Top;
                 int        bottom       = bounds.Bottom;
                 int        stride       = dstArgs.Surface.Stride;
                 int        num8         = srcArgs.Surface.Stride;
                 int        num9         = surface.Stride;
                 ColorBgra *pointAddress = dstArgs.Surface.GetPointAddress(left, top);
                 ColorBgra *bgraPtr2     = srcArgs.Surface.GetPointAddress(left, top);
                 byte *     numPtr       = (byte *)surface.Scan0;
                 for (int i = height; i > 0; i--)
                 {
                     ColorBgra.Underwrite(bgraPtr2, pointAddress, numPtr, width);
                     pointAddress += stride;
                     bgraPtr2     += num8;
                     numPtr       += num9;
                 }
             }
         }
     }
 }
Esempio n. 2
0
        private static unsafe void RenderWithClipMask(
            Effect effect,
            EffectConfigToken token,
            RenderArgs dstArgs,
            RenderArgs srcArgs,
            Rectangle[] rois,
            IRenderer <ColorAlpha8> clipMaskRenderer)
        {
            // Render the effect
            effect.Render(token, dstArgs, srcArgs, rois);

            if (effect.IsCancelRequested)
            {
                return;
            }

            if (clipMaskRenderer != null)
            {
                RectInt32 bounds = RectangleUtil.Bounds(rois).ToRectInt32();

                if (bounds.HasPositiveArea)
                {
                    // dstArgs = (srcArgs * (1 - clipMask)) + (dstArgs * clipMask)
                    // TODO: optimize, or at least refactor into its own method
                    using (ISurface <ColorAlpha8> clipMask = clipMaskRenderer.UseTileOrToSurface(bounds))
                    {
                        int width  = bounds.Width;
                        int height = bounds.Height;
                        int left   = bounds.Left;
                        int top    = bounds.Top;
                        int bottom = bounds.Bottom;

                        int dstStride      = dstArgs.Surface.Stride;
                        int srcStride      = srcArgs.Surface.Stride;
                        int clipMaskStride = clipMask.Stride;

                        ColorBgra *dstNextRowPtr      = dstArgs.Surface.GetPointAddress(left, top);
                        ColorBgra *srcNextRowPtr      = srcArgs.Surface.GetPointAddress(left, top);
                        byte *     clipMaskNextRowPtr = (byte *)clipMask.Scan0;

                        int rows = height;
                        while (rows > 0)
                        {
                            ColorBgra.Underwrite(srcNextRowPtr, dstNextRowPtr, clipMaskNextRowPtr, width);

                            dstNextRowPtr      = (ColorBgra *)((byte *)dstNextRowPtr + dstStride);
                            srcNextRowPtr      = (ColorBgra *)((byte *)srcNextRowPtr + srcStride);
                            clipMaskNextRowPtr = clipMaskNextRowPtr + clipMaskStride;
                            --rows;
                        }
                    }
                }
            }
        }