rndmcnlly (rndmcnlly) wrote,
rndmcnlly
rndmcnlly

intense optimization!

I actually had to break out a pencil and paper to get this one right: full integer-only alpha-blending with only 10 multiplies and single divide.

    // TODO: throw in appropriate rounding values
    cA = fA + bA - ( fA*bA+255 >> 8);
    tR = bA*bR >> 8;
    tG = bA*bG >> 8;
    tB = bA*bB >> 8;
    s  = s_lut[cA]; // 65535 / cA;
    cR = ((fA*(fR-tR) >> 8) + tR) * s >> 8; 
    cG = ((fA*(fG-tG) >> 8) + tG) * s >> 8; 
    cB = ((fA*(fB-tB) >> 8) + tB) * s >> 8; 



**edit: Since s only takes on 256 distinct values I can make a 256B lookup table (called s_lut) and eliminate the divide altogether. yay.
**eeeeedit: with a 64KiB table I can eliminate ALL of the multiplies!!
**eeeeeeeeeeedit: oh what, who put >> there in the precedence table..
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

  • 3 comments