Beispiel #1
0
 public static void Blit(LockedBitmap source, LockedBitmap target, System.Drawing.Rectangle srcRect, int destX, int destY)
 {
     for (int sx = srcRect.X, dx = destX; sx < srcRect.X + srcRect.Width; sx++, dx++)
     {
         for (int sy = srcRect.Y, dy = destY; sy < srcRect.Y + srcRect.Height; sy++, dy++)
         {
             Color sourcePixel = source.GetPixel(sx, sy);
             target.SetPixel(dx, dy, sourcePixel);
         }
     }
 }
Beispiel #2
0
        public static void BlitMask(LockedBitmap source, LockedBitmap target, System.Drawing.Rectangle srcRect, int destX, int destY)
        {
            if (source.Depth != 24 || target.Depth != 32)
            {
                throw new Exception("BlitMask requires the source to be 24-bit and the target to be 32-bit");
            }

            int targetStartX = Math.Max(destX, 0);
            int targetEndX   = Math.Min(destX + srcRect.Width, target.Width);
            int targetStartY = Math.Max(destY, 0);
            int targetEndY   = Math.Min(destY + srcRect.Height, target.Height);

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

            if (copyW < 0 || copyH < 0)
            {
                return;
            }

            int sourceStartX = srcRect.X + targetStartX - destX;
            int sourceStartY = srcRect.Y + targetStartY - destY;

            for (int sx = sourceStartX, dx = targetStartX; dx < targetEndX; sx++, dx++)
            {
                for (int sy = sourceStartY, dy = targetStartY; dy < targetEndY; sy++, dy++)
                {
                    Color sourcePixel = source.GetPixel(sx, sy);
                    int   lume        = sourcePixel.R + sourcePixel.G + sourcePixel.B;
                    lume /= 3;

                    if (lume > 255)
                    {
                        lume = 255;
                    }

                    target.SetComponent(dx, dy, 3, (byte)lume);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns true when the pixel specified is black.
        /// </summary>
        public static bool EmptyPixelAt(LockedBitmap lockedBitmap, int x, int y)
        {
            Color color = lockedBitmap.GetPixel(x, y);

            return(color.R == 0 && color.G == 0 && color.B == 0);
        }