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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
/* 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$
*
*/
/* SCI Resource library */
#ifndef _GFX_RESOURCE_H_
#define _GFX_RESOURCE_H_
#include "sci/gfx/gfx_system.h"
#include "sci/gfx/gfx_driver.h"
namespace Common {
class File;
}
namespace Sci {
/*** Styles for pic0 drawing ***/
/* Dithering modes */
#define GFXR_DITHER_MODE_D16 0 /* Sierra SCI style */
#define GFXR_DITHER_MODE_F256 1 /* Flat color interpolation */
#define GFXR_DITHER_MODE_D256 2 /* 256 color dithering */
/* Dithering patterns */
#define GFXR_DITHER_PATTERN_SCALED 0 /* Dither per pixel on the 320x200 grid */
#define GFXR_DITHER_PATTERN_1 1 /* Dither per pixel on the target */
#define SCI_TITLEBAR_SIZE 10
#define DRAWPIC01_FLAG_FILL_NORMALLY 1
#define DRAWPIC01_FLAG_OVERLAID_PIC 2
#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;
/* (gfx_pic_0.c) The 16 EGA base colors */
extern gfx_pixmap_color_t gfx_sci0_image_colors[][16];
/* (gfx_pic_0.c) The 256 interpolated colors (initialized when
** gfxr_init_pic() is called for the first time, or when gfxr_init_static_palette() is called)
*/
extern gfx_pixmap_color_t gfx_sci0_pic_colors[];
struct gfxr_pic0_params_t {
gfx_line_mode_t line_mode; /* one of GFX_LINE_MODE_* */
gfx_brush_mode_t brush_mode;
rect_t pic_port_bounds;
};
struct gfxr_pic_t {
int ID; /* pic number (NOT resource ID, just number) */
gfx_mode_t *mode;
gfx_pixmap_t *visual_map;
gfx_pixmap_t *priority_map;
gfx_pixmap_t *control_map;
byte aux_map[GFXR_AUX_MAP_SIZE];
/* Auxiliary map details:
** Bit 0: Vis
** Bit 1: Pri
** Bit 2: Ctrl
** Bit 3-5: 'filled' (all three bits are set to 1)
*/
rect_t bounds;
void *undithered_buffer; /* copies visual_map->index_data before dithering */
int undithered_buffer_size;
void *internal; /* Interpreter information, or NULL. Will be freed
** automatically when the pic is freed! */
};
struct gfxr_loop_t {
int cels_nr;
gfx_pixmap_t **cels;
};
struct gfxr_view_t {
int ID;
int flags;
int colors_nr;
gfx_pixmap_color_t *colors;
int loops_nr;
gfxr_loop_t *loops;
int translation[GFX_SCI0_IMAGE_COLORS_NR];
};
typedef enum {
GFXR_FONT_SCALE_FILTER_NONE
} gfxr_font_scale_filter_t;
struct text_fragment_t {
const char *offset;
int length;
};
/* unscaled color index mode: Used in addition to a scaled mode
** to render the pic resource twice. See gfxr_remove_artifacts_pic0().
*/
extern gfx_mode_t mode_1x1_color_index;
void gfxr_init_static_palette();
/* Initializes the static 256 color palette
** Parameters: (void)
** Returns : (void)
*/
gfxr_pic_t *gfxr_init_pic(gfx_mode_t *mode, int ID, int sci1);
/* Initializes a gfxr_pic_t for a specific mode
** Parameters: (gfx_mode_t *) mode: The specific graphics mode
** (int) ID: The ID to assign to the resulting pixmaps
** Returns : (gfxr_pic_t *) The allocated pic resource, or NULL on error.
** This function allocates memory for use by resource drawer functions.
*/
void gfxr_free_pic(gfx_driver_t *driver, gfxr_pic_t *pic);
/* Uninitializes a pic resource
** Parameters: (gfx_driver_t *) driver: The driver the pic should be removed from
** (gfxr_pic_t *) pic: The pic to free
** Returns : (void)
*/
void gfxr_free_view(gfx_driver_t *driver, gfxr_view_t *view);
/* Frees all memory associated with a view
** Paremeters: (gfx_driver_t *) driver: The driver the view should be removed from
** (gfxr_view_t *) view: The view to free
** Returns : (void)
*/
/*******************/
/* Font operations */
/*******************/
/* SCI0, SCI01 and SCI1 all use the same font format. */
/* SQ3 uses a somewhat different scheme for calculating text sizes: it counts
** whitespace while calculating the text size. */
#define GFXR_FONT_FLAG_COUNT_WHITESPACE (1<<0)
/* Don't give newline characters special semantics */
#define GFXR_FONT_FLAG_NO_NEWLINES (1<<1)
/* Interpret CR LF sequences as a single newline, rather than two of them */
#define GFXR_FONT_FLAG_EAT_TRAILING_LF (1<<2)
gfx_bitmap_font_t *gfxr_read_font(int id, byte *resource, int size);
/* Geneartes a bitmap font data structure from a resource
** Parameters: (int) id: Resource ID of the resulting font
** (byte *) resource: Pointer to the resource data
** (int) size: Size of the resource block
** Returns : (gfx_bitmap_font_t *) The resulting font structure, or
** NULL on error
*/
void gfxr_free_font(gfx_bitmap_font_t *font);
/* Frees a previously allocated font structure
** Parameters: (gfx_bitmap_font_t *) font: The font to free
** Returns : (void)
*/
gfx_bitmap_font_t *gfxr_scale_font(gfx_bitmap_font_t *font, gfx_mode_t *mode, gfxr_font_scale_filter_t filter);
/* Scales a font resource
** Parameters: (gfx_bitmap_font_t *) font: The font to scale
** (gfx_mode_t *) mode: The graphics mode to scale it for
** (gfxr_font_scale_filter_t) filter: A filter to use
** Returns : (gfx_bitmap_font_t *) A scaled font, or NULL on error
*/
text_fragment_t *gfxr_font_calculate_size(gfx_bitmap_font_t *font, int max_width, const char *text,
int *width, int *height, int *lines, int *line_height, int *last_offset, int flags);
/* Calculates the size that would be occupied by drawing a specified text
** Parameters: (gfx_bitmap_font_t *) font: The font to calculate with
** (int) max_width: Maximum pixel width allowed for the output
** (const char *) text: The text to calculate for
** (int) flags: Any text formatting flags
** Returns : (text_fragment *) a newly allocated array of text_fragments,
** containing the start and size of each string
** segment
** (int) *width: The resulting width
** (int) *height: The resulting height
** (int) *lines: Number of lines used
** (int) *line_height: Pixel height of a single line of text
** (int) *last_offset: Pixel offset after the last drawn line
** This function assumes 320x200 mode.
*/
gfx_pixmap_t *gfxr_draw_font(gfx_bitmap_font_t *font, const char *text, int characters,
gfx_pixmap_color_t *fg0, gfx_pixmap_color_t *fg1, gfx_pixmap_color_t *bg);
/* Draws text in a specific font to a pixmap
** Parameters: (gfx_bitmap_font_t *) font: The font to use for drawing
** (char *) text: The start of the text to draw
** (int) characters: The number of characters to draw
** (gfx_pixmap_color_t *) fg0: The first foreground color
** (gfx_pixmap_color_t *) fg1: The second foreground color
** (gfx_pixmap_color_t *) bg: The background color
** Returns : (gfx_pixmap_t *) The result pixmap, or NULL on error
** The results are written to the pixmap's index buffer. Contents of the
** foreground and background fields are copied into a newly allocated font
** structure, so that the pixmap may be translated directly.
** If any of the colors is null, it will be assumed to be transparent.
** In color index mode, the specified colors have to be preallocated.
*/
/*********************/
/* SCI0 operations */
/*********************/
void gfxr_clear_pic0(gfxr_pic_t *pic, int sci_titlebar_size);
/* Clears all pic buffers of one pic
** Parameters: (gfxr_pic_t) pic: The picture to clear
** (int) sci_titlebar_size: How much space to reserve for the title bar
** Returns : (void)
** This function should be called before gfxr_draw_pic0, unless cumulative
** drawing is intended
*/
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, int sci1,
gfx_pixmap_color_t *static_pal, int static_pal_nr);
/* Draws a pic resource (all formats prior to SCI1.1)
** Parameters: (gfxr_pic_t *) pic: The pic to draw to
** (int) fill_normally: If 1, the pic is drawn normally; if 0, all
** fill operations will fill with black
** (int) default_palette: The default palette to use for drawing
** (int) size: Resource size
** (byte *) resource: Pointer to the resource data
** (gfxr_pic0_params_t *) style: The drawing style
** (int) resid: The resource ID
** (int) sci1: Nonzero if SCI1
** (gfx_pixmap_color_t *) static_pal: The static palette
** (int) static_pal_nr: Number of entries in static palette
** Returns : (void)
** 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.
*/
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,
gfx_pixmap_color_t *static_pal, int static_pal_nr);
/* Draws a pic resource (SCI1.1)
** Parameters: (gfxr_pic_t *) pic: The pic to draw to
** (int) fill_normally: If 1, the pic is drawn normally; if 0, all
** fill operations will fill with black
** (int) default_palette: The default palette to use for drawing
** (int) size: Resource size
** (byte *) resource: Pointer to the resource data
** (gfxr_pic0_params_t *) style: The drawing style
** (int) resid: The resource ID
** (gfx_pixmap_color_t *) static_pal: The static palette
** (int) static_pal_nr: Number of entries in static palette
** Returns : (void)
** 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.
*/
void gfxr_remove_artifacts_pic0(gfxr_pic_t *dest, gfxr_pic_t *src);
/* Removes artifacts from a scaled pic
** Parameters: (gfxr_pic_t *) dest: The scaled pic
** (gfxr_pic_t *) src: An unscaled pic
** Returns : (void)
** 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.
*/
void gfxr_dither_pic0(gfxr_pic_t *pic, int mode, int pattern);
/* Dithers a gfxr_visual_map
** Parameters: (gfxr_pic_t *) pic: The pic to dither
** (int) mode: One of GFXR_DITHER_MODE
** (int) pattern: One of GFXR_DITHER_PATTERN
** Returns : (void)
*/
gfxr_view_t *gfxr_draw_view0(int id, byte *resource, int size, int palette);
/* Calculates an SCI0 view
** Parameters: (int) id: Resource ID of the view
** (byte *) resource: Pointer to the resource to read
** (int) size: Size of the resource
** (int) palette: The palette to use
** Returns : (gfxr_view_t *) The resulting view
*/
gfx_pixmap_t *gfxr_draw_cursor0(int id, byte *resource, int size);
/* Calculates an SCI0 cursor
** Parameters: (int) id: The cursor's resource ID
** (byte *) resource: Pointer to the resource data
** (int) size: Resource size
** Returns : (gfx_pixmap_t *) A newly allocated pixmap storing the cursor
*/
/**********************/
/* SCI01 operations */
/**********************/
gfx_pixmap_t *gfxr_draw_cursor01(int id, byte *resource, int size);
/* Calculates an SCI01 cursor
** Parameters: (int) id: The cursor's resource ID
** (byte *) resource: Pointer to the resource data
** (int) size: Resource size
** Returns : (gfx_pixmap_t *) A newly allocated pixmap containing an index
** color representation of the cursor
*/
/*********************/
/* SCI1 operations */
/*********************/
gfx_pixmap_color_t *gfxr_read_pal1(int id, int *colors_nr, byte *resource, int size);
/* Reads an SCI1 palette
** Parameters: (int) id: Resource ID for the palette (or the view it was found in)
** (int *) colors_nr: Pointer to the variable the number of colors
** will be stored in
** (byte *) resource: Source data
** (int) size: Size of the memory block pointed to by resource
** Returns : (gfx_pixmap_color_t *) *colors_nr color_t entries with the colors
*/
gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file);
/* Reads an SCI1 palette
** Parameters: (int *) colors_nr: Pointer to the variable the number of colors
** will be stored in
** (FILE *) f: Palette file
** Returns : (gfx_pixmap_color_t *) *colors_nr color_t entries with the colors
*/
gfx_pixmap_color_t *gfxr_read_pal11(int id, int *colors_nr, byte *resource, int size);
/* Reads an SCI1.1 palette
** Parameters: (int) id: Resource ID for the palette (or the view it was found in)
** (int *) colors_nr: Pointer to the variable the number of colors
** will be stored in
** (byte *) resource: Source data
** (int) size: Size of the memory block pointed to by resource
** Returns : (gfx_pixmap_color_t *) *colors_nr color_t entries with the colors
*/
gfxr_view_t *gfxr_draw_view1(int id, byte *resource, int size, gfx_pixmap_color_t *static_pal,
int static_pal_nr);
/* Calculates an SCI1 view
** Parameters: (int) id: Resource ID of the view
** (byte *) resource: Pointer to the resource to read
** (int) size: Size of the resource
** (gfx_pixmap_color_t *) static_pal: The static palette
** (int) static_pal_nr: Number of entries in static palette
** Returns : (gfxr_view_t *) The resulting view
*/
gfx_pixmap_t *gfxr_draw_cel11(int id, int loop, int cel, int mirrored, byte *resource_base, byte *cel_base, int size, gfxr_view_t *view);
gfx_pixmap_t *gfxr_endianness_adjust(gfx_pixmap_t *pixmap, gfx_mode_t *mode);
/* Endianness-adjusts a pixmap, if neccessary
** Parameters: (gfx_pixmap_t *) pixmap: The pixmap to adjust
** (gfx_mode_t *) mode: The mode to adjust it for
** Returns : (gfx_pixmap_t *) pixmap, or NULL on error
** The pixmap is adjusted iff the mode signals that this is
** required (by means of setting the appropriate flag), and
** the mode has a byte depth of more than 1.
*/
static inline int get_int_16(const byte *offset) {
return ((int) offset[0] | (((int) offset[1]) << 8));
}
} // End of namespace Sci
#endif /* !_GFX_RESOURCE_H_ */
|