git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1251 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2007-07-14 14:06:05 +00:00
parent 10eebb7009
commit 9193f07037
2 changed files with 41 additions and 13 deletions

View File

@@ -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;
}

View File

@@ -18,6 +18,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -26,6 +27,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />