Files
OpenRA/PaletteUsage/Program.cs
(no author) a22d2487d6 rough list of todo for openra
removed (c)TOSHIBA from Openra.TechTree - beedee fails
added first-pass c# support to corfu
converted ijw internet's todo file into the form corfu likes
palette usage analysis tool for openra, so we can find a good slot to hijack

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1319 993157c7-ee19-0410-b2c4-bb4e9862e678
2007-07-22 16:10:57 +00:00

52 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace PaletteUsage
{
class Program
{
static void Main(string[] args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.RestoreDirectory = true;
ofd.Filter = "PNG Image Cache (*.png)|*.png";
if (DialogResult.OK != ofd.ShowDialog())
return;
Bitmap bitmap = new Bitmap(ofd.FileName);
int[] f = new int[256];
foreach (byte b in ImageBytes(bitmap))
++f[b];
for (int i = 0; i < 256; i++)
{
if (i % 8 == 0)
Console.WriteLine();
Console.Write("{0} -> {1}", i.ToString().PadLeft(3), f[i].ToString().PadRight(8));
}
}
static IEnumerable<byte> ImageBytes(Bitmap bitmap)
{
int width = bitmap.Width;
int height = bitmap.Height;
for( int i = 0; i < width; i++ )
for (int j = 0; j < height; j++)
{
Color c = bitmap.GetPixel(i, j);
yield return (byte)c.R;
yield return (byte)c.G;
yield return (byte)c.B;
yield return (byte)c.A;
}
}
}
}