Hi,
I have this code that blends 2 pixels, but it's not really fast. Can
someone help me speeding it up?
#define GETR(a) (unsigned char)(((((a)>>1 1)&31)*255)/31)
#define GETG(a) (unsigned char)(((((a)>5) &63)*255)/63)
#define GETB(a) (unsigned char)(((((a) )&31)*255)/31)
inline unsigned short PackColor(unsig ned int r, unsigned int g,
unsigned int b)
{
return ((unsigned short)(
(b>>3) + ((g>>2)<<5) + ((r>>3)<<11)));
}
// Trying to simulate
// glBlendFunc(GL_ SRC_ALPHA, GL_ONE_MINUS_SR C_ALPHA);
//
// basically it's just
// red_destination =
// max(0xff,
// alpha*red_desti nation
// + (1-alpha)*red_sour ce
// );
//
// pDest = pointer to destination pixel
// colsrc = color of source pixel
// alpha = alpha value (0...255 instead of 0.0f...1.0f)
static void BlendPixelSub(u nsigned short* pDest, unsigned short
colsrc)
{
#define AONE(a) ((unsigned short)( ((a)*one_minus_ alpha) >>8))
#define ONE(a) ((unsigned short)( ((a*alpha) >>8))
register unsigned long r,g,b, r2, g2, b2;
unsigned int one_minus_alpha = 255-alpha;
// rip out rgb values (THIS IS SLOW)
r =GETR(*pDest);
g =GETG(*pDest);
b =GETB(*pDest);
r2=GETR(colsrc) ;
g2=GETG(colsrc) ;
b2=GETB(colsrc) ;
// alpha blend them
r=AONE(r) +ONE(r2);
g=AONE(g) +ONE(g2);
b=AONE(b) +ONE(b2);
// limit to 0xff
if(r>0xff)r=0xf f; if(g>0xff)g=0xf f; if(b>0xff)b=0xf f;
// put back
*pDest = PackColor(r, g, b);
#undef AONE
#undef ONE
}
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%c gl%ssic%ccom%c" , "ma", 58, 'g', 64, "ba", 46, 10);}
_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com