blendColor function
Blends two ARGB colors.
Implementation
int blendColor(int top, int bottom) {
if (bottom == 0) return top;
if (top == 0) return bottom;
final aTop = (top >> 24) & 0xFF;
if (aTop == 255) return top;
final rTop = (top >> 16) & 0xFF;
final gTop = (top >> 8) & 0xFF;
final bTop = top & 0xFF;
final aBottom = (bottom >> 24) & 0xFF;
final rBottom = (bottom >> 16) & 0xFF;
final gBottom = (bottom >> 8) & 0xFF;
final bBottom = bottom & 0xFF;
final invAlpha = 255 - aTop;
final effectiveBottomA = (aBottom * invAlpha) ~/ 255;
final outA = aTop + effectiveBottomA;
if (outA == 0) return 0;
final outR = (rTop * aTop + rBottom * effectiveBottomA) ~/ outA;
final outG = (gTop * aTop + gBottom * effectiveBottomA) ~/ outA;
final outB = (bTop * aTop + bBottom * effectiveBottomA) ~/ outA;
return (outA << 24) | (outR << 16) | (outG << 8) | outB;
}