GP2X Reading Pixels - Every Other Line Gets Skipped


Jan 2, 2007
I have some code to read from the back buffer, which works perfectly on windows debug version. However on the GP2X it seems that it skips every other line and reads a rectangle that's twice as big as the one I specified, but scaled by 1/2 in vertical.

Here's the code:
	unsigned long scanline = Screen.getWidth();
	Buffer = (unsigned short*)gl_malloc(Width*Height*sizeof(unsigned short)); //memset(Buffer, 0, Width*Height*2);
	register unsigned short* pScreen = (unsigned short*)Screen.getColorBuffer();
	register unsigned short* pBuf = Buffer;
	for(y = ClipY; y < ClipHeight; y++)
		for(x = ClipX; x < ClipWidth; x++)
			*pBuf++ = *pScreen++;

gl_malloc returns a mmap'ed memory from the upper 32 MB (mmuhack). The Screen.getColorBuffer is also in this memory space.
The graphic I am grabbing from looks correct. If I load an image into my sprite class, it works, too. But grabbed images are scaled by 1/2 in vertical, but the do have the correct size. I mean: I grab 32x32, and it returns me a grab of 32x64 scaled to 32x32.

Any ideas what this might be?
KungPhoo posted on Mar 23 2007 at 01:45 PM said:
Any ideas what this might be?

Different address for odd and even lines in your GP2X video mode ?
I don't know what the default video mode is, but it may be using this feature.
Last edited by a moderator:
Your 'for' goes from ClipX to ClipWidth, shouldn't this be taken for in your routines after the for loops, rather than just subtracting ClipWidth?
You should check what Screen.getWidth is actually returning, I don't know the exact interface you're using there but if it were in units of bytes instead of shorts then it'd be causing the problem you're describing.