aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gfx/gfx_resource.h
blob: 56fb16295afd53d662bc7faf7b850b9483873e67 (plain)
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * 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.
 *
 * $URL$
 * $Id$
 *
 */

/** @file gfx_resource.h
 * SCI Resource library.
 */

#ifndef SCI_GFX_GFX_RESOURCE_H
#define SCI_GFX_GFX_RESOURCE_H

#include "sci/gfx/gfx_system.h"
#include "sci/gfx/gfx_driver.h"

#include "common/rect.h"

namespace Common {
	class File;
}

namespace Sci {

/*** Styles for pic0 drawing ***/
/* Dithering modes for SCI0 games */
enum DitherMode {
	kDitherNone = 0,         // No dithering
	kDither16Colors = 1,     // Sierra SCI style
	kDither256Colors = 2     // Enhanced style
};

#define SCI_TITLEBAR_SIZE 10

#define DRAWPIC01_FLAG_FILL_NORMALLY 1
#define DRAWPIC01_FLAG_OVERLAID_PIC 2
#define DRAWPIC1_FLAG_MIRRORED 4

#define GFXR_AUX_MAP_SIZE (320*200)


#define GFX_SCI0_IMAGE_COLORS_NR 16
#define GFX_SCI0_PIC_COLORS_NR 256

#define GFX_SCI1_AMIGA_COLORS_NR 32

extern int sci0_palette;

/** The 16 EGA base colors */
extern Palette* gfx_sci0_image_pal[];
extern PaletteEntry gfx_sci0_image_colors[][16];

/**
 * The 256 interpolated colors (initialized when gfxr_init_pic() is called
 * for the first time, or when gfxr_init_static_palette() is called)
 */
extern Palette* gfx_sci0_pic_colors;


enum ViewType {
	kViewUnknown,
	kViewEga,
	kViewVga,
	kViewVga11,
	kViewAmiga
};

struct gfxr_pic0_params_t {
	gfx_line_mode_t line_mode; /* one of GFX_LINE_MODE_* */
	gfx_brush_mode_t brush_mode;
};

/** A SCI resource pic */
struct gfxr_pic_t {
	int ID; /**< pic number (NOT resource ID, just number) */
	gfx_mode_t *mode;
	gfx_pixmap_t *visual_map; /**< Visual part of pic */
	gfx_pixmap_t *priority_map; /**< Priority map for pic */
	gfx_pixmap_t *control_map; /**< Control map for pic */

	/**
	 * Auxiliary map.
	 * Bit 0: Vis
	 * Bit 1: Pri
	 * Bit 2: Ctrl
	 * Bit 3-5: 'filled' (all three bits are set to 1)
	 */
	byte aux_map[GFXR_AUX_MAP_SIZE];

	// rect_t bounds;	// unused

	void *undithered_buffer; /**< copies visual_map->index_data before dithering */
	int undithered_buffer_size;

	int *priorityTable;
};

/** A animation loop */
struct gfxr_loop_t {
	int cels_nr; /**< Number of 'cels' or frames in the animation */
	gfx_pixmap_t **cels; /**< Pointer to the pixmaps for the cels */
};

/** A graphics view */
struct gfxr_view_t {
	int ID;

	int flags;
	Palette *palette;

	int loops_nr;
	gfxr_loop_t *loops;
};

/**
 * Initializes the static 256 color palette.
 */
void gfxr_init_static_palette();

/** @name Resource picture management functions */
/** @{ */

/**
 * Initializes a gfxr_pic_t for a specific mode.
 *
 * This function allocates memory for use by resource drawer functions.
 *
 * @param[in] mode	The specific graphics mode
 * @param[in] ID	The ID to assign to the resulting pixmaps
 * @param[in] sci1	true if a SCI1 pic, false otherwise
 * @return			The allocated pic resource, or NULL on error.
 */
gfxr_pic_t *gfxr_init_pic(gfx_mode_t *mode, int ID, bool sci1);

/**
 * Uninitializes a pic resource.
 *
 * @param[in] pic	The pic to free
 */
void gfxr_free_pic(gfxr_pic_t *pic);

/**
 * Frees all memory associated with a view.
 *
 * @param[in] view	The view to free
 */
void gfxr_free_view(gfxr_view_t *view);
/** @} */
/** @name SCI0 resource picture operations */
/** @{ */

/**
 * Clears all pic buffers of one pic/
 *
 * This function should be called before gfxr_draw_pic0, unless cumulative
 * drawing is intended
 *
 * @param[in] pic			The picture to clear
 * @param[in] titlebar_size	How much space to reserve for the title bar
 */
void gfxr_clear_pic0(gfxr_pic_t *pic, int titlebar_size);

/**
 * Draws a pic resource (all formats prior to SCI1.1).
 *
 * The result is stored in gfxr_visual_map, gfxr_priority_map, and
 * gfxr_control_map. The palette entry of gfxr_visual_map is never used.
 * Note that the picture will not be drawn dithered; use gfxr_dither_pic0
 * for that.
 *
 * @param[in] pic				The pic to draw to
 * @param[in] fill_normally		If 1, the pic is drawn normally; if 0, all
 * 								fill operations will fill with black
 * @param[in] default_palette	The default palette to use for drawing
 * @param[in] size				Resource size
 * @param[in] resource			Pointer to the resource data
 * @param[in] style				The drawing style
 * @param[in] resid				The resource ID
 * @param[in] viewType			The view type for embedded views
 * @param[in] static_pal		The static palette
 * @param[in] portBounds		The bounds of the port being drawn to
 */
void gfxr_draw_pic01(gfxr_pic_t *pic, int fill_normally,
		int default_palette, int size, byte *resource,
		gfxr_pic0_params_t *style, int resid, ViewType viewType,
		Palette *static_pal, Common::Rect portBounds);

/**
 * Draws a pic resource (SCI1.1).
 *
 * The result is stored in gfxr_visual_map, gfxr_priority_map, and
 * gfxr_control_map. The palette entry of gfxr_visual_map is never used.
 * Note that the picture will not be drawn dithered; use gfxr_dither_pic11
 * for that.
 *
 * @param[in] pic				The pic to draw to
 * @param[in] fill_normally		If 1, the pic is drawn normally; if 0, all
 * 								fill operations will fill with black
 * @param[in] default_palette	The default palette to use for drawing
 * @param[in] size				Resource size
 * @param[in] resource			Pointer to the resource data
 * @param[in] style				The drawing style
 * @param[in] resid				The resource ID
 * @param[in] static_pal		The static palette
 * @param[in] portBounds		Bounds of the port being drawn to
 */
void gfxr_draw_pic11(gfxr_pic_t *pic, int fill_normally,
		int default_palette, int size, byte *resource,
		gfxr_pic0_params_t *style, int resid, Palette *static_pal,
		Common::Rect portBounds);

/**
 * Removes artifacts from a scaled pic.
 *
 * Using information from the (correctly rendered) src pic, this function
 * implements some heuristics to remove artifacts from dest. Must be used
 * before dither_pic0 is called, because it operates on the index buffer.
 *
 * @param[in] dest	The scaled pic
 * @param[in] src	An unscaled pic
 */
void gfxr_remove_artifacts_pic0(gfxr_pic_t *dest, gfxr_pic_t *src);

/**
 * Dithers a gfxr_visual_map.
 *
 * @param[in] pic		        The pic to dither
 * @param[DitherMode] mode		The dithering mode to use
 */
void gfxr_dither_pic0(gfxr_pic_t *pic, DitherMode mode);

/** @} */


/** @name SCI1/1.1 resource picture operations */
/** @{ */

/**
 * Reads an SCI1 palette.
 *
 * @param[in] id		Resource ID for the palette (or the view it was
 * 						found in)
 * @param[in] resource	Source data
 * @param[in] size		Size of the memory block pointed to by resource
 * @return				Palette with the colors
 */
Palette *gfxr_read_pal1(int id, byte *resource, int size);

/**
 * Reads an SCI1 palette.
 *
 * @param[in] file	Palette file
 * @return			Palette with the colors
 */
Palette *gfxr_read_pal1_amiga(Common::File &file);

/**
 * Reads an SCI1.1 palette.
 *
 * @param[in] id		Resource ID for the palette (or the view it was
 * 						found in)
 * @param[in] resource	Source data
 * @param[in] size		Size of the memory block pointed to by resource
 * @return				Palette with the colors
 */
Palette *gfxr_read_pal11(int id, byte *resource, int size);

gfx_pixmap_t *gfxr_draw_cel1(int id, int loop, int cel, int mirrored, byte *resource, byte *cel_base, int size, gfxr_view_t *view, ViewType viewType);
/** @} */

} // End of namespace Sci

#endif // SCI_GFX_GFX_RESOURCE_H