QuickFont.JBitmap.Blit C# (CSharp) Method

Blit() public method

public Blit ( JBitmap target, int px, int py ) : void
target JBitmap
px int
py int
return void
        public void Blit(JBitmap target, int px, int py)
        {




            if (target.format != format)
            {
                throw new Exception("Attempted to blit between bitmaps not of the same format");
            }

            int bpp = (int)format;

            int targetStartX, targetEndX;
            int targetStartY, targetEndY;
            int copyW, copyH;

            targetStartX = Math.Max(px, 0);
            targetEndX = Math.Min(px + bitmapData.Width, target.bitmapData.Width);

            targetStartY = Math.Max(py, 0);
            targetEndY = Math.Min(py + bitmapData.Height, target.bitmapData.Height);

            copyW = targetEndX - targetStartX;
            copyH = targetEndY - targetStartY;

            if (copyW < 0)
            {
                return;
            }

            if (copyH < 0)
            {
                return;
            }

            int sourceStartX = targetStartX - px;
            int sourceStartY = targetStartY - py;


            unsafe
            {
                byte* sourcePtr = (byte*)(bitmapData.Scan0);
                byte* targetPtr = (byte*)(target.bitmapData.Scan0);


                byte* targetY = targetPtr + targetStartY * target.bitmapData.Stride;
                byte* sourceY = sourcePtr + sourceStartY * bitmapData.Stride;
                for (int y = 0; y < copyH; y++, targetY += target.bitmapData.Stride, sourceY += bitmapData.Stride)
                {

                    byte* targetOffset = targetY + targetStartX*bpp;
                    byte* sourceOffset = sourceY + sourceStartX*bpp;
                    for (int x = 0; x < copyW*bpp; x++, targetOffset++, sourceOffset++)
                    {
                        *(targetOffset) = *(sourceOffset);

                    }

                }
            }



        }

Same methods

JBitmap::Blit ( JBitmap target, int srcPx, int srcPy, int srcW, int srcH, int px, int py ) : void