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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ULTIMA8_GRAPHICS_PALETTEMANAGER_H
24 #define ULTIMA8_GRAPHICS_PALETTEMANAGER_H
25 
26 #include "ultima/ultima8/graphics/palette.h"
27 #include "ultima/shared/std/containers.h"
28 
29 namespace Ultima {
30 namespace Ultima8 {
31 
32 class RenderSurface;
33 
34 class PaletteManager {
35 public:
36 	explicit PaletteManager(RenderSurface *rs);
37 	~PaletteManager();
38 
get_instance()39 	static PaletteManager *get_instance() {
40 		return _paletteManager;
41 	}
42 
43 	enum PalIndex {
44 		Pal_Game = 0,
45 		Pal_Movie = 1,
46 		Pal_Diff = 2,	// Crusaders only - difficulty screen??
47 		Pal_Misc = 3,	// Crusaders only - game menu
48 		Pal_Misc2 = 4,	// Crusaders only - ??
49 		Pal_Star = 5,	// Crusaders only - ??
50 		Pal_Cred = 6,	// Crusader: No regret only (but mentioned in the no remorse exe!)
51 		Pal_JPFontStart = 16
52 	};
53 
54 	void load(PalIndex index, Common::ReadStream &rs, Common::ReadStream &xformrs);
55 	void load(PalIndex index, Common::ReadStream &rs);
56 	Palette *getPalette(PalIndex index);
57 
58 	void duplicate(PalIndex src, PalIndex dest);
59 
60 	//! Re-convert a palette to native format after modifying it. If maxindex is set,
61 	//! only recalculate color indexes up to that value.
62 	void updatedPalette(PalIndex index, int maxindex = 0);
63 
64 	//! Apply a transform matrix to a palette (-4.11 fixed)
65 	void transformPalette(PalIndex index, const int16 matrix[12]);
66 
67 	//! reset the transformation matrix of a palette
68 	void untransformPalette(PalIndex index);
69 
70 	//! Get the current TransformMatrix for the given index
71 	bool getTransformMatrix(int16 matrix[12], PalIndex index);
72 
73 	// Get a TransformMatrix from a PalTransforms value (-4.11 fixed)
74 	static void getTransformMatrix(int16 matrix[12],
75 	                               PalTransforms trans);
76 
77 	// Create a custom Transform Matrix from RGBA col32. (-4.11 fixed)
78 	// Alpha will set how much of original palette to keep. 0 = keep none
79 	static void getTransformMatrix(int16 matrix[12], uint32 col32);
80 
81 	//! Change the Render Surface used by the PaletteManager
82 	void RenderSurfaceChanged(RenderSurface *rs);
83 
84 	//! Reset the Palette Manager
85 	void reset();
86 
87 	//! Reset all the transforms back to default
88 	void resetTransforms();
89 
90 private:
91 	Std::vector<Palette *> _palettes;
92 	RenderSurface *_renderSurface;
93 
94 	static PaletteManager *_paletteManager;
95 };
96 
97 } // End of namespace Ultima8
98 } // End of namespace Ultima
99 
100 #endif
101