on 3/11/00 2:35, David Fedor at [EMAIL PROTECTED] wrote:

> I'll just chime in and say that if you're on 3.5 or higher, you really
> really should use the WinSetPixel API.  Or else you're going to have to
> hope and pray that nobody does something... well... "interesting" with the
> screen or the screen buffer or other things like that.  You can't always
> anticipate everything that'll go on, but the APIs are guaranteed to work.
> (The occasional bug excepted, of course.)
> 
> So go ahead and hack, but since there's this lovely API sitting there,
> please do use it when you're on 3.5 or higher.  You and your users will
> thank you in the future.

And David is right... The right way to directly access screen memory is to
have your own offscreen buffer into which you draw before blasting it to the
screen using OS calls. Here is some example code that lets you access pixels
in your own buffer (code below rewritten without testing, double check my
formulas if this doesn't work :-)):

// PREREQUISITES:
unsigned char *buffer;  // pointer to your offscreen buffer
unsigned int rowbytes;  // number of bytes per screen row
unsigned int x, y;      // coordinates of the pixel you want to access

// set a pixel in 1bpp
unsigned char *p = buffer + y * rowbytes + (x >> 3);
*p |= 1 << (7 - (x & 7));

// clear a pixel in 1bpp
*p &= ~(1 << (7 - (x & 7)));

// set a pixel to color C in 2bpp
unsigned char *p = buffer + y * rowbytes + (x >> 2);
*p = (*p & ~(3 << (7 - ((x & 3) << 1)))) | (C << (7 - ((x & 3) << 1)));

// set a pixel to color C in 4bpp
unsigned char *p = buffer + y * rowbytes + (x >> 1);
*p = (*p & ~(15 << (1 - (x & 1)))) | (C << (15 << (1 - (x & 1))));

// set a pixel to color C in 8bpp
*(buffer + y * rowbytes + x) = C;


With a good optimizing compiler, intermediate results from the similar
expressions in the same line in the formulas above should be stored in a
register and reused, not calculated twice. But if you are not sure, you may
want to use a variable to store the calculated rotation count.

Also, the formulas for 2bpp and 4bpp may be optimized by removing the
negation in the mask and rotating a pre-negated mask with different values.

Hope this helps,
Florent.

-- 
Florent Pillet, Code Segment       [EMAIL PROTECTED]

BrainForest, outlines and action items for Palm OS handhelds
   -> Aportis Technologies Corp.     http://www.aportis.com/
PowerGlot, the premier localization tool for Mac OS software
   -> PowerGlot Software           http://www.powerglot.com/
Palm Buddy, MacOS active link companion for PalmOS handhelds
   -> ...and other tools... http://perso.wanadoo.fr/fpillet/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to