Hello coders,
does bitblt function account for alpha? How does that work, my image is now loading correct but I can't get the alpha to work. it should be in the right format cause RGB is coming up correctly, so what needs to be done to get alpha working?
Thanks
Jeff.
bitblt function
-
- Posts: 564
- Joined: Sat Jan 17, 2004 10:22 am
- Location: Sweden
- Contact:
well fwiw I knocked together a very quick and dirty alpha blending function last night for my game which is just an extension of the current - note this is bound to be terribly slow but it does at least work ;)
It requires a separate mask, in this case it's just 8bit so you'll need to have appropriate arrays looking something like this:
I also have code now set up to take 24bit bitmaps and produce the 16bit sprite & 8bit masks as above if anyone needs them (along with some extra stuff to print fonts from a bitmap organised like those shown .here
Code: Select all
#define MASK_RED 0x1F
#define MASK_GREEN 0x3E0
#define MASK_BLUE 0x7C00
#define GET_RED(c) ((unsigned char)((c & MASK_RED) << 3))
#define GET_GREEN(c) ((unsigned char)((c & MASK_GREEN) >> 2))
#define GET_BLUE(c) ((unsigned char)((c & MASK_BLUE) >> 7))
unsigned short alpha_blend(unsigned short front, unsigned short back, unsigned char alpha)
{
unsigned char beta = 255 - alpha;
return rgb2col(
((GET_RED(front) * alpha) + (GET_RED(back) * beta)) / 255,
((GET_GREEN(front) * alpha) + (GET_GREEN(back) * beta)) / 255,
((GET_BLUE(front) * alpha) + (GET_BLUE(back) * beta)) / 255);
}
void BitBltA(unsigned long x,unsigned long y,unsigned long w,unsigned long h,unsigned long mag,const unsigned short *d, const unsigned char * m)
{
unsigned char *vptr0; //pointer to vram
unsigned char *vptr; //pointer to vram
unsigned long xx,yy,mx,my;
const unsigned short *dd;
const unsigned char * mm;
vptr0=(unsigned char*)pgGetVramAddr(x,y);
for (yy=0; yy<h; yy++) {
for (my=0; my<mag; my++) {
vptr=vptr0;
dd=d;
mm=m;
for (xx=0; xx<w; xx++) {
for (mx=0; mx<mag; mx++) {
*(unsigned short *)vptr = alpha_blend(*dd,*(unsigned short *)vptr,*mm);
vptr+=PIXELSIZE*2;
}
dd++;
mm++;
}
vptr0+=LINESIZE*2;
}
d+=w;
m+=w;
}
}
Code: Select all
//Image size: (8,8)
const unsigned short bmp_shot_r[] =
{
0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
0x8000,0xd120,0xedc3,0xee43,0xff29,0xfff1,0xfff3,0x8000,
0x8000,0xd120,0xedc3,0xee43,0xff29,0xfff1,0xfff3,0x8000,
0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000
};
//Image size: (8,8)
const unsigned char mask_bmp_shot_r[] =
{
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0xff,0xff,0xff,0xff,0xff,0xff,0x0,
0x0,0xff,0xff,0xff,0xff,0xff,0xff,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
};
//call as such: BitBltA(x,y,8,8,2,bmp_shot_r,mask_bmp_shot_r);
-
- Posts: 564
- Joined: Sat Jan 17, 2004 10:22 am
- Location: Sweden
- Contact:
OK,
im seein some wierd results from your bitbltA function.
Here is my image and mask:
const unsigned short image[]={
0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,
0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,
0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,
0x6c04,0x6c04,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,
};
const unsigned short mask[]={
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,
};
This is a 16 bit image, with red on top and blue on the bottom, im just tryin to mask out either color and its coming up all messed up, it works fine if I use bitblt, but not right using bitbltA (the function you posted above) any ideas??
Thanks
Jeff
im seein some wierd results from your bitbltA function.
Here is my image and mask:
const unsigned short image[]={
0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,
0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,
0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x7c00,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,0x6c04,
0x6c04,0x6c04,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,
};
const unsigned short mask[]={
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,
};
This is a 16 bit image, with red on top and blue on the bottom, im just tryin to mask out either color and its coming up all messed up, it works fine if I use bitblt, but not right using bitbltA (the function you posted above) any ideas??
Thanks
Jeff