G
Gernot Frisch
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)>>11)&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(unsigned 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_SRC_ALPHA);
//
// basically it's just
// red_destination =
// max(0xff,
// alpha*red_destination
// + (1-alpha)*red_source
// );
//
// pDest = pointer to destination pixel
// colsrc = color of source pixel
// alpha = alpha value (0...255 instead of 0.0f...1.0f)
static void BlendPixelSub(unsigned 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=0xff; if(g>0xff)g=0xff; if(b>0xff)b=0xff;
// put back
*pDest = PackColor(r, g, b);
#undef AONE
#undef ONE
}
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%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
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)>>11)&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(unsigned 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_SRC_ALPHA);
//
// basically it's just
// red_destination =
// max(0xff,
// alpha*red_destination
// + (1-alpha)*red_source
// );
//
// pDest = pointer to destination pixel
// colsrc = color of source pixel
// alpha = alpha value (0...255 instead of 0.0f...1.0f)
static void BlendPixelSub(unsigned 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=0xff; if(g>0xff)g=0xff; if(b>0xff)b=0xff;
// put back
*pDest = PackColor(r, g, b);
#undef AONE
#undef ONE
}
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%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