Re: [AD] improvements on alpha blending...

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


some little remarks i forgot

> supposing the image has more than 20000 pixels (200 * 100 pixels for
> example)
actually more than 65536 calculations that is in pixels
65536 / 3 = 21845 pixels


> if (opacity == 0) {
>   for (int src = 0; src < 256; src++) {
>     for (int dst = 0; dst < 256; dst++) {
>       average[src][dst] = dst;
>     }
>   }
> }
> else if (opacity == 255) {
>   for (int src = 0; src < 256; src++) {
>     for (int dst = 0; dst < 256; dst++) {
>       average[src][dst] = src;
>     }
>   }
> }
> else {
>   float srcmul, dstmul;
>   srcmul = 255 /opacity;
>   dstmul = 255 / (255 - opacity);
>   for (int src = 0; src < 256; src++) {
>     for (int dst = 0; dst < 256; dst++) {
>       average[src][dst] = src * srcmul + dst * dstmul;
>     }
>   }
> }
we could add a 50% opacity optimized case
if (opacity == 127) { // i take 127 cause 255 / 2 = 127
   for (int src = 0; src < 256; src++) {
     for (int dst = 0; dst < 256; dst++) {
       average[src][dst] = (src + dst) / 2; // this gets optimized to a bit
shift
     }
   }
}



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/