This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_surface.h
620 lines (561 loc) · 21.7 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2010 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/**
24
25
26
* \file SDL_surface.h
*
* Header file for ::SDL_surface definition and management functions.
27
28
29
30
31
32
33
34
*/
#ifndef _SDL_surface_h
#define _SDL_surface_h
#include "SDL_stdinc.h"
#include "SDL_pixels.h"
#include "SDL_rect.h"
35
36
#include "SDL_blendmode.h"
#include "SDL_scalemode.h"
37
38
39
40
41
42
43
44
45
46
#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
47
48
49
50
51
52
53
/**
* \name Surface flags
*
* These are the currently supported flags for the ::SDL_surface.
*
* \internal
* Used internally (read-only).
54
55
56
57
*/
/*@{*/
#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
58
/*@}*//*Surface flags*/
59
60
61
62
/**
* Evaluates to true if the surface needs to be locked before access.
*/
63
64
65
#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
/**
66
* \brief A collection of pixels used in software blitting.
67
*
68
* \note This structure should be treated as read-only, except for \c pixels,
69
70
71
72
73
74
75
76
77
78
* 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 */
79
/** Application data associated with the surface */
80
81
void *userdata; /**< Read-write */
82
/** information needed for surfaces requiring locks */
83
84
85
int locked; /**< Read-only */
void *lock_data; /**< Read-only */
86
/** clipping information */
87
88
SDL_Rect clip_rect; /**< Read-only */
89
/** info for fast blit mapping to other surfaces */
90
91
struct SDL_BlitMap *map; /**< Private */
92
/** format version, bumped at every change to invalidate blit maps */
93
int format_version; /**< Private */
94
95
/** Reference count -- used when freeing surface */
96
97
98
99
int refcount; /**< Read-mostly */
} SDL_Surface;
/**
100
* \brief The type of function used for surface blitting functions.
101
102
103
104
*/
typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
struct SDL_Surface * dst, SDL_Rect * dstrect);
105
/**
106
* Allocate and free an RGB surface.
107
108
109
110
111
112
113
114
*
* 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.
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
*/
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);
/**
131
132
133
134
135
* \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.
136
137
138
139
*/
extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
SDL_Palette * palette);
140
/**
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
* \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()
158
159
*/
extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
160
/** \sa SDL_LockSurface() */
161
162
extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
163
/**
164
* Load a surface from a seekable SDL data stream (memory or file).
165
*
166
* If \c freesrc is non-zero, the stream will be closed after being read.
167
168
169
170
*
* The new surface should be freed with SDL_FreeSurface().
*
* \return the new surface, or NULL if there was an error.
171
172
173
174
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
int freesrc);
175
176
177
178
179
/**
* Load a surface from a file.
*
* Convenience macro.
*/
180
181
#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
182
/**
183
* Save a surface to a seekable SDL data stream (memory or file).
184
*
185
* If \c freedst is non-zero, the stream will be closed after being written.
186
187
*
* \return 0 if successful or -1 if there was an error.
188
189
190
191
*/
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
(SDL_Surface * surface, SDL_RWops * dst, int freedst);
192
193
194
195
196
/**
* Save a surface to a file.
*
* Convenience macro.
*/
197
198
199
#define SDL_SaveBMP(surface, file) \
SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
200
/**
201
202
203
204
205
206
* \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.
207
208
209
210
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
int flag);
211
/**
212
213
214
215
216
217
218
* \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
219
220
*/
extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
221
int flag, Uint32 key);
222
223
/**
224
* \brief Gets the color key (transparent pixel) in a blittable surface.
225
226
227
228
229
230
231
*
* \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.
232
233
234
235
*/
extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
Uint32 * key);
236
/**
237
238
239
* \brief Set an additional color value used in blit operations.
*
* \param surface The surface to update.
240
241
242
* \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.
243
244
245
246
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_GetSurfaceColorMod()
247
248
249
250
251
252
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
Uint8 r, Uint8 g, Uint8 b);
/**
253
254
255
* \brief Get the additional color value used in blit operations.
*
* \param surface The surface to query.
256
257
258
* \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.
259
260
261
262
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_SetSurfaceColorMod()
263
264
265
266
267
268
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
Uint8 * r, Uint8 * g,
Uint8 * b);
/**
269
270
271
* \brief Set an additional alpha value used in blit operations.
*
* \param surface The surface to update.
272
* \param alpha The alpha value multiplied into blit operations.
273
274
275
276
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_GetSurfaceAlphaMod()
277
278
279
280
281
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
Uint8 alpha);
/**
282
283
284
* \brief Get the additional alpha value used in blit operations.
*
* \param surface The surface to query.
285
* \param alpha A pointer filled in with the current alpha value.
286
287
288
289
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_SetSurfaceAlphaMod()
290
291
292
293
294
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
Uint8 * alpha);
/**
295
296
297
298
299
300
301
302
* \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()
303
304
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
305
SDL_BlendMode blendMode);
306
307
/**
308
309
310
311
312
313
314
315
* \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()
316
317
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
318
SDL_BlendMode *blendMode);
319
320
/**
321
322
323
* \brief Set the scale mode used for blit operations.
*
* \param surface The surface to update.
324
* \param scaleMode ::SDL_ScaleMode to use for blit scaling.
325
326
327
328
329
330
331
332
333
*
* \return 0 on success, or -1 if the surface is not valid or the scale mode is
* not supported.
*
* \note If the scale mode is not supported, the closest supported mode is
* chosen. Currently only ::SDL_TEXTURESCALEMODE_FAST is supported on
* surfaces.
*
* \sa SDL_GetSurfaceScaleMode()
334
335
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface * surface,
336
SDL_ScaleMode scaleMode);
337
338
/**
339
340
341
342
343
344
345
346
* \brief Get the scale mode used for blit operations.
*
* \param surface The surface to query.
* \param scaleMode A pointer filled in with the current scale mode.
*
* \return 0 on success, or -1 if the surface is not valid.
*
* \sa SDL_SetSurfaceScaleMode()
347
348
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface * surface,
349
SDL_ScaleMode *scaleMode);
350
351
/**
352
353
354
355
356
357
358
359
360
361
362
* 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.
363
364
365
366
*/
extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
const SDL_Rect * rect);
367
/**
368
369
370
371
* 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.
372
373
374
375
*/
extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
SDL_Rect * rect);
376
/**
377
378
379
380
381
382
383
384
* 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.
385
386
387
388
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
(SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
389
390
391
392
393
394
395
396
397
/**
* \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);
398
/**
399
400
401
402
403
404
* Draws a point with \c color.
*
* 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.
405
406
407
*/
extern DECLSPEC int SDLCALL SDL_DrawPoint
(SDL_Surface * dst, int x, int y, Uint32 color);
408
409
extern DECLSPEC int SDLCALL SDL_DrawPoints
(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
410
411
/**
412
413
414
* Blends a point with an RGBA value.
*
* \return 0 on success, or -1 on error.
415
*/
416
extern DECLSPEC int SDLCALL SDL_BlendPoint
417
(SDL_Surface * dst, int x, int y,
418
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
419
420
extern DECLSPEC int SDLCALL SDL_BlendPoints
(SDL_Surface * dst, const SDL_Point * points, int count,
421
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
422
423
/**
424
425
426
427
428
429
* Draws a line with \c color.
*
* 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.
430
431
432
*/
extern DECLSPEC int SDLCALL SDL_DrawLine
(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
433
434
extern DECLSPEC int SDLCALL SDL_DrawLines
(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
435
436
/**
437
438
439
* Blends an RGBA value along a line.
*
* \return 0 on success, or -1 on error.
440
441
*/
extern DECLSPEC int SDLCALL SDL_BlendLine
442
(SDL_Surface * dst, int x1, int y1, int x2, int y2,
443
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
444
445
extern DECLSPEC int SDLCALL SDL_BlendLines
(SDL_Surface * dst, const SDL_Point * points, int count,
446
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/**
* Draws the given rectangle with \c color.
*
* If \c rect is NULL, the whole surface will be outlined with \c color.
*
* 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.
*/
extern DECLSPEC int SDLCALL SDL_DrawRect
(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
extern DECLSPEC int SDLCALL SDL_DrawRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
/**
464
* Blends an RGBA value into the outline of the given rectangle.
465
*
466
* If \c rect is NULL, the whole surface will have a blended outline.
467
468
469
470
471
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendRect
(SDL_Surface * dst, const SDL_Rect * rect,
472
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
473
474
extern DECLSPEC int SDLCALL SDL_BlendRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count,
475
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
476
477
/**
478
479
* Performs a fast fill of the given rectangle with \c color.
*
480
* If \c rect is NULL, the whole surface will be filled with \c color.
481
482
483
484
485
*
* 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.
486
487
*/
extern DECLSPEC int SDLCALL SDL_FillRect
488
489
490
(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
extern DECLSPEC int SDLCALL SDL_FillRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
491
492
/**
493
494
* Blends an RGBA value into the given rectangle.
*
495
* If \c rect is NULL, the whole surface will be blended with the color.
496
497
*
* \return This function returns 0 on success, or -1 on error.
498
*/
499
extern DECLSPEC int SDLCALL SDL_BlendFillRect
500
(SDL_Surface * dst, const SDL_Rect * rect,
501
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
502
extern DECLSPEC int SDLCALL SDL_BlendFillRects
503
(SDL_Surface * dst, const SDL_Rect ** rects, int count,
504
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
505
506
/**
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
* 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
*
* If either of the surfaces were in video memory, and the blit returns -2,
* the video memory was lost, so it should be reloaded with artwork and
* re-blitted:
* @code
* while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
* while ( SDL_LockSurface(image) < 0 )
* Sleep(10);
* -- Write image pixels to image->pixels --
* SDL_UnlockSurface(image);
* }
* @endcode
*
* This happens under DirectX 5.0 when the system switches away from your
* fullscreen application. The lock will also fail until you have access
* to the video memory again.
*
* You should call SDL_BlitSurface() unless you know exactly how SDL
* blitting works internally and how to use the other blit functions.
580
581
582
*/
#define SDL_BlitSurface SDL_UpperBlit
583
584
/**
* This is the public blit function, SDL_BlitSurface(), and it performs
585
586
* rectangle validation and clipping before passing it to SDL_LowerBlit()
*/
587
extern DECLSPEC int SDLCALL SDL_UpperBlit
588
(SDL_Surface * src, const SDL_Rect * srcrect,
589
SDL_Surface * dst, SDL_Rect * dstrect);
590
591
592
/**
* This is a semi-private blit function and it performs low-level surface
593
594
* blitting only.
*/
595
596
597
598
599
extern DECLSPEC int SDLCALL SDL_LowerBlit
(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
/**
600
601
602
603
* \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.
604
605
*/
extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
606
const SDL_Rect * srcrect,
607
SDL_Surface * dst,
608
const SDL_Rect * dstrect);
609
610
611
612
613
614
615
616
617
618
619
620
/* 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: */