~ubuntu-branches/ubuntu/raring/scummvm/raring

« back to all changes in this revision

Viewing changes to engines/gob/surface.h

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: (21.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ScummVM - Graphic Adventure Engine
 
2
 *
 
3
 * ScummVM is the legal property of its developers, whose names
 
4
 * are too numerous to list here. Please refer to the COPYRIGHT
 
5
 * file distributed with this source distribution.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU General Public License
 
9
 * as published by the Free Software Foundation; either version 2
 
10
 * of the License, or (at your option) any later version.
 
11
 
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
20
 *
 
21
 * $URL$
 
22
 * $Id$
 
23
 *
 
24
 */
 
25
 
 
26
#ifndef GOB_SURFACE_H
 
27
#define GOB_SURFACE_H
 
28
 
 
29
#include "common/scummsys.h"
 
30
#include "common/ptr.h"
 
31
#include "common/rational.h"
 
32
#include "common/iff_container.h"
 
33
 
 
34
#include "graphics/iff.h"
 
35
 
 
36
namespace Common {
 
37
class SeekableReadStream;
 
38
}
 
39
 
 
40
namespace Gob {
 
41
 
 
42
enum ImageType {
 
43
        kImageTypeNone = -1,
 
44
        kImageTypeTGA  =  0,
 
45
        kImageTypeLBM,
 
46
        kImageTypeBRC,
 
47
        kImageTypeBMP,
 
48
        kImageTypeJPEG
 
49
};
 
50
 
 
51
class LBMLoader {
 
52
public:
 
53
        LBMLoader(Common::SeekableReadStream &stream);
 
54
 
 
55
        bool loadHeader (Graphics::BMHD &header);
 
56
        bool loadPalette(byte *palette);
 
57
        bool loadImage  (byte *image);
 
58
 
 
59
private:
 
60
        Common::IFFParser _parser;
 
61
 
 
62
        bool _hasHeader;
 
63
 
 
64
        Graphics::ILBMDecoder _decoder;
 
65
 
 
66
        byte *_palette;
 
67
        byte *_image;
 
68
 
 
69
        bool callbackHeader (Common::IFFChunk &chunk);
 
70
        bool callbackPalette(Common::IFFChunk &chunk);
 
71
        bool callbackImage  (Common::IFFChunk &chunk);
 
72
 
 
73
        bool readHeader();
 
74
};
 
75
 
 
76
/** An iterator over a surface's image data, automatically handles different color depths. */
 
77
class Pixel {
 
78
public:
 
79
        Pixel(byte *vidMem, uint8 bpp, byte *min, byte *max);
 
80
 
 
81
        Pixel &operator++();
 
82
        Pixel operator++(int x);
 
83
 
 
84
        Pixel &operator--();
 
85
        Pixel operator--(int x);
 
86
 
 
87
        Pixel &operator+=(int x);
 
88
        Pixel &operator-=(int x);
 
89
 
 
90
        uint32 get() const;
 
91
        void set(uint32 p);
 
92
 
 
93
        bool isValid() const;
 
94
 
 
95
private:
 
96
        byte *_vidMem;
 
97
        byte *_min, *_max;
 
98
        uint8 _bpp;
 
99
};
 
100
 
 
101
/** A const iterator over a surface's image data, automatically handles different color depths. */
 
102
class ConstPixel {
 
103
public:
 
104
        ConstPixel(const byte *vidMem, uint8 bpp, const byte *min, const byte *max);
 
105
 
 
106
        ConstPixel &operator++();
 
107
        ConstPixel operator++(int x);
 
108
 
 
109
        ConstPixel &operator--();
 
110
        ConstPixel operator--(int x);
 
111
 
 
112
        ConstPixel &operator+=(int x);
 
113
        ConstPixel &operator-=(int x);
 
114
 
 
115
        uint32 get() const;
 
116
 
 
117
        bool isValid() const;
 
118
 
 
119
private:
 
120
        const byte *_vidMem;
 
121
        const byte *_min, *_max;
 
122
        uint8 _bpp;
 
123
};
 
124
 
 
125
class Surface {
 
126
public:
 
127
        Surface(uint16 width, uint16 height, uint8 bpp, byte *vidMem = 0);
 
128
        ~Surface();
 
129
 
 
130
        uint16 getWidth () const;
 
131
        uint16 getHeight() const;
 
132
        uint8  getBPP   () const;
 
133
 
 
134
        byte *getData(uint16 x = 0, uint16 y = 0);
 
135
        const byte *getData(uint16 x = 0, uint16 y = 0) const;
 
136
 
 
137
        void resize(uint16 width, uint16 height);
 
138
 
 
139
        void setBPP(uint8 bpp);
 
140
 
 
141
        Pixel get(uint16 x = 0, uint16 y = 0);
 
142
        ConstPixel get(uint16 x = 0, uint16 y = 0) const;
 
143
 
 
144
        void blit(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
 
145
                  int16 x, int16 y, int32 transp = -1);
 
146
        void blit(const Surface &from, int16 x, int16 y, int32 transp = -1);
 
147
        void blit(const Surface &from, int32 transp = -1);
 
148
 
 
149
        void blitScaled(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
 
150
                        int16 x, int16 y, Common::Rational scale, int32 transp = -1);
 
151
        void blitScaled(const Surface &from, int16 x, int16 y, Common::Rational scale, int32 transp = -1);
 
152
        void blitScaled(const Surface &from, Common::Rational scale, int32 transp = -1);
 
153
 
 
154
        void fillRect(uint16 left, uint16 top, uint16 right, uint16 bottom, uint32 color);
 
155
        void fill(uint32 color);
 
156
        void clear();
 
157
 
 
158
        void shadeRect(uint16 left, uint16 top, uint16 right, uint16 bottom,
 
159
                        uint32 color, uint8 strength);
 
160
 
 
161
        void putPixel(uint16 x, uint16 y, uint32 color);
 
162
        void drawLine(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint32 color);
 
163
        void drawCircle(uint16 x0, uint16 y0, uint16 radius, uint32 color, int16 pattern = 0);
 
164
 
 
165
        void blitToScreen(uint16 left, uint16 top, uint16 right, uint16 bottom, uint16 x, uint16 y) const;
 
166
 
 
167
        bool loadImage(Common::SeekableReadStream &stream);
 
168
        bool loadImage(Common::SeekableReadStream &stream, ImageType type);
 
169
 
 
170
        static ImageType identifyImage(Common::SeekableReadStream &stream);
 
171
 
 
172
private:
 
173
        uint16 _width;
 
174
        uint16 _height;
 
175
        uint8  _bpp;
 
176
 
 
177
        bool  _ownVidMem;
 
178
        byte *_vidMem;
 
179
 
 
180
        static bool clipBlitRect(int16 &left, int16 &top, int16 &right, int16 &bottom, int16 &x, int16 &y,
 
181
                                 uint16 dWidth, uint16 dHeight, uint16 sWidth, uint16 sHeight);
 
182
 
 
183
        bool loadTGA (Common::SeekableReadStream &stream);
 
184
        bool loadLBM (Common::SeekableReadStream &stream);
 
185
        bool loadBRC (Common::SeekableReadStream &stream);
 
186
        bool loadBMP (Common::SeekableReadStream &stream);
 
187
        bool loadJPEG(Common::SeekableReadStream &stream);
 
188
};
 
189
 
 
190
typedef Common::SharedPtr<Surface> SurfacePtr;
 
191
 
 
192
} // End of namespace Gob
 
193
 
 
194
#endif // GOB_SURFACE_H