Created
October 8, 2010 21:16
-
-
Save chrisforbes/617571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tiberium green -> blue remapper. | |
using System.Drawing; | |
using System.IO; | |
using System.Drawing.Imaging; | |
using System; | |
using System.Collections.Generic; | |
namespace remaptib | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (var f in Directory.GetFiles(args[0], "*.png")) | |
{ | |
using (var b = (Bitmap)Bitmap.FromFile(f)) | |
{ | |
var bits = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); | |
unsafe | |
{ | |
byte* p = (byte*)bits.Scan0; | |
for (var j = 0; j < bits.Height; j++) | |
{ | |
for (var i = 0; i < bits.Width; i++) | |
*p++ = RemapColor(*p); | |
p += bits.Stride - bits.Width; | |
} | |
} | |
b.UnlockBits(bits); | |
b.Save(@"d:\crap\output\" + Path.GetFileName(f)); | |
} | |
} | |
} | |
static byte RemapColor(byte b) | |
{ | |
switch (b) | |
{ | |
case 0xa5: return 0x09; | |
case 0xa6: return 0x0a; | |
case 0xa7: return 0x0b; | |
case 0x9e: return 0x09; | |
case 0x9d: return 0x09; | |
case 0x9f: return 0x0b; | |
case 0x9c: return 0x09; | |
case 0xb9: return 0x87; | |
case 0xb3: return 0x77; | |
case 0x05: return 0x09; | |
default: | |
return b; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment