ScummVM API documentation
palette.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_PALETTE_H
24 #define BAGEL_BOFLIB_GFX_PALETTE_H
25 
26 #include "graphics/screen.h"
27 #include "bagel/boflib/error.h"
28 #include "bagel/boflib/object.h"
29 #include "bagel/boflib/stdinc.h"
30 
31 namespace Bagel {
32 
33 #define PAL_DEFAULT 0x0000
34 #define PAL_ANIMATED 0x0001
35 #define PAL_EXPLICIT 0x0002
36 
37 typedef uint32 RGBCOLOR;
38 struct HPALETTE {
39  byte _data[PALETTE_SIZE];
40  int16 _numColors;
41  HPALETTE(int16 numColors = PALETTE_COUNT);
42 };
43 
44 struct PALETTEENTRY {
45  byte peRed;
46  byte peGreen;
47  byte peBlue;
48  byte peFlags;
49 };
50 struct LOGPALETTE {
51  int16 palNumEntries;
52  int16 palVersion;
53  PALETTEENTRY palPalEntry[1];
54 };
55 
56 #define RGB(r, g, b) ((RGBCOLOR)(((byte)(r) | ((uint16)((byte)(g)) << 8)) | (((uint32)(byte)(b)) << 16)))
57 
58 struct BOFRGBQUAD {
59  byte rgbBlue;
60  byte rgbGreen;
61  byte rgbRed;
62  byte rgbReserved;
63 };
64 
65 #define GetRed(rgb) ((byte)((rgb) & 0x000000FF))
66 #define GetGreen(rgb) ((byte)(((rgb) >> 8) & 0x000000FF))
67 #define GetBlue(rgb) ((byte)(((rgb) >> 16) & 0x000000FF))
68 
69 class CBofPalette : public CBofError, public CBofObject {
70 protected:
71  HPALETTE _palette;
72 
73  static CBofPalette *_pSharedPalette;
74  static char _szSharedPalFile[MAX_FNAME];
75 
79  void ReleasePalette();
80 
81 public:
85  CBofPalette();
86 
91  CBofPalette(const char *pszFileName);
92 
96  CBofPalette(const HPALETTE &hPalette);
97 
104  ErrorCode loadPalette(const char *pszFileName, uint16 nFlags = PAL_DEFAULT);
105 
106  ErrorCode createDefault(uint16 nFlags = PAL_DEFAULT);
107 
108  byte getNearestIndex(RGBCOLOR cColor);
109 
110  RGBCOLOR getColor(byte nIndex);
111 
116  void setPalette(const HPALETTE &hPalette);
117 
118  const HPALETTE &getPalette() const {
119  return _palette;
120  }
121 
122  const byte *getData() const {
123  return _palette._data;
124  }
125 
126  void setData(const byte* colors) {
127  memcpy(_palette._data, colors, PALETTE_SIZE);
128  }
129 
130  virtual ~CBofPalette();
131 
135  CBofPalette *copyPalette();
136 
140  static void initialize();
141 
146  static ErrorCode setSharedPalette(const char *pszFileName);
147 
152  static CBofPalette *getSharedPalette();
153 };
154 
155 } // namespace Bagel
156 
157 #endif
Definition: palette.h:44
Definition: object.h:28
Definition: error.h:50
Definition: palette.h:50
Definition: palette.h:58
Definition: bagel.h:31
Definition: palette.h:69
Definition: palette.h:38