Page 1 of 1

pcx image as background

Posted: Fri Jun 24, 2011 4:15 am
by meeces2911
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.

Re: pcx image as background

Posted: Fri Jun 24, 2011 1:45 pm
by elhobbs
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

Posted: Fri Jun 24, 2011 2:33 pm
by ritz
Here's some code I posted on forums just the other day:

Code: Select all

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


	return tp; // free(tp);

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

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


Re: pcx image as background

Posted: Sat Jun 25, 2011 3:11 am
by meeces2911
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

Posted: Sat Jun 25, 2011 5:03 pm
by mtheall
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: ... x256&MB2=0

Re: pcx image as background

Posted: Sun Jun 26, 2011 1:52 am
by meeces2911
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.