PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Wrong colors using memset()

I ran into a color issue when using memset() that produces colors not at all what they should be.

Basically, I want to fill a square of the screenBuffer with a particular color. This works fine for black (0x0000) and white (0xFFFF), but everything else gets screwy.

Here's a code snippet:

Code:
void square( short x1, short y1, short x2, short y2, PIXEL color )
{
for (short v = y1; v < y2; v++)
memset( gScreenBuffer+(v*SCREEN_WIDTH+x1), color, sizeof(PIXEL)*(x2-x1) );
}


I'm pretty sure the problem stems from the color being written into memory with incorrect sizing. (Black and white work fine because all 0's or all 1's being misaligned across byte boundries is ok.)

I'd like a quicker method of filling a square than writing a color directly into each PIXEL of the screenBuffer.

Can one of you guys help out?

Thanks,

Andre
This was discussed in another thread in this forum:

http://forums.pocketmatrix.com/viewtopic.php?t=1346

Pam
Hi Andre,

Please be aware that the previous example by Dan East only works if you are going to fill the entire buffer. If you are going for segments you need to check your pointer for odd word alignment, otherwise it will sometimes crash on Pocket PCs but work perfectly well on statinary PCs.

/Johan
It's as I thought for the mis-alignment. Thanks for the posts.

I am not sure Dan's code helps me, as he loops through the screenBuffer and fills it pixel by pixel. I was already doing that, so this just solidifies that method as "the" solution. (Besides using black and white. :) Sorry, memset().

Thanks again for the info,

Andre