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 AGS_LIB_ALLEGRO_GRAPHICS_H
24 #define AGS_LIB_ALLEGRO_GRAPHICS_H
25 
26 #include "graphics/managed_surface.h"
27 #include "ags/lib/allegro/base.h"
28 #include "ags/lib/allegro/fixed.h"
29 #include "ags/lib/allegro/surface.h"
30 #include "common/array.h"
31 
32 namespace AGS3 {
33 
34 #define GFX_TEXT                       -1
35 #define GFX_AUTODETECT                 0
36 #define GFX_AUTODETECT_FULLSCREEN      1
37 #define GFX_AUTODETECT_WINDOWED        2
38 #define GFX_SAFE                       AL_ID('S','A','F','E')
39 #define GFX_NONE                       AL_ID('N','O','N','E')
40 
41 /* Bitfield for relaying graphics driver type information */
42 #define GFX_TYPE_UNKNOWN     0
43 #define GFX_TYPE_WINDOWED    1
44 #define GFX_TYPE_FULLSCREEN  2
45 #define GFX_TYPE_DEFINITE    4
46 #define GFX_TYPE_MAGIC       8
47 
48 /* drawing modes for draw_sprite_ex() */
49 #define DRAW_SPRITE_NORMAL 0
50 #define DRAW_SPRITE_LIT 1
51 #define DRAW_SPRITE_TRANS 2
52 
53 /* flipping modes for draw_sprite_ex() */
54 #define DRAW_SPRITE_NO_FLIP 0x0
55 #define DRAW_SPRITE_H_FLIP  0x1
56 #define DRAW_SPRITE_V_FLIP  0x2
57 #define DRAW_SPRITE_VH_FLIP 0x3
58 
59 /* Blender mode defines, for the gfx_driver->set_blender_mode() function */
60 #define blender_mode_none            0
61 #define blender_mode_trans           1
62 #define blender_mode_add             2
63 #define blender_mode_burn            3
64 #define blender_mode_color           4
65 #define blender_mode_difference      5
66 #define blender_mode_dissolve        6
67 #define blender_mode_dodge           7
68 #define blender_mode_hue             8
69 #define blender_mode_invert          9
70 #define blender_mode_luminance      10
71 #define blender_mode_multiply       11
72 #define blender_mode_saturation     12
73 #define blender_mode_screen         13
74 #define blender_mode_alpha          14
75 
76 
77 #define SCREEN_W     (gfx_driver ? gfx_driver->w : 0)
78 #define SCREEN_H     (gfx_driver ? gfx_driver->h : 0)
79 
80 #define VIRTUAL_W    (screen ? screen->w : 0)
81 #define VIRTUAL_H    (screen ? screen->h : 0)
82 
83 #define COLORCONV_NONE              0
84 
85 #define COLORCONV_8_TO_15           1
86 #define COLORCONV_8_TO_16           2
87 #define COLORCONV_8_TO_24           4
88 #define COLORCONV_8_TO_32           8
89 
90 #define COLORCONV_15_TO_8           0x10
91 #define COLORCONV_15_TO_16          0x20
92 #define COLORCONV_15_TO_24          0x40
93 #define COLORCONV_15_TO_32          0x80
94 
95 #define COLORCONV_16_TO_8           0x100
96 #define COLORCONV_16_TO_15          0x200
97 #define COLORCONV_16_TO_24          0x400
98 #define COLORCONV_16_TO_32          0x800
99 
100 #define COLORCONV_24_TO_8           0x1000
101 #define COLORCONV_24_TO_15          0x2000
102 #define COLORCONV_24_TO_16          0x4000
103 #define COLORCONV_24_TO_32          0x8000
104 
105 #define COLORCONV_32_TO_8           0x10000
106 #define COLORCONV_32_TO_15          0x20000
107 #define COLORCONV_32_TO_16          0x40000
108 #define COLORCONV_32_TO_24          0x80000
109 
110 #define COLORCONV_32A_TO_8          0x100000
111 #define COLORCONV_32A_TO_15         0x200000
112 #define COLORCONV_32A_TO_16         0x400000
113 #define COLORCONV_32A_TO_24         0x800000
114 
115 #define COLORCONV_DITHER_PAL        0x1000000
116 #define COLORCONV_DITHER_HI         0x2000000
117 #define COLORCONV_KEEP_TRANS        0x4000000
118 
119 #define COLORCONV_DITHER            (COLORCONV_DITHER_PAL |          \
120                                      COLORCONV_DITHER_HI)
121 
122 #define COLORCONV_EXPAND_256        (COLORCONV_8_TO_15 |             \
123                                      COLORCONV_8_TO_16 |             \
124                                      COLORCONV_8_TO_24 |             \
125                                      COLORCONV_8_TO_32)
126 
127 #define COLORCONV_REDUCE_TO_256     (COLORCONV_15_TO_8 |             \
128                                      COLORCONV_16_TO_8 |             \
129                                      COLORCONV_24_TO_8 |             \
130                                      COLORCONV_32_TO_8 |             \
131                                      COLORCONV_32A_TO_8)
132 
133 #define COLORCONV_EXPAND_15_TO_16    COLORCONV_15_TO_16
134 
135 #define COLORCONV_REDUCE_16_TO_15    COLORCONV_16_TO_15
136 
137 #define COLORCONV_EXPAND_HI_TO_TRUE (COLORCONV_15_TO_24 |            \
138                                      COLORCONV_15_TO_32 |            \
139                                      COLORCONV_16_TO_24 |            \
140                                      COLORCONV_16_TO_32)
141 
142 #define COLORCONV_REDUCE_TRUE_TO_HI (COLORCONV_24_TO_15 |            \
143                                      COLORCONV_24_TO_16 |            \
144                                      COLORCONV_32_TO_15 |            \
145                                      COLORCONV_32_TO_16)
146 
147 #define COLORCONV_24_EQUALS_32      (COLORCONV_24_TO_32 |            \
148                                      COLORCONV_32_TO_24)
149 
150 #define COLORCONV_TOTAL             (COLORCONV_EXPAND_256 |          \
151                                      COLORCONV_REDUCE_TO_256 |       \
152                                      COLORCONV_EXPAND_15_TO_16 |     \
153                                      COLORCONV_REDUCE_16_TO_15 |     \
154                                      COLORCONV_EXPAND_HI_TO_TRUE |   \
155                                      COLORCONV_REDUCE_TRUE_TO_HI |   \
156                                      COLORCONV_24_EQUALS_32 |        \
157                                      COLORCONV_32A_TO_15 |           \
158                                      COLORCONV_32A_TO_16 |           \
159                                      COLORCONV_32A_TO_24)
160 
161 #define COLORCONV_PARTIAL           (COLORCONV_EXPAND_15_TO_16 |     \
162                                      COLORCONV_REDUCE_16_TO_15 |     \
163                                      COLORCONV_24_EQUALS_32)
164 
165 #define COLORCONV_MOST              (COLORCONV_EXPAND_15_TO_16 |     \
166                                      COLORCONV_REDUCE_16_TO_15 |     \
167                                      COLORCONV_EXPAND_HI_TO_TRUE |   \
168                                      COLORCONV_REDUCE_TRUE_TO_HI |   \
169                                      COLORCONV_24_EQUALS_32)
170 
171 #define COLORCONV_KEEP_ALPHA        (COLORCONV_TOTAL                 \
172                                      & ~(COLORCONV_32A_TO_8 |        \
173                                              COLORCONV_32A_TO_15 |       \
174                                              COLORCONV_32A_TO_16 |       \
175                                              COLORCONV_32A_TO_24))
176 
177 AL_FUNC(void, set_color_conversion, (int mode));
178 AL_FUNC(int, get_color_conversion, ());
179 AL_FUNC(int, set_gfx_mode, (int card, int w, int h, int depth));
180 
181 AL_FUNC(void, set_clip_rect, (BITMAP *bitmap, int x1, int y1, int x2, int y2));
182 AL_FUNC(void, get_clip_rect, (BITMAP *bitmap, int *x1, int *y1, int *x2, int *y2));
183 AL_FUNC(void, clear_bitmap, (BITMAP *bitmap));
184 
185 AL_FUNC(void, acquire_bitmap, (BITMAP *bitmap));
186 AL_FUNC(void, release_bitmap, (BITMAP *bitmap));
187 AL_FUNC(void, draw_sprite, (BITMAP *bmp, const BITMAP *sprite, int x, int y));
188 AL_FUNC(void, stretch_sprite, (BITMAP *bmp, const BITMAP *sprite, int x, int y, int w, int h));
189 
190 extern void clear_to_color(BITMAP *bitmap, int color);
191 extern int bitmap_color_depth(BITMAP *bmp);
192 extern int bitmap_mask_color(BITMAP *bmp);
193 extern void add_palette_if_needed(Graphics::ManagedSurface &surf);
194 extern void blit(const BITMAP *src, BITMAP *dest, int src_x, int src_y, int dst_x, int dst_y, int width, int height);
195 extern void masked_blit(const BITMAP *src, BITMAP *dest, int src_x, int src_y, int dst_x, int dst_y, int width, int height);
196 extern void stretch_blit(const BITMAP *src, BITMAP *dest, int source_x, int source_y, int source_width, int source_height,
197                          int dest_x, int dest_y, int dest_width, int dest_height);
198 extern void masked_stretch_blit(const BITMAP *src, BITMAP *dest, int source_x, int source_y, int source_width, int source_height,
199                                 int dest_x, int dest_y, int dest_width, int dest_height);
200 extern void draw_trans_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y);
201 extern void draw_lit_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, int color);
202 extern void draw_sprite_h_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y);
203 extern void draw_sprite_v_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y);
204 extern void draw_sprite_vh_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y);
205 extern void rotate_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, fixed angle);
206 extern void pivot_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, int cx, int cy, fixed angle);
207 
208 extern bool is_screen_bitmap(BITMAP *bmp);
209 extern bool is_video_bitmap(BITMAP *bmp);
210 extern bool is_linear_bitmap(BITMAP *bmp);
211 extern bool is_planar_bitmap(BITMAP *bmp);
212 extern void bmp_select(BITMAP *bmp);
213 extern byte *bmp_write_line(BITMAP *bmp, int line);
214 extern void bmp_unwrite_line(BITMAP *bmp);
215 extern void bmp_write8(byte *addr, int color);
216 extern void bmp_write15(byte *addr, int color);
217 extern void bmp_write16(byte *addr, int color);
218 extern void bmp_write24(byte *addr, int color);
219 extern void bmp_write32(byte *addr, int color);
220 extern void memory_putpixel(BITMAP *bmp, int x, int y, int color);
221 extern void putpixel(BITMAP *bmp, int x, int y, int color);
222 extern void _putpixel(BITMAP *bmp, int x, int y, int color);
223 extern void _putpixel15(BITMAP *bmp, int x, int y, int color);
224 extern void _putpixel16(BITMAP *bmp, int x, int y, int color);
225 extern void _putpixel24(BITMAP *bmp, int x, int y, int color);
226 extern void _putpixel32(BITMAP *bmp, int x, int y, int color);
227 extern int getpixel(const BITMAP *bmp, int x, int y);
228 extern int _getpixel(const BITMAP *bmp, int x, int y);
229 extern int _getpixel15(const BITMAP *bmp, int x, int y);
230 extern int _getpixel16(const BITMAP *bmp, int x, int y);
231 extern int _getpixel24(const BITMAP *bmp, int x, int y);
232 extern int _getpixel32(const BITMAP *bmp, int x, int y);
233 extern void line(BITMAP *bmp, int x1, int y_1, int x2, int y2, int color);
234 extern void rect(BITMAP *bmp, int x1, int y_1, int x2, int y2, int color);
235 extern void rectfill(BITMAP *bmp, int x1, int y_1, int x2, int y2, int color);
236 extern void triangle(BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color);
237 extern void circlefill(BITMAP *bmp, int x, int y, int radius, int color);
238 
239 } // namespace AGS3
240 
241 #endif
242