Created
May 11, 2010 08:56
-
-
Save chrisforbes/397084 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.IO; | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
namespace remapsmoke | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (var fn in Directory.GetFiles(@"d:\\crap\temphax\", "*.png")) | |
{ | |
using (var img = (Bitmap)Bitmap.FromFile(fn)) | |
{ | |
UsedColors(img); | |
img.Save(@"d:\\crap\output\" + Path.GetFileName(fn)); | |
} | |
} | |
} | |
static byte RemapColor(byte c) | |
{ | |
if (c < 0x90 || c >= 0x9c) return c; | |
return (byte)(((c - 0x90) * 4) / 3 + 0x50); | |
} | |
static void UsedColors(Bitmap b) | |
{ | |
var data = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); | |
unsafe | |
{ | |
var p = (byte*)data.Scan0; | |
for (var i = 0; i < b.Width; i++) | |
for (var j = 0; j < b.Height; j++) | |
p[j * data.Stride + i] = RemapColor(p[j * data.Stride + i]); | |
} | |
b.UnlockBits(data); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment