 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
webjeff
Joined: 05 May 2005 Posts: 66
|
Posted: Sat May 14, 2005 3:38 pm Post subject: bitblt function |
|
|
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. |
|
| Back to top |
|
 |
Orion_
Joined: 27 Jan 2005 Posts: 69
|
Posted: Sat May 14, 2005 4:26 pm Post subject: |
|
|
| modify the function to support alpha :) |
|
| Back to top |
|
 |
blackdroid
Joined: 17 Jan 2004 Posts: 564 Location: Sweden
|
Posted: Sat May 14, 2005 8:16 pm Post subject: |
|
|
since you are uploading it to vram directly and not doing it via gpu pipeline you have to do the alpha calculation yourself. _________________ Kung VU |
|
| Back to top |
|
 |
Tychom
Joined: 14 May 2005 Posts: 7
|
Posted: Sat May 14, 2005 10:32 pm Post subject: |
|
|
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 ;)
| Code: |
#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;
}
} |
It requires a separate mask, in this case it's just 8bit so you'll need to have appropriate arrays looking something like this:
| Code: |
//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);
|
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 |
|
| Back to top |
|
 |
Tychom
Joined: 14 May 2005 Posts: 7
|
Posted: Sat May 14, 2005 10:38 pm Post subject: |
|
|
| As an aside, has anyone idea about how much static data can be held (i.e. how big the stack can be), without malloc i'm storing already upwards of 300k in bitmap & mask data.. |
|
| Back to top |
|
 |
blackdroid
Joined: 17 Jan 2004 Posts: 564 Location: Sweden
|
Posted: Sat May 14, 2005 11:01 pm Post subject: |
|
|
well you know where userspace starts, and you have 24MB to play with, lots of pointers to use in case you worry about stack trashing. _________________ Kung VU |
|
| Back to top |
|
 |
webjeff
Joined: 05 May 2005 Posts: 66
|
Posted: Sun May 15, 2005 12:47 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Tychom
Joined: 14 May 2005 Posts: 7
|
Posted: Sun May 15, 2005 1:07 am Post subject: |
|
|
| the mask array should be of type "const unsigned char []", not short. Other than that, your mask array is split 40-60% so you'll still see a bit of blue (if that's what you wanted then all's good :) ) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|