PocketMatrix forums

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

EasyCE clear() function

GeoffSulcer · 14 Dec 2001, 10:09 UTC
Ok, this may be a bonehead question.  In the clear() function from EasyCE:

Code:

void clear( PIXEL color )
{
     memset( getbuffer(), color, 320 * 480 );
}


Why 480?  Is the buffer not 320 * 240 in size?

-Snork
Look at the docs for memset.  It fills the specified number of bytes, not WORDs.  The Pocket PC display is 320*240 WORDS, or 320*240*2 bytes.

Memset expects bytes. A pixel is two bytes.
GeoffSulcer · 14 Dec 2001, 11:02 UTC
Duh!

Thanks.  I knew i was missing something obvious.

-Snork
Hmm. I don't think that will work right for most colors. A color value of 0x1234 would result in the buffer being set to 0x343434...  Black and white would work fine though. :)

Dan East
Yes, good point Dan.  memset is filling on a per-byte basis and if your upper byte isn't the same as your lower byte then you're hosed.

BTW, you've got a typo in that source you've posted:

couplet<<16;

should be

couplet<<=16;

How about this? This assumes PIXEL is two bytes:
[fixed]
void clear(PIXEL color) {
 unsigned int couplet=color;
 couplet<<=16;
 couplet|=color;

 unsigned int *cur=(unsigned int *)getbuffer();
 unsigned int *end=cur+
   (320*240*sizeof(color))/sizeof(unsigned int);

 while (cur<end)
   *cur++=couplet;
}[/fixed]

Dan East
You would normally see "Last modification..." here, but I'm hiding it from you. :D [color=#3366cc]Last modification: Dan East - 12/14/01 at 11:31:02
Thanks Digby! Those types of errors really suck. I don't know if eVC++ would give you a "this operator has no effect" warning or not.

The sample code has been corrected...

Dan East
Hm, pretty stupid mistake I made in that clear function. :) Problem probably is that I never used it with anything else than black. :)