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#include "graphics/pixelformat.h"
37
38namespace Common {
39class SeekableReadStream;
40}
41
42namespace Image {
43class ImageDecoder;
44}
45
46namespace Gob {
47
48enum ImageType {
49 kImageTypeNone = -1,
50 kImageTypeTGA = 0,
51 kImageTypeIFF,
52 kImageTypeBRC,
53 kImageTypeBMP,
54 kImageTypeJPEG
55};
56
58class Pixel {
59public:
60 Pixel(byte *vidMem, uint8 bpp, byte *min, byte *max);
61
62 Pixel &operator++();
63 Pixel operator++(int x);
64
65 Pixel &operator--();
66 Pixel operator--(int x);
67
68 Pixel &operator+=(int x);
69 Pixel &operator-=(int x);
70
71 uint32 get() const;
72 void set(uint32 p);
73
74 bool isValid() const;
75
76private:
77 byte *_vidMem;
78 byte *_min, *_max;
79 uint8 _bpp;
80};
81
84public:
85 ConstPixel(const byte *vidMem, uint8 bpp, const byte *min, const byte *max);
86
87 ConstPixel &operator++();
88 ConstPixel operator++(int x);
89
90 ConstPixel &operator--();
91 ConstPixel operator--(int x);
92
93 ConstPixel &operator+=(int x);
94 ConstPixel &operator-=(int x);
95
96 uint32 get() const;
97
98 bool isValid() const;
99
100private:
101 const byte *_vidMem;
102 const byte *_min, *_max;
103 uint8 _bpp;
104};
105
106class Surface {
107public:
108 Surface(uint16 width, uint16 height, uint8 bpp, byte *vidMem = nullptr, const uint32 *highColorMap = nullptr, bool ownHighColorMap = false);
109 Surface(uint16 width, uint16 height, uint8 bpp, const byte *vidMem, const uint32 *highColorMap = nullptr, bool ownHighColorMap = false);
110 ~Surface();
111
112 uint16 getWidth () const;
113 uint16 getHeight() const;
114 uint8 getBPP () const;
115
116 byte *getData(uint16 x = 0, uint16 y = 0);
117 const byte *getData(uint16 x = 0, uint16 y = 0) const;
118
119 void resize(uint16 width, uint16 height);
120
121 void setBPP(uint8 bpp);
122
123 Pixel get(uint16 x = 0, uint16 y = 0);
124 ConstPixel get(uint16 x = 0, uint16 y = 0) const;
125
126 void blit(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
127 int16 x, int16 y, int32 transp = -1, bool yAxisReflexion = false);
128 void blit(const Surface &from, int16 x, int16 y, int32 transp = -1);
129 void blit(const Surface &from, int32 transp = -1);
130
131 void blitScaled(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
132 int16 x, int16 y, Common::Rational scale, int32 transp = -1);
133 void blitScaled(const Surface &from, int16 x, int16 y, Common::Rational scale, int32 transp = -1);
134 void blitScaled(const Surface &from, Common::Rational scale, int32 transp = -1);
135
136 void blitShaded(const Surface &from, int16 left, int16 top, int16 right, int16 bottom,
137 int16 x, int16 y, uint8 strength, int32 transp, Graphics::PixelFormat pixelFormat);
138
139 void fillRectRaw(int16 left, int16 top, int16 right, int16 bottom, uint32 color);
140 void fillRect(int16 left, int16 top, int16 right, int16 bottom, uint8 colorIndex);
141 void fillArea(int16 left, int16 top, int16 right, int16 bottom, uint8 fillColorIndex, uint8 backgroundColorIndex);
142 Common::Rect fillAreaAtPoint(int16 left, int16 top, uint8 fillColorIndex);
143 void fill(uint32 color);
144 void clear();
145
146 void shadeRect(uint16 left, uint16 top, uint16 right, uint16 bottom,
147 uint8 colorIndex, uint8 strength);
148
149 void recolor(uint8 from, uint8 to);
150
151 void putPixelRaw(uint16 x, uint16 y, uint32 color);
152 void putPixel(uint16 x, uint16 y, uint8 colorIndex);
153 void drawLineRaw(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint32 colorIndex);
154 void drawLine(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint8 colorIndex);
155 void drawRect(uint16 left, uint16 top, uint16 right, uint16 bottom, uint8 colorIndex);
156 void drawCircle(uint16 x0, uint16 y0, uint16 radius, uint8 colorIndex, int16 pattern = 0);
157
158 void blitToScreen(uint16 left, uint16 top, uint16 right, uint16 bottom, uint16 x, uint16 y) const;
159
160 bool loadImage(Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom,
161 int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
162 bool loadImage(Common::SeekableReadStream &stream, ImageType type, int16 left, int16 top, int16 right, int16 bottom,
163 int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
164
165 uint32 getColorFromIndex(uint8 index) const;
166
167 static ImageType identifyImage(Common::SeekableReadStream &stream);
168 static bool getImageInfo(Common::SeekableReadStream &stream, uint32 &width, uint32 &height, uint32 &bpp);
169 static void computeHighColorMap(uint32 *highColorMap, const byte *palette,
170 const Graphics::PixelFormat &format,
171 bool useSpecialBlackWhiteValues,
172 int16 startColor = 0, int16 colorCount = 256,
173 int16 startColorSrc = -1);
174
175private:
176 uint16 _width;
177 uint16 _height;
178 uint8 _bpp;
179
180 bool _ownVidMem;
181 byte *_vidMem;
182
183 bool _ownHighColorMap;
184 const uint32 *_highColorMap;
185
186 static bool clipBlitRect(int16 &left, int16 &top, int16 &right, int16 &bottom, int16 &x, int16 &y,
187 uint16 dWidth, uint16 dHeight, uint16 sWidth, uint16 sHeight);
188
189 bool loadImage(Image::ImageDecoder &decoder, Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom,
190 int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
191
192 bool loadTGA (Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
193 bool loadIFF (Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
194 bool loadBRC (Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
195 bool loadBMP (Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
196 bool loadJPEG(Common::SeekableReadStream &stream, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp, Graphics::PixelFormat format);
197};
198
200
201} // End of namespace Gob
202
203#endif // GOB_SURFACE_H
Definition: rational.h:40
Definition: stream.h:745
Definition: surface.h:83
Definition: surface.h:58
Definition: surface.h:106
Definition: image_decoder.h:53
Definition: algorithm.h:29
Definition: rect.h:536
Definition: pixelformat.h:138