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