~ubuntu-branches/ubuntu/lucid/asc/lucid

« back to all changes in this revision

Viewing changes to source/graphics/surface.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Eddy Petrișor, Gonéri Le Bouder, Cyril Brulebois, Barry deFreese
  • Date: 2008-01-08 19:54:18 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080108195418-n19fc4eobhhqxcy5
Tags: 2.0.1.0-1
[ Eddy Petrișor ]
* fixed Homepage semifield

[ Gonéri Le Bouder ]
* add a watchfile
* move homepage from the description to the new Homepage field

[ Cyril Brulebois ]
* Added Vcs-Svn and Vcs-Browser fields in the control file.

[ Barry deFreese ]
* Fix make-clean lintian warning
* New upstream release
* Bump debhelper build-dep to match compat
* Add desktop file
* Update watch file for new upstream naming
* Remove nostrip check from rules
* Bump Standards Version to 3.7.3
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
 typedef SDLmm::SPoint SPoint;
28
28
 
 
29
 //! A Device Independent color. Shamelessly pinched from Paragui to reduce coupling
 
30
class DI_Color : public SDL_Color {
 
31
public:
 
32
        DI_Color();
 
33
        DI_Color(const SDL_Color& c);
 
34
        DI_Color(Uint32 c);
 
35
        DI_Color(Uint8 r, Uint8 g, Uint8 b);
 
36
 
 
37
        DI_Color& operator=(const SDL_Color& c);
 
38
 
 
39
        DI_Color& operator=(Uint32 c);
 
40
 
 
41
        // operator Uint32() const;
 
42
 
 
43
        inline Uint32 MapRGB(SDL_PixelFormat* format) const {
 
44
                return SDL_MapRGB(format, r, g, b);
 
45
        }
 
46
 
 
47
        inline Uint32 MapRGBA(SDL_PixelFormat* format, Uint8 a) const {
 
48
                return SDL_MapRGBA(format, r, g, b, a);
 
49
        }
 
50
 
 
51
        inline bool operator!=(const DI_Color& c) const {
 
52
      return !operator==(c);// ((r != c.r) || (g != c.g) || (b != c.b));
 
53
        }
 
54
   
 
55
   inline bool operator==(const DI_Color& c) const {
 
56
      return ((r == c.r) && (g == c.g) && (b == c.b));
 
57
   }
 
58
   
 
59
};
 
60
 
 
61
 
29
62
 class Surface: public SDLmm::Surface {
 
63
      void* pixelDataPointer; // in some situations
30
64
    public:
31
 
      explicit Surface( SDL_Surface *surface) : SDLmm::Surface(surface) {};
32
 
      Surface(const SDLmm::Surface& other) : SDLmm::Surface( other ) {};
33
 
      Surface() {};
34
 
 
 
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) {};
 
70
 
 
71
      Surface Duplicate() const;
 
72
 
 
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 );
 
75
      
 
76
      static Surface Wrap( SDL_Surface *surface) { surface->refcount++; return Surface(surface);};
 
77
      
 
78
      static void SetScreen( SDL_Surface* screen );
 
79
      
35
80
      /**
36
81
         Creates an image from an BGI image structure.
37
82
      */
38
 
      void newFromBGI( void* img );
 
83
      void  newFromBGI( void* img );
 
84
      void* toBGI() const;
39
85
 
 
86
      void FillTransparent();
 
87
      
40
88
      void read ( tnstream& stream ) ;
 
89
      void readImageFile ( tnstream& stream ) ;
41
90
      void write ( tnstream& stream ) const;
42
 
 
43
 
 };
44
 
 
45
 
 
 
91
      void strech ( int width, int height );
 
92
 
 
93
      void writeDefaultPixelFormat ( tnstream& stream ) ;
 
94
      static void readDefaultPixelFormat ( tnstream& stream );
 
95
 
 
96
      //! assigns the default ASC palette to the surface (only for 8 Bit surfaces)
 
97
      void assignDefaultPalette();
 
98
 
 
99
      void assignPalette(SDL_Color* colors, int startColor = 0, int colorNum = 256 );
 
100
 
 
101
      //! tries to automatically detect the color key of the surface
 
102
      void detectColorKey( bool RLE = false );
 
103
 
 
104
      bool isTransparent( SDLmm::Color col ) const;
 
105
 
 
106
      void ColorKey2AlphaChannel() ;
 
107
 
 
108
      bool hasAlpha();
 
109
      /*
 
110
      SDLmm::ColorRGB GetRGB(SDLmm::Color pixel) const;
 
111
      SDLmm::ColorRGBA GetRGBA(SDLmm::Color pixel) const;
 
112
      */
 
113
 
 
114
      int getMemoryFootprint() const;
 
115
      
 
116
      SDL_Surface* getBaseSurface() { return me; };
 
117
      const SDL_Surface* getBaseSurface() const { return me; };
 
118
      ~Surface();
 
119
   protected:
 
120
      virtual int getDepthFormat() { return -1; };
 
121
      void convert();
 
122
           
 
123
   private:
 
124
      static SDLmm::PixelFormat* default8bit;
 
125
      static SDLmm::PixelFormat* default32bit;
 
126
 
 
127
 };
 
128
 
 
129
 class TypedSurfaceBase  : public Surface{
 
130
    protected:
 
131
      explicit TypedSurfaceBase( SDL_Surface *surface) : Surface(surface) {};
 
132
      TypedSurfaceBase(const SDLmm::Surface& other) : Surface( other ) {};
 
133
      TypedSurfaceBase() : Surface(NULL) {};
 
134
 };     
 
135
 
 
136
 template<int colorDepth> class TypedSurface : public TypedSurfaceBase {
 
137
    public:
 
138
      static const int depth = colorDepth;
 
139
      explicit TypedSurface( SDL_Surface *surface) : TypedSurfaceBase(surface) {};
 
140
      
 
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 );
 
145
      };
 
146
      
 
147
      TypedSurface(const TypedSurface<colorDepth>& other) : TypedSurfaceBase( other ) {};
 
148
      TypedSurface() : TypedSurfaceBase(NULL) {};
 
149
   protected:
 
150
      virtual int getDepthFormat() { return depth; };
 
151
 };
 
152
 
 
153
 typedef TypedSurface<1> Surface8;
 
154
 typedef TypedSurface<4> Surface32;
 
155
 
 
156
 
 
157
 template<int depth> TypedSurface<depth>& castSurface( Surface& s ) {
 
158
    assert ( s.GetPixelFormat().BytesPerPixel() == depth );
 
159
    return static_cast<TypedSurface<depth>& >(s);
 
160
 };
 
161
 
 
162
 
 
163
 void applyFieldMask( Surface& s, int x = 0, int y = 0, bool detectColorKey = true );
 
164
 
 
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 );
 
167
 
 
168
 Surface rotateSurface( Surface& s, int degrees );
 
169
 
 
170
class SurfaceLock {
 
171
      Surface& surf;
 
172
   public:
 
173
      SurfaceLock( Surface& s ) : surf(s) { s.Lock(); };
 
174
      ~SurfaceLock() { surf.Unlock(); };
 
175
};
 
176
 
 
177
 
 
178
 
46
179
#endif
47
180