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
00032 #ifndef SURFACE_INCLUDED
00033 #define SURFACE_INCLUDED
00034
00035 #ifdef _MSC_VER
00036 #pragma warning( disable : 4530 )
00037 #pragma warning( disable : 4786 )
00038 #endif
00039
00040 #include <string>
00041
00042 #include "SDL.h"
00043 #include "../../grinliz/gltypes.h"
00044 #include "color.h"
00045 #include "../engine/krmath.h"
00046 #include "../engine/kyrabuild.h"
00047
00048 struct KrPaintInfo;
00049 class KrTexture;
00050
00051
00057 class KrPainter
00058 {
00059 public:
00060 KrPainter( SDL_Surface* _surface );
00061 KrPainter( KrPaintInfo* _info );
00062
00063 ~KrPainter();
00064
00069 void SetPixel( int x, int y, const KrRGBA& color );
00070
00072 void SetPixel( void* target, U8 red, U8 green, U8 blue, U8 alpha );
00073
00075 void DrawBox( int x, int y, int w, int h,
00076 U8 red, U8 green, U8 blue );
00077
00079 void DrawBox( int x, int y, int w, int h,
00080 const KrRGBA* colors, int nColors );
00081
00083 void DrawFilledBox( int x, int y, int w, int h,
00084 U8 red, U8 green, U8 blue );
00085
00087 void DrawVLine( int x, int y, int h,
00088 U8 red, U8 green, U8 blue );
00089
00091 void DrawVLine( int x, int y, int h,
00092 const KrRGBA* colors, int nColors );
00093
00094
00096 void DrawHLine( int x, int y, int h,
00097 U8 red, U8 green, U8 blue );
00098
00100 void DrawHLine( int x, int y, int h,
00101 const KrRGBA* colors, int nColors );
00102
00103
00104
00105
00106 int CalcTransparentRun( int xmin, int xmax, int y );
00107
00108
00109
00110
00111 int CalcTransparentColumn( int ymin, int ymax, int x );
00112
00113
00114
00115
00116
00117 int CalcNotTransparentRun( int xmin, int xmax, int y );
00118
00119
00120
00121
00122
00123 int CalcOpaqueRun( int xmin, int xmax, int y );
00124
00125
00126
00127
00128
00129 int CalcTranslucentRun( int xmin, int xmax, int y );
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 int FindPixel( int x, int y, int dx, int dy, KrRGBA color, bool useAlpha, bool invert = false );
00141
00146 void BreakPixel( int x, int y, U8* r, U8* g, U8* b, U8* a );
00147
00152 void BreakPixel( int x, int y, KrRGBA* rgba ) { BreakPixel( x, y, &rgba->c.red, &rgba->c.green, &rgba->c.blue, &rgba->c.alpha ); }
00153
00154 private:
00155 SDL_Surface* surface;
00156 };
00157
00158
00159 typedef void (*KrPaintFunc)( KrPaintInfo* info,
00160 void* target,
00161 KrRGBA* source,
00162 int nPixel,
00163 const KrColorTransform cform );
00164
00165 typedef void (*KrPaintFuncRotated)( KrPaintInfo* info,
00166 void* target,
00167 KrRGBA* source,
00168 int sPitch,
00169 int nPixel );
00170
00171
00172 struct KrPaintInfo
00173 {
00174
00175 KrPaintInfo( SDL_Surface* screen );
00176
00177
00178 KrPaintInfo( KrRGBA* memory, int width, int height );
00179
00180 ~KrPaintInfo() { if ( needToFreeSurface ) SDL_FreeSurface( surface ); }
00181
00182
00183
00184
00185 KrPaintFunc GetBlitter( bool sourceAlpha,
00186 const KrColorTransform cform );
00187
00188
00189 void SetOpenGLTextureMode( bool sourceAlpha,
00190 const KrColorTransform cform,
00191 bool isScaled,
00192 KrTexture* texture );
00193
00194 void GetBlitterName( KrPaintFunc func, std::string* name );
00195
00196 bool OpenGL() { return openGL; }
00197
00198 int width;
00199 int height;
00200 int pitch;
00201 int bytesPerPixel;
00202 void* pixels;
00203 bool openGL;
00204
00205
00206
00207 U8 redShift;
00208 U8 greenShift;
00209 U8 blueShift;
00210 U8 alphaShift;
00211
00212 U32 redMask;
00213 U32 greenMask;
00214 U32 blueMask;
00215 U32 alphaMask;
00216
00217 U8 redLoss;
00218 U8 greenLoss;
00219 U8 blueLoss;
00220 U8 alphaLoss;
00221
00222
00223 U8 redByte;
00224 U8 greenByte;
00225 U8 blueByte;
00226
00227 KrPaintFunc Paint_Simple_NoAlpha;
00228 KrPaintFunc Paint_Color_NoAlpha;
00229 KrPaintFunc Paint_Alpha_NoAlpha;
00230 KrPaintFunc Paint_Full_NoAlpha;
00231
00232 KrPaintFunc Paint_Simple_Alpha;
00233 KrPaintFunc Paint_Color_Alpha;
00234 KrPaintFunc Paint_Alpha_Alpha;
00235 KrPaintFunc Paint_Full_Alpha;
00236
00237 KrPaintFuncRotated PaintRotated_Simple_NoAlpha;
00238
00239 SDL_Surface* surface;
00240
00241 private:
00242 bool needToFreeSurface;
00243 void InitCopies();
00244 };
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 void KrPaint32_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00261 void KrPaint32B_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00262
00263 void KrPaint32_Color_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00264 void KrPaint32_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00265 void KrPaint32_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00266 void KrPaint32_Simple_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00267 void KrPaint32_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00268 void KrPaint32_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00269 void KrPaint32_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00270
00271 void KrPaintRGBA_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00272 void KrPaintRGBA_Color_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00273 void KrPaintRGBA_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00274 void KrPaintRGBA_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00275 void KrPaintRGBA_Simple_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00276 void KrPaintRGBA_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00277 void KrPaintRGBA_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00278 void KrPaintRGBA_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00279
00280 void KrPaint24_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00281 void KrPaint24_Color_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00282 void KrPaint24_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00283 void KrPaint24_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00284 void KrPaint24_Simple_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00285 void KrPaint24_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00286 void KrPaint24_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00287 void KrPaint24_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00288
00289 void KrPaint16_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00290 void KrPaint16_Color_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00291 void KrPaint16_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00292 void KrPaint16_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00293 void KrPaint16_Simple_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00294 void KrPaint16_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00295 void KrPaint16_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00296 void KrPaint16_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00297
00298 void KrPaintRGBARotated_Simple_NoAlpha( KrPaintInfo* info,
00299 void* target,
00300 KrRGBA* source,
00301 int sPitch,
00302 int nPixel );
00303 void KrPaint32Rotated_Simple_NoAlpha( KrPaintInfo* info,
00304 void* target,
00305 KrRGBA* source,
00306 int sPitch,
00307 int nPixel );
00308 void KrPaint24Rotated_Simple_NoAlpha( KrPaintInfo* info,
00309 void* target,
00310 KrRGBA* source,
00311 int sPitch,
00312 int nPixel );
00313 void KrPaint16Rotated_Simple_NoAlpha( KrPaintInfo* info,
00314 void* target,
00315 KrRGBA* source,
00316 int sPitch,
00317 int nPixel );
00318
00319 #endif
00320