public void ScrollHV(BitmapBits destination, int dstY, int srcY, params int[] srcX) { if (dstY < 0 || dstY >= destination.Height) { return; } for (int i = 0; i < srcX.Length; i++) { srcX[i] %= Width; if (srcX[i] < 0) { srcX[i] += Width; } } srcY %= Height; if (srcY < 0) { srcY += Height; } int rowSrc = GetPixelIndex(0, srcY); int rowDst = destination.GetPixelIndex(0, dstY); for (int y = 0; y < destination.Height - dstY; y++) { int amount = srcX[(srcY + y) % srcX.Length]; Array.Copy(Bits, rowSrc + amount, destination.Bits, rowDst, Math.Min(Width - amount, destination.Width)); if (amount != 0 && Width - amount < destination.Width) { Array.Copy(Bits, rowSrc, destination.Bits, rowDst + Width - amount, Math.Min(amount, destination.Width - (Width - amount))); } rowSrc = (rowSrc + Width) % Bits.Length; rowDst += destination.Width; } }
public void DrawBitmapBounded(BitmapBits source, int x, int y) { if (x >= 0 && y >= 0 && x + source.Width <= Width && y + source.Height <= Height) { DrawBitmap(source, x, y); return; } int srct = 0; if (y < 0) { srct = -y; } int srcb = source.Height; if (srcb > Height - y) { srcb = Height - y; } if (x == 0 && source.Width == Width) { Array.Copy(source.Bits, source.GetPixelIndex(0, srct), Bits, GetPixelIndex(0, y + srct), GetPixelIndex(0, srcb - srct)); return; } int srcl = 0; if (x < 0) { srcl = -x; } int srcr = source.Width; if (srcr > Width - x) { srcr = Width - x; } for (int c = srct; c < srcb; c++) { Array.Copy(source.Bits, source.GetPixelIndex(srcl, c), Bits, GetPixelIndex(x + srcl, y + c), srcr - srcl); } }