File: bitmap.h

package info (click to toggle)
residualvm 0.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 31,292 kB
  • sloc: cpp: 227,029; sh: 7,256; xml: 1,731; perl: 1,067; java: 861; asm: 738; python: 691; ansic: 272; makefile: 139; objc: 81; sed: 22; php: 1
file content (191 lines) | stat: -rw-r--r-- 4,970 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* ResidualVM - A 3D game interpreter
 *
 * ResidualVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the AUTHORS
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef GRIM_BITMAP_H
#define GRIM_BITMAP_H

#include "graphics/pixelformat.h"

#include "common/endian.h"
#include "common/hashmap.h"
#include "common/hash-str.h"

#include "engines/grim/pool.h"

namespace Graphics {
class PixelBuffer;
}

namespace Common {
class SeekableReadStream;
}

namespace Grim {

/**
 * This BitmapData class keeps the actual bitmap data and can be shared
 * between Bitmap instances, by using getBitmapData.
 * Bitmap still keeps the data that can change between the instances
 * i.e. _x, _y and _currImage.
 * They are automatically deleted if they are not used by any bitmap anymore.
 */
class BitmapData {
public:
	BitmapData(const Common::String &fname);
	BitmapData(const Graphics::PixelBuffer &buf, int w, int h, const char *fname);
	BitmapData();
	~BitmapData();

	void freeData();

	void load();

	/**
	 * Loads an EMI TILE-bitmap.
	 *
	 * @param data      the data for the TILE.
	 * @param len       the length of the data.
	 */
	bool loadTile(Common::SeekableReadStream *data);
	bool loadGrimBm(Common::SeekableReadStream *data);
	bool loadTGA(Common::SeekableReadStream *data);

	static BitmapData *getBitmapData(const Common::String &fname);
	static Common::HashMap<Common::String, BitmapData *> *_bitmaps;

	const Graphics::PixelBuffer &getImageData(int num) const;

	/**
	 * Convert a bitmap to another color-format.
	 *
	 * @param format    the format to convert to.
	 */
	void convertToColorFormat(const Graphics::PixelFormat &format);

	/**
	 * Convert a bitmap to another color-format.
	 *
	 * @param format    the format to convert to.
	 */
	void convertToColorFormat(int num, const Graphics::PixelFormat &format);

	Common::String _fname;
	int _numImages;
	int _width, _height, _x, _y;
	int _format;
	int _numTex;
	int _bpp;
	int _colorFormat;
	void *_texIds;
	bool _hasTransparency;
	bool _loaded;
	bool _keepData;

	int _refCount;

	float *_texc;

	struct Vert {
		uint32 _texid;
		uint32 _pos;
		uint32 _verts;
	};
	struct Layer {
		uint32 _offset;
		uint32 _numImages;
	};
	Vert *_verts;
	Layer *_layers;
	uint32 _numCoords;
	uint32 _numVerts;
	uint32 _numLayers;

// private:
	Graphics::PixelBuffer *_data;
	void *_userData;
};

class Bitmap : public PoolObject<Bitmap> {
public:
	/**
	 * Construct a bitmap from the given data.
	 *
	 * @oaram filename  the filename of the bitmap
	 * @param data      the actual data to construct from
	 * @param len       the length of the data
	 */
	Bitmap(const Common::String &filename);
	Bitmap(const Graphics::PixelBuffer &buf, int width, int height, const char *filename);
	Bitmap();

	static int32 getStaticTag() { return MKTAG('V', 'B', 'U', 'F'); }

	static Bitmap *create(const Common::String &filename);

	const Common::String &getFilename() const { return _data->_fname; }

	void draw();
	void draw(int x, int y);

	void drawLayer(uint32 layer);

	/**
	 * Set which image in an animated bitmap to use
	 *
	 * @param n     the image to be selected
	 */
	void setActiveImage(int n);

	int getNumImages() const;
	int getNumLayers() const;
	int getActiveImage() const { return _currImage; }
	bool getHasTransparency() const { return _data->_hasTransparency; }
	int getFormat() const { return _data->_format; }
	int getWidth() const { return _data->_width; }
	int getHeight() const { return _data->_height; }

	const Graphics::PixelBuffer &getData(int num) const { return _data->getImageData(num); }
	const Graphics::PixelBuffer &getData() const { return getData(_currImage); }
	BitmapData *getBitmapData() const { return _data; }
	void *getTexIds() const { return _data->_texIds; }
	int getNumTex() const { return _data->_numTex; }
	const Graphics::PixelFormat &getPixelFormat(int num) const;

	void saveState(SaveGame *state) const;
	void restoreState(SaveGame *state);

	virtual ~Bitmap();

//private:
	void freeData();

	BitmapData *_data;
	/**
	 * Specifies a one-based index to the current image in BitmapData.
	 * _currImage==0 means a null image is chosen.
	 */
	int _currImage;
};

} // end of namespace Grim

#endif