Apachai.Effects.Core.PixelOp.ApplyBase C# (CSharp) Method

ApplyBase() public method

Provides a default implementation for performing dst = F(dst, src) or F(src) over some rectangle of interest. May be slightly faster than calling the other multi-parameter Apply method, as less variables are used in the implementation, thus inducing less register pressure.
public ApplyBase ( FastBitmap dst, Point dstOffset, FastBitmap src, Point srcOffset, Size roiSize ) : void
dst System.Drawing.FastBitmap The Surface to write pixels to, and from which pixels are read and used as the lhs parameter for calling the method PixelData Apply(PixelData, PixelData).
dstOffset Point The pixel offset that defines the upper-left of the rectangle-of-interest for the dst Surface.
src System.Drawing.FastBitmap The Surface to read pixels from for the rhs parameter given to the method PixelData Apply(PixelData, PixelData)b>.
srcOffset Point The pixel offset that defines the upper-left of the rectangle-of-interest for the src Surface.
roiSize System.Drawing.Size The size of the rectangles-of-interest for all Surfaces.
return void
        public void ApplyBase(FastBitmap dst, Point dstOffset, FastBitmap src, Point srcOffset, Size roiSize)
        {
            // Create bounding rectangles for each Surface
            Rectangle dstRect = new Rectangle (dstOffset, roiSize);

            if (dstRect.Width == 0 || dstRect.Height == 0)
                return;

            Rectangle srcRect = new Rectangle (srcOffset, roiSize);

            if (srcRect.Width == 0 || srcRect.Height == 0)
                return;

            // Clip those rectangles to those Surface's bounding rectangles
            Rectangle dstClip = Rectangle.Intersect (dstRect, dst.GetBounds ());
            Rectangle srcClip = Rectangle.Intersect (srcRect, src.GetBounds ());

            // If any of those Rectangles actually got clipped, then throw an exception
            if (dstRect != dstClip)
                throw new ArgumentOutOfRangeException
                (
                    "roiSize",
                    "Destination roi out of bounds" +
                    string.Format (", dst.Size=({0},{1}", dst.Width, dst.Height) +
                    ", dst.Bounds=" + dst.GetBounds ().ToString () +
                    ", dstOffset=" + dstOffset.ToString () +
                    string.Format (", src.Size=({0},{1}", src.Width, src.Height) +
                    ", srcOffset=" + srcOffset.ToString () +
                    ", roiSize=" + roiSize.ToString () +
                    ", dstRect=" + dstRect.ToString () +
                    ", dstClip=" + dstClip.ToString () +
                    ", srcRect=" + srcRect.ToString () +
                    ", srcClip=" + srcClip.ToString ()
                );

            if (srcRect != srcClip)
                throw new ArgumentOutOfRangeException ("roiSize", "Source roi out of bounds");

            // Cache the width and height properties
            int width = roiSize.Width;
            int height = roiSize.Height;

            // Do the work.
            unsafe {
                for (int row = 0; row < roiSize.Height; ++row) {
                    PixelData* dstPtr = dst.GetPointAddress (dstOffset.X, dstOffset.Y + row);
                    PixelData* srcPtr = src.GetPointAddress (srcOffset.X, srcOffset.Y + row);
                    Apply (dstPtr, srcPtr, width);
                }
            }
        }