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 GLK_PICTURE_H
24 #define GLK_PICTURE_H
25 
26 #include "common/array.h"
27 #include "graphics/managed_surface.h"
28 
29 namespace Glk {
30 
31 /**
32  * Picture/image class
33  */
34 struct Picture : Graphics::ManagedSurface {
35 private:
36 	int _transColor;
37 public:
38 	int _refCount;
39 	Common::String _name;
40 	bool _scaled;
41 
42 	/**
43 	 * Constructor
44 	 */
PicturePicture45 	Picture() : Graphics::ManagedSurface(), _refCount(0), _scaled(false), _transColor(0x7777) {}
46 
47 	/**
48 	 * Constructor
49 	 */
50 	Picture(int width, int height, const Graphics::PixelFormat &fmt);
51 	/**
52 	 * Increment reference counter
53 	 */
54 	void increment();
55 
56 	/**
57 	 * Decrement reference counter
58 	 */
59 	void decrement();
60 
61 	/**
62 	 * Draw the picture
63 	 */
64 	void drawPicture(const Common::Point &destPos, const Common::Rect &box);
65 
66 	/**
67 	 * Get the transparency color
68 	 */
getTransparentColorPicture69 	uint getTransparentColor() const { return _transColor; }
70 
71 	/**
72 	 * Set the transparency color
73 	 */
setTransparentColorPicture74 	void setTransparentColor(uint color) { _transColor = color; }
75 };
76 
77 /**
78  * Picture entry in the in-memory store
79  */
80 struct PictureEntry {
81 	Picture *_picture;
82 	Picture *_scaled;
PictureEntryPictureEntry83 	PictureEntry() : _picture(nullptr), _scaled(nullptr) {}
84 };
85 
86 /**
87  * Pictures manager
88  */
89 class Pictures {
90 private:
91 	int _refCount;
92 	Common::Array<PictureEntry> _store;
93 	Common::Array<Common::String> _adaptivePics;
94 	Common::Array<byte> _savedPalette;
95 private:
96 	/**
97 	 * Stores an original picture in the store
98 	 */
99 	void storeOriginal(Picture *pic);
100 
101 	/**
102 	 * Stores a scaled picture in the store
103 	 */
104 	void storeScaled(Picture *pic);
105 public:
106 	/**
107 	 * Constructor
108 	 */
109 	Pictures();
110 
111 	/**
112 	 * Destructor
113 	 */
~Pictures()114 	~Pictures() { clear(); }
115 
116 	/**
117 	 * Clear the picture list
118 	 */
119 	void clear();
120 
121 	/**
122 	 * Increments the count of the number of pictures in use
123 	 */
124 	void increment();
125 
126 	/**
127 	 * Decrements the count of the number of pictures in use
128 	 */
129 	void decrement();
130 
131 	/**
132 	 * Searches for an existing picture entry
133 	 */
134 	PictureEntry *search(const Common::String &name);
135 
136 	/**
137 	 * Stores a picture in the store
138 	 */
139 	void store(Picture *pic);
140 
141 	/**
142 	 * Retrieves a picture from the store
143 	 */
144 	Picture *retrieve(const Common::String &name, bool scaled);
145 
146 	/**
147 	 * Load a given picture
148 	 */
149 	Picture *load(const Common::String &name);
150 
151 	/**
152 	 * Rescale the passed picture to a new picture of a given size
153 	 */
154 	Picture *scale(Picture *src, size_t sx, size_t sy);
155 };
156 
157 } // End of namespace Glk
158 
159 #endif
160