Skip to content

Commit

Permalink
More BitmapBits optimizations, adding DrawBitmapBehind.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed May 19, 2015
1 parent f24cf55 commit 989e7eb
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions SonLVLAPI/BitmapBits.cs
Expand Up @@ -288,6 +288,11 @@ public Bitmap ToBitmap1bpp(params Color[] palette)

public void DrawBitmap(BitmapBits source, int x, int y)
{
if (x == 0 && source.Width == Width)
{
source.Bits.CopyTo(Bits, GetPixelIndex(0, y));
return;
}
for (int i = 0; i < source.Height; i++)
{
int di = GetPixelIndex(x, y + i);
Expand Down Expand Up @@ -323,20 +328,55 @@ public void DrawBitmapComposited(BitmapBits source, Point location)
DrawBitmapComposited(source, location.X, location.Y);
}

public void DrawBitmapBounded(BitmapBits source, int x, int y)
public void DrawBitmapBehind(BitmapBits source, int x, int y)
{
int srcl = 0;
if (x < 0)
srcl = -x;
int srct = 0;
if (y < 0)
srct = -y;
int srcr = source.Width;
if (srcr > Width - x)
srcr = Width - x;
int srcb = source.Height;
if (srcb > Height - y)
srcb = Height - y;
for (int c = srct; c < srcb; c++)
for (int r = srcl; r < srcr; r++)
if (this[x + r, y + c] == 0)
this[x + r, y + c] = source[r, c];
}

public void DrawBitmapBehind(BitmapBits source, Point location)
{
DrawBitmapBehind(source, location.X, location.Y);
}

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), srcb - srct);
return;
}
int srcl = 0;
if (x < 0)
srcl = -x;
int srct = 0;
if (y < 0)
srct = -y;
int srcr = source.Width;
if (srcr > Width - x)
srcr = Width - x;
int srcb = source.Height;
if (srcb > Height - y)
srcb = Height - y;
for (int c = srct; c < srcb; c++)
Array.Copy(source.Bits, source.GetPixelIndex(srcl, c), Bits, GetPixelIndex(x + srcl, y + c), srcr - srcl);
}
Expand Down

0 comments on commit 989e7eb

Please sign in to comment.