SDL 2.0
SDL_surface.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
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.
8
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:
12
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.
20*/
21
22/**
23 * # CategorySurface
24 *
25 * Header file for SDL_Surface definition and management functions.
26 */
27
28#ifndef SDL_surface_h_
29#define SDL_surface_h_
30
31#include "SDL_stdinc.h"
32#include "SDL_pixels.h"
33#include "SDL_rect.h"
34#include "SDL_blendmode.h"
35#include "SDL_rwops.h"
36
37#include "begin_code.h"
38/* Set up for C function definitions, even when using C++ */
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * \name Surface flags
45 *
46 * These are the currently supported flags for the SDL_Surface.
47 *
48 * \internal
49 * Used internally (read-only).
50 */
51/* @{ */
52#define SDL_SWSURFACE 0 /**< Just here for compatibility */
53#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
54#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
55#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
56#define SDL_SIMD_ALIGNED 0x00000008 /**< Surface uses aligned memory */
57/* @} *//* Surface flags */
58
59/**
60 * Evaluates to true if the surface needs to be locked before access.
61 */
62#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
63
64typedef struct SDL_BlitMap SDL_BlitMap; /* this is an opaque type. */
65
66/**
67 * A collection of pixels used in software blitting.
68 *
69 * This structure should be treated as read-only, except for `pixels`, which,
70 * if not NULL, contains the raw pixel data for the surface.
71 */
72typedef struct SDL_Surface
73{
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 */
79
80 /** Application data associated with the surface */
81 void *userdata; /**< Read-write */
82
83 /** information needed for surfaces requiring locks */
84 int locked; /**< Read-only */
85
86 /** list of BlitMap that hold a reference to this surface */
87 void *list_blitmap; /**< Private */
88
89 /** clipping information */
90 SDL_Rect clip_rect; /**< Read-only */
91
92 /** info for fast blit mapping to other surfaces */
93 SDL_BlitMap *map; /**< Private */
94
95 /** Reference count -- used when freeing surface */
96 int refcount; /**< Read-mostly */
98
99/**
100 * The type of function used for surface blitting functions.
101 */
102typedef int (SDLCALL *SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
103 struct SDL_Surface * dst, SDL_Rect * dstrect);
104
105/**
106 * The formula used for converting between YUV and RGB
107 */
109{
110 SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
111 SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
113 SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
115
116/**
117 * Allocate a new RGB surface.
118 *
119 * If `depth` is 4 or 8 bits, an empty palette is allocated for the surface.
120 * If `depth` is greater than 8 bits, the pixel format is set using the
121 * [RGBA]mask parameters.
122 *
123 * The [RGBA]mask parameters are the bitmasks used to extract that color from
124 * a pixel. For instance, `Rmask` being 0xFF000000 means the red data is
125 * stored in the most significant byte. Using zeros for the RGB masks sets a
126 * default value, based on the depth. For example:
127 *
128 * ```c++
129 * SDL_CreateRGBSurface(0,w,h,32,0,0,0,0);
130 * ```
131 *
132 * However, using zero for the Amask results in an Amask of 0.
133 *
134 * By default surfaces with an alpha mask are set up for blending as with:
135 *
136 * ```c++
137 * SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)
138 * ```
139 *
140 * You can change this by calling SDL_SetSurfaceBlendMode() and selecting a
141 * different `blendMode`.
142 *
143 * \param flags the flags are unused and should be set to 0.
144 * \param width the width of the surface.
145 * \param height the height of the surface.
146 * \param depth the depth of the surface in bits.
147 * \param Rmask the red mask for the pixels.
148 * \param Gmask the green mask for the pixels.
149 * \param Bmask the blue mask for the pixels.
150 * \param Amask the alpha mask for the pixels.
151 * \returns the new SDL_Surface structure that is created or NULL if it fails;
152 * call SDL_GetError() for more information.
153 *
154 * \since This function is available since SDL 2.0.0.
155 *
156 * \sa SDL_CreateRGBSurfaceFrom
157 * \sa SDL_CreateRGBSurfaceWithFormat
158 * \sa SDL_FreeSurface
159 */
160extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
161 (Uint32 flags, int width, int height, int depth,
162 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
163
164
165/* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
166
167/**
168 * Allocate a new RGB surface with a specific pixel format.
169 *
170 * This function operates mostly like SDL_CreateRGBSurface(), except instead
171 * of providing pixel color masks, you provide it with a predefined format
172 * from SDL_PixelFormatEnum.
173 *
174 * \param flags the flags are unused and should be set to 0.
175 * \param width the width of the surface.
176 * \param height the height of the surface.
177 * \param depth the depth of the surface in bits.
178 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
179 * \returns the new SDL_Surface structure that is created or NULL if it fails;
180 * call SDL_GetError() for more information.
181 *
182 * \since This function is available since SDL 2.0.5.
183 *
184 * \sa SDL_CreateRGBSurface
185 * \sa SDL_CreateRGBSurfaceFrom
186 * \sa SDL_FreeSurface
187 */
189 (Uint32 flags, int width, int height, int depth, Uint32 format);
190
191/**
192 * Allocate a new RGB surface with existing pixel data.
193 *
194 * This function operates mostly like SDL_CreateRGBSurface(), except it does
195 * not allocate memory for the pixel data, instead the caller provides an
196 * existing buffer of data for the surface to use.
197 *
198 * No copy is made of the pixel data. Pixel data is not managed automatically;
199 * you must free the surface before you free the pixel data.
200 *
201 * \param pixels a pointer to existing pixel data.
202 * \param width the width of the surface.
203 * \param height the height of the surface.
204 * \param depth the depth of the surface in bits.
205 * \param pitch the pitch of the surface in bytes.
206 * \param Rmask the red mask for the pixels.
207 * \param Gmask the green mask for the pixels.
208 * \param Bmask the blue mask for the pixels.
209 * \param Amask the alpha mask for the pixels.
210 * \returns the new SDL_Surface structure that is created or NULL if it fails;
211 * call SDL_GetError() for more information.
212 *
213 * \since This function is available since SDL 2.0.0.
214 *
215 * \sa SDL_CreateRGBSurface
216 * \sa SDL_CreateRGBSurfaceWithFormat
217 * \sa SDL_CreateRGBSurfaceWithFormatFrom
218 * \sa SDL_FreeSurface
219 */
220extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
221 int width,
222 int height,
223 int depth,
224 int pitch,
225 Uint32 Rmask,
226 Uint32 Gmask,
227 Uint32 Bmask,
228 Uint32 Amask);
229
230/* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
231
232/**
233 * Allocate a new RGB surface with with a specific pixel format and existing
234 * pixel data.
235 *
236 * This function operates mostly like SDL_CreateRGBSurfaceFrom(), except
237 * instead of providing pixel color masks, you provide it with a predefined
238 * format from SDL_PixelFormatEnum.
239 *
240 * No copy is made of the pixel data. Pixel data is not managed automatically;
241 * you must free the surface before you free the pixel data.
242 *
243 * \param pixels a pointer to existing pixel data.
244 * \param width the width of the surface.
245 * \param height the height of the surface.
246 * \param depth the depth of the surface in bits.
247 * \param pitch the pitch of the surface in bytes.
248 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
249 * \returns the new SDL_Surface structure that is created or NULL if it fails;
250 * call SDL_GetError() for more information.
251 *
252 * \since This function is available since SDL 2.0.5.
253 *
254 * \sa SDL_CreateRGBSurfaceFrom
255 * \sa SDL_CreateRGBSurfaceWithFormat
256 * \sa SDL_FreeSurface
257 */
259 (void *pixels, int width, int height, int depth, int pitch, Uint32 format);
260
261/**
262 * Free an RGB surface.
263 *
264 * It is safe to pass NULL to this function.
265 *
266 * \param surface the SDL_Surface to free.
267 *
268 * \since This function is available since SDL 2.0.0.
269 *
270 * \sa SDL_CreateRGBSurface
271 * \sa SDL_CreateRGBSurfaceFrom
272 * \sa SDL_LoadBMP
273 * \sa SDL_LoadBMP_RW
274 */
275extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
276
277/**
278 * Set the palette used by a surface.
279 *
280 * A single palette can be shared with many surfaces.
281 *
282 * \param surface the SDL_Surface structure to update.
283 * \param palette the SDL_Palette structure to use.
284 * \returns 0 on success or a negative error code on failure; call
285 * SDL_GetError() for more information.
286 *
287 * \since This function is available since SDL 2.0.0.
288 */
289extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
290 SDL_Palette * palette);
291
292/**
293 * Set up a surface for directly accessing the pixels.
294 *
295 * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
296 * and read from `surface->pixels`, using the pixel format stored in
297 * `surface->format`. Once you are done accessing the surface, you should use
298 * SDL_UnlockSurface() to release it.
299 *
300 * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
301 * 0, then you can read and write to the surface at any time, and the pixel
302 * format of the surface will not change.
303 *
304 * \param surface the SDL_Surface structure to be locked.
305 * \returns 0 on success or a negative error code on failure; call
306 * SDL_GetError() for more information.
307 *
308 * \since This function is available since SDL 2.0.0.
309 *
310 * \sa SDL_MUSTLOCK
311 * \sa SDL_UnlockSurface
312 */
313extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
314
315/**
316 * Release a surface after directly accessing the pixels.
317 *
318 * \param surface the SDL_Surface structure to be unlocked.
319 *
320 * \since This function is available since SDL 2.0.0.
321 *
322 * \sa SDL_LockSurface
323 */
324extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
325
326/**
327 * Load a BMP image from a seekable SDL data stream.
328 *
329 * The new surface should be freed with SDL_FreeSurface(). Not doing so will
330 * result in a memory leak.
331 *
332 * src is an open SDL_RWops buffer, typically loaded with SDL_RWFromFile.
333 * Alternatively, you might also use the macro SDL_LoadBMP to load a bitmap
334 * from a file, convert it to an SDL_Surface and then close the file.
335 *
336 * \param src the data stream for the surface.
337 * \param freesrc non-zero to close the stream after being read.
338 * \returns a pointer to a new SDL_Surface structure or NULL if there was an
339 * error; call SDL_GetError() for more information.
340 *
341 * \since This function is available since SDL 2.0.0.
342 *
343 * \sa SDL_FreeSurface
344 * \sa SDL_RWFromFile
345 * \sa SDL_LoadBMP
346 * \sa SDL_SaveBMP_RW
347 */
348extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
349 int freesrc);
350
351/**
352 * Load a surface from a file.
353 *
354 * Convenience macro.
355 */
356#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
357
358/**
359 * Save a surface to a seekable SDL data stream in BMP format.
360 *
361 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
362 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
363 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
364 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
365 * not supported.
366 *
367 * \param surface the SDL_Surface structure containing the image to be saved.
368 * \param dst a data stream to save to.
369 * \param freedst non-zero to close the stream after being written.
370 * \returns 0 on success or a negative error code on failure; call
371 * SDL_GetError() for more information.
372 *
373 * \since This function is available since SDL 2.0.0.
374 *
375 * \sa SDL_LoadBMP_RW
376 * \sa SDL_SaveBMP
377 */
378extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
379 (SDL_Surface * surface, SDL_RWops * dst, int freedst);
380
381/**
382 * Save a surface to a file.
383 *
384 * Convenience macro.
385 */
386#define SDL_SaveBMP(surface, file) \
387 SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
388
389/**
390 * Set the RLE acceleration hint for a surface.
391 *
392 * If RLE is enabled, color key and alpha blending blits are much faster, but
393 * the surface must be locked before directly accessing the pixels.
394 *
395 * \param surface the SDL_Surface structure to optimize.
396 * \param flag 0 to disable, non-zero to enable RLE acceleration.
397 * \returns 0 on success or a negative error code on failure; call
398 * SDL_GetError() for more information.
399 *
400 * \since This function is available since SDL 2.0.0.
401 *
402 * \sa SDL_BlitSurface
403 * \sa SDL_LockSurface
404 * \sa SDL_UnlockSurface
405 */
406extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
407 int flag);
408
409/**
410 * Returns whether the surface is RLE enabled
411 *
412 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
413 *
414 * \param surface the SDL_Surface structure to query.
415 * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
416 *
417 * \since This function is available since SDL 2.0.14.
418 *
419 * \sa SDL_SetSurfaceRLE
420 */
421extern DECLSPEC SDL_bool SDLCALL SDL_HasSurfaceRLE(SDL_Surface * surface);
422
423/**
424 * Set the color key (transparent pixel) in a surface.
425 *
426 * The color key defines a pixel value that will be treated as transparent in
427 * a blit. For example, one can use this to specify that cyan pixels should be
428 * considered transparent, and therefore not rendered.
429 *
430 * It is a pixel of the format used by the surface, as generated by
431 * SDL_MapRGB().
432 *
433 * RLE acceleration can substantially speed up blitting of images with large
434 * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details.
435 *
436 * \param surface the SDL_Surface structure to update.
437 * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key.
438 * \param key the transparent pixel.
439 * \returns 0 on success or a negative error code on failure; call
440 * SDL_GetError() for more information.
441 *
442 * \since This function is available since SDL 2.0.0.
443 *
444 * \sa SDL_BlitSurface
445 * \sa SDL_GetColorKey
446 */
447extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
448 int flag, Uint32 key);
449
450/**
451 * Returns whether the surface has a color key
452 *
453 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
454 *
455 * \param surface the SDL_Surface structure to query.
456 * \return SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
457 *
458 * \since This function is available since SDL 2.0.9.
459 *
460 * \sa SDL_SetColorKey
461 * \sa SDL_GetColorKey
462 */
463extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface);
464
465/**
466 * Get the color key (transparent pixel) for a surface.
467 *
468 * The color key is a pixel of the format used by the surface, as generated by
469 * SDL_MapRGB().
470 *
471 * If the surface doesn't have color key enabled this function returns -1.
472 *
473 * \param surface the SDL_Surface structure to query.
474 * \param key a pointer filled in with the transparent pixel.
475 * \returns 0 on success or a negative error code on failure; call
476 * SDL_GetError() for more information.
477 *
478 * \since This function is available since SDL 2.0.0.
479 *
480 * \sa SDL_BlitSurface
481 * \sa SDL_SetColorKey
482 */
483extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
484 Uint32 * key);
485
486/**
487 * Set an additional color value multiplied into blit operations.
488 *
489 * When this surface is blitted, during the blit operation each source color
490 * channel is modulated by the appropriate color value according to the
491 * following formula:
492 *
493 * `srcC = srcC * (color / 255)`
494 *
495 * \param surface the SDL_Surface structure to update.
496 * \param r the red color value multiplied into blit operations.
497 * \param g the green color value multiplied into blit operations.
498 * \param b the blue color value multiplied into blit operations.
499 * \returns 0 on success or a negative error code on failure; call
500 * SDL_GetError() for more information.
501 *
502 * \since This function is available since SDL 2.0.0.
503 *
504 * \sa SDL_GetSurfaceColorMod
505 * \sa SDL_SetSurfaceAlphaMod
506 */
507extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
508 Uint8 r, Uint8 g, Uint8 b);
509
510
511/**
512 * Get the additional color value multiplied into blit operations.
513 *
514 * \param surface the SDL_Surface structure to query.
515 * \param r a pointer filled in with the current red color value.
516 * \param g a pointer filled in with the current green color value.
517 * \param b a pointer filled in with the current blue color value.
518 * \returns 0 on success or a negative error code on failure; call
519 * SDL_GetError() for more information.
520 *
521 * \since This function is available since SDL 2.0.0.
522 *
523 * \sa SDL_GetSurfaceAlphaMod
524 * \sa SDL_SetSurfaceColorMod
525 */
526extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
527 Uint8 * r, Uint8 * g,
528 Uint8 * b);
529
530/**
531 * Set an additional alpha value used in blit operations.
532 *
533 * When this surface is blitted, during the blit operation the source alpha
534 * value is modulated by this alpha value according to the following formula:
535 *
536 * `srcA = srcA * (alpha / 255)`
537 *
538 * \param surface the SDL_Surface structure to update.
539 * \param alpha the alpha value multiplied into blit operations.
540 * \returns 0 on success or a negative error code on failure; call
541 * SDL_GetError() for more information.
542 *
543 * \since This function is available since SDL 2.0.0.
544 *
545 * \sa SDL_GetSurfaceAlphaMod
546 * \sa SDL_SetSurfaceColorMod
547 */
548extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
549 Uint8 alpha);
550
551/**
552 * Get the additional alpha value used in blit operations.
553 *
554 * \param surface the SDL_Surface structure to query.
555 * \param alpha a pointer filled in with the current alpha value.
556 * \returns 0 on success or a negative error code on failure; call
557 * SDL_GetError() for more information.
558 *
559 * \since This function is available since SDL 2.0.0.
560 *
561 * \sa SDL_GetSurfaceColorMod
562 * \sa SDL_SetSurfaceAlphaMod
563 */
564extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
565 Uint8 * alpha);
566
567/**
568 * Set the blend mode used for blit operations.
569 *
570 * To copy a surface to another surface (or texture) without blending with the
571 * existing data, the blendmode of the SOURCE surface should be set to
572 * `SDL_BLENDMODE_NONE`.
573 *
574 * \param surface the SDL_Surface structure to update.
575 * \param blendMode the SDL_BlendMode to use for blit blending.
576 * \returns 0 on success or a negative error code on failure; call
577 * SDL_GetError() for more information.
578 *
579 * \since This function is available since SDL 2.0.0.
580 *
581 * \sa SDL_GetSurfaceBlendMode
582 */
583extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
584 SDL_BlendMode blendMode);
585
586/**
587 * Get the blend mode used for blit operations.
588 *
589 * \param surface the SDL_Surface structure to query.
590 * \param blendMode a pointer filled in with the current SDL_BlendMode.
591 * \returns 0 on success or a negative error code on failure; call
592 * SDL_GetError() for more information.
593 *
594 * \since This function is available since SDL 2.0.0.
595 *
596 * \sa SDL_SetSurfaceBlendMode
597 */
598extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
599 SDL_BlendMode *blendMode);
600
601/**
602 * Set the clipping rectangle for a surface.
603 *
604 * When `surface` is the destination of a blit, only the area within the clip
605 * rectangle is drawn into.
606 *
607 * Note that blits are automatically clipped to the edges of the source and
608 * destination surfaces.
609 *
610 * \param surface the SDL_Surface structure to be clipped.
611 * \param rect the SDL_Rect structure representing the clipping rectangle, or
612 * NULL to disable clipping.
613 * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
614 * SDL_FALSE and blits will be completely clipped.
615 *
616 * \since This function is available since SDL 2.0.0.
617 *
618 * \sa SDL_BlitSurface
619 * \sa SDL_GetClipRect
620 */
621extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
622 const SDL_Rect * rect);
623
624/**
625 * Get the clipping rectangle for a surface.
626 *
627 * When `surface` is the destination of a blit, only the area within the clip
628 * rectangle is drawn into.
629 *
630 * \param surface the SDL_Surface structure representing the surface to be
631 * clipped.
632 * \param rect an SDL_Rect structure filled in with the clipping rectangle for
633 * the surface.
634 *
635 * \since This function is available since SDL 2.0.0.
636 *
637 * \sa SDL_BlitSurface
638 * \sa SDL_SetClipRect
639 */
640extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
641 SDL_Rect * rect);
642
643/*
644 * Creates a new surface identical to the existing surface.
645 *
646 * The returned surface should be freed with SDL_FreeSurface().
647 *
648 * \param surface the surface to duplicate.
649 * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
650 * more information.
651 */
652extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface);
653
654/**
655 * Copy an existing surface to a new surface of the specified format.
656 *
657 * This function is used to optimize images for faster *repeat* blitting. This
658 * is accomplished by converting the original and storing the result as a new
659 * surface. The new, optimized surface can then be used as the source for
660 * future blits, making them faster.
661 *
662 * \param src the existing SDL_Surface structure to convert.
663 * \param fmt the SDL_PixelFormat structure that the new surface is optimized
664 * for.
665 * \param flags the flags are unused and should be set to 0; this is a
666 * leftover from SDL 1.2's API.
667 * \returns the new SDL_Surface structure that is created or NULL if it fails;
668 * call SDL_GetError() for more information.
669 *
670 * \since This function is available since SDL 2.0.0.
671 *
672 * \sa SDL_AllocFormat
673 * \sa SDL_ConvertSurfaceFormat
674 * \sa SDL_CreateRGBSurface
675 */
676extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
677 (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
678
679/**
680 * Copy an existing surface to a new surface of the specified format enum.
681 *
682 * This function operates just like SDL_ConvertSurface(), but accepts an
683 * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
684 * it might be easier to call but it doesn't have access to palette
685 * information for the destination surface, in case that would be important.
686 *
687 * \param src the existing SDL_Surface structure to convert.
688 * \param pixel_format the SDL_PixelFormatEnum that the new surface is
689 * optimized for.
690 * \param flags the flags are unused and should be set to 0; this is a
691 * leftover from SDL 1.2's API.
692 * \returns the new SDL_Surface structure that is created or NULL if it fails;
693 * call SDL_GetError() for more information.
694 *
695 * \since This function is available since SDL 2.0.0.
696 *
697 * \sa SDL_AllocFormat
698 * \sa SDL_ConvertSurface
699 * \sa SDL_CreateRGBSurface
700 */
701extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
702 (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
703
704/**
705 * Copy a block of pixels of one format to another format.
706 *
707 * \param width the width of the block to copy, in pixels.
708 * \param height the height of the block to copy, in pixels.
709 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format.
710 * \param src a pointer to the source pixels.
711 * \param src_pitch the pitch of the source pixels, in bytes.
712 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format.
713 * \param dst a pointer to be filled in with new pixel data.
714 * \param dst_pitch the pitch of the destination pixels, in bytes.
715 * \returns 0 on success or a negative error code on failure; call
716 * SDL_GetError() for more information.
717 *
718 * \since This function is available since SDL 2.0.0.
719 */
720extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
721 Uint32 src_format,
722 const void * src, int src_pitch,
723 Uint32 dst_format,
724 void * dst, int dst_pitch);
725
726/**
727 * Premultiply the alpha on a block of pixels.
728 *
729 * This is safe to use with src == dst, but not for other overlapping areas.
730 *
731 * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
732 *
733 * \param width the width of the block to convert, in pixels.
734 * \param height the height of the block to convert, in pixels.
735 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format.
736 * \param src a pointer to the source pixels.
737 * \param src_pitch the pitch of the source pixels, in bytes.
738 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format.
739 * \param dst a pointer to be filled in with premultiplied pixel data.
740 * \param dst_pitch the pitch of the destination pixels, in bytes.
741 * \returns 0 on success or a negative error code on failure; call
742 * SDL_GetError() for more information.
743 *
744 * \since This function is available since SDL 2.0.18.
745 */
746extern DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height,
747 Uint32 src_format,
748 const void * src, int src_pitch,
749 Uint32 dst_format,
750 void * dst, int dst_pitch);
751
752/**
753 * Perform a fast fill of a rectangle with a specific color.
754 *
755 * `color` should be a pixel of the format used by the surface, and can be
756 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
757 * alpha component then the destination is simply filled with that alpha
758 * information, no blending takes place.
759 *
760 * If there is a clip rectangle set on the destination (set via
761 * SDL_SetClipRect()), then this function will fill based on the intersection
762 * of the clip rectangle and `rect`.
763 *
764 * \param dst the SDL_Surface structure that is the drawing target.
765 * \param rect the SDL_Rect structure representing the rectangle to fill, or
766 * NULL to fill the entire surface.
767 * \param color the color to fill with.
768 * \returns 0 on success or a negative error code on failure; call
769 * SDL_GetError() for more information.
770 *
771 * \since This function is available since SDL 2.0.0.
772 *
773 * \sa SDL_FillRects
774 */
775extern DECLSPEC int SDLCALL SDL_FillRect
776 (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
777
778/**
779 * Perform a fast fill of a set of rectangles with a specific color.
780 *
781 * `color` should be a pixel of the format used by the surface, and can be
782 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
783 * alpha component then the destination is simply filled with that alpha
784 * information, no blending takes place.
785 *
786 * If there is a clip rectangle set on the destination (set via
787 * SDL_SetClipRect()), then this function will fill based on the intersection
788 * of the clip rectangle and `rect`.
789 *
790 * \param dst the SDL_Surface structure that is the drawing target.
791 * \param rects an array of SDL_Rect representing the rectangles to fill.
792 * \param count the number of rectangles in the array.
793 * \param color the color to fill with.
794 * \returns 0 on success or a negative error code on failure; call
795 * SDL_GetError() for more information.
796 *
797 * \since This function is available since SDL 2.0.0.
798 *
799 * \sa SDL_FillRect
800 */
801extern DECLSPEC int SDLCALL SDL_FillRects
802 (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
803
804/* !!! FIXME: merge this documentation with the wiki */
805
806/**
807 * Performs a fast blit from the source surface to the destination surface.
808 *
809 * This assumes that the source and destination rectangles are the same size.
810 * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
811 * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
812 * `dstrect` after all clipping is performed.
813 *
814 * The blit function should not be called on a locked surface.
815 *
816 * The blit semantics for surfaces with and without blending and colorkey are
817 * defined as follows:
818 *
819 * ```
820 * RGBA->RGB:
821 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
822 * alpha-blend (using the source alpha-channel and per-surface alpha)
823 * SDL_SRCCOLORKEY ignored.
824 * Source surface blend mode set to SDL_BLENDMODE_NONE:
825 * copy RGB.
826 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
827 * RGB values of the source color key, ignoring alpha in the
828 * comparison.
829 *
830 * RGB->RGBA:
831 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
832 * alpha-blend (using the source per-surface alpha)
833 * Source surface blend mode set to SDL_BLENDMODE_NONE:
834 * copy RGB, set destination alpha to source per-surface alpha value.
835 * both:
836 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
837 * source color key.
838 *
839 * RGBA->RGBA:
840 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
841 * alpha-blend (using the source alpha-channel and per-surface alpha)
842 * SDL_SRCCOLORKEY ignored.
843 * Source surface blend mode set to SDL_BLENDMODE_NONE:
844 * copy all of RGBA to the destination.
845 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
846 * RGB values of the source color key, ignoring alpha in the
847 * comparison.
848 *
849 * RGB->RGB:
850 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
851 * alpha-blend (using the source per-surface alpha)
852 * Source surface blend mode set to SDL_BLENDMODE_NONE:
853 * copy RGB.
854 * both:
855 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
856 * source color key.
857 * ```
858 *
859 * You should call SDL_BlitSurface() unless you know exactly how SDL blitting
860 * works internally and how to use the other blit functions.
861 *
862 * \returns 0 if the blit is successful, otherwise it returns -1.
863 */
864#define SDL_BlitSurface SDL_UpperBlit
865
866/**
867 * Perform a fast blit from the source surface to the destination surface.
868 *
869 * SDL_UpperBlit() has been replaced by SDL_BlitSurface(), which is merely a
870 * macro for this function with a less confusing name.
871 *
872 * \since This function is available since SDL 2.0.0.
873 *
874 * \sa SDL_BlitSurface
875 */
876extern DECLSPEC int SDLCALL SDL_UpperBlit
877 (SDL_Surface * src, const SDL_Rect * srcrect,
878 SDL_Surface * dst, SDL_Rect * dstrect);
879
880/**
881 * Perform low-level surface blitting only.
882 *
883 * This is a semi-private blit function and it performs low-level surface
884 * blitting, assuming the input rectangles have already been clipped.
885 *
886 * Unless you know what you're doing, you should be using SDL_BlitSurface()
887 * instead.
888 *
889 * \param src the SDL_Surface structure to be copied from.
890 * \param srcrect the SDL_Rect structure representing the rectangle to be
891 * copied, or NULL to copy the entire surface.
892 * \param dst the SDL_Surface structure that is the blit target.
893 * \param dstrect the SDL_Rect structure representing the rectangle that is
894 * copied into.
895 * \returns 0 on success or a negative error code on failure; call
896 * SDL_GetError() for more information.
897 *
898 * \since This function is available since SDL 2.0.0.
899 *
900 * \sa SDL_BlitSurface
901 */
902extern DECLSPEC int SDLCALL SDL_LowerBlit
903 (SDL_Surface * src, SDL_Rect * srcrect,
904 SDL_Surface * dst, SDL_Rect * dstrect);
905
906
907/**
908 * Perform a fast, low quality, stretch blit between two surfaces of the same
909 * format.
910 *
911 * Please use SDL_BlitScaled() instead.
912 *
913 * \since This function is available since SDL 2.0.0.
914 */
915extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
916 const SDL_Rect * srcrect,
917 SDL_Surface * dst,
918 const SDL_Rect * dstrect);
919
920/**
921 * Perform bilinear scaling between two surfaces of the same format, 32BPP.
922 *
923 * \since This function is available since SDL 2.0.16.
924 */
925extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface * src,
926 const SDL_Rect * srcrect,
927 SDL_Surface * dst,
928 const SDL_Rect * dstrect);
929
930
931/**
932 * Perform a scaled surface copy to a destination surface.
933 *
934 * SDL_UpperBlitScaled() has been replaced by SDL_BlitScaled(), which is
935 * merely a macro for this function with a less confusing name.
936 *
937 * \since This function is available since SDL 2.0.0.
938 *
939 * \sa SDL_BlitScaled
940 */
941extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
942 (SDL_Surface * src, const SDL_Rect * srcrect,
943 SDL_Surface * dst, SDL_Rect * dstrect);
944
945#define SDL_BlitScaled SDL_UpperBlitScaled
946
947
948/**
949 * Perform low-level surface scaled blitting only.
950 *
951 * This is a semi-private function and it performs low-level surface blitting,
952 * assuming the input rectangles have already been clipped.
953 *
954 * \param src the SDL_Surface structure to be copied from.
955 * \param srcrect the SDL_Rect structure representing the rectangle to be
956 * copied.
957 * \param dst the SDL_Surface structure that is the blit target.
958 * \param dstrect the SDL_Rect structure representing the rectangle that is
959 * copied into.
960 * \returns 0 on success or a negative error code on failure; call
961 * SDL_GetError() for more information.
962 *
963 * \since This function is available since SDL 2.0.0.
964 *
965 * \sa SDL_BlitScaled
966 */
967extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
968 (SDL_Surface * src, SDL_Rect * srcrect,
969 SDL_Surface * dst, SDL_Rect * dstrect);
970
971/**
972 * Set the YUV conversion mode
973 *
974 * \since This function is available since SDL 2.0.8.
975 */
976extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
977
978/**
979 * Get the YUV conversion mode
980 *
981 * \since This function is available since SDL 2.0.8.
982 */
984
985/**
986 * Get the YUV conversion mode, returning the correct mode for the resolution
987 * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
988 *
989 * \since This function is available since SDL 2.0.8.
990 */
991extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
992
993/* Ends C function definitions when using C++ */
994#ifdef __cplusplus
995}
996#endif
997#include "close_code.h"
998
999#endif /* SDL_surface_h_ */
1000
1001/* vi: set ts=4 sw=4 expandtab: */
SDL_BlendMode
uint8_t Uint8
Definition SDL_stdinc.h:203
SDL_bool
Definition SDL_stdinc.h:187
uint32_t Uint32
Definition SDL_stdinc.h:231
SDL_YUV_CONVERSION_MODE
@ SDL_YUV_CONVERSION_BT601
@ SDL_YUV_CONVERSION_JPEG
@ SDL_YUV_CONVERSION_BT709
@ SDL_YUV_CONVERSION_AUTOMATIC
SDL_bool SDL_HasSurfaceRLE(SDL_Surface *surface)
SDL_Surface * SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
SDL_Surface * SDL_ConvertSurface(SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags)
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
int(* SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect, struct SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_UpperBlitScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_LowerBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
SDL_Surface * SDL_DuplicateSurface(SDL_Surface *surface)
SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
SDL_bool SDL_HasColorKey(SDL_Surface *surface)
SDL_Surface * SDL_LoadBMP_RW(SDL_RWops *src, int freesrc)
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
int SDL_LockSurface(SDL_Surface *surface)
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
SDL_Surface * SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
int SDL_PremultiplyAlpha(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
struct SDL_BlitMap SDL_BlitMap
Definition SDL_surface.h:64
int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
void SDL_UnlockSurface(SDL_Surface *surface)
int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
int SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
int SDL_GetColorKey(SDL_Surface *surface, Uint32 *key)
int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
int SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
int SDL_SoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
int SDL_LowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
void SDL_FreeSurface(SDL_Surface *surface)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode(void)
SDL_Surface * SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
SDL_Surface * SDL_ConvertSurfaceFormat(SDL_Surface *src, Uint32 pixel_format, Uint32 flags)
int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
SDL_Surface * SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format)
int SDL_UpperBlit(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
void SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution(int width, int height)
int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_PixelFormat * format
Definition SDL_surface.h:75
void * list_blitmap
Definition SDL_surface.h:87
Uint32 flags
Definition SDL_surface.h:74
SDL_Rect clip_rect
Definition SDL_surface.h:90
void * pixels
Definition SDL_surface.h:78
SDL_BlitMap * map
Definition SDL_surface.h:93
void * userdata
Definition SDL_surface.h:81