27
27
typedef SDLmm::SPoint SPoint;
29
//! A Device Independent color. Shamelessly pinched from Paragui to reduce coupling
30
class DI_Color : public SDL_Color {
33
DI_Color(const SDL_Color& c);
35
DI_Color(Uint8 r, Uint8 g, Uint8 b);
37
DI_Color& operator=(const SDL_Color& c);
39
DI_Color& operator=(Uint32 c);
41
// operator Uint32() const;
43
inline Uint32 MapRGB(SDL_PixelFormat* format) const {
44
return SDL_MapRGB(format, r, g, b);
47
inline Uint32 MapRGBA(SDL_PixelFormat* format, Uint8 a) const {
48
return SDL_MapRGBA(format, r, g, b, a);
51
inline bool operator!=(const DI_Color& c) const {
52
return !operator==(c);// ((r != c.r) || (g != c.g) || (b != c.b));
55
inline bool operator==(const DI_Color& c) const {
56
return ((r == c.r) && (g == c.g) && (b == c.b));
29
62
class Surface: public SDLmm::Surface {
63
void* pixelDataPointer; // in some situations
31
explicit Surface( SDL_Surface *surface) : SDLmm::Surface(surface) {};
32
Surface(const SDLmm::Surface& other) : SDLmm::Surface( other ) {};
65
static const Uint32 transparent = 0;
66
static const Uint32 opaque = 255l;
67
explicit Surface( SDL_Surface *surface);
68
Surface(const SDLmm::Surface& other);
69
Surface() : SDLmm::Surface(NULL), pixelDataPointer(NULL) {};
71
Surface Duplicate() const;
73
static Surface createSurface( int width, int height, SDLmm::Color color = 255 );
74
static Surface createSurface( int width, int height, int depth, SDLmm::Color color = 0xff0000ff );
76
static Surface Wrap( SDL_Surface *surface) { surface->refcount++; return Surface(surface);};
78
static void SetScreen( SDL_Surface* screen );
36
81
Creates an image from an BGI image structure.
38
void newFromBGI( void* img );
83
void newFromBGI( void* img );
86
void FillTransparent();
40
88
void read ( tnstream& stream ) ;
89
void readImageFile ( tnstream& stream ) ;
41
90
void write ( tnstream& stream ) const;
91
void strech ( int width, int height );
93
void writeDefaultPixelFormat ( tnstream& stream ) ;
94
static void readDefaultPixelFormat ( tnstream& stream );
96
//! assigns the default ASC palette to the surface (only for 8 Bit surfaces)
97
void assignDefaultPalette();
99
void assignPalette(SDL_Color* colors, int startColor = 0, int colorNum = 256 );
101
//! tries to automatically detect the color key of the surface
102
void detectColorKey( bool RLE = false );
104
bool isTransparent( SDLmm::Color col ) const;
106
void ColorKey2AlphaChannel() ;
110
SDLmm::ColorRGB GetRGB(SDLmm::Color pixel) const;
111
SDLmm::ColorRGBA GetRGBA(SDLmm::Color pixel) const;
114
int getMemoryFootprint() const;
116
SDL_Surface* getBaseSurface() { return me; };
117
const SDL_Surface* getBaseSurface() const { return me; };
120
virtual int getDepthFormat() { return -1; };
124
static SDLmm::PixelFormat* default8bit;
125
static SDLmm::PixelFormat* default32bit;
129
class TypedSurfaceBase : public Surface{
131
explicit TypedSurfaceBase( SDL_Surface *surface) : Surface(surface) {};
132
TypedSurfaceBase(const SDLmm::Surface& other) : Surface( other ) {};
133
TypedSurfaceBase() : Surface(NULL) {};
136
template<int colorDepth> class TypedSurface : public TypedSurfaceBase {
138
static const int depth = colorDepth;
139
explicit TypedSurface( SDL_Surface *surface) : TypedSurfaceBase(surface) {};
141
//! the parameter depthcheck is primarily there to prevent accidential usage of this constructor
142
explicit TypedSurface( SDLmm::Surface& surface , int depthCheck ) : TypedSurfaceBase(surface) {
143
assert ( surface.GetPixelFormat().BytesPerPixel() == depth );
144
assert ( depthCheck == depth );
147
TypedSurface(const TypedSurface<colorDepth>& other) : TypedSurfaceBase( other ) {};
148
TypedSurface() : TypedSurfaceBase(NULL) {};
150
virtual int getDepthFormat() { return depth; };
153
typedef TypedSurface<1> Surface8;
154
typedef TypedSurface<4> Surface32;
157
template<int depth> TypedSurface<depth>& castSurface( Surface& s ) {
158
assert ( s.GetPixelFormat().BytesPerPixel() == depth );
159
return static_cast<TypedSurface<depth>& >(s);
163
void applyFieldMask( Surface& s, int x = 0, int y = 0, bool detectColorKey = true );
165
//! applies a field mask that uses FEFEFE Color as Colorkey to load old images
166
void applyLegacyFieldMask( Surface& s, int x = 0, int y = 0, bool detectColorKey = false );
168
Surface rotateSurface( Surface& s, int degrees );
173
SurfaceLock( Surface& s ) : surf(s) { s.Lock(); };
174
~SurfaceLock() { surf.Unlock(); };