-
-/* Set pixel function */
-void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
-{
- Uint8 *ubuff8;
- Uint16 *ubuff16;
- Uint32 *ubuff32;
- Uint32 color;
-
- /* Lock the screen, if needed */
- if(SDL_MUSTLOCK(screen)) {
- if(SDL_LockSurface(screen) < 0)
- return;
- }
-
- /* Get the color */
- color = SDL_MapRGB( screen->format, r, g, b );
-
- /* How we draw the pixel depends on the bitdepth */
- switch(screen->format->BytesPerPixel) {
- case 1:
- ubuff8 = (Uint8*) screen->pixels;
- ubuff8 += (y * screen->pitch) + x;
- *ubuff8 = (Uint8) color;
- break;
- case 2:
- ubuff16 = (Uint16*) screen->pixels;
- ubuff16 += ((y * screen->pitch)>>2) + x;
- *ubuff16 = (Uint16) color;
- break;
- case 3:
- ubuff8 = (Uint8*) screen->pixels;
- ubuff8 += (y * screen->pitch) + x;
-
- r = (color>>screen->format->Rshift)&0xFF;
- g = (color>>screen->format->Gshift)&0xFF;
- b = (color>>screen->format->Bshift)&0xFF;
-
- ubuff8[0] = r;
- ubuff8[1] = g;
- ubuff8[2] = b;
- break;
-
- case 4:
- ubuff32 = (Uint32*) screen->pixels;
- ubuff32 += ((y*screen->pitch)>>2) + x;
- *ubuff32 = color;
- break;
-
- default:
- fprintf(stderr, "Error: Unknown bitdepth!\n");
- }
-
- /* Unlock the screen if needed */
- if(SDL_MUSTLOCK(screen)) {
- SDL_UnlockSurface(screen);
- }
-}