Original Post
Hey guys, I'm a bit confused as how to apply a hue ramp to a bitmap, based on the individual colours of each pixel. The idea, is to create a tinted version of the original bitmap. If any of you remember the original BreakOut, if you collected a power-up, the paddle would gradually tint itself to a specific tint (red for example) for the duration of the power-up and then revert to the original colours. I guess I can't really explain this without uploading some images, so take a look at these: Original Tint to red Now the thing is, I don't want to just "flick" between the original and tinted images. I'd rather manipulate the bitmap directly and alter the pixels, gradually shading them from the original to the tinted version. Working with Allegro, I've managed to create a hue ramp that works with primitives and gradually shades between each ramp. That works well, but obviously assumes the colours of the bitmap in question, are already suitable for ramping (as in, straight from dark red->red or red->orange). Now the question is, how to get from the original colours, to a specified ramp? For example, the RGB of the top left pixels (after the grey portion) for the original/tinted versions, are:
int HueRamp(int *r, int *g, int *b, const int rampEnd)
{
static currentRamp = RAMP_RED;
switch (currentRamp)
{
case RAMP_RED:
(*r != 255) ? (*r)++ : currentRamp = RAMP_ORANGE;
break;
case RAMP_ORANGE:
(*g != 128) ? (*g)++ : currentRamp = RAMP_YELLOW;
break;
case RAMP_YELLOW:
(*g != 255) ? (*g)++ : currentRamp = RAMP_GREEN;
break;
case RAMP_GREEN:
(*r != 0) ? (*r)-- : currentRamp = RAMP_CYAN;
break;
case RAMP_CYAN:
(*b != 255) ? (*b)++ : currentRamp = RAMP_BLUE;
break;
case RAMP_BLUE:
(*g != 0) ? (*g)-- : currentRamp = RAMP_PURPLE;
break;
case RAMP_PURPLE:
(*r != 128) ? (*r)++ : currentRamp = RAMP_DARKRED;
break;
case RAMP_DARKRED:
(*b != 0) ? (*b)-- : currentRamp = RAMP_RED;
break;
}
return currentRamp;
}
Orange->Red
255 142 29 Original
- 255 29 29 Tinted
-----------------
0 113 0 Difference
255 223 190 Original
- 255 190 190 Tinted
-----------------
0 33 0 Difference
I made a blue version as well, and from original to blue (same pixel example):
Orange->Blue
255 142 29 Original
- 29 29 255 Tinted
-----------------
226 113 -226 Difference
So how do I get from one to the other? I'm guessing I need to somehow "scale" the tint for each pixel, depending on its original colour so that it doesn't end up as a solid colour, such as red or orange. However, how I'd go about that, I'm not entirely sure. If this doesn't make sense, I'll try to explain further. Thanks in advance, -hellz