00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "drawing.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00061
00062
00063
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
00099
00100
00101
00102
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