Sorry I didn't see this earlier, I don't check the forum as often as Reddit as with Reddit I have a phone app to amuse myself when I am away from my PC.
When you said:
Doesn't seem like you're having a lot of luck finding an answer
You forgot to account for your own answer!
From the wiki:
When the game draws a tile, it will select a foreground color, a background color, and a tile based on the item being drawn. The background color will be used in place of magenta (Hex code #FF00FF or RGB 255 0 255). All other colors in the tile will be treated as a mask against the foreground color. Pure white (#FFFFFF) will always show the foreground color, while light grey (#CCCCCC) will be a slightly darker version of the foreground color, and dark grey (#888888) will be a dark version of the foreground color. Black (#000000) will always be black. It is impossible to use different shades of the background color.
This is exactly what I needed! Thanks!
It even contains the maths - I'm fairly sure just from reading this, having played the game and seen the originals before they were rendered that this is exactly what it does! I think no one copied it from 40d wiki page, that's all.
I can write code from this!
Edit: Looking at the most recent Phoebus file it isn't entirely up to date, but I know what it is doing different.
So - the biggest change it appears from Pheobus is colours other than grey.
When I look at the original image
http://dwarffortresswiki.org/images/f/f1/Phoebus_16x16.png for example, the off/on levers - they contain green and red. Clearly they want to stay!
So I added a new rule - colours will be used as a mask except grey, white and black.
White will use the foreground colour instead of a mask.
A colour is "grey" when red, green and blue are equal - this should use the mask formula you linked to. After test processing the Pheobus file, what looked to me to be "grey" remained in a few spots - upon checking, it was #2b2c2b - the rgb values were slightly different but it was clearly supposed to be grey not a colour given contex.
I updated my definition of equal to be a little more tollerant - after playing with the Phoebus file, the value difference in hex values that should be taken as a colour is 62 which would be fine, except setting the tollerence that high also got the green of the leaves.
Black is the background color. I left it black - for most things it is a black outline so it worked for the demo.
When red, green and blue do not match, that is a "colour" should remain unchanged when processed. So they green of the "on" state stays green.
Using those rules, I was able to re-process the image into red #ff0000, green #00ff00 and blue #0000ff versions.
Red -
http://i.imgur.com/x3bwvtB.pngGreen -
http://i.imgur.com/CCAo4Np.pngBlue -
http://i.imgur.com/2fSStRP.pngObviously these are not realistic foreground colours for all the elements but since the process works, it is a case of getting each foreground colour from the config files (not too difficult) - the tolerence value may also need tweaking on a per element basis.
There are a few interesting exceptions - Strawberry bushes have the following set in the raws - [SHRUB_COLOR:2:4:1] - which is bright green foreground, dark green background.
The Alpha layer (which I've just preserved for now) actually servers as the background colour and allows berries to be coloured separately.
The colors.txt file defines what exactly "Red" and "Green" are for those particular tilesets, that shouldn't be too hard to get hold of either.
So - Thanks! I created working code from your post!
I could play with the berry trees a little more(and I probably will eventually) but I don't see a huge need since I only wanted different coloured backgrounds that roughly mimicked in game materials so that people could use a tool that actually looks like Dwarf Fortress to create structures and import them into Quickfort.
Now that I definitely can colour tilesets outside of Dwarf Fortress... on to finding a Tileset with a license that will let me use it or someone who has made one I can convince.
Thanks again!
Edit 2: Couldn't resist screwing around - also got the bushes to show berries in the background colour -
http://i.imgur.com/3wAIEwG.pngObviously, in game the whole tilesheet isn't recoloured like this all the objects are different colour combinations, etc.