Advanced Strategic Command
drawing.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include "drawing.h"
22 
23 /*
24 SDLmm::ColorRGB lightenColor( const SDLmm::ColorRGB& color, float factor )
25 {
26  SDLmm::ColorRGB c = color;
27  c.r = min( max( int( float(c.r) * factor ), 0 ), 255);
28  c.g = min( max( int( float(c.g) * factor ), 0 ), 255);
29  c.b = min( max( int( float(c.b) * factor ), 0 ), 255);
30  return c;
31 };
32 
33 */
34 
36 
38  public:
40  for ( int i = 0; i < 256; ++i )
41  for ( int j = 0; j < 256; ++j ) {
42  int v = i * j / 16;
43  if ( v > 255 )
44  v = 255;
45  if ( v < 0 )
46  v = 0;
48  }
49  };
51 
52 #if 0
53 SDLmm::Color lighten_Color( SDLmm::Color color, Uint8 factor16 )
54 {
55  SDLmm::Color c = saturationTranslationTable[color & 0xff][factor16] |
56  (saturationTranslationTable[(color >> 8) & 0xff][factor16] << 8 ) |
57  (saturationTranslationTable[(color >> 16) & 0xff][factor16] << 16 ) |
58  (color & 0xff000000);
59  /*
60  SDLmm::Color c = min( max( int( float(color & 0xff) * factor ), 0 ), 255) |
61  (min( max( int( float((color >> 8) & 0xff) * factor ), 0 ), 255) << 8) |
62  (min( max( int( float((color >> 16) & 0xff) * factor ), 0 ), 255) << 16) |
63  (color & 0xff000000);
64  */
65  return c;
66 }
67 
68 SDL_Color lightenColor( const SDL_Color& color, float factor )
69 {
70  SDL_Color c = color;
71  c.r = min( max( int( float(c.r) * factor ), 0 ), 255);
72  c.g = min( max( int( float(c.g) * factor ), 0 ), 255);
73  c.b = min( max( int( float(c.b) * factor ), 0 ), 255);
74  return c;
75 };
76 
77 
78 void lighten_Color( SDLmm::Color* color, float factor )
79 {
80  *color = lighten_Color( *color, factor );
81 }
82 
83 
84 
85 
86 void PutPixel( Surface& s, const SPoint& pos, Uint32 src )
87 {
88  typedef Uint32 PixelType;
89 
90  char* c = (char*) s.pixels();
91  c += pos.y * s.pitch();
92  PixelType* dest = (Uint32*) c;
93  dest += pos.x;
94 
95  PixelType alpha = src >> 24;
96 
97  if ( alpha != PixelType(Surface::transparent)) {
98  // copied from SDL
99 
100  /*
101  * take out the middle component (green), and process
102  * the other two in parallel. One multiply less.
103  */
104  PixelType d = *dest;
105  PixelType dalpha = d & 0xff000000;
106  PixelType s1 = src & 0xff00ff;
107  PixelType d1 = d & 0xff00ff;
108  d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
109  src &= 0xff00;
110  d &= 0xff00;
111  d = (d + ((src - d) * alpha >> 8)) & 0xff00;
112  *dest = d1 | d | dalpha;
113  }
114 }
115 #endif
116 
static const Uint32 transparent
Definition: surface.h:65
SDLmm::Color Color
Definition: blitter.h:35
SDLmm::SPoint SPoint
Definition: surface.h:27
class TableGenerator tableGenerator
Uint8 saturationTranslationTable[256][256]
Definition: drawing.cpp:35
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
SDLmm::Color lighten_Color(SDLmm::Color color, int factor16)
Definition: lighten.h:37