ScummVM API documentation
image.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 
22 #ifndef ULTIMA4_GFX_IMAGE_H
23 #define ULTIMA4_GFX_IMAGE_H
24 
25 #include "ultima/ultima4/core/types.h"
26 #include "ultima/ultima4/gfx/textcolor.h"
27 #include "graphics/managed_surface.h"
28 
29 namespace Ultima {
30 namespace Ultima4 {
31 
32 typedef Graphics::ManagedSurface *BackendSurface;
33 
34 #define DARK_GRAY_HALO RGBA(14,15,16,255)
35 
36 struct RGBA {
37  RGBA(int red, int green, int blue, int alpha) : r(red), g(green), b(blue), a(alpha) {}
38  RGBA() : r(0), g(0), b(0), a(255) {}
39  uint r, g, b, a;
40 
41  operator uint32() const {
42  return r | (g << 8) | (b << 16) | (0xff << 24);
43  }
44 };
45 bool operator==(const RGBA &lhs, const RGBA &rhs);
46 
47 class Image;
48 
49 struct SubImage : public Common::Rect {
50  Common::String _name;
51  Common::String _srcImageName;
52 };
53 
54 #define IM_OPAQUE (uint) 255
55 #define IM_TRANSPARENT 0
56 
65 class Image {
66 private:
67  Graphics::ManagedSurface *_surface;
68  DisposeAfterUse::Flag _disposeAfterUse;
69  bool _paletted;
70  RGBA _backgroundColor;
71  Image(); /* use create method to construct images */
72 
73  // disallow assignments, copy construction
74  Image(const Image &);
75  const Image &operator=(const Image &);
76 
77  Graphics::ManagedSurface *getSurface(Image *d) const;
78 
79  uint getColor(byte r, byte g, byte b, byte a);
80 public:
85  static Image *create(int w, int h);
86 
91  static Image *create(int w, int h, const Graphics::PixelFormat &format);
92 
96  static Image *createScreenImage();
97 
101  static Image *duplicate(Image *image, const Graphics::PixelFormat &format);
102 
106  ~Image();
107 
108  void createInternal(int w, int h, const Graphics::PixelFormat &format);
109 
110  /* palette handling */
114  void setPalette(const byte *colors, unsigned n_colors);
115 
119  void setPaletteFromImage(const Image *src);
120  bool getTransparentIndex(uint &index) const;
121  void performTransparencyHack(uint colorValue, uint numFrames, uint currentFrameIndex, uint haloWidth, uint haloOpacityIncrementByPixelDistance);
122  void setTransparentIndex(uint index);
123 
127  bool setFontColor(ColorFG fg, ColorBG bg);
128 
132  bool setFontColorFG(ColorFG fg);
133 
137  bool setFontColorBG(ColorBG bg);
138 
142  RGBA getPaletteColor(int index); // returns the color of the specified palette index
143 
147  bool setPaletteIndex(uint index, uint8 r, uint8 g, uint8 b);
148 
149  RGBA setColor(uint8 r, uint8 g, uint8 b, uint8 a = IM_OPAQUE);
150 
151 
152  /* alpha handling */
153  bool isAlphaOn() const;
154  void alphaOn();
155  void alphaOff();
156 
157 
158  /* Will clear the image to the background color, and set the internal backgroundColor variable */
159  void initializeToBackgroundColor(RGBA backgroundColor = DARK_GRAY_HALO);
160  /* Will make the pixels that match the background color disappear, with a blur halo */
161  void makeBackgroundColorTransparent(int haloSize = 0, int shadowOpacity = 255);
162 
163 
164  //void finalizeAlphaSurface(RGBA * key = nullptr);
165 
166  /* writing to image */
167 
171  void putPixel(int x, int y, int r, int g, int b, int a); //TODO Consider using &
172 
178  void putPixelIndex(int x, int y, uint index);
179 
183  void fillRect(int x, int y, int w, int h, int r, int g, int b, int a = IM_OPAQUE);
184 
185  void blitFrom(const Graphics::Surface &src);
186 
187  /* reading from image */
191  void getPixel(int x, int y, uint &r, uint &g, uint &b, uint &a) const;
192 
198  void getPixelIndex(int x, int y, uint &index) const;
199 
200  /* image drawing methods */
204  void draw(int x, int y) const {
205  drawOn(nullptr, x, y);
206  }
207 
213  void drawSubRect(int x, int y, int rx, int ry, int rw, int rh) const {
214  drawSubRectOn(nullptr, x, y, rx, ry, rw, rh);
215  }
216 
222  void drawSubRectInverted(int x, int y, int rx, int ry, int rw, int rh) const {
223  drawSubRectInvertedOn(nullptr, x, y, rx, ry, rw, rh);
224  }
225 
226  /* image drawing methods for drawing onto another image instead of the screen */
230  void drawOn(Image *d, int x, int y) const;
231 
235  void drawSubRectOn(Image *d, int x, int y, int rx, int ry, int rw, int rh) const;
236 
240  void drawSubRectInvertedOn(Image *d, int x, int y, int rx, int ry, int rw, int rh) const;
241 
242  int width() const {
243  return _surface->w;
244  }
245  int height() const {
246  return _surface->h;
247  }
248  Graphics::PixelFormat format() const {
249  return _surface->format;
250  }
251  bool isIndexed() const {
252  return _paletted;
253  }
254  BackendSurface getSurface() {
255  return _surface;
256  }
257 
258  void drawHighlighted();
259 
264  void dump();
265 };
266 
267 } // End of namespace Ultima4
268 } // End of namespace Ultima
269 
270 #endif
Definition: managed_surface.h:51
Definition: str.h:59
int16 & w
Definition: managed_surface.h:117
Definition: surface.h:67
Definition: image.h:36
Definition: pixelformat.h:138
void drawSubRect(int x, int y, int rx, int ry, int rw, int rh) const
Definition: image.h:213
Definition: rect.h:144
Definition: image.h:49
Definition: detection.h:27
void drawSubRectInverted(int x, int y, int rx, int ry, int rw, int rh) const
Definition: image.h:222
int16 & h
Definition: managed_surface.h:118
PixelFormat & format
Definition: managed_surface.h:120
Definition: movie_decoder.h:32
void draw(int x, int y) const
Definition: image.h:204