2 * Written By: Garrett Banuk <mongoose@mongeese.org>
3 * This is free, just be sure to give me credit when using it
4 * in any of your programs.
7 /* internal.[c,h] are various routines used internally
8 * by SDL_console and DrawText. */
14 * Return the pixel value at (x, y)
15 * NOTE: The surface must be locked before calling this!
17 Uint32 DT_GetPixel(SDL_Surface *surface, int x, int y) {
18 int bpp = surface->format->BytesPerPixel;
19 /* Here p is the address to the pixel we want to retrieve */
20 Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
28 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
29 return p[0] << 16 | p[1] << 8 | p[2];
31 return p[0] | p[1] << 8 | p[2] << 16;
35 return 0; /* shouldn't happen, but avoids warnings */
40 * Set the pixel at (x, y) to the given value
41 * NOTE: The surface must be locked before calling this!
43 void DT_PutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
44 int bpp = surface->format->BytesPerPixel;
45 /* Here p is the address to the pixel we want to set */
46 Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
53 *(Uint16 *) p = pixel;
56 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
57 p[0] = (pixel >> 16) & 0xff;
58 p[1] = (pixel >> 8) & 0xff;
62 p[1] = (pixel >> 8) & 0xff;
63 p[2] = (pixel >> 16) & 0xff;
67 *(Uint32 *) p = pixel;