What’s the absolute most compatible way (ie, it would work under ANY pixel
depth) to read pixels from a surface?
I’ve looked at the drawing-SDL library someone posted (hey! you didn’t put
your name or e-mail address in either H or C file!) and it only does
drawing TO the surface.
I’d like to read FROM it. All of the demos and examples that do anything
like that (for example, any of the flame/fire ones) just set up a color
palette first. But… I won’t really have that much control over the colors
being used on the surface, so setting up a palette beforehand isn’t useful.
Thanks!
-bill!
William Kendrick wrote:
What’s the absolute most compatible way (ie, it would work under ANY pixel
depth) to read pixels from a surface?
I’ve looked at the drawing-SDL library someone posted (hey! you didn’t put
your name or e-mail address in either H or C file!) and it only does
drawing TO the surface.
I’d like to read FROM it. All of the demos and examples that do anything
like that (for example, any of the flame/fire ones) just set up a color
palette first. But… I won’t really have that much control over the colors
being used on the surface, so setting up a palette beforehand isn’t useful.
I tried using the following code to do that job (seems to work on both
16 and 32-bit color depths with no change; don’t have the ability to set
to anything else):
SDL_Surface thesurface;
int x, y; / these should be set to the appropriate coordinates */
Uint32 pixel;
Uint32 bpp, ofs;
pixel = 0;
bpp = thesurface->format->BytesPerPixel;
ofs = thesurface->pitchy + xbpp;
memcpy(&pixel, screen->pixels + ofs, bpp);–
| Rafael R. Sevilla @Rafael_R_Sevilla |
| Instrumentation, Robotics, and Control Laboratory |
College of Engineering, University of the Philippines, Diliman |
Remember to lock the surface before reading and unlock after (if the surface
is in vidmem)
NeilOn Fri, 3 Dec 1999, Rafael R. Sevilla wrote:
William Kendrick wrote:
What’s the absolute most compatible way (ie, it would work under ANY pixel
depth) to read pixels from a surface?
I’ve looked at the drawing-SDL library someone posted (hey! you didn’t put
your name or e-mail address in either H or C file!) and it only does
drawing TO the surface.
I’d like to read FROM it. All of the demos and examples that do anything
like that (for example, any of the flame/fire ones) just set up a color
palette first. But… I won’t really have that much control over the colors
being used on the surface, so setting up a palette beforehand isn’t useful.
I tried using the following code to do that job (seems to work on both
16 and 32-bit color depths with no change; don’t have the ability to set
to anything else):
SDL_Surface thesurface;
int x, y; / these should be set to the appropriate coordinates */
Uint32 pixel;
Uint32 bpp, ofs;
pixel = 0;
bpp = thesurface->format->BytesPerPixel;
ofs = thesurface->pitchy + xbpp;
memcpy(&pixel, screen->pixels + ofs, bpp);
–
| Rafael R. Sevilla dido at pacific.net.ph |
| Instrumentation, Robotics, and Control Laboratory |
College of Engineering, University of the Philippines, Diliman |
–
Neil McGill mailto:Neil_McGill *8^) . .
Software Developer:ISDN, Cisco Systems Ltd ~~""~""~"~"|~"~
3rd Floor, 96 Commercial Street, Edinburgh, EH6 6LX, UK ||| |||
Tel: 0131 561 3622 Fax: 0131 561 3601 Mob: 07714 226 281 .:|||||:.:|||||:.