So im completely new to this, but i managed to get bmp and png files to display as backgrounds... but i was wondering if the same can be done for pcx.
i saw the loadPCX() function, but im not entirely sure how that works.
Anyone know of either some code, or a tutorial documenting this ?
(or if it can even be done...)
Im aware that i could just convert the images to something like png or bmp, but i'd rather keep then in their original format.
pcx image as background
Re: pcx image as background
I am a little confused why you might think this is not possible. can you maybe clarify what you think would be the issue?
Re: pcx image as background
Here's some code I posted on gbadev.org forums just the other day:
Code: Select all
u8*
v_readraw (char *filename)
{
u8 *tp;
int fp;
u32 flen;
struct stat st;
fp = open(filename, O_RDONLY);
if (fp == -1)
return 0;
if (fstat(fp, &st) == -1)
return 0;
flen = st.st_size;
tp = (u8*) malloc(flen);
if (!tp)
{ close(fp); return 0; }
if (read(fp, tp, flen) == -1)
{ close(fp); free(tp); return 0; }
close(fp);
return tp; // free(tp);
}
void
v_ldpcxbg (char *sbgimg, int screen)
{
sImage pcx;
void *gfxptr, *palptr;
u8 *tp = v_readraw(sbgimg);
if (!tp) OOP("v_readraw()");
if (!loadPCX((u8*)tp, &pcx))
OOP("loadPCX()");
free(tp);
if (screen == 1)
{ gfxptr = (void*)BG_GFX_SUB;
palptr = (void*)BG_PALETTE_SUB; }
else { gfxptr = (void*)BG_GFX;
palptr = (void*)BG_PALETTE; }
swiCopy((void*)pcx.image.data8, gfxptr, ((pcx.width*pcx.height)>>2) | COPY_MODE_WORD);
swiCopy((void*)pcx.palette, palptr, ((256*2)>>2) | COPY_MODE_WORD);
imageDestroy(&pcx);
}
-
- Posts: 4
- Joined: Fri Jun 24, 2011 4:10 am
Re: pcx image as background
The only reason i thought it wasn't possible, was because so far the only way i have displayed a background picture, was with the image data, and a palette... and with pcx, i didnt see a palette... but ritz's code looks very helpful, thanks.
Re: pcx image as background
The code you posted requires that a background is set up to be displayed. This can be accomplished with bgInit or bgInitSub, depending on if you want it to be on the main screen or the sub screen. Additionally, it looks like the code assumes the bg is an 8bpp bitmap. Since it copies the data into BG_GFX[_SUB], this means it will reside at map base 0. Therefore, your bgInit call would look something like this for a 256x256 8bpp bitmap:
bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
The last parameter has no effect since this is a bitmap background, but libnds requires that it is 0. Additionally, this setup will require Mode 5. You can do it in Mode 4 or 5 if the bg layer (first parameter) is 3.
You may find this useful:
http://mtheall.com/vram.php?MS=0&TS=0&T ... x256&MB2=0
bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
The last parameter has no effect since this is a bitmap background, but libnds requires that it is 0. Additionally, this setup will require Mode 5. You can do it in Mode 4 or 5 if the bg layer (first parameter) is 3.
You may find this useful:
http://mtheall.com/vram.php?MS=0&TS=0&T ... x256&MB2=0
-
- Posts: 4
- Joined: Fri Jun 24, 2011 4:10 am
Re: pcx image as background
Thanks mtheall, your allocation view is really cool. Yeah, i had worked out that i needed to init the bg
But now i have a new problem... how do i scale or wrap an image that is 320x200 ... i suppose i could turn the pcx data into tiles and to it that way somehow... hmmm, ill have a go, and then post back if i run into problems.
But now i have a new problem... how do i scale or wrap an image that is 320x200 ... i suppose i could turn the pcx data into tiles and to it that way somehow... hmmm, ill have a go, and then post back if i run into problems.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests