diff --git a/OpenRa.BlockCacheVisualizer/Form1.cs b/OpenRa.BlockCacheVisualizer/Form1.cs index 001757b0a2..127edef200 100644 --- a/OpenRa.BlockCacheVisualizer/Form1.cs +++ b/OpenRa.BlockCacheVisualizer/Form1.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; +using System.Drawing.Imaging; namespace OpenRa.BlockCacheVisualizer { @@ -43,26 +44,51 @@ namespace OpenRa.BlockCacheVisualizer } } - int MaskColor(Color c, uint mask) + uint MaskColor(uint c, uint mask) { - uint hax = (uint)c.ToArgb() & mask; + uint hax = c & mask; - hax = ( hax & 0xffff ) | (hax >> 16); - hax = (hax & 0xff) | (hax >> 8); - - return (int)hax; + hax = (hax & 0xffff) | (hax >> 16); + return (hax & 0xff) | (hax >> 8); } Bitmap ExtractChannelToBitmap(Bitmap src, Bitmap pal, uint mask) { - Bitmap dest = new Bitmap(src.Width / 2, src.Height / 2); + Bitmap dest = new Bitmap(src.Width / 2, src.Height / 2, pal.PixelFormat); - for( int i = 0; i < dest.Width; i++ ) - for (int j = 0; j < dest.Height; j++) - { - int index = MaskColor(src.GetPixel(2 * i, 2 * j), mask); - dest.SetPixel(i, j, pal.GetPixel(index, 0)); - } + BitmapData destData = dest.LockBits(new Rectangle(new Point(), dest.Size), ImageLockMode.WriteOnly, + dest.PixelFormat); + + BitmapData paletteData = pal.LockBits(new Rectangle(new Point(), pal.Size), ImageLockMode.ReadOnly, + pal.PixelFormat); + + BitmapData srcData = src.LockBits(new Rectangle(new Point(), src.Size), ImageLockMode.ReadOnly, + src.PixelFormat); + + int strideInts = destData.Stride/4; + int strideInts2 = srcData.Stride/4; + + unsafe + { + uint* pdest = (uint*)destData.Scan0.ToPointer(); + uint* ppal = (uint*)paletteData.Scan0.ToPointer(); + uint* psrc = (uint*)srcData.Scan0.ToPointer(); + + int h = dest.Height; int w = dest.Width; + + for (int j = 0; j < h; j++) + for (int i = 0; i < w; i++) + { + uint srcc = psrc[2 * j * strideInts2 + 2 * i]; + uint index = MaskColor(srcc, mask); + uint data = ppal[index]; + pdest[j * strideInts + i] = data; + } + } + + dest.UnlockBits(destData); + pal.UnlockBits(paletteData); + src.UnlockBits(srcData); return dest; } diff --git a/OpenRa.BlockCacheVisualizer/OpenRa.BlockCacheVisualizer.csproj b/OpenRa.BlockCacheVisualizer/OpenRa.BlockCacheVisualizer.csproj index b058495057..3d1d52c839 100644 --- a/OpenRa.BlockCacheVisualizer/OpenRa.BlockCacheVisualizer.csproj +++ b/OpenRa.BlockCacheVisualizer/OpenRa.BlockCacheVisualizer.csproj @@ -18,6 +18,7 @@ DEBUG;TRACE prompt 4 + true pdbonly @@ -26,6 +27,7 @@ TRACE prompt 4 + true