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

drawing.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003     Copyright (C) 1994-2003  Martin Bickel  and  Marc Schellenberger
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; see the file COPYING. If not, write to the
00017     Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00018     Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include "drawing.h"
00022 
00023 /*
00024 SDLmm::ColorRGB lightenColor( const SDLmm::ColorRGB& color, float factor )
00025 {
00026    SDLmm::ColorRGB c  = color;
00027    c.r =  min( max( int( float(c.r) * factor ), 0 ), 255);
00028    c.g =  min( max( int( float(c.g) * factor ), 0 ), 255);
00029    c.b =  min( max( int( float(c.b) * factor ), 0 ), 255);
00030    return c;
00031 };
00032 
00033 */
00034 
00035 char saturationTranslationTable[256][256];
00036 
00037 class TableGenerator {
00038    public:
00039       TableGenerator() {
00040          for ( int i = 0; i < 256; ++i )
00041             for ( int j = 0; j < 256; ++j ) {
00042                int v = i * j / 16;
00043                if ( v > 255 )
00044                   v = 255;
00045                if ( v < 0 )
00046                   v = 0;
00047                saturationTranslationTable[i][j] = v;
00048             }
00049       };
00050 } tableGenerator;
00051 
00052 #if 0
00053 SDLmm::Color lighten_Color( SDLmm::Color color, char factor16 )
00054 {
00055    SDLmm::Color c = saturationTranslationTable[color & 0xff][factor16] |
00056          (saturationTranslationTable[(color >> 8) & 0xff][factor16] << 8 ) |
00057          (saturationTranslationTable[(color >> 16) & 0xff][factor16] << 16 ) |
00058          (color & 0xff000000);
00059    /*
00060    SDLmm::Color c = min( max( int( float(color & 0xff) * factor ), 0 ), 255) |
00061                     (min( max( int( float((color >> 8) & 0xff) * factor ), 0 ), 255) << 8) |
00062                     (min( max( int( float((color >> 16) & 0xff) * factor ), 0 ), 255) << 16) |
00063                     (color & 0xff000000);
00064    */
00065    return c;
00066 }
00067 
00068 SDL_Color lightenColor( const SDL_Color& color, float factor )
00069 {
00070    SDL_Color c  = color;
00071    c.r =  min( max( int( float(c.r) * factor ), 0 ), 255);
00072    c.g =  min( max( int( float(c.g) * factor ), 0 ), 255);
00073    c.b =  min( max( int( float(c.b) * factor ), 0 ), 255);
00074    return c;
00075 };
00076 
00077 
00078 void lighten_Color( SDLmm::Color* color, float factor )
00079 {
00080    *color = lighten_Color( *color, factor );
00081 }
00082 
00083 
00084 
00085 
00086 void PutPixel( Surface& s, const SPoint& pos, Uint32 src )
00087 {
00088    typedef Uint32 PixelType;
00089    
00090    char* c = (char*) s.pixels();
00091    c += pos.y * s.pitch();
00092    PixelType* dest = (Uint32*) c;
00093    dest += pos.x;
00094 
00095    PixelType alpha = src >> 24;   
00096    
00097    if ( alpha != PixelType(Surface::transparent)) {
00098       // copied from SDL
00099 
00100       /*
00101        * take out the middle component (green), and process
00102        * the other two in parallel. One multiply less.
00103        */
00104       PixelType d = *dest;
00105       PixelType dalpha = d & 0xff000000;
00106       PixelType s1 = src & 0xff00ff;
00107       PixelType d1 = d & 0xff00ff;
00108       d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
00109       src &= 0xff00;
00110       d &= 0xff00;
00111       d = (d + ((src - d) * alpha >> 8)) & 0xff00;
00112       *dest = d1 | d | dalpha;
00113    }
00114 }
00115 #endif
00116 

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