00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "pgdraw.h"
00032
00033 void PG_Draw::SetPixel(int x, int y, const PG_Color& c, SDL_Surface * surface) {
00034 static PG_Color old;
00035 Uint8 ri,gi,bi;
00036
00037 static Uint32 pixel;
00038 static Uint8 *bits;
00039 static Uint8 bpp;
00040
00041 static SDL_Rect rect;
00042 SDL_GetClipRect(surface, &rect);
00043
00044 if((x < rect.x) || (y < rect.y)) {
00045 return;
00046 }
00047
00048 if((x >= rect.x+rect.w) || (y >= rect.y+rect.h)) {
00049 return;
00050 }
00051
00052 bpp = surface->format->BytesPerPixel;
00053 bits = ((Uint8 *) surface->pixels) + y * surface->pitch + x * bpp;
00054
00055 if(old != c) {
00056 pixel = c.MapRGB(surface->format);
00057 old = c;
00058 }
00059
00060
00061 switch (bpp) {
00062 case 1:
00063 *((Uint8 *) (bits)) = (Uint8) pixel;
00064 break;
00065
00066 case 2:
00067 *((Uint16 *) (bits)) = (Uint16) pixel;
00068 break;
00069
00070 case 3: {
00071 ri = (pixel >> surface->format->Rshift) & 0xFF;
00072 gi = (pixel >> surface->format->Gshift) & 0xFF;
00073 bi = (pixel >> surface->format->Bshift) & 0xFF;
00074 *((bits) + surface->format->Rshift / 8) = ri;
00075 *((bits) + surface->format->Gshift / 8) = gi;
00076 *((bits) + surface->format->Bshift / 8) = bi;
00077 }
00078 break;
00079
00080 case 4:
00081 *((Uint32 *) (bits)) = (Uint32) pixel;
00082 break;
00083 }
00084 }