You need to merge the chromatic values at all pixels. In RGB, there are three colours. Extract each color value separately from the pixel and merge them to build a new RGB value.
Here's my own implementation using my own colour type defined as an array of three bytes (red, green & blue). Many other colour types encode colour as a 4 byte integer (for convenience), where three bytes are used and the other is padding.
typedef unsigned __int8 BGRCol[3];
Code:
void BtCol::BGRMerge(const BGRCol orig, const BGRCol mask, int percMask, BGRCol& rslt)
{
// Static BGR merge (used with bitmap ScanLine)
if (percMask <= 0)
{
rslt[BGR_BLUE] = orig[BGR_BLUE];
rslt[BGR_GREEN] = orig[BGR_GREEN];
rslt[BGR_RED] = orig[BGR_RED];
}
else
if (percMask >= 100)
{
rslt[0BGR_BLUE] = mask[BGR_BLUE];
rslt[BGR_GREEN] = mask[BGR_GREEN];
rslt[BGR_RED] = mask[BGR_RED];
}
else
{
int remPerc = 100 - percMask;
rslt[BGR_BLUE] = (orig[BGR_BLUE] * remPerc / 100) + (mask[BGR_BLUE] * percMask / 100);
rslt[BGR_GREEN] = (orig[BGR_GREEN] * remPerc / 100) + (mask[BGR_GREEN] * percMask / 100);
rslt[BGR_RED] = (orig[BGR_RED] * remPerc / 100) + (mask[BGR_RED] * percMask / 100);
}