Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

setpixel.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     setpixel - draw a single pixel onto a surface
00004  
00005     Copyright (C) 2000,2001,2002  Alexander Pipelka
00006  
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011  
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016  
00017     You should have received a copy of the GNU Library General Public
00018     License along with this library; if not, write to the Free
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  
00021     Alexander Pipelka
00022     pipelka@teleweb.at
00023  
00024     Last Update:      $Author: mbickel $
00025     Update Date:      $Date: 2007-04-13 16:16:01 $
00026     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/draw/setpixel.cpp,v $
00027     CVS/RCS Revision: $Revision: 1.2 $
00028     Status:           $State: Exp $
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         /* Set the pixel */
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: {                       /* Format/endian independent */
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 }

Generated on Tue Jun 24 01:27:52 2008 for Advanced Strategic Command by  doxygen 1.4.2