pcx image as background

Post Reply
meeces2911
Posts: 4
Joined: Fri Jun 24, 2011 4:10 am

pcx image as background

Post by meeces2911 » Fri Jun 24, 2011 4:15 am

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.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: pcx image as background

Post by elhobbs » Fri Jun 24, 2011 1:45 pm

I am a little confused why you might think this is not possible. can you maybe clarify what you think would be the issue?

ritz
Posts: 24
Joined: Thu Jun 04, 2009 3:17 pm
Location: Canada

Re: pcx image as background

Post by ritz » Fri Jun 24, 2011 2:33 pm

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);
}

meeces2911
Posts: 4
Joined: Fri Jun 24, 2011 4:10 am

Re: pcx image as background

Post by meeces2911 » Sat Jun 25, 2011 3:11 am

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.

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: pcx image as background

Post by mtheall » Sat Jun 25, 2011 5:03 pm

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

meeces2911
Posts: 4
Joined: Fri Jun 24, 2011 4:10 am

Re: pcx image as background

Post by meeces2911 » Sun Jun 26, 2011 1:52 am

Thanks mtheall, your allocation view is really cool. Yeah, i had worked out that i needed to init the bg :D

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests