SDL 3.0
SDL_surface.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 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 * \file SDL_surface.h
24 *
25 * \brief Header file for ::SDL_Surface definition and management functions.
26 */
27
28#ifndef SDL_surface_h_
29#define SDL_surface_h_
30
31#include <SDL3/SDL_stdinc.h>
32#include <SDL3/SDL_pixels.h>
33#include <SDL3/SDL_rect.h>
34#include <SDL3/SDL_blendmode.h>
35#include <SDL3/SDL_rwops.h>
36
37#include <SDL3/SDL_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 * \brief A collection of pixels used in software blitting.
68 *
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.
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 * \brief The type of function used for surface blitting functions.
101 */
102typedef int (SDLCALL *SDL_blit) (struct SDL_Surface *src, const SDL_Rect *srcrect,
103 struct SDL_Surface *dst, const SDL_Rect *dstrect);
104
105/**
106 * \brief The formula used for converting between YUV and RGB
107 */
108typedef enum
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 with a specific pixel format.
118 *
119 * \param width the width of the surface
120 * \param height the height of the surface
121 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
122 * \returns the new SDL_Surface structure that is created or NULL if it fails;
123 * call SDL_GetError() for more information.
124 *
125 * \since This function is available since SDL 3.0.0.
126 *
127 * \sa SDL_CreateSurfaceFrom
128 * \sa SDL_DestroySurface
129 */
130extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface
131 (int width, int height, Uint32 format);
132
133/**
134 * Allocate a new RGB surface with a specific pixel format and existing pixel
135 * data.
136 *
137 * No copy is made of the pixel data. Pixel data is not managed automatically;
138 * you must free the surface before you free the pixel data.
139 *
140 * Pitch is the offset in bytes from one row of pixels to the next, e.g.
141 * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
142 *
143 * You may pass NULL for pixels and 0 for pitch to create a surface that you
144 * will fill in with valid values later.
145 *
146 * \param pixels a pointer to existing pixel data
147 * \param width the width of the surface
148 * \param height the height of the surface
149 * \param pitch the pitch of the surface in bytes
150 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
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 3.0.0.
155 *
156 * \sa SDL_CreateSurface
157 * \sa SDL_DestroySurface
158 */
159extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom
160 (void *pixels, int width, int height, int pitch, Uint32 format);
161
162/**
163 * Free an RGB surface.
164 *
165 * It is safe to pass NULL to this function.
166 *
167 * \param surface the SDL_Surface to free.
168 *
169 * \since This function is available since SDL 3.0.0.
170 *
171 * \sa SDL_CreateSurface
172 * \sa SDL_CreateSurfaceFrom
173 * \sa SDL_LoadBMP
174 * \sa SDL_LoadBMP_RW
175 */
176extern DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
177
178/**
179 * Set the palette used by a surface.
180 *
181 * A single palette can be shared with many surfaces.
182 *
183 * \param surface the SDL_Surface structure to update
184 * \param palette the SDL_Palette structure to use
185 * \returns 0 on success or a negative error code on failure; call
186 * SDL_GetError() for more information.
187 *
188 * \since This function is available since SDL 3.0.0.
189 */
190extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface,
191 SDL_Palette *palette);
192
193/**
194 * Set up a surface for directly accessing the pixels.
195 *
196 * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
197 * and read from `surface->pixels`, using the pixel format stored in
198 * `surface->format`. Once you are done accessing the surface, you should use
199 * SDL_UnlockSurface() to release it.
200 *
201 * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
202 * 0, then you can read and write to the surface at any time, and the pixel
203 * format of the surface will not change.
204 *
205 * \param surface the SDL_Surface structure to be locked
206 * \returns 0 on success or a negative error code on failure; call
207 * SDL_GetError() for more information.
208 *
209 * \since This function is available since SDL 3.0.0.
210 *
211 * \sa SDL_MUSTLOCK
212 * \sa SDL_UnlockSurface
213 */
214extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
215
216/**
217 * Release a surface after directly accessing the pixels.
218 *
219 * \param surface the SDL_Surface structure to be unlocked
220 *
221 * \since This function is available since SDL 3.0.0.
222 *
223 * \sa SDL_LockSurface
224 */
225extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
226
227/**
228 * Load a BMP image from a seekable SDL data stream.
229 *
230 * The new surface should be freed with SDL_DestroySurface(). Not doing so
231 * will result in a memory leak.
232 *
233 * \param src the data stream for the surface
234 * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
235 * even in the case of an error
236 * \returns a pointer to a new SDL_Surface structure or NULL if there was an
237 * error; call SDL_GetError() for more information.
238 *
239 * \since This function is available since SDL 3.0.0.
240 *
241 * \sa SDL_DestroySurface
242 * \sa SDL_LoadBMP
243 * \sa SDL_SaveBMP_RW
244 */
245extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc);
246
247/**
248 * Load a BMP image from a file.
249 *
250 * The new surface should be freed with SDL_DestroySurface(). Not doing so
251 * will result in a memory leak.
252 *
253 * \param file the BMP file to load
254 * \returns a pointer to a new SDL_Surface structure or NULL if there was an
255 * error; call SDL_GetError() for more information.
256 *
257 * \since This function is available since SDL 3.0.0.
258 *
259 * \sa SDL_DestroySurface
260 * \sa SDL_LoadBMP_RW
261 * \sa SDL_SaveBMP
262 */
263extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
264
265/**
266 * Save a surface to a seekable SDL data stream in BMP format.
267 *
268 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
269 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
270 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
271 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
272 * not supported.
273 *
274 * \param surface the SDL_Surface structure containing the image to be saved
275 * \param dst a data stream to save to
276 * \param freedst if SDL_TRUE, calls SDL_RWclose() on `dst` before returning,
277 * even in the case of an error
278 * \returns 0 on success or a negative error code on failure; call
279 * SDL_GetError() for more information.
280 *
281 * \since This function is available since SDL 3.0.0.
282 *
283 * \sa SDL_LoadBMP_RW
284 * \sa SDL_SaveBMP
285 */
286extern DECLSPEC int SDLCALL SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, SDL_bool freedst);
287
288/**
289 * Save a surface to a file.
290 *
291 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
292 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
293 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
294 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
295 * not supported.
296 *
297 * \param surface the SDL_Surface structure containing the image to be saved
298 * \param file a file to save to
299 * \returns 0 on success or a negative error code on failure; call
300 * SDL_GetError() for more information.
301 *
302 * \since This function is available since SDL 3.0.0.
303 *
304 * \sa SDL_LoadBMP
305 * \sa SDL_SaveBMP_RW
306 */
307extern DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
308
309/**
310 * Set the RLE acceleration hint for a surface.
311 *
312 * If RLE is enabled, color key and alpha blending blits are much faster, but
313 * the surface must be locked before directly accessing the pixels.
314 *
315 * \param surface the SDL_Surface structure to optimize
316 * \param flag 0 to disable, non-zero to enable RLE acceleration
317 * \returns 0 on success or a negative error code on failure; call
318 * SDL_GetError() for more information.
319 *
320 * \since This function is available since SDL 3.0.0.
321 *
322 * \sa SDL_BlitSurface
323 * \sa SDL_LockSurface
324 * \sa SDL_UnlockSurface
325 */
326extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface,
327 int flag);
328
329/**
330 * Returns whether the surface is RLE enabled
331 *
332 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
333 *
334 * \param surface the SDL_Surface structure to query
335 * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
336 *
337 * \since This function is available since SDL 3.0.0.
338 *
339 * \sa SDL_SetSurfaceRLE
340 */
341extern DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
342
343/**
344 * Set the color key (transparent pixel) in a surface.
345 *
346 * The color key defines a pixel value that will be treated as transparent in
347 * a blit. For example, one can use this to specify that cyan pixels should be
348 * considered transparent, and therefore not rendered.
349 *
350 * It is a pixel of the format used by the surface, as generated by
351 * SDL_MapRGB().
352 *
353 * RLE acceleration can substantially speed up blitting of images with large
354 * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details.
355 *
356 * \param surface the SDL_Surface structure to update
357 * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key
358 * \param key the transparent pixel
359 * \returns 0 on success or a negative error code on failure; call
360 * SDL_GetError() for more information.
361 *
362 * \since This function is available since SDL 3.0.0.
363 *
364 * \sa SDL_BlitSurface
365 * \sa SDL_GetSurfaceColorKey
366 */
367extern DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface,
368 int flag, Uint32 key);
369
370/**
371 * Returns whether the surface has a color key
372 *
373 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
374 *
375 * \param surface the SDL_Surface structure to query
376 * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
377 *
378 * \since This function is available since SDL 3.0.0.
379 *
380 * \sa SDL_SetSurfaceColorKey
381 * \sa SDL_GetSurfaceColorKey
382 */
383extern DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
384
385/**
386 * Get the color key (transparent pixel) for a surface.
387 *
388 * The color key is a pixel of the format used by the surface, as generated by
389 * SDL_MapRGB().
390 *
391 * If the surface doesn't have color key enabled this function returns -1.
392 *
393 * \param surface the SDL_Surface structure to query
394 * \param key a pointer filled in with the transparent pixel
395 * \returns 0 on success or a negative error code on failure; call
396 * SDL_GetError() for more information.
397 *
398 * \since This function is available since SDL 3.0.0.
399 *
400 * \sa SDL_BlitSurface
401 * \sa SDL_SetSurfaceColorKey
402 */
403extern DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface,
404 Uint32 *key);
405
406/**
407 * Set an additional color value multiplied into blit operations.
408 *
409 * When this surface is blitted, during the blit operation each source color
410 * channel is modulated by the appropriate color value according to the
411 * following formula:
412 *
413 * `srcC = srcC * (color / 255)`
414 *
415 * \param surface the SDL_Surface structure to update
416 * \param r the red color value multiplied into blit operations
417 * \param g the green color value multiplied into blit operations
418 * \param b the blue color value multiplied into blit operations
419 * \returns 0 on success or a negative error code on failure; call
420 * SDL_GetError() for more information.
421 *
422 * \since This function is available since SDL 3.0.0.
423 *
424 * \sa SDL_GetSurfaceColorMod
425 * \sa SDL_SetSurfaceAlphaMod
426 */
427extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface,
428 Uint8 r, Uint8 g, Uint8 b);
429
430
431/**
432 * Get the additional color value multiplied into blit operations.
433 *
434 * \param surface the SDL_Surface structure to query
435 * \param r a pointer filled in with the current red color value
436 * \param g a pointer filled in with the current green color value
437 * \param b a pointer filled in with the current blue color value
438 * \returns 0 on success or a negative error code on failure; call
439 * SDL_GetError() for more information.
440 *
441 * \since This function is available since SDL 3.0.0.
442 *
443 * \sa SDL_GetSurfaceAlphaMod
444 * \sa SDL_SetSurfaceColorMod
445 */
446extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface,
447 Uint8 *r, Uint8 *g,
448 Uint8 *b);
449
450/**
451 * Set an additional alpha value used in blit operations.
452 *
453 * When this surface is blitted, during the blit operation the source alpha
454 * value is modulated by this alpha value according to the following formula:
455 *
456 * `srcA = srcA * (alpha / 255)`
457 *
458 * \param surface the SDL_Surface structure to update
459 * \param alpha the alpha value multiplied into blit operations
460 * \returns 0 on success or a negative error code on failure; call
461 * SDL_GetError() for more information.
462 *
463 * \since This function is available since SDL 3.0.0.
464 *
465 * \sa SDL_GetSurfaceAlphaMod
466 * \sa SDL_SetSurfaceColorMod
467 */
468extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface,
469 Uint8 alpha);
470
471/**
472 * Get the additional alpha value used in blit operations.
473 *
474 * \param surface the SDL_Surface structure to query
475 * \param alpha a pointer filled in with the current alpha value
476 * \returns 0 on success or a negative error code on failure; call
477 * SDL_GetError() for more information.
478 *
479 * \since This function is available since SDL 3.0.0.
480 *
481 * \sa SDL_GetSurfaceColorMod
482 * \sa SDL_SetSurfaceAlphaMod
483 */
484extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface,
485 Uint8 *alpha);
486
487/**
488 * Set the blend mode used for blit operations.
489 *
490 * To copy a surface to another surface (or texture) without blending with the
491 * existing data, the blendmode of the SOURCE surface should be set to
492 * `SDL_BLENDMODE_NONE`.
493 *
494 * \param surface the SDL_Surface structure to update
495 * \param blendMode the SDL_BlendMode to use for blit blending
496 * \returns 0 on success or a negative error code on failure; call
497 * SDL_GetError() for more information.
498 *
499 * \since This function is available since SDL 3.0.0.
500 *
501 * \sa SDL_GetSurfaceBlendMode
502 */
503extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface,
504 SDL_BlendMode blendMode);
505
506/**
507 * Get the blend mode used for blit operations.
508 *
509 * \param surface the SDL_Surface structure to query
510 * \param blendMode a pointer filled in with the current SDL_BlendMode
511 * \returns 0 on success or a negative error code on failure; call
512 * SDL_GetError() for more information.
513 *
514 * \since This function is available since SDL 3.0.0.
515 *
516 * \sa SDL_SetSurfaceBlendMode
517 */
518extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface,
519 SDL_BlendMode *blendMode);
520
521/**
522 * Set the clipping rectangle for a surface.
523 *
524 * When `surface` is the destination of a blit, only the area within the clip
525 * rectangle is drawn into.
526 *
527 * Note that blits are automatically clipped to the edges of the source and
528 * destination surfaces.
529 *
530 * \param surface the SDL_Surface structure to be clipped
531 * \param rect the SDL_Rect structure representing the clipping rectangle, or
532 * NULL to disable clipping
533 * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
534 * SDL_FALSE and blits will be completely clipped.
535 *
536 * \since This function is available since SDL 3.0.0.
537 *
538 * \sa SDL_BlitSurface
539 * \sa SDL_GetSurfaceClipRect
540 */
541extern DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface,
542 const SDL_Rect *rect);
543
544/**
545 * Get the clipping rectangle for a surface.
546 *
547 * When `surface` is the destination of a blit, only the area within the clip
548 * rectangle is drawn into.
549 *
550 * \param surface the SDL_Surface structure representing the surface to be
551 * clipped
552 * \param rect an SDL_Rect structure filled in with the clipping rectangle for
553 * the surface
554 * \returns 0 on success or a negative error code on failure; call
555 * SDL_GetError() for more information.
556 *
557 * \since This function is available since SDL 3.0.0.
558 *
559 * \sa SDL_BlitSurface
560 * \sa SDL_SetSurfaceClipRect
561 */
562extern DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface,
563 SDL_Rect *rect);
564
565/*
566 * Creates a new surface identical to the existing surface.
567 *
568 * The returned surface should be freed with SDL_DestroySurface().
569 *
570 * \param surface the surface to duplicate.
571 * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
572 * more information.
573 *
574 * \since This function is available since SDL 3.0.0.
575 */
576extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
577
578/**
579 * Copy an existing surface to a new surface of the specified format.
580 *
581 * This function is used to optimize images for faster *repeat* blitting. This
582 * is accomplished by converting the original and storing the result as a new
583 * surface. The new, optimized surface can then be used as the source for
584 * future blits, making them faster.
585 *
586 * \param surface the existing SDL_Surface structure to convert
587 * \param format the SDL_PixelFormat structure that the new surface is
588 * optimized for
589 * \returns the new SDL_Surface structure that is created or NULL if it fails;
590 * call SDL_GetError() for more information.
591 *
592 * \since This function is available since SDL 3.0.0.
593 *
594 * \sa SDL_CreatePixelFormat
595 * \sa SDL_ConvertSurfaceFormat
596 * \sa SDL_CreateSurface
597 */
598extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface,
599 const SDL_PixelFormat *format);
600
601/**
602 * Copy an existing surface to a new surface of the specified format enum.
603 *
604 * This function operates just like SDL_ConvertSurface(), but accepts an
605 * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
606 * it might be easier to call but it doesn't have access to palette
607 * information for the destination surface, in case that would be important.
608 *
609 * \param surface the existing SDL_Surface structure to convert
610 * \param pixel_format the SDL_PixelFormatEnum that the new surface is
611 * optimized for
612 * \returns the new SDL_Surface structure that is created or NULL if it fails;
613 * call SDL_GetError() for more information.
614 *
615 * \since This function is available since SDL 3.0.0.
616 *
617 * \sa SDL_CreatePixelFormat
618 * \sa SDL_ConvertSurface
619 * \sa SDL_CreateSurface
620 */
621extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *surface,
622 Uint32 pixel_format);
623
624/**
625 * Copy a block of pixels of one format to another format.
626 *
627 * \param width the width of the block to copy, in pixels
628 * \param height the height of the block to copy, in pixels
629 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
630 * \param src a pointer to the source pixels
631 * \param src_pitch the pitch of the source pixels, in bytes
632 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
633 * \param dst a pointer to be filled in with new pixel data
634 * \param dst_pitch the pitch of the destination pixels, in bytes
635 * \returns 0 on success or a negative error code on failure; call
636 * SDL_GetError() for more information.
637 *
638 * \since This function is available since SDL 3.0.0.
639 */
640extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
641 Uint32 src_format,
642 const void *src, int src_pitch,
643 Uint32 dst_format,
644 void *dst, int dst_pitch);
645
646/**
647 * Premultiply the alpha on a block of pixels.
648 *
649 * This is safe to use with src == dst, but not for other overlapping areas.
650 *
651 * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
652 *
653 * \param width the width of the block to convert, in pixels
654 * \param height the height of the block to convert, in pixels
655 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
656 * \param src a pointer to the source pixels
657 * \param src_pitch the pitch of the source pixels, in bytes
658 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
659 * \param dst a pointer to be filled in with premultiplied pixel data
660 * \param dst_pitch the pitch of the destination pixels, in bytes
661 * \returns 0 on success or a negative error code on failure; call
662 * SDL_GetError() for more information.
663 *
664 * \since This function is available since SDL 3.0.0.
665 */
666extern DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height,
667 Uint32 src_format,
668 const void *src, int src_pitch,
669 Uint32 dst_format,
670 void *dst, int dst_pitch);
671
672/**
673 * Perform a fast fill of a rectangle with a specific color.
674 *
675 * `color` should be a pixel of the format used by the surface, and can be
676 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
677 * alpha component then the destination is simply filled with that alpha
678 * information, no blending takes place.
679 *
680 * If there is a clip rectangle set on the destination (set via
681 * SDL_SetSurfaceClipRect()), then this function will fill based on the
682 * intersection of the clip rectangle and `rect`.
683 *
684 * \param dst the SDL_Surface structure that is the drawing target
685 * \param rect the SDL_Rect structure representing the rectangle to fill, or
686 * NULL to fill the entire surface
687 * \param color the color to fill with
688 * \returns 0 on success or a negative error code on failure; call
689 * SDL_GetError() for more information.
690 *
691 * \since This function is available since SDL 3.0.0.
692 *
693 * \sa SDL_FillSurfaceRects
694 */
695extern DECLSPEC int SDLCALL SDL_FillSurfaceRect
696 (SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
697
698/**
699 * Perform a fast fill of a set of rectangles with a specific color.
700 *
701 * `color` should be a pixel of the format used by the surface, and can be
702 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
703 * alpha component then the destination is simply filled with that alpha
704 * information, no blending takes place.
705 *
706 * If there is a clip rectangle set on the destination (set via
707 * SDL_SetSurfaceClipRect()), then this function will fill based on the
708 * intersection of the clip rectangle and `rect`.
709 *
710 * \param dst the SDL_Surface structure that is the drawing target
711 * \param rects an array of SDL_Rects representing the rectangles to fill.
712 * \param count the number of rectangles in the array
713 * \param color the color to fill with
714 * \returns 0 on success or a negative error code on failure; call
715 * SDL_GetError() for more information.
716 *
717 * \since This function is available since SDL 3.0.0.
718 *
719 * \sa SDL_FillSurfaceRect
720 */
721extern DECLSPEC int SDLCALL SDL_FillSurfaceRects
722 (SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
723
724/**
725 * Performs a fast blit from the source surface to the destination surface.
726 *
727 * This assumes that the source and destination rectangles are the same size.
728 * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
729 * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
730 * `dstrect` after all clipping is performed.
731 *
732 * The blit function should not be called on a locked surface.
733 *
734 * The blit semantics for surfaces with and without blending and colorkey are
735 * defined as follows:
736 *
737 * ```c
738 * RGBA->RGB:
739 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
740 * alpha-blend (using the source alpha-channel and per-surface alpha)
741 * SDL_SRCCOLORKEY ignored.
742 * Source surface blend mode set to SDL_BLENDMODE_NONE:
743 * copy RGB.
744 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
745 * RGB values of the source color key, ignoring alpha in the
746 * comparison.
747 *
748 * RGB->RGBA:
749 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
750 * alpha-blend (using the source per-surface alpha)
751 * Source surface blend mode set to SDL_BLENDMODE_NONE:
752 * copy RGB, set destination alpha to source per-surface alpha value.
753 * both:
754 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
755 * source color key.
756 *
757 * RGBA->RGBA:
758 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
759 * alpha-blend (using the source alpha-channel and per-surface alpha)
760 * SDL_SRCCOLORKEY ignored.
761 * Source surface blend mode set to SDL_BLENDMODE_NONE:
762 * copy all of RGBA to the destination.
763 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
764 * RGB values of the source color key, ignoring alpha in the
765 * comparison.
766 *
767 * RGB->RGB:
768 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
769 * alpha-blend (using the source per-surface alpha)
770 * Source surface blend mode set to SDL_BLENDMODE_NONE:
771 * copy RGB.
772 * both:
773 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
774 * source color key.
775 * ```
776 *
777 * \param src the SDL_Surface structure to be copied from
778 * \param srcrect the SDL_Rect structure representing the rectangle to be
779 * copied, or NULL to copy the entire surface
780 * \param dst the SDL_Surface structure that is the blit target
781 * \param dstrect the SDL_Rect structure representing the target rectangle in
782 * the destination surface, filled with the actual rectangle
783 * used after clipping
784 * \returns 0 on success or a negative error code on failure; call
785 * SDL_GetError() for more information.
786 *
787 * \since This function is available since SDL 3.0.0.
788 *
789 * \sa SDL_BlitSurface
790 */
791extern DECLSPEC int SDLCALL SDL_BlitSurface
792 (SDL_Surface *src, const SDL_Rect *srcrect,
793 SDL_Surface *dst, SDL_Rect *dstrect);
794
795/**
796 * Perform low-level surface blitting only.
797 *
798 * This is a semi-private blit function and it performs low-level surface
799 * blitting, assuming the input rectangles have already been clipped.
800 *
801 * \param src the SDL_Surface structure to be copied from
802 * \param srcrect the SDL_Rect structure representing the rectangle to be
803 * copied, or NULL to copy the entire surface
804 * \param dst the SDL_Surface structure that is the blit target
805 * \param dstrect the SDL_Rect structure representing the target rectangle in
806 * the destination surface
807 * \returns 0 on success or a negative error code on failure; call
808 * SDL_GetError() for more information.
809 *
810 * \since This function is available since SDL 3.0.0.
811 *
812 * \sa SDL_BlitSurface
813 */
814extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked
815 (SDL_Surface *src, const SDL_Rect *srcrect,
816 SDL_Surface *dst, const SDL_Rect *dstrect);
817
818
819/**
820 * Perform a fast, low quality, stretch blit between two surfaces of the same
821 * format.
822 *
823 * **WARNING**: Please use SDL_BlitSurfaceScaled() instead.
824 *
825 * \param src the SDL_Surface structure to be copied from
826 * \param srcrect the SDL_Rect structure representing the rectangle to be
827 * copied
828 * \param dst the SDL_Surface structure that is the blit target
829 * \param dstrect the SDL_Rect structure representing the target rectangle in
830 * the destination surface
831 * \returns 0 on success or a negative error code on failure; call
832 * SDL_GetError() for more information.
833 *
834 * \since This function is available since SDL 3.0.0.
835 */
836extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src,
837 const SDL_Rect *srcrect,
838 SDL_Surface *dst,
839 const SDL_Rect *dstrect);
840
841/**
842 * Perform bilinear scaling between two surfaces of the same format, 32BPP.
843 *
844 * \param src the SDL_Surface structure to be copied from
845 * \param srcrect the SDL_Rect structure representing the rectangle to be
846 * copied
847 * \param dst the SDL_Surface structure that is the blit target
848 * \param dstrect the SDL_Rect structure representing the target rectangle in
849 * the destination surface
850 * \returns 0 on success or a negative error code on failure; call
851 * SDL_GetError() for more information.
852 *
853 * \since This function is available since SDL 3.0.0.
854 */
855extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src,
856 const SDL_Rect *srcrect,
857 SDL_Surface *dst,
858 const SDL_Rect *dstrect);
859
860
861/**
862 * Perform a scaled surface copy to a destination surface.
863 *
864 * \param src the SDL_Surface structure to be copied from
865 * \param srcrect the SDL_Rect structure representing the rectangle to be
866 * copied
867 * \param dst the SDL_Surface structure that is the blit target
868 * \param dstrect the SDL_Rect structure representing the target rectangle in
869 * the destination surface, filled with the actual rectangle
870 * used after clipping
871 * \returns 0 on success or a negative error code on failure; call
872 * SDL_GetError() for more information.
873 *
874 * \since This function is available since SDL 3.0.0.
875 */
876extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
877 (SDL_Surface *src, const SDL_Rect *srcrect,
878 SDL_Surface *dst, SDL_Rect *dstrect);
879
880/**
881 * Perform low-level surface scaled blitting only.
882 *
883 * This is a semi-private function and it performs low-level surface blitting,
884 * assuming the input rectangles have already been clipped.
885 *
886 * \param src the SDL_Surface structure to be copied from
887 * \param srcrect the SDL_Rect structure representing the rectangle to be
888 * copied
889 * \param dst the SDL_Surface structure that is the blit target
890 * \param dstrect the SDL_Rect structure representing the target rectangle in
891 * the destination surface
892 * \returns 0 on success or a negative error code on failure; call
893 * SDL_GetError() for more information.
894 *
895 * \since This function is available since SDL 3.0.0.
896 *
897 * \sa SDL_BlitSurfaceScaled
898 */
899extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled
900 (SDL_Surface *src, const SDL_Rect *srcrect,
901 SDL_Surface *dst, const SDL_Rect *dstrect);
902
903/**
904 * Set the YUV conversion mode
905 *
906 * \param mode YUV conversion mode
907 *
908 * \since This function is available since SDL 3.0.0.
909 */
910extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
911
912/**
913 * Get the YUV conversion mode
914 *
915 * \returns YUV conversion mode
916 *
917 * \since This function is available since SDL 3.0.0.
918 */
920
921/**
922 * Get the YUV conversion mode, returning the correct mode for the resolution
923 * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
924 *
925 * \param width width
926 * \param height height
927 * \returns YUV conversion mode
928 *
929 * \since This function is available since SDL 3.0.0.
930 */
931extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
932
933/* Ends C function definitions when using C++ */
934#ifdef __cplusplus
935}
936#endif
937#include <SDL3/SDL_close_code.h>
938
939#endif /* SDL_surface_h_ */
Header file declaring the SDL_BlendMode enumeration.
SDL_BlendMode
The blend mode used in SDL_RenderTexture() and drawing operations.
Header for the enumerated pixel format definitions.
Header file for SDL_rect definition and management functions.
This is a general header that includes C language support.
uint8_t Uint8
Definition SDL_stdinc.h:147
SDL_bool
Definition SDL_stdinc.h:130
uint32_t Uint32
Definition SDL_stdinc.h:171
SDL_YUV_CONVERSION_MODE
The formula used for converting between YUV and RGB.
@ SDL_YUV_CONVERSION_BT601
@ SDL_YUV_CONVERSION_JPEG
@ SDL_YUV_CONVERSION_BT709
@ SDL_YUV_CONVERSION_AUTOMATIC
int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
int(* SDL_blit)(struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect)
The type of function used for surface blitting functions.
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
void SDL_DestroySurface(SDL_Surface *surface)
SDL_Surface * SDL_ConvertSurfaceFormat(SDL_Surface *surface, Uint32 pixel_format)
SDL_Surface * SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitch, Uint32 format)
int SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
SDL_Surface * SDL_DuplicateSurface(SDL_Surface *surface)
int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
int SDL_LockSurface(SDL_Surface *surface)
int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
int SDL_PremultiplyAlpha(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)
struct SDL_BlitMap SDL_BlitMap
Definition SDL_surface.h:64
int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
int SDL_SetSurfaceColorKey(SDL_Surface *surface, int flag, Uint32 key)
SDL_Surface * SDL_CreateSurface(int width, int height, Uint32 format)
int SDL_SaveBMP(SDL_Surface *surface, const char *file)
void SDL_UnlockSurface(SDL_Surface *surface)
int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect)
int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
SDL_Surface * SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc)
int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface)
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_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, SDL_bool freedst)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode(void)
int SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key)
SDL_bool SDL_SurfaceHasRLE(SDL_Surface *surface)
SDL_Surface * SDL_LoadBMP(const char *file)
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const 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)
A collection of pixels used in software blitting.
Definition SDL_surface.h:73
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