2
Simple DirectMedia Layer
3
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
25
* Header file for ::SDL_surface definition and management functions.
28
#ifndef _SDL_surface_h
29
#define _SDL_surface_h
31
#include "SDL_stdinc.h"
32
#include "SDL_pixels.h"
34
#include "SDL_blendmode.h"
35
#include "SDL_rwops.h"
37
#include "begin_code.h"
38
/* Set up for C function definitions, even when using C++ */
48
* These are the currently supported flags for the ::SDL_surface.
51
* Used internally (read-only).
54
#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
55
#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
56
#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
57
/*@}*//*Surface flags*/
60
* Evaluates to true if the surface needs to be locked before access.
62
#define SDL_MUSTLOCK(S) 1
63
/* XXX Emscripten: we always need to lock.
64
(((S)->flags & SDL_RLEACCEL) != 0) */
67
* \brief A collection of pixels used in software blitting.
69
* \note This structure should be treated as read-only, except for \c pixels,
70
* which, if not NULL, contains the raw pixel data for the surface.
72
typedef struct SDL_Surface
74
Uint32 flags; /**< Read-only */
75
SDL_PixelFormat *format; /**< Read-only */
76
int w, h; /**< Read-only */
77
int pitch; /**< Read-only */
78
void *pixels; /**< Read-write */
80
/** Application data associated with the surface */
81
void *userdata; /**< Read-write */
83
/** information needed for surfaces requiring locks */
84
int locked; /**< Read-only */
85
void *lock_data; /**< Read-only */
87
/** clipping information */
88
SDL_Rect clip_rect; /**< Read-only */
90
/** info for fast blit mapping to other surfaces */
91
struct SDL_BlitMap *map; /**< Private */
93
/** Reference count -- used when freeing surface */
94
int refcount; /**< Read-mostly */
98
* \brief The type of function used for surface blitting functions.
100
typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
101
struct SDL_Surface * dst, SDL_Rect * dstrect);
104
* Allocate and free an RGB surface.
106
* If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
107
* If the depth is greater than 8 bits, the pixel format is set using the
110
* If the function runs out of memory, it will return NULL.
112
* \param flags The \c flags are obsolete and should be set to 0.
114
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
115
(Uint32 flags, int width, int height, int depth,
116
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
117
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
126
extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
129
* \brief Set the palette used by a surface.
131
* \return 0, or -1 if the surface format doesn't use a palette.
133
* \note A single palette can be shared with many surfaces.
135
extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
136
SDL_Palette * palette);
139
* \brief Sets up a surface for directly accessing the pixels.
141
* Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
142
* to and read from \c surface->pixels, using the pixel format stored in
143
* \c surface->format. Once you are done accessing the surface, you should
144
* use SDL_UnlockSurface() to release it.
146
* Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
147
* to 0, then you can read and write to the surface at any time, and the
148
* pixel format of the surface will not change.
150
* No operating system or library calls should be made between lock/unlock
151
* pairs, as critical system locks may be held during this time.
153
* SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
155
* \sa SDL_UnlockSurface()
157
extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
158
/** \sa SDL_LockSurface() */
159
extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
162
* Load a surface from a seekable SDL data stream (memory or file).
164
* If \c freesrc is non-zero, the stream will be closed after being read.
166
* The new surface should be freed with SDL_FreeSurface().
168
* \return the new surface, or NULL if there was an error.
170
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
174
* Load a surface from a file.
178
#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
181
* Save a surface to a seekable SDL data stream (memory or file).
183
* If \c freedst is non-zero, the stream will be closed after being written.
185
* \return 0 if successful or -1 if there was an error.
187
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
188
(SDL_Surface * surface, SDL_RWops * dst, int freedst);
191
* Save a surface to a file.
195
#define SDL_SaveBMP(surface, file) \
196
SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
199
* \brief Sets the RLE acceleration hint for a surface.
201
* \return 0 on success, or -1 if the surface is not valid
203
* \note If RLE is enabled, colorkey and alpha blending blits are much faster,
204
* but the surface must be locked before directly accessing the pixels.
206
extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
210
* \brief Sets the color key (transparent pixel) in a blittable surface.
212
* \param surface The surface to update
213
* \param flag Non-zero to enable colorkey and 0 to disable colorkey
214
* \param key The transparent pixel in the native surface format
216
* \return 0 on success, or -1 if the surface is not valid
218
extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
219
int flag, Uint32 key);
222
* \brief Gets the color key (transparent pixel) in a blittable surface.
224
* \param surface The surface to update
225
* \param key A pointer filled in with the transparent pixel in the native
228
* \return 0 on success, or -1 if the surface is not valid or colorkey is not
231
extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
235
* \brief Set an additional color value used in blit operations.
237
* \param surface The surface to update.
238
* \param r The red color value multiplied into blit operations.
239
* \param g The green color value multiplied into blit operations.
240
* \param b The blue color value multiplied into blit operations.
242
* \return 0 on success, or -1 if the surface is not valid.
244
* \sa SDL_GetSurfaceColorMod()
246
extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
247
Uint8 r, Uint8 g, Uint8 b);
251
* \brief Get the additional color value used in blit operations.
253
* \param surface The surface to query.
254
* \param r A pointer filled in with the current red color value.
255
* \param g A pointer filled in with the current green color value.
256
* \param b A pointer filled in with the current blue color value.
258
* \return 0 on success, or -1 if the surface is not valid.
260
* \sa SDL_SetSurfaceColorMod()
262
extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
263
Uint8 * r, Uint8 * g,
267
* \brief Set an additional alpha value used in blit operations.
269
* \param surface The surface to update.
270
* \param alpha The alpha value multiplied into blit operations.
272
* \return 0 on success, or -1 if the surface is not valid.
274
* \sa SDL_GetSurfaceAlphaMod()
276
extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
280
* \brief Get the additional alpha value used in blit operations.
282
* \param surface The surface to query.
283
* \param alpha A pointer filled in with the current alpha value.
285
* \return 0 on success, or -1 if the surface is not valid.
287
* \sa SDL_SetSurfaceAlphaMod()
289
extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
293
* \brief Set the blend mode used for blit operations.
295
* \param surface The surface to update.
296
* \param blendMode ::SDL_BlendMode to use for blit blending.
298
* \return 0 on success, or -1 if the parameters are not valid.
300
* \sa SDL_GetSurfaceBlendMode()
302
extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
303
SDL_BlendMode blendMode);
306
* \brief Get the blend mode used for blit operations.
308
* \param surface The surface to query.
309
* \param blendMode A pointer filled in with the current blend mode.
311
* \return 0 on success, or -1 if the surface is not valid.
313
* \sa SDL_SetSurfaceBlendMode()
315
extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
316
SDL_BlendMode *blendMode);
319
* Sets the clipping rectangle for the destination surface in a blit.
321
* If the clip rectangle is NULL, clipping will be disabled.
323
* If the clip rectangle doesn't intersect the surface, the function will
324
* return SDL_FALSE and blits will be completely clipped. Otherwise the
325
* function returns SDL_TRUE and blits to the surface will be clipped to
326
* the intersection of the surface area and the clipping rectangle.
328
* Note that blits are automatically clipped to the edges of the source
329
* and destination surfaces.
331
extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
332
const SDL_Rect * rect);
335
* Gets the clipping rectangle for the destination surface in a blit.
337
* \c rect must be a pointer to a valid rectangle which will be filled
338
* with the correct values.
340
extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
344
* Creates a new surface of the specified format, and then copies and maps
345
* the given surface to it so the blit of the converted surface will be as
346
* fast as possible. If this function fails, it returns NULL.
348
* The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
349
* semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and
350
* SDL will try to RLE accelerate colorkey and alpha blits in the resulting
353
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
354
(SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
355
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
356
(SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
359
* \brief Copy a block of pixels of one format to another format
361
extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
363
const void * src, int src_pitch,
365
void * dst, int dst_pitch);
368
* Performs a fast fill of the given rectangle with \c color.
370
* If \c rect is NULL, the whole surface will be filled with \c color.
372
* The color should be a pixel of the format used by the surface, and
373
* can be generated by the SDL_MapRGB() function.
375
* \return 0 on success, or -1 on error.
377
extern DECLSPEC int SDLCALL SDL_FillRect
378
(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
379
extern DECLSPEC int SDLCALL SDL_FillRects
380
(SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
383
* Performs a fast blit from the source surface to the destination surface.
385
* This assumes that the source and destination rectangles are
386
* the same size. If either \c srcrect or \c dstrect are NULL, the entire
387
* surface (\c src or \c dst) is copied. The final blit rectangles are saved
388
* in \c srcrect and \c dstrect after all clipping is performed.
390
* \return If the blit is successful, it returns 0, otherwise it returns -1.
392
* The blit function should not be called on a locked surface.
394
* The blit semantics for surfaces with and without alpha and colorkey
395
* are defined as follows:
399
alpha-blend (using alpha-channel).
400
SDL_SRCCOLORKEY ignored.
401
SDL_SRCALPHA not set:
403
if SDL_SRCCOLORKEY set, only copy the pixels matching the
404
RGB values of the source colour key, ignoring alpha in the
409
alpha-blend (using the source per-surface alpha value);
410
set destination alpha to opaque.
411
SDL_SRCALPHA not set:
412
copy RGB, set destination alpha to source per-surface alpha value.
414
if SDL_SRCCOLORKEY set, only copy the pixels matching the
419
alpha-blend (using the source alpha channel) the RGB values;
420
leave destination alpha untouched. [Note: is this correct?]
421
SDL_SRCCOLORKEY ignored.
422
SDL_SRCALPHA not set:
423
copy all of RGBA to the destination.
424
if SDL_SRCCOLORKEY set, only copy the pixels matching the
425
RGB values of the source colour key, ignoring alpha in the
430
alpha-blend (using the source per-surface alpha value).
431
SDL_SRCALPHA not set:
434
if SDL_SRCCOLORKEY set, only copy the pixels matching the
438
* You should call SDL_BlitSurface() unless you know exactly how SDL
439
* blitting works internally and how to use the other blit functions.
441
#define SDL_BlitSurface SDL_UpperBlit
444
* This is the public blit function, SDL_BlitSurface(), and it performs
445
* rectangle validation and clipping before passing it to SDL_LowerBlit()
447
extern DECLSPEC int SDLCALL SDL_UpperBlit
448
(SDL_Surface * src, const SDL_Rect * srcrect,
449
SDL_Surface * dst, SDL_Rect * dstrect);
452
* This is a semi-private blit function and it performs low-level surface
455
extern DECLSPEC int SDLCALL SDL_LowerBlit
456
(SDL_Surface * src, SDL_Rect * srcrect,
457
SDL_Surface * dst, SDL_Rect * dstrect);
460
* \brief Perform a fast, low quality, stretch blit between two surfaces of the
463
* \note This function uses a static buffer, and is not thread-safe.
465
extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
466
const SDL_Rect * srcrect,
468
const SDL_Rect * dstrect);
470
#define SDL_BlitScaled SDL_UpperBlitScaled
473
* This is the public scaled blit function, SDL_BlitScaled(), and it performs
474
* rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
476
extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
477
(SDL_Surface * src, const SDL_Rect * srcrect,
478
SDL_Surface * dst, SDL_Rect * dstrect);
481
* This is a semi-private blit function and it performs low-level surface
482
* scaled blitting only.
484
extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
485
(SDL_Surface * src, SDL_Rect * srcrect,
486
SDL_Surface * dst, SDL_Rect * dstrect);
489
/* Ends C function definitions when using C++ */
495
#include "close_code.h"
497
#endif /* _SDL_surface_h */
499
/* vi: set ts=4 sw=4 expandtab: */