Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Figure out what blend mode we want, and do the blending.
- if(blendMode == BlendMode::Mask)
- {
- //The mask "alpha" applied to the tile, is determined by the alpha of the mask, or the
- //blackness of the mask. So basically, the average of the RGB colors with alpha affecting it also.
- int finalAlpha = (colorA.GetAlpha() * colorB.GetAverageValue()) / 255;
- finalColor.SetAlpha(finalAlpha);
- }
- else if(blendMode == BlendMode::Normal)
- {
- float alpha = (float(colorB.GetAlpha()) / 255.0f);
- finalColor.SetR(((1.0f - alpha) * colorA.GetR()) + (alpha * colorB.GetR()));
- finalColor.SetG(((1.0f - alpha) * colorA.GetG()) + (alpha * colorB.GetG()));
- finalColor.SetB(((1.0f - alpha) * colorA.GetB()) + (alpha * colorB.GetB()));
- //Leave the tile's alpha unchanged.
- finalColor.SetAlpha(colorA.GetAlpha());
- }
- else if(blendMode == BlendMode::Overlay)
- {
- //Overlay must be done per color channel.
- /*if(colorA.GetR() <= 128)
- finalColor.SetR((2 * colorA.GetR() * colorB.GetR()) / 256);
- else
- finalColor.SetR(255 - (((255 - (2 * (colorA.GetR() - 128))) * (255 - colorB.GetR())) / 256));
- if(colorA.GetG() <= 128)
- finalColor.SetG((2 * colorA.GetG() * colorB.GetG()) / 256);
- else
- finalColor.SetG(255 - (((255 - (2 * (colorA.GetG() - 128))) * (255 - colorB.GetG())) / 256));
- if(colorA.GetB() <= 128)
- finalColor.SetB((2 * colorA.GetB() * colorB.GetB()) / 256);
- else
- finalColor.SetB(255 - (((255 - (2 * (colorA.GetB() - 128))) * (255 - colorB.GetB())) / 256));*/
- if(colorB.GetR() <= 128)
- finalColor.SetR((2 * colorB.GetR() * colorA.GetR()) / 256);
- else
- finalColor.SetR(255 - (((255 - (2 * (colorB.GetR() - 128))) * (255 - colorA.GetR())) / 256));
- if(colorB.GetG() <= 128)
- finalColor.SetG((2 * colorB.GetG() * colorA.GetG()) / 256);
- else
- finalColor.SetG(255 - (((255 - (2 * (colorB.GetG() - 128))) * (255 - colorA.GetG())) / 256));
- if(colorB.GetB() <= 128)
- finalColor.SetB((2 * colorB.GetB() * colorA.GetB()) / 256);
- else
- finalColor.SetB(255 - (((255 - (2 * (colorB.GetB() - 128))) * (255 - colorA.GetB())) / 256));
- BUILD_NOTE("Shouldn't this be SetAlpha(colorA.GetAlpha())?")
- finalColor.SetAlpha(255); //Undo any changes to alpha.
- }
- else if(blendMode == BlendMode::Multiply)
- {
- finalColor = (colorA * colorB);
- finalColor.SetAlpha(255); //Undo any changes to alpha.
- }
- else if(blendMode == BlendMode::Screen)
- {
- const cColor FULL_COLOR(255, 255, 255, 255);
- finalColor = FULL_COLOR - ((FULL_COLOR - colorA) * (FULL_COLOR - colorB));
- finalColor.SetAlpha(255); //Undo any changes to alpha.
- }
- else if(blendMode == BlendMode::Dodge)
- {
- finalColor.SetR((colorA.GetR() * 256) / ((255 - colorB.GetR()) + 1));
- finalColor.SetG((colorA.GetG() * 256) / ((255 - colorB.GetG()) + 1));
- finalColor.SetB((colorA.GetB() * 256) / ((255 - colorB.GetB()) + 1));
- //finalColor.SetAlpha((colorA.GetAlpha() * 256) / ((255 - colorB.GetAlpha()) + 1));
- //Leave the tile's alpha unchanged.
- finalColor.SetAlpha(colorA.GetAlpha());
- }
- else if(blendMode == BlendMode::Burn)
- {
- //This works, even with alpha, but it doesn't match PaintShopPro's result.
- /*unsigned int redFactor = colorB.GetR() + (255 - colorB.GetAlpha()) + 1;
- if(redFactor > 255) redFactor = 255;
- finalColor.SetR(255 - (((255 * (255 - colorA.GetR())) / redFactor)));
- unsigned int greenFactor = colorB.GetG() + (255 - colorB.GetAlpha()) + 1;
- if(greenFactor > 255) greenFactor = 255;
- finalColor.SetG(255 - (((255 * (255 - colorA.GetG())) / greenFactor)));
- unsigned int blueFactor = colorB.GetB() + (255 - colorB.GetAlpha()) + 1;
- if(blueFactor > 255) blueFactor = 255;
- finalColor.SetB(255 - (((255 * (255 - colorA.GetB())) / blueFactor)));*/
- //GIMP version:
- finalColor.SetR(255 - ((256 * (255 - colorA.GetR())) / (colorB.GetR() + 1)));
- finalColor.SetG(255 - ((256 * (255 - colorA.GetG())) / (colorB.GetG() + 1)));
- finalColor.SetB(255 - ((256 * (255 - colorA.GetB())) / (colorB.GetB() + 1)));
- //Leave the tile's alpha unchanged.
- finalColor.SetAlpha(colorA.GetAlpha());
- }
Advertisement
Add Comment
Please, Sign In to add comment