Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
497 lines (445 loc) · 17.5 KB

SDL_surface.h

File metadata and controls

497 lines (445 loc) · 17.5 KB
 
Apr 8, 2011
Apr 8, 2011
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Oct 19, 2009
Oct 19, 2009
23
24
25
* \file SDL_surface.h
*
* Header file for ::SDL_surface definition and management functions.
26
27
28
29
30
31
32
33
*/
#ifndef _SDL_surface_h
#define _SDL_surface_h
#include "SDL_stdinc.h"
#include "SDL_pixels.h"
#include "SDL_rect.h"
Dec 12, 2010
Dec 12, 2010
34
#include "SDL_blendmode.h"
35
36
37
38
39
40
41
42
43
44
#include "SDL_rwops.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
Oct 19, 2009
Oct 19, 2009
45
46
47
48
49
50
51
/**
* \name Surface flags
*
* These are the currently supported flags for the ::SDL_surface.
*
* \internal
* Used internally (read-only).
Oct 4, 2009
Oct 4, 2009
52
53
54
55
*/
/*@{*/
#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
Feb 13, 2011
Feb 13, 2011
56
#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
Oct 19, 2009
Oct 19, 2009
57
/*@}*//*Surface flags*/
Oct 19, 2009
Oct 19, 2009
59
60
61
/**
* Evaluates to true if the surface needs to be locked before access.
*/
62
63
64
#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
/**
Oct 19, 2009
Oct 19, 2009
65
* \brief A collection of pixels used in software blitting.
Oct 19, 2009
Oct 19, 2009
67
* \note This structure should be treated as read-only, except for \c pixels,
68
69
70
71
72
73
74
75
76
77
* which, if not NULL, contains the raw pixel data for the surface.
*/
typedef struct SDL_Surface
{
Uint32 flags; /**< Read-only */
SDL_PixelFormat *format; /**< Read-only */
int w, h; /**< Read-only */
int pitch; /**< Read-only */
void *pixels; /**< Read-write */
Feb 26, 2010
Feb 26, 2010
78
/** Application data associated with the surface */
79
80
void *userdata; /**< Read-write */
Oct 19, 2009
Oct 19, 2009
81
/** information needed for surfaces requiring locks */
82
83
84
int locked; /**< Read-only */
void *lock_data; /**< Read-only */
Oct 19, 2009
Oct 19, 2009
85
/** clipping information */
86
87
SDL_Rect clip_rect; /**< Read-only */
Oct 19, 2009
Oct 19, 2009
88
/** info for fast blit mapping to other surfaces */
89
90
struct SDL_BlitMap *map; /**< Private */
Oct 19, 2009
Oct 19, 2009
91
/** Reference count -- used when freeing surface */
92
93
94
95
int refcount; /**< Read-mostly */
} SDL_Surface;
/**
Oct 19, 2009
Oct 19, 2009
96
* \brief The type of function used for surface blitting functions.
97
98
99
100
*/
typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
struct SDL_Surface * dst, SDL_Rect * dstrect);
Oct 4, 2009
Oct 4, 2009
101
/**
Mar 5, 2010
Mar 5, 2010
102
* Allocate and free an RGB surface.
Oct 19, 2009
Oct 19, 2009
103
104
105
106
107
108
109
110
*
* If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
* If the depth is greater than 8 bits, the pixel format is set using the
* flags '[RGB]mask'.
*
* If the function runs out of memory, it will return NULL.
*
* \param flags The \c flags are obsolete and should be set to 0.
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
(Uint32 flags, int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
int width,
int height,
int depth,
int pitch,
Uint32 Rmask,
Uint32 Gmask,
Uint32 Bmask,
Uint32 Amask);
extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
/**
Oct 19, 2009
Oct 19, 2009
127
128
129
130
131
* \brief Set the palette used by a surface.
*
* \return 0, or -1 if the surface format doesn't use a palette.
*
* \note A single palette can be shared with many surfaces.
132
133
134
135
*/
extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
SDL_Palette * palette);
Oct 4, 2009
Oct 4, 2009
136
/**
Oct 19, 2009
Oct 19, 2009
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
* \brief Sets up a surface for directly accessing the pixels.
*
* Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
* to and read from \c surface->pixels, using the pixel format stored in
* \c surface->format. Once you are done accessing the surface, you should
* use SDL_UnlockSurface() to release it.
*
* Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
* to 0, then you can read and write to the surface at any time, and the
* pixel format of the surface will not change.
*
* No operating system or library calls should be made between lock/unlock
* pairs, as critical system locks may be held during this time.
*
* SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
*
* \sa SDL_UnlockSurface()
154
155
*/
extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
Oct 4, 2009
Oct 4, 2009
156
/** \sa SDL_LockSurface() */
157
158
extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
Oct 4, 2009
Oct 4, 2009
159
/**
Jan 12, 2011
Jan 12, 2011
160
* Load a surface from a seekable SDL data stream (memory or file).
Oct 19, 2009
Oct 19, 2009
161
*
Jan 12, 2011
Jan 12, 2011
162
* If \c freesrc is non-zero, the stream will be closed after being read.
Oct 19, 2009
Oct 19, 2009
163
164
165
166
*
* The new surface should be freed with SDL_FreeSurface().
*
* \return the new surface, or NULL if there was an error.
167
168
169
170
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
int freesrc);
Oct 19, 2009
Oct 19, 2009
171
172
173
174
175
/**
* Load a surface from a file.
*
* Convenience macro.
*/
176
177
#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
Oct 4, 2009
Oct 4, 2009
178
/**
Jan 12, 2011
Jan 12, 2011
179
* Save a surface to a seekable SDL data stream (memory or file).
Oct 19, 2009
Oct 19, 2009
180
*
Jan 12, 2011
Jan 12, 2011
181
* If \c freedst is non-zero, the stream will be closed after being written.
Oct 19, 2009
Oct 19, 2009
182
183
*
* \return 0 if successful or -1 if there was an error.
184
185
186
187
*/
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
(SDL_Surface * surface, SDL_RWops * dst, int freedst);
Oct 19, 2009
Oct 19, 2009
188
189
190
191
192
/**
* Save a surface to a file.
*
* Convenience macro.
*/
193
194
195
#define SDL_SaveBMP(surface, file) \
SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
Oct 4, 2009
Oct 4, 2009
196
/**
Oct 19, 2009
Oct 19, 2009
197
198
199
200
201
202
* \brief Sets the RLE acceleration hint for a surface.
*
* \return 0 on success, or -1 if the surface is not valid
*
* \note If RLE is enabled, colorkey and alpha blending blits are much faster,
* but the surface must be locked before directly accessing the pixels.
203
204
205
206
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
int flag);
Oct 4, 2009
Oct 4, 2009
207
/**
Oct 19, 2009
Oct 19, 2009
208
209
210
211
212
213
214
* \brief Sets the color key (transparent pixel) in a blittable surface.
*
* \param surface The surface to update
* \param flag Non-zero to enable colorkey and 0 to disable colorkey
* \param key The transparent pixel in the native surface format
*
* \return 0 on success, or -1 if the surface is not valid
215
216
*/
extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
Dec 14, 2009
Dec 14, 2009
217
int flag, Uint32 key);
Oct 4, 2009
Oct 4, 2009
219
/**
Dec 12, 2009
Dec 12, 2009
220
* \brief Gets the color key (transparent pixel) in a blittable surface.
Oct 19, 2009
Oct 19, 2009
221
222
223
224
225
226
227
*
* \param surface The surface to update
* \param key A pointer filled in with the transparent pixel in the native
* surface format
*
* \return 0 on success, or -1 if the surface is not valid or colorkey is not
* enabled.
Apr 3, 2009
Apr 3, 2009
228
229
230
231
*/
extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
Uint32 * key);
Oct 19, 2009
Oct 19, 2009
233
234
235
* \brief Set an additional color value used in blit operations.
*
* \param surface The surface to update.
Jan 12, 2011
Jan 12, 2011
236
237
238
* \param r The red color value multiplied into blit operations.
* \param g The green color value multiplied into blit operations.
* \param b The blue color value multiplied into blit operations.
Oct 19, 2009
Oct 19, 2009
239
240
241
242
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_GetSurfaceColorMod()
243
244
245
246
247
248
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
Uint8 r, Uint8 g, Uint8 b);
/**
Oct 19, 2009
Oct 19, 2009
249
250
251
* \brief Get the additional color value used in blit operations.
*
* \param surface The surface to query.
Jan 12, 2011
Jan 12, 2011
252
253
254
* \param r A pointer filled in with the current red color value.
* \param g A pointer filled in with the current green color value.
* \param b A pointer filled in with the current blue color value.
Oct 19, 2009
Oct 19, 2009
255
256
257
258
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_SetSurfaceColorMod()
259
260
261
262
263
264
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
Uint8 * r, Uint8 * g,
Uint8 * b);
/**
Oct 19, 2009
Oct 19, 2009
265
266
267
* \brief Set an additional alpha value used in blit operations.
*
* \param surface The surface to update.
Jan 12, 2011
Jan 12, 2011
268
* \param alpha The alpha value multiplied into blit operations.
Oct 19, 2009
Oct 19, 2009
269
270
271
272
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_GetSurfaceAlphaMod()
273
274
275
276
277
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
Uint8 alpha);
/**
Oct 19, 2009
Oct 19, 2009
278
279
280
* \brief Get the additional alpha value used in blit operations.
*
* \param surface The surface to query.
Jan 12, 2011
Jan 12, 2011
281
* \param alpha A pointer filled in with the current alpha value.
Oct 19, 2009
Oct 19, 2009
282
283
284
285
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_SetSurfaceAlphaMod()
286
287
288
289
290
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
Uint8 * alpha);
/**
Oct 19, 2009
Oct 19, 2009
291
292
293
294
295
296
297
298
* \brief Set the blend mode used for blit operations.
*
* \param surface The surface to update.
* \param blendMode ::SDL_BlendMode to use for blit blending.
*
* \return 0 on success, or -1 if the parameters are not valid.
*
* \sa SDL_GetSurfaceBlendMode()
299
300
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
Dec 12, 2010
Dec 12, 2010
301
SDL_BlendMode blendMode);
Oct 19, 2009
Oct 19, 2009
304
305
306
307
308
309
310
311
* \brief Get the blend mode used for blit operations.
*
* \param surface The surface to query.
* \param blendMode A pointer filled in with the current blend mode.
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_SetSurfaceBlendMode()
312
313
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
Dec 12, 2010
Dec 12, 2010
314
SDL_BlendMode *blendMode);
Oct 4, 2009
Oct 4, 2009
316
/**
Oct 19, 2009
Oct 19, 2009
317
318
319
320
321
322
323
324
325
326
327
* Sets the clipping rectangle for the destination surface in a blit.
*
* If the clip rectangle is NULL, clipping will be disabled.
*
* If the clip rectangle doesn't intersect the surface, the function will
* return SDL_FALSE and blits will be completely clipped. Otherwise the
* function returns SDL_TRUE and blits to the surface will be clipped to
* the intersection of the surface area and the clipping rectangle.
*
* Note that blits are automatically clipped to the edges of the source
* and destination surfaces.
328
329
330
331
*/
extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
const SDL_Rect * rect);
Oct 4, 2009
Oct 4, 2009
332
/**
Oct 19, 2009
Oct 19, 2009
333
334
335
336
* Gets the clipping rectangle for the destination surface in a blit.
*
* \c rect must be a pointer to a valid rectangle which will be filled
* with the correct values.
337
338
339
340
*/
extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
SDL_Rect * rect);
Oct 4, 2009
Oct 4, 2009
341
/**
Oct 19, 2009
Oct 19, 2009
342
343
344
345
346
347
348
349
* Creates a new surface of the specified format, and then copies and maps
* the given surface to it so the blit of the converted surface will be as
* fast as possible. If this function fails, it returns NULL.
*
* The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
* semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and
* SDL will try to RLE accelerate colorkey and alpha blits in the resulting
* surface.
350
351
352
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
(SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
Feb 22, 2011
Feb 22, 2011
353
354
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
(SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
Nov 15, 2009
Nov 15, 2009
356
357
358
359
360
361
362
363
364
/**
* \brief Copy a block of pixels of one format to another format
*/
extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
Uint32 src_format,
const void * src, int src_pitch,
Uint32 dst_format,
void * dst, int dst_pitch);
Oct 4, 2009
Oct 4, 2009
365
/**
Oct 19, 2009
Oct 19, 2009
366
367
* Performs a fast fill of the given rectangle with \c color.
*
Dec 9, 2009
Dec 9, 2009
368
* If \c rect is NULL, the whole surface will be filled with \c color.
Oct 19, 2009
Oct 19, 2009
369
370
371
372
373
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
374
375
*/
extern DECLSPEC int SDLCALL SDL_FillRect
Dec 9, 2009
Dec 9, 2009
376
377
(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
extern DECLSPEC int SDLCALL SDL_FillRects
Feb 15, 2011
Feb 15, 2011
378
(SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
Oct 4, 2009
Oct 4, 2009
380
/**
Oct 19, 2009
Oct 19, 2009
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
* Performs a fast blit from the source surface to the destination surface.
*
* This assumes that the source and destination rectangles are
* the same size. If either \c srcrect or \c dstrect are NULL, the entire
* surface (\c src or \c dst) is copied. The final blit rectangles are saved
* in \c srcrect and \c dstrect after all clipping is performed.
*
* \return If the blit is successful, it returns 0, otherwise it returns -1.
*
* The blit function should not be called on a locked surface.
*
* The blit semantics for surfaces with and without alpha and colorkey
* are defined as follows:
* \verbatim
RGBA->RGB:
SDL_SRCALPHA set:
alpha-blend (using alpha-channel).
SDL_SRCCOLORKEY ignored.
SDL_SRCALPHA not set:
copy RGB.
if SDL_SRCCOLORKEY set, only copy the pixels matching the
RGB values of the source colour key, ignoring alpha in the
comparison.
RGB->RGBA:
SDL_SRCALPHA set:
alpha-blend (using the source per-surface alpha value);
set destination alpha to opaque.
SDL_SRCALPHA not set:
copy RGB, set destination alpha to source per-surface alpha value.
both:
if SDL_SRCCOLORKEY set, only copy the pixels matching the
source colour key.
RGBA->RGBA:
SDL_SRCALPHA set:
alpha-blend (using the source alpha channel) the RGB values;
leave destination alpha untouched. [Note: is this correct?]
SDL_SRCCOLORKEY ignored.
SDL_SRCALPHA not set:
copy all of RGBA to the destination.
if SDL_SRCCOLORKEY set, only copy the pixels matching the
RGB values of the source colour key, ignoring alpha in the
comparison.
RGB->RGB:
SDL_SRCALPHA set:
alpha-blend (using the source per-surface alpha value).
SDL_SRCALPHA not set:
copy RGB.
both:
if SDL_SRCCOLORKEY set, only copy the pixels matching the
source colour key.
\endverbatim
*
* You should call SDL_BlitSurface() unless you know exactly how SDL
* blitting works internally and how to use the other blit functions.
438
439
440
*/
#define SDL_BlitSurface SDL_UpperBlit
Oct 19, 2009
Oct 19, 2009
441
442
/**
* This is the public blit function, SDL_BlitSurface(), and it performs
Oct 4, 2009
Oct 4, 2009
443
444
* rectangle validation and clipping before passing it to SDL_LowerBlit()
*/
445
extern DECLSPEC int SDLCALL SDL_UpperBlit
Jan 4, 2011
Jan 4, 2011
446
(SDL_Surface * src, const SDL_Rect * srcrect,
447
SDL_Surface * dst, SDL_Rect * dstrect);
Oct 4, 2009
Oct 4, 2009
448
Oct 19, 2009
Oct 19, 2009
449
450
/**
* This is a semi-private blit function and it performs low-level surface
Oct 4, 2009
Oct 4, 2009
451
452
* blitting only.
*/
453
454
455
456
457
extern DECLSPEC int SDLCALL SDL_LowerBlit
(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
/**
Oct 19, 2009
Oct 19, 2009
458
459
460
461
* \brief Perform a fast, low quality, stretch blit between two surfaces of the
* same pixel format.
*
* \note This function uses a static buffer, and is not thread-safe.
462
463
*/
extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
Dec 3, 2008
Dec 3, 2008
464
const SDL_Rect * srcrect,
Dec 3, 2008
Dec 3, 2008
466
const SDL_Rect * dstrect);
Mar 14, 2011
Mar 14, 2011
468
469
#define SDL_BlitScaled SDL_UpperBlitScaled
Feb 14, 2011
Feb 14, 2011
470
/**
Mar 14, 2011
Mar 14, 2011
471
472
* This is the public scaled blit function, SDL_BlitScaled(), and it performs
* rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
Feb 14, 2011
Feb 14, 2011
473
*/
Mar 14, 2011
Mar 14, 2011
474
extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
Feb 14, 2011
Feb 14, 2011
475
(SDL_Surface * src, const SDL_Rect * srcrect,
Mar 14, 2011
Mar 14, 2011
476
477
478
479
480
481
482
483
484
SDL_Surface * dst, SDL_Rect * dstrect);
/**
* This is a semi-private blit function and it performs low-level surface
* scaled blitting only.
*/
extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
Feb 14, 2011
Feb 14, 2011
485
486
487
488
489
490
491
492
493
494
495
496
497
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_surface_h */
/* vi: set ts=4 sw=4 expandtab: */