ScummVM API documentation
surface.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_SURFACE_H
29 #define GOB_SURFACE_H
30 
31 #include "common/scummsys.h"
32 #include "common/ptr.h"
33 #include "common/rational.h"
34 #include "common/rect.h"
35 
36 namespace Common {
37 class SeekableReadStream;
38 }
39 
40 namespace Gob {
41 
42 enum ImageType {
43  kImageTypeNone = -1,
44  kImageTypeTGA = 0,
45  kImageTypeIFF,
46  kImageTypeBRC,
47  kImageTypeBMP,
48  kImageTypeJPEG
49 };
50 
52 class Pixel {
53 public:
54  Pixel(byte *vidMem, uint8 bpp, byte *min, byte *max);
55 
56  Pixel &operator++();
57  Pixel operator++(int x);
58 
59  Pixel &operator--();
60  Pixel operator--(int x);
61 
62  Pixel &operator+=(int x);
63  Pixel &operator-=(int x);
64 
65  uint32 get() const;
66  void set(uint32 p);
67 
68  bool isValid() const;
69 
70 private:
71  byte *_vidMem;
72  byte *_min, *_max;
73  uint8 _bpp;
74 };
75 
77 class ConstPixel {
78 public:
79  ConstPixel(const byte *vidMem, uint8 bpp, const byte *min, const byte *max);
80 
81  ConstPixel &operator++();
82  ConstPixel operator++(int x);
83 
84  ConstPixel &operator--();
85  ConstPixel operator--(int x);
86 
87  ConstPixel &operator+=(int x);
88  ConstPixel &operator-=(int x);
89 
90  uint32 get() const;
91 
92  bool isValid() const;
93 
94 private:
95  const byte *_vidMem;
96  const byte *_min, *_max;
97  uint8 _bpp;
98 };
99 
100 class Surface {
101 public:
102  Surface(uint16 width, uint16 height, uint8 bpp, byte *vidMem = 0);
103  Surface(uint16 width, uint16 height, uint8 bpp, const byte *vidMem);
104  ~Surface();
105 
106  uint16 getWidth () const;
107  uint16 getHeight() const;
108  uint8 getBPP () const;
109 
110  byte *getData(uint16 x = 0, uint16 y = 0);
111  const byte *getData(uint16 x = 0, uint16 y = 0) const;
112 
113  void resize(uint16 width, uint16 height);
114 
115  void setBPP(uint8 bpp);
116 
117  Pixel get(uint16 x = 0, uint16 y = 0);
118  ConstPixel get(uint16 x = 0, uint16 y = 0) const;
119 
120  void blit(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
121  int16 x, int16 y, int32 transp = -1, bool yAxisReflexion = false);
122  void blit(const Surface &from, int16 x, int16 y, int32 transp = -1);
123  void blit(const Surface &from, int32 transp = -1);
124 
125  void blitScaled(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
126  int16 x, int16 y, Common::Rational scale, int32 transp = -1);
127  void blitScaled(const Surface &from, int16 x, int16 y, Common::Rational scale, int32 transp = -1);
128  void blitScaled(const Surface &from, Common::Rational scale, int32 transp = -1);
129 
130  void fillRect(int16 left, int16 top, int16 right, int16 bottom, uint32 color);
131  void fillArea(int16 left, int16 top, int16 right, int16 bottom, uint32 fillColor, uint32 backgroundColor);
132  Common::Rect fillAreaAtPoint(int16 left, int16 top, uint32 fillColor);
133  void fill(uint32 color);
134  void clear();
135 
136  void shadeRect(uint16 left, uint16 top, uint16 right, uint16 bottom,
137  uint32 color, uint8 strength);
138 
139  void recolor(uint8 from, uint8 to);
140 
141  void putPixel(uint16 x, uint16 y, uint32 color);
142  void drawLine(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint32 color);
143  void drawRect(uint16 left, uint16 top, uint16 right, uint16 bottom, uint32 color);
144  void drawCircle(uint16 x0, uint16 y0, uint16 radius, uint32 color, int16 pattern = 0);
145 
146  void blitToScreen(uint16 left, uint16 top, uint16 right, uint16 bottom, uint16 x, uint16 y) const;
147 
148  bool loadImage(Common::SeekableReadStream &stream);
149  bool loadImage(Common::SeekableReadStream &stream, ImageType type);
150 
151  static ImageType identifyImage(Common::SeekableReadStream &stream);
152 
153 private:
154  uint16 _width;
155  uint16 _height;
156  uint8 _bpp;
157 
158  bool _ownVidMem;
159  byte *_vidMem;
160 
161  static bool clipBlitRect(int16 &left, int16 &top, int16 &right, int16 &bottom, int16 &x, int16 &y,
162  uint16 dWidth, uint16 dHeight, uint16 sWidth, uint16 sHeight);
163 
164  bool loadTGA (Common::SeekableReadStream &stream);
165  bool loadIFF (Common::SeekableReadStream &stream);
166  bool loadBRC (Common::SeekableReadStream &stream);
167  bool loadBMP (Common::SeekableReadStream &stream);
168  bool loadJPEG(Common::SeekableReadStream &stream);
169 };
170 
172 
173 } // End of namespace Gob
174 
175 #endif // GOB_SURFACE_H
Definition: surface.h:52
Definition: rect.h:144
Definition: stream.h:745
Definition: rational.h:40
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: anifile.h:40
Definition: algorithm.h:29
Definition: surface.h:100
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Definition: surface.h:77