ScummVM API documentation
bitmap.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BOFLIB_GFX_BMP_H
24 #define BAGEL_BOFLIB_GFX_BMP_H
25 
26 #include "graphics/managed_surface.h"
27 #include "bagel/boflib/cache.h"
28 #include "bagel/boflib/error.h"
29 #include "bagel/boflib/object.h"
30 #include "bagel/boflib/point.h"
31 #include "bagel/boflib/rect.h"
32 #include "bagel/boflib/size.h"
33 #include "bagel/boflib/stdinc.h"
34 #include "bagel/boflib/gfx/palette.h"
35 
36 namespace Bagel {
37 
38 // Color constants
39 //
40 #define NOT_TRANSPARENT -1
41 
42 #define COLOR_WHITE 255
43 #define COLOR_BLACK 0
44 
45 #define CBMP_FADE_SPEED 10
46 #define CBMP_FADE_SIZE 4
47 
48 #define CBMP_CURT_SPEED 8 // Must be a power of 2
49 
50 #define CBMP_LINE_SPEED 32 // Should be a power of 4
51 
52 // forward declare CBofWindow
53 class CBofWindow;
54 
55 class CBofBitmap : public CBofError, public CBofObject, public CCache {
56 protected:
61  bool alloc() override;
62 
66  void free() override;
67 
68  //
69  // data members
70  //
71  static bool _bUseBackdrop;
72 
73  char _szFileName[MAX_FNAME];
74 
76 
77  byte *_pBits = nullptr;
78 
79  CBofPalette *_pPalette = nullptr;
80 
81  int _nScanDX = 0;
82  int _nDX = 0;
83  int _nDY = 0;
84  bool _bTopDown = false;
85 
86  bool _bOwnPalette = false;
87  bool _bReadOnly = false;
88  bool _bInitialized = false;
89 
90 public:
94  CBofBitmap();
95 
104  CBofBitmap(int dx, int dy, CBofPalette *pPalette, bool bOwnPalette = false, byte *pPrivateBuff = nullptr);
105 
112  CBofBitmap(const char *pszFileName, CBofPalette *pPalette = nullptr, bool bOwnPalette = false);
113 
117  virtual ~CBofBitmap();
118 
123  ErrorCode buildBitmap(CBofPalette *pPalette);
124 
131  ErrorCode loadBitmap(const char *pszFileName, CBofPalette *pPalette);
132 
136  void releaseBitmap();
137 
138  //
139  // Palette routines
140  //
141 
147  void setPalette(CBofPalette *pPalette, bool bOwnPalette = false);
148 
149  CBofPalette *getPalette() {
150  return _pPalette;
151  }
152 
153  void setIsOwnPalette(bool own) {
154  _bOwnPalette = own;
155  }
156 
157  //
158  // Misc routines
159  //
160 
167  byte *getPixelAddress(int x, int y);
168  byte *getPixelAddress(CBofPoint *pPoint) {
169  return getPixelAddress(pPoint->x, pPoint->y);
170  }
171 
172  CBofSize getSize() {
173  return CBofSize(_nDX, _nDY);
174  }
175 
176  CBofRect getRect() {
177  return CBofRect(0, 0, _nDX - 1, _nDY - 1);
178  }
179 
180  void setReadOnly(bool bReadOnly) {
181  _bReadOnly = bReadOnly;
182  }
183 
184  bool getReadOnly() {
185  return _bReadOnly;
186  }
187 
188  bool isTopDown() {
189  return _bTopDown;
190  }
191 
192  int width() {
193  return _nDX;
194  }
195 
196  int widthBytes() {
197  return _nScanDX;
198  }
199 
200  int height() {
201  return _nDY;
202  }
203 
204  operator Graphics::ManagedSurface &() {
205  return _bitmap;
206  }
207 
208  Graphics::ManagedSurface getSurface();
209 
214  const char *getFileName();
215 
216  //
217  // Drawing routines
218  //
228  ErrorCode paint(CBofWindow *pWnd, int x, int y, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
229 
238  ErrorCode paint(CBofWindow *pWnd, CBofRect *pDstRect = nullptr, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
239 
248  ErrorCode paintMaskBackdrop(CBofWindow *pWnd, CBofRect *pDstRect = nullptr, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
249 
259  ErrorCode paint(CBofBitmap *pBmp, int x, int y, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
260 
269  ErrorCode paint(CBofBitmap *pBmp, CBofRect *pDstRect = nullptr, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
270 
271  //
272  // Special Paint routines Optimized for specific tasks
273  //
274 
275  // Stretches 4 pixel wide
286  ErrorCode paintStretch4(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect);
287 
296  ErrorCode paintStretchOpt(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect, int nOptSize);
297 
303  ErrorCode paint1To1(CBofBitmap *pBmp);
304 
311  ErrorCode captureScreen(CBofWindow *pWnd, CBofRect *pSrcRect, CBofRect *pDstRect = nullptr);
312 
323  ErrorCode fadeIn(CBofWindow *pWnd, int x = 0, int y = 0, int nMaskColor = NOT_TRANSPARENT, int nBlockSize = CBMP_FADE_SIZE, int nSpeed = CBMP_FADE_SPEED);
324 
325  ErrorCode curtain(CBofWindow *pWnd, int nSpeed = CBMP_CURT_SPEED, int nMaskColor = NOT_TRANSPARENT);
326  ErrorCode fadeLines(CBofWindow *pWnd, int nSpeed = CBMP_LINE_SPEED, int nMaskColor = NOT_TRANSPARENT);
327 
334  byte readPixel(int x, int y);
335 
342  void writePixel(int x, int y, byte iColor);
343 
351  void circle(int x, int y, uint16 nRadius, byte iColor);
352 
361  void line(int nSrcX, int nSrcY, int nDstX, int nDstY, byte iColor);
362 
369  void line(CBofPoint *pSrc, CBofPoint *pDest, byte iColor);
370 
376  void drawRect(CBofRect *cRect, byte iColor);
377 
383  void fillRect(CBofRect *cRect, byte iColor);
384 
391  ErrorCode scrollRight(int nPixels, CBofRect *pRect = nullptr);
392 
393 
394  ErrorCode scrollLeft(int nPixels, CBofRect *pRect = nullptr) {
395  return scrollRight(-nPixels, pRect);
396  }
397 
403  ErrorCode scrollUp(int nPixels);
404 
405  static void setUseBackdrop(bool b) {
406  _bUseBackdrop = b;
407  }
408  static bool getUseBackdrop() {
409  return _bUseBackdrop;
410  }
411 };
412 
414 //
415 // Misc graphics routines
416 //
418 
426 extern CBofBitmap *loadBitmap(const char *pszFileName, CBofPalette *pPalette = nullptr, bool bSharedPal = false);
427 
438 extern ErrorCode paintBitmap(CBofWindow *pWindow, const char *pszFileName, CBofRect *pDstRect = nullptr,
439  CBofRect *pSrcRect = nullptr, CBofPalette *pPalette = nullptr, int nMaskColor = NOT_TRANSPARENT);
440 
441 } // namespace Bagel
442 
443 #endif
Definition: managed_surface.h:51
Definition: window.h:50
void writePixel(int x, int y, byte iColor)
ErrorCode scrollUp(int nPixels)
ErrorCode scrollRight(int nPixels, CBofRect *pRect=nullptr)
Definition: cache.h:31
byte * getPixelAddress(int x, int y)
ErrorCode fadeIn(CBofWindow *pWnd, int x=0, int y=0, int nMaskColor=-1, int nBlockSize=4, int nSpeed=10)
ErrorCode paintStretchOpt(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect, int nOptSize)
Definition: object.h:28
Definition: size.h:31
Definition: bitmap.h:55
void free() override
bool alloc() override
byte readPixel(int x, int y)
void line(int nSrcX, int nSrcY, int nDstX, int nDstY, byte iColor)
virtual ~CBofBitmap()
void drawRect(CBofRect *cRect, byte iColor)
Definition: rect.h:36
ErrorCode paintMaskBackdrop(CBofWindow *pWnd, CBofRect *pDstRect=nullptr, CBofRect *pSrcRect=nullptr, int nMaskColor=-1)
void setPalette(CBofPalette *pPalette, bool bOwnPalette=false)
Definition: error.h:50
ErrorCode paint(CBofWindow *pWnd, int x, int y, CBofRect *pSrcRect=nullptr, int nMaskColor=-1)
ErrorCode captureScreen(CBofWindow *pWnd, CBofRect *pSrcRect, CBofRect *pDstRect=nullptr)
Definition: bagel.h:31
Definition: point.h:34
Definition: palette.h:69
void fillRect(CBofRect *cRect, byte iColor)
ErrorCode loadBitmap(const char *pszFileName, CBofPalette *pPalette)
ErrorCode buildBitmap(CBofPalette *pPalette)
ErrorCode paintStretch4(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect)
The Destination rectangle MUST be divisible by 4. Both bitmaps must be Bottom-Up. The Source must be ...
ErrorCode paint1To1(CBofBitmap *pBmp)
void circle(int x, int y, uint16 nRadius, byte iColor)
const char * getFileName()