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/palette.h"
28 #include "bagel/boflib/cache.h"
29 #include "bagel/boflib/error.h"
30 #include "bagel/boflib/object.h"
31 #include "bagel/boflib/point.h"
32 #include "bagel/boflib/rect.h"
33 #include "bagel/boflib/size.h"
34 #include "bagel/boflib/stdinc.h"
35 
36 namespace Bagel {
37 namespace SpaceBar {
38 
39 // Color constants
40 //
41 enum {
42  NOT_TRANSPARENT = -1,
43  COLOR_WHITE = 255,
44  COLOR_BLACK = 0
45 };
46 
47 #define CBMP_FADE_SPEED 10
48 #define CBMP_FADE_SIZE 4
49 
50 #define CBMP_CURT_SPEED 8 // Must be a power of 2
51 
52 #define CBMP_LINE_SPEED 32 // Should be a power of 4
53 
54 // forward declare CBofWindow
55 class CBofWindow;
56 
57 class CBofBitmap : public CBofError, public CBofObject, public CCache {
58 protected:
63  bool alloc() override;
64 
68  void free() override;
69 
70  //
71  // data members
72  //
73  static bool _bUseBackdrop;
74 
75  char _szFileName[MAX_FNAME];
76 
78 
79  byte *_pBits = nullptr;
80 
81  CBofPalette *_pPalette = nullptr;
82 
83  int _nScanDX = 0;
84  int _nDX = 0;
85  int _nDY = 0;
86  bool _bTopDown = false;
87 
88  bool _bOwnPalette = false;
89  bool _bReadOnly = false;
90  bool _bInitialized = false;
91 
92 public:
96  CBofBitmap();
97 
106  CBofBitmap(int dx, int dy, CBofPalette *pPalette, bool bOwnPalette = false, byte *pPrivateBuff = nullptr);
107 
114  CBofBitmap(const char *pszFileName, CBofPalette *pPalette = nullptr, bool bOwnPalette = false);
115 
119  virtual ~CBofBitmap();
120 
125  ErrorCode buildBitmap(CBofPalette *pPalette);
126 
133  ErrorCode loadBitmap(const char *pszFileName, CBofPalette *pPalette);
134 
138  void releaseBitmap();
139 
140  //
141  // Palette routines
142  //
143 
149  void setPalette(CBofPalette *pPalette, bool bOwnPalette = false);
150 
151  CBofPalette *getPalette() {
152  return _pPalette;
153  }
154 
155  void setIsOwnPalette(bool own) {
156  _bOwnPalette = own;
157  }
158 
159  //
160  // Misc routines
161  //
162 
169  byte *getPixelAddress(int x, int y);
170  byte *getPixelAddress(CBofPoint *pPoint) {
171  return getPixelAddress(pPoint->x, pPoint->y);
172  }
173 
174  CBofSize getSize() {
175  return CBofSize(_nDX, _nDY);
176  }
177 
178  CBofRect getRect() {
179  return CBofRect(0, 0, _nDX - 1, _nDY - 1);
180  }
181 
182  void setReadOnly(bool bReadOnly) {
183  _bReadOnly = bReadOnly;
184  }
185 
186  bool getReadOnly() {
187  return _bReadOnly;
188  }
189 
190  bool isTopDown() {
191  return _bTopDown;
192  }
193 
194  int width() {
195  return _nDX;
196  }
197 
198  int widthBytes() {
199  return _nScanDX;
200  }
201 
202  int height() {
203  return _nDY;
204  }
205 
206  operator Graphics::ManagedSurface &() {
207  return _bitmap;
208  }
209 
210  Graphics::ManagedSurface getSurface();
211 
216  const char *getFileName();
217 
218  //
219  // Drawing routines
220  //
230  ErrorCode paint(CBofWindow *pWnd, int x, int y, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
231 
240  ErrorCode paint(CBofWindow *pWnd, CBofRect *pDstRect = nullptr, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
241 
250  ErrorCode paintMaskBackdrop(CBofWindow *pWnd, CBofRect *pDstRect = nullptr, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
251 
261  ErrorCode paint(CBofBitmap *pBmp, int x, int y, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
262 
271  ErrorCode paint(CBofBitmap *pBmp, CBofRect *pDstRect = nullptr, CBofRect *pSrcRect = nullptr, int nMaskColor = NOT_TRANSPARENT);
272 
273  //
274  // Special Paint routines Optimized for specific tasks
275  //
276 
277  // Stretches 4 pixel wide
288  ErrorCode paintStretch4(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect);
289 
298  ErrorCode paintStretchOpt(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect, int nOptSize);
299 
305  ErrorCode paint1To1(CBofBitmap *pBmp);
306 
313  ErrorCode captureScreen(CBofWindow *pWnd, CBofRect *pSrcRect, CBofRect *pDstRect = nullptr);
314 
325  ErrorCode fadeIn(CBofWindow *pWnd, int x = 0, int y = 0, int nMaskColor = NOT_TRANSPARENT, int nBlockSize = CBMP_FADE_SIZE, int nSpeed = CBMP_FADE_SPEED);
326 
327  ErrorCode curtain(CBofWindow *pWnd, int nSpeed = CBMP_CURT_SPEED, int nMaskColor = NOT_TRANSPARENT);
328  ErrorCode fadeLines(CBofWindow *pWnd, int nSpeed = CBMP_LINE_SPEED, int nMaskColor = NOT_TRANSPARENT);
329 
336  byte readPixel(int x, int y);
337 
344  void writePixel(int x, int y, byte iColor);
345 
353  void circle(int x, int y, uint16 nRadius, byte iColor);
354 
363  void line(int nSrcX, int nSrcY, int nDstX, int nDstY, byte iColor);
364 
371  void line(CBofPoint *pSrc, CBofPoint *pDest, byte iColor);
372 
378  void drawRect(CBofRect *cRect, byte iColor);
379 
385  void fillRect(CBofRect *cRect, byte iColor);
386 
393  ErrorCode scrollRight(int nPixels, CBofRect *pRect = nullptr);
394 
395 
396  ErrorCode scrollLeft(int nPixels, CBofRect *pRect = nullptr) {
397  return scrollRight(-nPixels, pRect);
398  }
399 
405  ErrorCode scrollUp(int nPixels);
406 
407  static void setUseBackdrop(bool b) {
408  _bUseBackdrop = b;
409  }
410  static bool getUseBackdrop() {
411  return _bUseBackdrop;
412  }
413 };
414 
416 //
417 // Misc graphics routines
418 //
420 
428 extern CBofBitmap *loadBitmap(const char *pszFileName, CBofPalette *pPalette = nullptr, bool bSharedPal = false);
429 
440 extern ErrorCode paintBitmap(CBofWindow *pWindow, const char *pszFileName, CBofRect *pDstRect = nullptr,
441  CBofRect *pSrcRect = nullptr, CBofPalette *pPalette = nullptr, int nMaskColor = NOT_TRANSPARENT);
442 
443 } // namespace SpaceBar
444 } // namespace Bagel
445 
446 #endif
Definition: managed_surface.h:51
Definition: cache.h:31
void setPalette(CBofPalette *pPalette, bool bOwnPalette=false)
Definition: object.h:28
Definition: size.h:32
ErrorCode loadBitmap(const char *pszFileName, CBofPalette *pPalette)
ErrorCode buildBitmap(CBofPalette *pPalette)
byte * getPixelAddress(int x, int y)
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 ...
Definition: window.h:53
void circle(int x, int y, uint16 nRadius, byte iColor)
void writePixel(int x, int y, byte iColor)
ErrorCode paint(CBofWindow *pWnd, int x, int y, CBofRect *pSrcRect=nullptr, int nMaskColor=NOT_TRANSPARENT)
Definition: rect.h:35
ErrorCode fadeIn(CBofWindow *pWnd, int x=0, int y=0, int nMaskColor=NOT_TRANSPARENT, int nBlockSize=4, int nSpeed=10)
ErrorCode paintMaskBackdrop(CBofWindow *pWnd, CBofRect *pDstRect=nullptr, CBofRect *pSrcRect=nullptr, int nMaskColor=NOT_TRANSPARENT)
ErrorCode paintStretchOpt(CBofBitmap *pBmp, CBofRect *pDstRect, CBofRect *pSrcRect, int nOptSize)
Definition: error.h:52
ErrorCode paint1To1(CBofBitmap *pBmp)
void line(int nSrcX, int nSrcY, int nDstX, int nDstY, byte iColor)
byte readPixel(int x, int y)
void drawRect(CBofRect *cRect, byte iColor)
Definition: palette.h:64
Definition: afxwin.h:27
ErrorCode scrollRight(int nPixels, CBofRect *pRect=nullptr)
Definition: point.h:32
ErrorCode scrollUp(int nPixels)
ErrorCode captureScreen(CBofWindow *pWnd, CBofRect *pSrcRect, CBofRect *pDstRect=nullptr)
Definition: bitmap.h:57
void fillRect(CBofRect *cRect, byte iColor)