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.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Drawing.Imaging;
namespace OpenRa.BlockCacheVisualizer 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 & 0xffff) | (hax >> 16);
hax = (hax & 0xff) | (hax >> 8); return (hax & 0xff) | (hax >> 8);
return (int)hax;
} }
Bitmap ExtractChannelToBitmap(Bitmap src, Bitmap pal, uint mask) 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++ ) BitmapData destData = dest.LockBits(new Rectangle(new Point(), dest.Size), ImageLockMode.WriteOnly,
for (int j = 0; j < dest.Height; j++) dest.PixelFormat);
{
int index = MaskColor(src.GetPixel(2 * i, 2 * j), mask); BitmapData paletteData = pal.LockBits(new Rectangle(new Point(), pal.Size), ImageLockMode.ReadOnly,
dest.SetPixel(i, j, pal.GetPixel(index, 0)); 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; return dest;
} }

View File

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