summary refs log tree commit diff
path: root/misc/sdl/sdl_icon_gen.cs
blob: 90d0e5f66b4e478eeb46dc2683400f42d5676fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;

namespace test 
{
	public static class Program 
	{
		const string src = "CCicon.ico";
		const string dst = "CCIcon_SDL.h";
		
		static void DumpIcon(StreamWriter sw, int width, int height) {
			using (Icon icon = new Icon(src, width, height)) {
				using (Bitmap bmp = icon.ToBitmap()) {
					for (int y = 0; y < bmp.Height; y++) {
						for (int x = 0; x < bmp.Width; x++) {
							Color c = bmp.GetPixel(x, y);
							int p = (c.A << 24) | (c.R << 16) | (c.G << 8) | c.B;
							sw.Write("0x" + ((uint)p).ToString("X8") + ",");
						}
						sw.WriteLine();
					}
				}
			}
			sw.WriteLine("static const int CCIcon_Width  = {0};", width);
			sw.WriteLine("static const int CCIcon_Height = {0};", height);
			sw.WriteLine("static const int CCIcon_Pitch  = {0};", width * 4);
		}
		
		public static void Main(string[] args) {
			using (StreamWriter sw = new StreamWriter(dst)) {
				sw.WriteLine("/* Generated using misc/sdl/sdl_icon_gen.cs */");
				sw.WriteLine("");
				sw.WriteLine("static const unsigned CCIcon_Data[] = {");
				DumpIcon(sw, 64, 64);
				sw.WriteLine("};");
			}
		}
	}
}