Tuesday, January 23, 2018

Color Condundrum

Today was so much more productive. I discovered that the three to five second delay I was having with my screen updates. It was due to a really nasty hack I put into Nermal to make it function. I decided to get that working once and for all. I don't have a solution yet, but I'm working on it.

Rules of  Engagement originally ran in 4 bit color. This gives you 24 or 16 colors to play with. With so little colors, you did not have a "transparency". ROE gets around this by assigning black as a "mask". This means that you can have some functions that alter colors, except for black. This becomes useful later.

I'm trying to duplicate this functionality in Allegro 5 with 24 bit color. (If you are counting 224 is 16,777,216 colors to work with. Considerably more!) Besides the boost in colors, I also have variable transparencies as well.

 My grief comes down to a function called DoColorMask(). In the original game, the function would copy a bitmap from a source location to a destination. While the the bitmap was pixel-for-pixel being copied over, it would check the color of the pixel being copied. If the pixel isn't black, then change the pixel color to a color you would give it. This means that if you have a solid red colored button with black text, you can use the function to make the button white with black text. This function is often used to make buttons "flash"

The upshot is this is a poor-man's tint function.

Allegro has a comparable function called  al_draw_tinted_bitmap_region(). It's promising, except there are issues I'm not sure how to resolve yet.

Full, Red, Green, and Blue Channels
The first thing I did was try a few color tinting experiments. I took a standard colorbar pattern and decided to see what happened when I ramped the tint to 100% in a particular color channel. In the pictures you can see in the upper left  the "normal" color bars. The upper right is red channel, lower left is green channel and lower right is blue channel. The problem with this approach is that it will "block" all colors that are not in that channel. For example, the blue in the red channel is black because... well, there is no blue in the red channel, only red.

Using alpha to "Push" a channel color
My second experiment was to overlay  the altered color channel back into the normal channel with a 50% opacity. That looked a little better and I can now "push" a color towards the color tint I want. However a problem with this is I can't alter the luminosity. In other words, I can't make a color brighter then the original color. (I can't turn red into pink, or white, just into a mix of blue or green).

Can't go above full brightness
I tried a few luminosity experiments, but that just kind of confirmed what I thought. I have the ability to make the bitmaps darker, but I can't monkey with the gamma the way I want with the tools I have. It's not horrible. It just means I need to make better tools.

Gimps "Colorize" in the blue channel.
The solution I actually need is use something like Gimp's "Colorize" function. How that works is that you give it a picture, and it will strip everything out but the luminosity channel (Makes it black and white). Then it applies a color tint to that channel. From there you adjust three sliders for Hue, Saturation, and Lightness. I don't think there is an easy way to do this in Allegro, well, short of brute-forcing it on a pixel-by-pixel basis, and that's what I'm trying to get away from. I'll be doing more colorspace experiments tomorrow.

No comments:

Post a Comment