Mercurial > hg > dmlib
annotate dmlib.h @ 108:72813cece1ba
Move some lerp functions to the header as static inline functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 03 Oct 2012 09:39:15 +0300 |
parents | 93fbce0e6591 |
children | c36e0316de9f |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
3 * -- Main header file | |
4 * Programmed and designed by Matti 'ccr' Hamalainen | |
5 * (C) Copyright 2011 Tecnic Software productions (TNSP) | |
6 */ | |
7 #ifndef DMLIB_H | |
8 #define DMLIB_H | |
9 | |
10 #include <SDL.h> | |
11 #include <stdarg.h> | |
12 | |
13 #ifdef DM_USE_ASSERTS | |
14 #include <assert.h> | |
15 #else | |
16 #define assert(NEXPR) // stub | |
17 #endif | |
18 | |
19 #ifdef __cplusplus | |
20 extern "C" { | |
21 #endif | |
22 | |
23 // Defaults | |
24 //#define DM_PROG_AUTHOR "By Matti 'ccr' Hmlinen (C) Copyright 2012 TNSP" | |
25 //#define DM_PROG_LICENSE "This software is licensed under GNU GPL version 2" | |
26 | |
27 #define DM_PROG_AUTHOR "" | |
28 #define DM_PROG_LICENSE "" | |
29 | |
30 /* Error codes | |
31 */ | |
32 enum { | |
33 // General error codes | |
34 DMERR_OK = 0, | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
35 DMERR_PROGRESS, // Status OK, but operation in progress |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
36 |
0 | 37 DMERR_FOPEN, |
38 DMERR_FREAD, | |
39 DMERR_FWRITE, | |
40 DMERR_FSEEK, | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
41 DMERR_NOT_FOUND, // Resource/data not found |
0 | 42 |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
43 DMERR_INVALID_DATA, // Some data was invalid |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
44 DMERR_MALLOC, // Memory allocation failure |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
45 DMERR_ALREADY_INIT, // Resource has already been initialized |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
46 DMERR_INIT_FAIL, // General initialization failure |
0 | 47 DMERR_INVALID_ARGS, |
48 | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
49 DMERR_NULLPTR, // NULL pointer specified in critical argument |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
50 DMERR_NOT_SUPPORTED,// Operation not supported |
0 | 51 DMERR_OUT_OF_DATA, |
52 DMERR_EXTRA_DATA, | |
53 DMERR_BOUNDS, | |
54 | |
55 // PACK-file subsystem | |
56 DMERR_NOTPACK, | |
57 DMERR_VERSION, | |
58 DMERR_INVALID, | |
59 DMERR_COMPRESSION, | |
60 }; | |
61 | |
62 | |
63 // Resource management defines | |
64 #define DMRES_NAME_LEN 32 | |
65 #define DMRES_DATA_PACK "data.pak" // Name of the data-file | |
66 #define DMRES_DATA_PATH "DATA/" // Sub-directory path | |
67 #define DMRES_RES_FILE "res.txt" // Resource data file | |
68 | |
69 | |
70 // Mutexes | |
71 #define DMMutex SDL_mutex | |
72 #define dmCreateMutex() SDL_CreateMutex() | |
73 #define dmDestroyMutex(x) SDL_DestroyMutex(x) | |
74 #define dmMutexLock(x) SDL_mutexP(x) | |
75 #define dmMutexUnlock(x) SDL_mutexV(x) | |
76 | |
77 | |
78 /* Define a boolean type | |
79 */ | |
80 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) | |
81 typedef enum { FALSE = 0, TRUE = 1 } BOOL; | |
82 #endif | |
83 | |
84 #ifndef BOOL | |
85 #ifdef bool | |
86 #define BOOL bool | |
87 #else | |
88 #define BOOL int | |
89 #endif | |
90 #endif | |
91 | |
92 | |
93 /* Fixed point math type | |
94 */ | |
95 typedef union | |
96 { | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
97 Sint64 dw; |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
98 Sint32 w[2]; |
0 | 99 } DMFixedPoint; |
100 | |
101 | |
102 typedef union | |
103 { | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
104 Sint32 dw; |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
105 Sint16 w[2]; |
0 | 106 } DMFixedPoint32; |
107 | |
108 | |
109 /* Macros for fixed point math | |
110 */ | |
111 #if __GNUC__ >= 3 | |
112 # define FP_SET(a, k) a.dw = k ## ULL | |
113 #else | |
114 # define FP_SET(a, k) a.dw = k | |
115 #endif | |
116 | |
117 #define FP_CONV(a, k) a.dw = k | |
118 | |
119 #ifndef SDL_BYTEORDER | |
120 # error Undefined byteorder! | |
121 #endif | |
122 | |
123 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
124 # define FP_SETH(a, k) a.w[0] = (k) | |
125 # define FP_SETL(a, k) a.w[1] = (k) | |
126 # define FP_SETHL(a, h, l) { a.w[0] = (h); a.w[1] = (l); } | |
127 # define FP_GETH(a) a.w[0] | |
128 # define FP_GETL(a) a.w[1] | |
129 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
130 # define FP_SETH(a, k) a.w[1] = (k) | |
131 # define FP_SETL(a, k) a.w[0] = (k) | |
132 # define FP_SETHL(a, h, l) { a.w[1] = (h); a.w[0] = (l); } | |
133 # define FP_GETH(a) a.w[1] | |
134 # define FP_GETL(a) a.w[0] | |
135 #else | |
136 # error Unsupported byte order! | |
137 #endif | |
138 | |
139 #define FP_PRINTF(a) printf("%.8x:%.8x", FP_GETH(a), FP_GETL(a)) | |
140 #define FP_PRINTF32(a) printf("%.4x:%.4x", FP_GETH(a), FP_GETL(a)) | |
141 | |
142 #define FP_ADD(a, b) a.dw += b.dw | |
143 #define FP_SUB(a, b) a.dw -= b.dw | |
144 #define FP_ADD_R(r, a, b) r.dw = a.dw + b.dw | |
145 #define FP_SUB_R(r, a, b) r.dw = a.dw - b.dw | |
146 #define FP_DIV(a, b) a.dw /= b.dw | |
147 #define FP_MUL(a, b) a.dw *= b.dw | |
148 #define FP_DIV_R(r, a, b) r.dw = (a.dw / b.dw) | |
149 #define FP_MUL_R(r, a, b) r.dw = (a.dw * b.dw) | |
150 | |
151 | |
152 /* Miscellaneous types | |
153 */ | |
154 typedef struct | |
155 { | |
156 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
157 Uint8 a,g,b,r; | |
158 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
159 Uint8 r,g,b,a; | |
160 #endif | |
161 } DMRGBA32; | |
162 | |
163 | |
164 typedef float DMFloat; | |
165 | |
166 | |
167 /* Drawing modes used by blitting and some other functions. | |
168 */ | |
169 enum | |
170 { | |
171 DMD_NONE = 0x0000, | |
172 DMD_TRANSPARENT = 0x0001, | |
173 DMD_SATURATE = 0x0002, | |
174 | |
175 DMD_ANTIALIAS = 0x0004, | |
176 | |
177 DMD_NMODES = 6 | |
178 }; | |
179 | |
180 | |
181 // Available bitdepths. Not all functions may support every one of these. | |
182 enum | |
183 { | |
184 DMD_8BIT = 0, | |
185 DMD_32BIT, | |
186 | |
187 DMD_NBITDEPTHS | |
188 }; | |
189 | |
190 | |
191 static inline int dmBitsPerPixel2Index(int bpp) | |
192 { | |
193 return (bpp == 8 ? 0 : (bpp == 32 ? 1 : -1)); | |
194 } | |
195 | |
196 | |
197 /* Generic parameter interpolation | |
198 */ | |
199 #define DMM_S_CURVE(t) ((t) * (t) * (3.0f - 2.0f * (t))) | |
200 #define DMM_LERP(t, a, b) ((a) + (t) * ((b) - (a))) | |
201 | |
202 typedef struct | |
203 { | |
204 DMFloat start, end, nsteps; | |
205 } DMLerpContext; | |
206 | |
207 | |
208 void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps); | |
108
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
209 DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
210 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
211 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
212 static inline DMFloat dmClamp10(const DMFloat a) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
213 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
214 return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a)); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
215 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
216 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
217 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
218 static inline DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
219 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
220 const DMFloat n = step / ctx->nsteps; |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
221 const DMFloat v = DMM_S_CURVE(n); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
222 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
223 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
224 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
225 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
226 static inline DMFloat dmLerpSCurveClamp(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
227 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
228 const DMFloat n = dmClamp10(step / ctx->nsteps); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
229 const DMFloat v = DMM_S_CURVE(n); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
230 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
231 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
232 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
233 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
234 static inline DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
235 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
236 const DMFloat v = step / ctx->nsteps; |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
237 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
238 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
239 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
240 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
241 static inline DMFloat dmLerp1Clamp(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
242 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
243 const DMFloat v = dmClamp10(step / ctx->nsteps); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
244 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
245 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
246 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
247 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
248 static inline DMFloat dmCatmullRomClamp(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
249 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
250 return dmCatmullRom(dmClamp10(t), p0, p1, p2, p3); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
251 } |
0 | 252 |
253 | |
254 /* Perlin noise | |
255 */ | |
256 void dmPerlinInit(void); | |
257 DMFloat dmPerlinNoise2D(DMFloat x, DMFloat y, DMFloat alpha, DMFloat beta, int n); | |
258 | |
259 | |
260 /* Arbitrary line drawing | |
261 */ | |
262 #ifdef DM_GFX_LINES | |
263 typedef int (*DMDrawLineFunc)(SDL_Surface *src, int x0, int y0, int x1, int y1, const Uint32 color); | |
264 DMDrawLineFunc dmGetDrawLineFunc(SDL_PixelFormat *dst, int mode); | |
265 int dmDrawLineAny(SDL_Surface *src, int x0, int y0, int x1, int y1, const Uint32 color, int mode); | |
266 #endif | |
267 | |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
268 |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
269 /* Various blitting functions |
0 | 270 */ |
271 #ifdef DM_GFX_BLITS | |
272 typedef int (*DMScaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst); | |
273 | |
274 DMScaledBlitFunc dmGetScaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode); | |
275 int dmScaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst, int mode); | |
19
10f58ff516b3
Add function prototypes for two special case scaled blit functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
276 |
10f58ff516b3
Add function prototypes for two special case scaled blit functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
277 int dmScaledBlitSurface32to32TransparentX(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst); |
10f58ff516b3
Add function prototypes for two special case scaled blit functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
278 int dmScaledBlitSurface32to32TransparentGA(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst, Uint32 alpha); |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
279 |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
280 |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
281 typedef int (*DMUnscaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst); |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
282 |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
283 DMUnscaledBlitFunc dmGetUnscaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode); |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
284 int dmUnscaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst, int mode); |
0 | 285 #endif |
286 | |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
287 |
0 | 288 /* Misc functions |
289 */ | |
290 #ifdef DM_GFX_MISC | |
291 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col); | |
292 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col); | |
293 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col); | |
294 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol); | |
90
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
295 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
296 static inline void dmClearSurface(SDL_Surface *screen, const Uint32 col) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
297 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
298 SDL_FillRect(screen, NULL, col); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
299 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
300 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
301 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
302 static inline Uint32 dmMapRGB(SDL_Surface *screen, int r, int g, int b) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
303 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
304 return SDL_MapRGB(screen->format, r, g, b); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
305 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
306 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
307 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
308 static inline Uint32 dmMapRGBA(SDL_Surface *screen, int r, int g, int b, int a) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
309 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
310 return SDL_MapRGBA(screen->format, r, g, b, a); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
311 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
312 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
313 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
314 static inline int dmDirectBlitSurface(SDL_Surface *bmp, SDL_Surface *screen) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
315 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
316 return SDL_BlitSurface(bmp, NULL, screen, NULL); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
317 } |
0 | 318 #endif |
319 | |
320 | |
321 /* Global variables | |
322 */ | |
323 extern char *dmProgName, | |
324 *dmProgDesc, | |
325 *dmProgVersion, | |
326 *dmProgAuthor, | |
327 *dmProgLicense; | |
328 | |
329 extern int dmVerbosity; | |
330 void dmInitProg(char *name, char *desc, char *version, char *author, char *license); | |
331 void dmPrintBanner(FILE *outFile, const char *name, const char *usage); | |
332 | |
333 void dmMsgVA(int level, const char *fmt, va_list ap); | |
334 void dmMsg(int level, const char *fmt, ...); | |
335 void dmPrintVA(int level, const char *fmt, va_list ap); | |
336 void dmPrint(int level, const char *fmt, ...); | |
337 void dmErrorVA(const char *fmt, va_list); | |
338 void dmError(const char *fmt, ...); | |
339 | |
340 void * dmMalloc(size_t); | |
341 void * dmMalloc0(size_t); | |
342 void * dmRealloc(void *, size_t); | |
343 void * dmCalloc(size_t, size_t); | |
344 void dmFree(void *); | |
345 | |
346 BOOL dmGetIntVal(const char *s, int *i); | |
347 | |
348 int dmGetErrno(); | |
349 const char *dmErrorStr(int error); | |
350 | |
351 char * dm_strdup(const char *); | |
352 char * dm_strdup_vprintf(const char *, va_list); | |
353 char * dm_strdup_printf(const char *, ...); | |
354 | |
355 | |
356 /* Endianess swapping macros | |
357 */ | |
358 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \ | |
359 (Uint16) ((Uint16) (value) >> 8) | \ | |
360 (Uint16) ((Uint16) (value) << 8)) ) | |
361 | |
362 | |
363 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \ | |
364 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \ | |
365 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \ | |
366 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \ | |
367 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24))) | |
368 | |
369 #ifdef DM_HAVE_64BIT | |
370 #define DM_SWAP_64_LE_BE(value) ((Uint64) ( \ | |
371 (((Uint64) (value) & (Uint64) 0x00000000000000ffULL) << 56) | \ | |
372 (((Uint64) (value) & (Uint64) 0x000000000000ff00ULL) << 40) | \ | |
373 (((Uint64) (value) & (Uint64) 0x0000000000ff0000ULL) << 24) | \ | |
374 (((Uint64) (value) & (Uint64) 0x00000000ff000000ULL) << 8) | \ | |
375 (((Uint64) (value) & (Uint64) 0x000000ff00000000ULL) >> 8) | \ | |
376 (((Uint64) (value) & (Uint64) 0x0000ff0000000000ULL) >> 24) | \ | |
377 (((Uint64) (value) & (Uint64) 0x00ff000000000000ULL) >> 40) | \ | |
378 (((Uint64) (value) & (Uint64) 0xff00000000000000ULL) >> 56))) | |
379 #endif | |
380 | |
381 /* Macros that swap only when needed ... | |
382 */ | |
383 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
384 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) | |
385 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
386 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value) | |
387 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value) | |
388 | |
389 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value)) | |
390 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value)) | |
391 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value)) | |
392 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value)) | |
393 | |
394 # ifdef DM_HAVE_64BIT | |
395 # define DM_LE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value) | |
396 # define DM_NATIVE_TO_LE64(value) DM_SWAP_64_LE_BE(value) | |
397 # define DM_BE64_TO_NATIVE(value) ((Uint64) (value)) | |
398 # define DM_NATIVE_TO_BE64(value) ((Uint64) (value)) | |
399 # endif | |
400 | |
401 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
402 | |
403 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value)) | |
404 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value)) | |
405 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value)) | |
406 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value)) | |
407 | |
408 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) | |
409 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
410 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value) | |
411 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value) | |
412 | |
413 # ifdef DM_HAVE_64BIT | |
414 # define DM_LE64_TO_NATIVE(value) ((Uint64) (value)) | |
415 # define DM_NATIVE_TO_LE64(value) ((Uint64) (value)) | |
416 # define DM_BE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value) | |
417 # define DM_NATIVE_TO_BE64(value) DM_SWAP_64_LE_BE(value) | |
418 # endif | |
419 #endif | |
420 | |
421 | |
422 #ifdef __cplusplus | |
423 } | |
424 #endif | |
425 #endif // DMLIB_H |