SDL 3.0
SDL_surface.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 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 * 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_error.h>
33#include <SDL3/SDL_blendmode.h>
34#include <SDL3/SDL_pixels.h>
35#include <SDL3/SDL_properties.h>
36#include <SDL3/SDL_rect.h>
37#include <SDL3/SDL_iostream.h>
38
39#include <SDL3/SDL_begin_code.h>
40/* Set up for C function definitions, even when using C++ */
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/**
46 * The flags on an SDL_Surface.
47 *
48 * These are generally considered read-only.
49 *
50 * \since This datatype is available since SDL 3.0.0.
51 */
53
54#define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */
55#define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */
56#define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */
57#define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */
58
59/**
60 * Evaluates to true if the surface needs to be locked before access.
61 *
62 * \since This macro is available since SDL 3.0.0.
63 */
64#define SDL_MUSTLOCK(S) ((((S)->flags & SDL_SURFACE_LOCK_NEEDED)) == SDL_SURFACE_LOCK_NEEDED)
65
66/**
67 * The scaling mode.
68 *
69 * \since This enum is available since SDL 3.0.0.
70 */
71typedef enum SDL_ScaleMode
72{
73 SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
74 SDL_SCALEMODE_LINEAR /**< linear filtering */
76
77/**
78 * The flip mode.
79 *
80 * \since This enum is available since SDL 3.0.0.
81 */
82typedef enum SDL_FlipMode
83{
84 SDL_FLIP_NONE, /**< Do not flip */
85 SDL_FLIP_HORIZONTAL, /**< flip horizontally */
86 SDL_FLIP_VERTICAL /**< flip vertically */
88
89/* Internal surface data */
91
92/**
93 * A collection of pixels used in software blitting.
94 *
95 * Pixels are arranged in memory in rows, with the top row first. Each row
96 * occupies an amount of memory given by the pitch (sometimes known as the row
97 * stride in non-SDL APIs).
98 *
99 * Within each row, pixels are arranged from left to right until the width is
100 * reached. Each pixel occupies a number of bits appropriate for its format,
101 * with most formats representing each pixel as one or more whole bytes (in
102 * some indexed formats, instead multiple pixels are packed into each byte),
103 * and a byte order given by the format. After encoding all pixels, any
104 * remaining bytes to reach the pitch are used as padding to reach a desired
105 * alignment, and have undefined contents.
106 *
107 * \since This struct is available since SDL 3.0.0.
108 */
109typedef struct SDL_Surface
110{
111 SDL_SurfaceFlags flags; /**< Read-only */
112 SDL_PixelFormat format; /**< Read-only */
113 int w, h; /**< Read-only */
114 int pitch; /**< Read-only */
115 void *pixels; /**< Read-only pointer, writable pixels if non-NULL */
116
117 int refcount; /**< Application reference count, used when freeing surface */
118
119 SDL_SurfaceData *internal; /**< Private */
120
122
123
124/**
125 * Allocate a new surface with a specific pixel format.
126 *
127 * The pixels of the new surface are initialized to zero.
128 *
129 * \param width the width of the surface.
130 * \param height the height of the surface.
131 * \param format the SDL_PixelFormat for the new surface's pixel format.
132 * \returns the new SDL_Surface structure that is created or NULL on failure;
133 * call SDL_GetError() for more information.
134 *
135 * \since This function is available since SDL 3.0.0.
136 *
137 * \sa SDL_CreateSurfaceFrom
138 * \sa SDL_DestroySurface
139 */
140extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
141
142/**
143 * Allocate a new surface with a specific pixel format and existing pixel
144 * data.
145 *
146 * No copy is made of the pixel data. Pixel data is not managed automatically;
147 * you must free the surface before you free the pixel data.
148 *
149 * Pitch is the offset in bytes from one row of pixels to the next, e.g.
150 * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
151 *
152 * You may pass NULL for pixels and 0 for pitch to create a surface that you
153 * will fill in with valid values later.
154 *
155 * \param width the width of the surface.
156 * \param height the height of the surface.
157 * \param format the SDL_PixelFormat for the new surface's pixel format.
158 * \param pixels a pointer to existing pixel data.
159 * \param pitch the number of bytes between each row, including padding.
160 * \returns the new SDL_Surface structure that is created or NULL on failure;
161 * call SDL_GetError() for more information.
162 *
163 * \since This function is available since SDL 3.0.0.
164 *
165 * \sa SDL_CreateSurface
166 * \sa SDL_DestroySurface
167 */
168extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
169
170/**
171 * Free a surface.
172 *
173 * It is safe to pass NULL to this function.
174 *
175 * \param surface the SDL_Surface to free.
176 *
177 * \since This function is available since SDL 3.0.0.
178 *
179 * \sa SDL_CreateStackSurface
180 * \sa SDL_CreateSurface
181 * \sa SDL_CreateSurfaceFrom
182 */
183extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
184
185/**
186 * Get the properties associated with a surface.
187 *
188 * The following properties are understood by SDL:
189 *
190 * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
191 * surfaces, this defines the value of 100% diffuse white, with higher
192 * values being displayed in the High Dynamic Range headroom. This defaults
193 * to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
194 * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
195 * surfaces, this defines the maximum dynamic range used by the content, in
196 * terms of the SDR white point. This defaults to 0.0, which disables tone
197 * mapping.
198 * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
199 * used when compressing from a surface with high dynamic range to another
200 * with lower dynamic range. Currently this supports "chrome", which uses
201 * the same tone mapping that Chrome uses for HDR content, the form "*=N",
202 * where N is a floating point scale factor applied in linear space, and
203 * "none", which disables tone mapping. This defaults to "chrome".
204 *
205 * \param surface the SDL_Surface structure to query.
206 * \returns a valid property ID on success or 0 on failure; call
207 * SDL_GetError() for more information.
208 *
209 * \since This function is available since SDL 3.0.0.
210 */
211extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
212
213#define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
214#define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
215#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
216
217/**
218 * Set the colorspace used by a surface.
219 *
220 * Setting the colorspace doesn't change the pixels, only how they are
221 * interpreted in color operations.
222 *
223 * \param surface the SDL_Surface structure to update.
224 * \param colorspace an SDL_ColorSpace value describing the surface
225 * colorspace.
226 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
227 * for more information.
228 *
229 * \since This function is available since SDL 3.0.0.
230 *
231 * \sa SDL_GetSurfaceColorspace
232 */
233extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
234
235/**
236 * Get the colorspace used by a surface.
237 *
238 * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
239 * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
240 * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
241 *
242 * \param surface the SDL_Surface structure to query.
243 * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
244 * the surface is NULL.
245 *
246 * \since This function is available since SDL 3.0.0.
247 *
248 * \sa SDL_SetSurfaceColorspace
249 */
250extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
251
252/**
253 * Create a palette and associate it with a surface.
254 *
255 * This function creates a palette compatible with the provided surface. The
256 * palette is then returned for you to modify, and the surface will
257 * automatically use the new palette in future operations. You do not need to
258 * destroy the returned palette, it will be freed when the reference count
259 * reaches 0, usually when the surface is destroyed.
260 *
261 * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
262 * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
263 * white and 1 as black. Other surfaces will get a palette initialized with
264 * white in every entry.
265 *
266 * If this function is called for a surface that already has a palette, a new
267 * palette will be created to replace it.
268 *
269 * \param surface the SDL_Surface structure to update.
270 * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
271 * the surface didn't have an index format); call SDL_GetError() for
272 * more information.
273 *
274 * \since This function is available since SDL 3.0.0.
275 *
276 * \sa SDL_SetPaletteColors
277 */
278extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
279
280/**
281 * Set the palette used by a surface.
282 *
283 * A single palette can be shared with many surfaces.
284 *
285 * \param surface the SDL_Surface structure to update.
286 * \param palette the SDL_Palette structure to use.
287 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
288 * for more information.
289 *
290 * \since This function is available since SDL 3.0.0.
291 *
292 * \sa SDL_CreatePalette
293 * \sa SDL_GetSurfacePalette
294 */
295extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
296
297/**
298 * Get the palette used by a surface.
299 *
300 * \param surface the SDL_Surface structure to query.
301 * \returns a pointer to the palette used by the surface, or NULL if there is
302 * no palette used.
303 *
304 * \since This function is available since SDL 3.0.0.
305 *
306 * \sa SDL_SetSurfacePalette
307 */
308extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
309
310/**
311 * Add an alternate version of a surface.
312 *
313 * This function adds an alternate version of this surface, usually used for
314 * content with high DPI representations like cursors or icons. The size,
315 * format, and content do not need to match the original surface, and these
316 * alternate versions will not be updated when the original surface changes.
317 *
318 * This function adds a reference to the alternate version, so you should call
319 * SDL_DestroySurface() on the image after this call.
320 *
321 * \param surface the SDL_Surface structure to update.
322 * \param image a pointer to an alternate SDL_Surface to associate with this
323 * surface.
324 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
325 * for more information.
326 *
327 * \since This function is available since SDL 3.0.0.
328 *
329 * \sa SDL_RemoveSurfaceAlternateImages
330 * \sa SDL_GetSurfaceImages
331 * \sa SDL_SurfaceHasAlternateImages
332 */
333extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image);
334
335/**
336 * Return whether a surface has alternate versions available.
337 *
338 * \param surface the SDL_Surface structure to query.
339 * \returns SDL_TRUE if alternate versions are available or SDL_TRUE
340 * otherwise.
341 *
342 * \since This function is available since SDL 3.0.0.
343 *
344 * \sa SDL_AddSurfaceAlternateImage
345 * \sa SDL_RemoveSurfaceAlternateImages
346 * \sa SDL_GetSurfaceImages
347 */
348extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasAlternateImages(SDL_Surface *surface);
349
350/**
351 * Get an array including all versions of a surface.
352 *
353 * This returns all versions of a surface, with the surface being queried as
354 * the first element in the returned array.
355 *
356 * Freeing the array of surfaces does not affect the surfaces in the array.
357 * They are still referenced by the surface being queried and will be cleaned
358 * up normally.
359 *
360 * \param surface the SDL_Surface structure to query.
361 * \param count a pointer filled in with the number of surface pointers
362 * returned, may be NULL.
363 * \returns a NULL terminated array of SDL_Surface pointers or NULL on
364 * failure; call SDL_GetError() for more information. This should be
365 * freed with SDL_free() when it is no longer needed.
366 *
367 * \since This function is available since SDL 3.0.0.
368 *
369 * \sa SDL_AddSurfaceAlternateImage
370 * \sa SDL_RemoveSurfaceAlternateImages
371 * \sa SDL_SurfaceHasAlternateImages
372 */
373extern SDL_DECLSPEC SDL_Surface ** SDLCALL SDL_GetSurfaceImages(SDL_Surface *surface, int *count);
374
375/**
376 * Remove all alternate versions of a surface.
377 *
378 * This function removes a reference from all the alternative versions,
379 * destroying them if this is the last reference to them.
380 *
381 * \param surface the SDL_Surface structure to update.
382 *
383 * \since This function is available since SDL 3.0.0.
384 *
385 * \sa SDL_AddSurfaceAlternateImage
386 * \sa SDL_GetSurfaceImages
387 * \sa SDL_SurfaceHasAlternateImages
388 */
389extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface);
390
391/**
392 * Set up a surface for directly accessing the pixels.
393 *
394 * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
395 * and read from `surface->pixels`, using the pixel format stored in
396 * `surface->format`. Once you are done accessing the surface, you should use
397 * SDL_UnlockSurface() to release it.
398 *
399 * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
400 * 0, then you can read and write to the surface at any time, and the pixel
401 * format of the surface will not change.
402 *
403 * \param surface the SDL_Surface structure to be locked.
404 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
405 * for more information.
406 *
407 * \since This function is available since SDL 3.0.0.
408 *
409 * \sa SDL_MUSTLOCK
410 * \sa SDL_UnlockSurface
411 */
412extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockSurface(SDL_Surface *surface);
413
414/**
415 * Release a surface after directly accessing the pixels.
416 *
417 * \param surface the SDL_Surface structure to be unlocked.
418 *
419 * \since This function is available since SDL 3.0.0.
420 *
421 * \sa SDL_LockSurface
422 */
423extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
424
425/**
426 * Load a BMP image from a seekable SDL data stream.
427 *
428 * The new surface should be freed with SDL_DestroySurface(). Not doing so
429 * will result in a memory leak.
430 *
431 * \param src the data stream for the surface.
432 * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
433 * even in the case of an error.
434 * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
435 * SDL_GetError() for more information.
436 *
437 * \since This function is available since SDL 3.0.0.
438 *
439 * \sa SDL_DestroySurface
440 * \sa SDL_LoadBMP
441 * \sa SDL_SaveBMP_IO
442 */
443extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio);
444
445/**
446 * Load a BMP image from a file.
447 *
448 * The new surface should be freed with SDL_DestroySurface(). Not doing so
449 * will result in a memory leak.
450 *
451 * \param file the BMP file to load.
452 * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
453 * SDL_GetError() for more information.
454 *
455 * \since This function is available since SDL 3.0.0.
456 *
457 * \sa SDL_DestroySurface
458 * \sa SDL_LoadBMP_IO
459 * \sa SDL_SaveBMP
460 */
461extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
462
463/**
464 * Save a surface to a seekable SDL data stream in BMP format.
465 *
466 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
467 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
468 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
469 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
470 * not supported.
471 *
472 * \param surface the SDL_Surface structure containing the image to be saved.
473 * \param dst a data stream to save to.
474 * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `dst` before returning,
475 * even in the case of an error.
476 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
477 * for more information.
478 *
479 * \since This function is available since SDL 3.0.0.
480 *
481 * \sa SDL_LoadBMP_IO
482 * \sa SDL_SaveBMP
483 */
484extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio);
485
486/**
487 * Save a surface to a file.
488 *
489 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
490 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
491 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
492 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
493 * not supported.
494 *
495 * \param surface the SDL_Surface structure containing the image to be saved.
496 * \param file a file to save to.
497 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
498 * for more information.
499 *
500 * \since This function is available since SDL 3.0.0.
501 *
502 * \sa SDL_LoadBMP
503 * \sa SDL_SaveBMP_IO
504 */
505extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
506
507/**
508 * Set the RLE acceleration hint for a surface.
509 *
510 * If RLE is enabled, color key and alpha blending blits are much faster, but
511 * the surface must be locked before directly accessing the pixels.
512 *
513 * \param surface the SDL_Surface structure to optimize.
514 * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable
515 * it.
516 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
517 * for more information.
518 *
519 * \since This function is available since SDL 3.0.0.
520 *
521 * \sa SDL_BlitSurface
522 * \sa SDL_LockSurface
523 * \sa SDL_UnlockSurface
524 */
525extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled);
526
527/**
528 * Returns whether the surface is RLE enabled.
529 *
530 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
531 *
532 * \param surface the SDL_Surface structure to query.
533 * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
534 *
535 * \since This function is available since SDL 3.0.0.
536 *
537 * \sa SDL_SetSurfaceRLE
538 */
539extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
540
541/**
542 * Set the color key (transparent pixel) in a surface.
543 *
544 * The color key defines a pixel value that will be treated as transparent in
545 * a blit. For example, one can use this to specify that cyan pixels should be
546 * considered transparent, and therefore not rendered.
547 *
548 * It is a pixel of the format used by the surface, as generated by
549 * SDL_MapRGB().
550 *
551 * \param surface the SDL_Surface structure to update.
552 * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color
553 * key.
554 * \param key the transparent pixel.
555 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
556 * for more information.
557 *
558 * \since This function is available since SDL 3.0.0.
559 *
560 * \sa SDL_GetSurfaceColorKey
561 * \sa SDL_SetSurfaceRLE
562 * \sa SDL_SurfaceHasColorKey
563 */
564extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key);
565
566/**
567 * Returns whether the surface has a color key.
568 *
569 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
570 *
571 * \param surface the SDL_Surface structure to query.
572 * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
573 *
574 * \since This function is available since SDL 3.0.0.
575 *
576 * \sa SDL_SetSurfaceColorKey
577 * \sa SDL_GetSurfaceColorKey
578 */
579extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
580
581/**
582 * Get the color key (transparent pixel) for a surface.
583 *
584 * The color key is a pixel of the format used by the surface, as generated by
585 * SDL_MapRGB().
586 *
587 * If the surface doesn't have color key enabled this function returns
588 * SDL_FALSE.
589 *
590 * \param surface the SDL_Surface structure to query.
591 * \param key a pointer filled in with the transparent pixel.
592 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
593 * for more information.
594 *
595 * \since This function is available since SDL 3.0.0.
596 *
597 * \sa SDL_SetSurfaceColorKey
598 * \sa SDL_SurfaceHasColorKey
599 */
600extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
601
602/**
603 * Set an additional color value multiplied into blit operations.
604 *
605 * When this surface is blitted, during the blit operation each source color
606 * channel is modulated by the appropriate color value according to the
607 * following formula:
608 *
609 * `srcC = srcC * (color / 255)`
610 *
611 * \param surface the SDL_Surface structure to update.
612 * \param r the red color value multiplied into blit operations.
613 * \param g the green color value multiplied into blit operations.
614 * \param b the blue color value multiplied into blit operations.
615 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
616 * for more information.
617 *
618 * \since This function is available since SDL 3.0.0.
619 *
620 * \sa SDL_GetSurfaceColorMod
621 * \sa SDL_SetSurfaceAlphaMod
622 */
623extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
624
625
626/**
627 * Get the additional color value multiplied into blit operations.
628 *
629 * \param surface the SDL_Surface structure to query.
630 * \param r a pointer filled in with the current red color value.
631 * \param g a pointer filled in with the current green color value.
632 * \param b a pointer filled in with the current blue color value.
633 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
634 * for more information.
635 *
636 * \since This function is available since SDL 3.0.0.
637 *
638 * \sa SDL_GetSurfaceAlphaMod
639 * \sa SDL_SetSurfaceColorMod
640 */
641extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
642
643/**
644 * Set an additional alpha value used in blit operations.
645 *
646 * When this surface is blitted, during the blit operation the source alpha
647 * value is modulated by this alpha value according to the following formula:
648 *
649 * `srcA = srcA * (alpha / 255)`
650 *
651 * \param surface the SDL_Surface structure to update.
652 * \param alpha the alpha value multiplied into blit operations.
653 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
654 * for more information.
655 *
656 * \since This function is available since SDL 3.0.0.
657 *
658 * \sa SDL_GetSurfaceAlphaMod
659 * \sa SDL_SetSurfaceColorMod
660 */
661extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
662
663/**
664 * Get the additional alpha value used in blit operations.
665 *
666 * \param surface the SDL_Surface structure to query.
667 * \param alpha a pointer filled in with the current alpha value.
668 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
669 * for more information.
670 *
671 * \since This function is available since SDL 3.0.0.
672 *
673 * \sa SDL_GetSurfaceColorMod
674 * \sa SDL_SetSurfaceAlphaMod
675 */
676extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
677
678/**
679 * Set the blend mode used for blit operations.
680 *
681 * To copy a surface to another surface (or texture) without blending with the
682 * existing data, the blendmode of the SOURCE surface should be set to
683 * `SDL_BLENDMODE_NONE`.
684 *
685 * \param surface the SDL_Surface structure to update.
686 * \param blendMode the SDL_BlendMode to use for blit blending.
687 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
688 * for more information.
689 *
690 * \since This function is available since SDL 3.0.0.
691 *
692 * \sa SDL_GetSurfaceBlendMode
693 */
694extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
695
696/**
697 * Get the blend mode used for blit operations.
698 *
699 * \param surface the SDL_Surface structure to query.
700 * \param blendMode a pointer filled in with the current SDL_BlendMode.
701 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
702 * for more information.
703 *
704 * \since This function is available since SDL 3.0.0.
705 *
706 * \sa SDL_SetSurfaceBlendMode
707 */
708extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
709
710/**
711 * Set the clipping rectangle for a surface.
712 *
713 * When `surface` is the destination of a blit, only the area within the clip
714 * rectangle is drawn into.
715 *
716 * Note that blits are automatically clipped to the edges of the source and
717 * destination surfaces.
718 *
719 * \param surface the SDL_Surface structure to be clipped.
720 * \param rect the SDL_Rect structure representing the clipping rectangle, or
721 * NULL to disable clipping.
722 * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
723 * SDL_FALSE and blits will be completely clipped.
724 *
725 * \since This function is available since SDL 3.0.0.
726 *
727 * \sa SDL_GetSurfaceClipRect
728 */
729extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
730
731/**
732 * Get the clipping rectangle for a surface.
733 *
734 * When `surface` is the destination of a blit, only the area within the clip
735 * rectangle is drawn into.
736 *
737 * \param surface the SDL_Surface structure representing the surface to be
738 * clipped.
739 * \param rect an SDL_Rect structure filled in with the clipping rectangle for
740 * the surface.
741 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
742 * for more information.
743 *
744 * \since This function is available since SDL 3.0.0.
745 *
746 * \sa SDL_SetSurfaceClipRect
747 */
748extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
749
750/**
751 * Flip a surface vertically or horizontally.
752 *
753 * \param surface the surface to flip.
754 * \param flip the direction to flip.
755 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
756 * for more information.
757 *
758 * \since This function is available since SDL 3.0.0.
759 */
760extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
761
762/**
763 * Creates a new surface identical to the existing surface.
764 *
765 * If the original surface has alternate images, the new surface will have a
766 * reference to them as well.
767 *
768 * The returned surface should be freed with SDL_DestroySurface().
769 *
770 * \param surface the surface to duplicate.
771 * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
772 * more information.
773 *
774 * \since This function is available since SDL 3.0.0.
775 *
776 * \sa SDL_DestroySurface
777 */
778extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
779
780/**
781 * Creates a new surface identical to the existing surface, scaled to the
782 * desired size.
783 *
784 * The returned surface should be freed with SDL_DestroySurface().
785 *
786 * \param surface the surface to duplicate and scale.
787 * \param width the width of the new surface.
788 * \param height the height of the new surface.
789 * \param scaleMode the SDL_ScaleMode to be used.
790 * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
791 * more information.
792 *
793 * \since This function is available since SDL 3.0.0.
794 *
795 * \sa SDL_DestroySurface
796 */
797extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode);
798
799/**
800 * Copy an existing surface to a new surface of the specified format.
801 *
802 * This function is used to optimize images for faster *repeat* blitting. This
803 * is accomplished by converting the original and storing the result as a new
804 * surface. The new, optimized surface can then be used as the source for
805 * future blits, making them faster.
806 *
807 * If you are converting to an indexed surface and want to map colors to a
808 * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
809 *
810 * If the original surface has alternate images, the new surface will have a
811 * reference to them as well.
812 *
813 * \param surface the existing SDL_Surface structure to convert.
814 * \param format the new pixel format.
815 * \returns the new SDL_Surface structure that is created or NULL on failure;
816 * call SDL_GetError() for more information.
817 *
818 * \since This function is available since SDL 3.0.0.
819 *
820 * \sa SDL_ConvertSurfaceAndColorspace
821 * \sa SDL_DestroySurface
822 */
823extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
824
825/**
826 * Copy an existing surface to a new surface of the specified format and
827 * colorspace.
828 *
829 * This function converts an existing surface to a new format and colorspace
830 * and returns the new surface. This will perform any pixel format and
831 * colorspace conversion needed.
832 *
833 * If the original surface has alternate images, the new surface will have a
834 * reference to them as well.
835 *
836 * \param surface the existing SDL_Surface structure to convert.
837 * \param format the new pixel format.
838 * \param palette an optional palette to use for indexed formats, may be NULL.
839 * \param colorspace the new colorspace.
840 * \param props an SDL_PropertiesID with additional color properties, or 0.
841 * \returns the new SDL_Surface structure that is created or NULL on failure;
842 * call SDL_GetError() for more information.
843 *
844 * \since This function is available since SDL 3.0.0.
845 *
846 * \sa SDL_ConvertSurface
847 * \sa SDL_ConvertSurface
848 * \sa SDL_DestroySurface
849 */
850extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
851
852/**
853 * Copy a block of pixels of one format to another format.
854 *
855 * \param width the width of the block to copy, in pixels.
856 * \param height the height of the block to copy, in pixels.
857 * \param src_format an SDL_PixelFormat value of the `src` pixels format.
858 * \param src a pointer to the source pixels.
859 * \param src_pitch the pitch of the source pixels, in bytes.
860 * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
861 * \param dst a pointer to be filled in with new pixel data.
862 * \param dst_pitch the pitch of the destination pixels, in bytes.
863 * \returns SDL_FALSE on success or SDL_FALSE on failure; call SDL_GetError()
864 * for more information.
865 *
866 * \since This function is available since SDL 3.0.0.
867 *
868 * \sa SDL_ConvertPixelsAndColorspace
869 */
870extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch);
871
872/**
873 * Copy a block of pixels of one format and colorspace to another format and
874 * colorspace.
875 *
876 * \param width the width of the block to copy, in pixels.
877 * \param height the height of the block to copy, in pixels.
878 * \param src_format an SDL_PixelFormat value of the `src` pixels format.
879 * \param src_colorspace an SDL_ColorSpace value describing the colorspace of
880 * the `src` pixels.
881 * \param src_properties an SDL_PropertiesID with additional source color
882 * properties, or 0.
883 * \param src a pointer to the source pixels.
884 * \param src_pitch the pitch of the source pixels, in bytes.
885 * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
886 * \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
887 * the `dst` pixels.
888 * \param dst_properties an SDL_PropertiesID with additional destination color
889 * properties, or 0.
890 * \param dst a pointer to be filled in with new pixel data.
891 * \param dst_pitch the pitch of the destination pixels, in bytes.
892 * \returns SDL_FALSE on success or SDL_FALSE on failure; call SDL_GetError()
893 * for more information.
894 *
895 * \since This function is available since SDL 3.0.0.
896 *
897 * \sa SDL_ConvertPixels
898 */
899extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
900
901/**
902 * Premultiply the alpha on a block of pixels.
903 *
904 * This is safe to use with src == dst, but not for other overlapping areas.
905 *
906 * \param width the width of the block to convert, in pixels.
907 * \param height the height of the block to convert, in pixels.
908 * \param src_format an SDL_PixelFormat value of the `src` pixels format.
909 * \param src a pointer to the source pixels.
910 * \param src_pitch the pitch of the source pixels, in bytes.
911 * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
912 * \param dst a pointer to be filled in with premultiplied pixel data.
913 * \param dst_pitch the pitch of the destination pixels, in bytes.
914 * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha
915 * multiplication, SDL_FALSE to do multiplication in sRGB space.
916 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
917 * for more information.
918 *
919 * \since This function is available since SDL 3.0.0.
920 */
921extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, SDL_bool linear);
922
923/**
924 * Premultiply the alpha in a surface.
925 *
926 * This is safe to use with src == dst, but not for other overlapping areas.
927 *
928 * \param surface the surface to modify.
929 * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha
930 * multiplication, SDL_FALSE to do multiplication in sRGB space.
931 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
932 * for more information.
933 *
934 * \since This function is available since SDL 3.0.0.
935 */
936extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear);
937
938/**
939 * Clear a surface with a specific color, with floating point precision.
940 *
941 * This function handles all surface formats, and ignores any clip rectangle.
942 *
943 * If the surface is YUV, the color is assumed to be in the sRGB colorspace,
944 * otherwise the color is assumed to be in the colorspace of the suface.
945 *
946 * \param surface the SDL_Surface to clear.
947 * \param r the red component of the pixel, normally in the range 0-1.
948 * \param g the green component of the pixel, normally in the range 0-1.
949 * \param b the blue component of the pixel, normally in the range 0-1.
950 * \param a the alpha component of the pixel, normally in the range 0-1.
951 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
952 * for more information.
953 *
954 * \since This function is available since SDL 3.0.0.
955 */
956extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a);
957
958/**
959 * Perform a fast fill of a rectangle with a specific color.
960 *
961 * `color` should be a pixel of the format used by the surface, and can be
962 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
963 * alpha component then the destination is simply filled with that alpha
964 * information, no blending takes place.
965 *
966 * If there is a clip rectangle set on the destination (set via
967 * SDL_SetSurfaceClipRect()), then this function will fill based on the
968 * intersection of the clip rectangle and `rect`.
969 *
970 * \param dst the SDL_Surface structure that is the drawing target.
971 * \param rect the SDL_Rect structure representing the rectangle to fill, or
972 * NULL to fill the entire surface.
973 * \param color the color to fill with.
974 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
975 * for more information.
976 *
977 * \since This function is available since SDL 3.0.0.
978 *
979 * \sa SDL_FillSurfaceRects
980 */
981extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
982
983/**
984 * Perform a fast fill of a set of rectangles with a specific color.
985 *
986 * `color` should be a pixel of the format used by the surface, and can be
987 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
988 * alpha component then the destination is simply filled with that alpha
989 * information, no blending takes place.
990 *
991 * If there is a clip rectangle set on the destination (set via
992 * SDL_SetSurfaceClipRect()), then this function will fill based on the
993 * intersection of the clip rectangle and `rect`.
994 *
995 * \param dst the SDL_Surface structure that is the drawing target.
996 * \param rects an array of SDL_Rects representing the rectangles to fill.
997 * \param count the number of rectangles in the array.
998 * \param color the color to fill with.
999 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1000 * for more information.
1001 *
1002 * \since This function is available since SDL 3.0.0.
1003 *
1004 * \sa SDL_FillSurfaceRect
1005 */
1006extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
1007
1008/**
1009 * Performs a fast blit from the source surface to the destination surface.
1010 *
1011 * This assumes that the source and destination rectangles are the same size.
1012 * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
1013 * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
1014 * `dstrect` after all clipping is performed.
1015 *
1016 * The blit function should not be called on a locked surface.
1017 *
1018 * The blit semantics for surfaces with and without blending and colorkey are
1019 * defined as follows:
1020 *
1021 * ```
1022 * RGBA->RGB:
1023 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
1024 * alpha-blend (using the source alpha-channel and per-surface alpha)
1025 * SDL_SRCCOLORKEY ignored.
1026 * Source surface blend mode set to SDL_BLENDMODE_NONE:
1027 * copy RGB.
1028 * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
1029 * RGB values of the source color key, ignoring alpha in the
1030 * comparison.
1031 *
1032 * RGB->RGBA:
1033 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
1034 * alpha-blend (using the source per-surface alpha)
1035 * Source surface blend mode set to SDL_BLENDMODE_NONE:
1036 * copy RGB, set destination alpha to source per-surface alpha value.
1037 * both:
1038 * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
1039 * source color key.
1040 *
1041 * RGBA->RGBA:
1042 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
1043 * alpha-blend (using the source alpha-channel and per-surface alpha)
1044 * SDL_SRCCOLORKEY ignored.
1045 * Source surface blend mode set to SDL_BLENDMODE_NONE:
1046 * copy all of RGBA to the destination.
1047 * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
1048 * RGB values of the source color key, ignoring alpha in the
1049 * comparison.
1050 *
1051 * RGB->RGB:
1052 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
1053 * alpha-blend (using the source per-surface alpha)
1054 * Source surface blend mode set to SDL_BLENDMODE_NONE:
1055 * copy RGB.
1056 * both:
1057 * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
1058 * source color key.
1059 * ```
1060 *
1061 * \param src the SDL_Surface structure to be copied from.
1062 * \param srcrect the SDL_Rect structure representing the rectangle to be
1063 * copied, or NULL to copy the entire surface.
1064 * \param dst the SDL_Surface structure that is the blit target.
1065 * \param dstrect the SDL_Rect structure representing the x and y position in
1066 * the destination surface, or NULL for (0,0). The width and
1067 * height are ignored, and are copied from `srcrect`. If you
1068 * want a specific width and height, you should use
1069 * SDL_BlitSurfaceScaled().
1070 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1071 * for more information.
1072 *
1073 * \threadsafety The same destination surface should not be used from two
1074 * threads at once. It is safe to use the same source surface
1075 * from multiple threads.
1076 *
1077 * \since This function is available since SDL 3.0.0.
1078 *
1079 * \sa SDL_BlitSurfaceScaled
1080 */
1081extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
1082
1083/**
1084 * Perform low-level surface blitting only.
1085 *
1086 * This is a semi-private blit function and it performs low-level surface
1087 * blitting, assuming the input rectangles have already been clipped.
1088 *
1089 * \param src the SDL_Surface structure to be copied from.
1090 * \param srcrect the SDL_Rect structure representing the rectangle to be
1091 * copied, may not be NULL.
1092 * \param dst the SDL_Surface structure that is the blit target.
1093 * \param dstrect the SDL_Rect structure representing the target rectangle in
1094 * the destination surface, may not be NULL.
1095 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1096 * for more information.
1097 *
1098 * \threadsafety The same destination surface should not be used from two
1099 * threads at once. It is safe to use the same source surface
1100 * from multiple threads.
1101 *
1102 * \since This function is available since SDL 3.0.0.
1103 *
1104 * \sa SDL_BlitSurface
1105 */
1106extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
1107
1108/**
1109 * Perform a scaled blit to a destination surface, which may be of a different
1110 * format.
1111 *
1112 * \param src the SDL_Surface structure to be copied from.
1113 * \param srcrect the SDL_Rect structure representing the rectangle to be
1114 * copied, or NULL to copy the entire surface.
1115 * \param dst the SDL_Surface structure that is the blit target.
1116 * \param dstrect the SDL_Rect structure representing the target rectangle in
1117 * the destination surface, or NULL to fill the entire
1118 * destination surface.
1119 * \param scaleMode the SDL_ScaleMode to be used.
1120 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1121 * for more information.
1122 *
1123 * \threadsafety The same destination surface should not be used from two
1124 * threads at once. It is safe to use the same source surface
1125 * from multiple threads.
1126 *
1127 * \since This function is available since SDL 3.0.0.
1128 *
1129 * \sa SDL_BlitSurface
1130 */
1131extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
1132
1133/**
1134 * Perform low-level surface scaled blitting only.
1135 *
1136 * This is a semi-private function and it performs low-level surface blitting,
1137 * assuming the input rectangles have already been clipped.
1138 *
1139 * \param src the SDL_Surface structure to be copied from.
1140 * \param srcrect the SDL_Rect structure representing the rectangle to be
1141 * copied, may not be NULL.
1142 * \param dst the SDL_Surface structure that is the blit target.
1143 * \param dstrect the SDL_Rect structure representing the target rectangle in
1144 * the destination surface, may not be NULL.
1145 * \param scaleMode the SDL_ScaleMode to be used.
1146 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1147 * for more information.
1148 *
1149 * \threadsafety The same destination surface should not be used from two
1150 * threads at once. It is safe to use the same source surface
1151 * from multiple threads.
1152 *
1153 * \since This function is available since SDL 3.0.0.
1154 *
1155 * \sa SDL_BlitSurfaceScaled
1156 */
1157extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
1158
1159/**
1160 * Perform a tiled blit to a destination surface, which may be of a different
1161 * format.
1162 *
1163 * The pixels in `srcrect` will be repeated as many times as needed to
1164 * completely fill `dstrect`.
1165 *
1166 * \param src the SDL_Surface structure to be copied from.
1167 * \param srcrect the SDL_Rect structure representing the rectangle to be
1168 * copied, or NULL to copy the entire surface.
1169 * \param dst the SDL_Surface structure that is the blit target.
1170 * \param dstrect the SDL_Rect structure representing the target rectangle in
1171 * the destination surface, or NULL to fill the entire surface.
1172 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1173 * for more information.
1174 *
1175 * \threadsafety The same destination surface should not be used from two
1176 * threads at once. It is safe to use the same source surface
1177 * from multiple threads.
1178 *
1179 * \since This function is available since SDL 3.0.0.
1180 *
1181 * \sa SDL_BlitSurface
1182 */
1183extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
1184
1185/**
1186 * Perform a scaled and tiled blit to a destination surface, which may be of a
1187 * different format.
1188 *
1189 * The pixels in `srcrect` will be scaled and repeated as many times as needed
1190 * to completely fill `dstrect`.
1191 *
1192 * \param src the SDL_Surface structure to be copied from.
1193 * \param srcrect the SDL_Rect structure representing the rectangle to be
1194 * copied, or NULL to copy the entire surface.
1195 * \param scale the scale used to transform srcrect into the destination
1196 * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
1197 * 64x64 tiles.
1198 * \param scaleMode scale algorithm to be used.
1199 * \param dst the SDL_Surface structure that is the blit target.
1200 * \param dstrect the SDL_Rect structure representing the target rectangle in
1201 * the destination surface, or NULL to fill the entire surface.
1202 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1203 * for more information.
1204 *
1205 * \threadsafety The same destination surface should not be used from two
1206 * threads at once. It is safe to use the same source surface
1207 * from multiple threads.
1208 *
1209 * \since This function is available since SDL 3.0.0.
1210 *
1211 * \sa SDL_BlitSurface
1212 */
1213extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect);
1214
1215/**
1216 * Perform a scaled blit using the 9-grid algorithm to a destination surface,
1217 * which may be of a different format.
1218 *
1219 * The pixels in the source surface are split into a 3x3 grid, using the
1220 * different corner sizes for each corner, and the sides and center making up
1221 * the remaining pixels. The corners are then scaled using `scale` and fit
1222 * into the corners of the destination rectangle. The sides and center are
1223 * then stretched into place to cover the remaining destination rectangle.
1224 *
1225 * \param src the SDL_Surface structure to be copied from.
1226 * \param srcrect the SDL_Rect structure representing the rectangle to be used
1227 * for the 9-grid, or NULL to use the entire surface.
1228 * \param left_width the width, in pixels, of the left corners in `srcrect`.
1229 * \param right_width the width, in pixels, of the right corners in `srcrect`.
1230 * \param top_height the height, in pixels, of the top corners in `srcrect`.
1231 * \param bottom_height the height, in pixels, of the bottom corners in
1232 * `srcrect`.
1233 * \param scale the scale used to transform the corner of `srcrect` into the
1234 * corner of `dstrect`, or 0.0f for an unscaled blit.
1235 * \param scaleMode scale algorithm to be used.
1236 * \param dst the SDL_Surface structure that is the blit target.
1237 * \param dstrect the SDL_Rect structure representing the target rectangle in
1238 * the destination surface, or NULL to fill the entire surface.
1239 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1240 * for more information.
1241 *
1242 * \threadsafety The same destination surface should not be used from two
1243 * threads at once. It is safe to use the same source surface
1244 * from multiple threads.
1245 *
1246 * \since This function is available since SDL 3.0.0.
1247 *
1248 * \sa SDL_BlitSurface
1249 */
1250extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect);
1251
1252/**
1253 * Map an RGB triple to an opaque pixel value for a surface.
1254 *
1255 * This function maps the RGB color value to the specified pixel format and
1256 * returns the pixel value best approximating the given RGB color value for
1257 * the given pixel format.
1258 *
1259 * If the surface has a palette, the index of the closest matching color in
1260 * the palette will be returned.
1261 *
1262 * If the surface pixel format has an alpha component it will be returned as
1263 * all 1 bits (fully opaque).
1264 *
1265 * If the pixel format bpp (color depth) is less than 32-bpp then the unused
1266 * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
1267 * format the return value can be assigned to a Uint16, and similarly a Uint8
1268 * for an 8-bpp format).
1269 *
1270 * \param surface the surface to use for the pixel format and palette.
1271 * \param r the red component of the pixel in the range 0-255.
1272 * \param g the green component of the pixel in the range 0-255.
1273 * \param b the blue component of the pixel in the range 0-255.
1274 * \returns a pixel value.
1275 *
1276 * \since This function is available since SDL 3.0.0.
1277 *
1278 * \sa SDL_MapSurfaceRGBA
1279 */
1280extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
1281
1282/**
1283 * Map an RGBA quadruple to a pixel value for a surface.
1284 *
1285 * This function maps the RGBA color value to the specified pixel format and
1286 * returns the pixel value best approximating the given RGBA color value for
1287 * the given pixel format.
1288 *
1289 * If the surface pixel format has no alpha component the alpha value will be
1290 * ignored (as it will be in formats with a palette).
1291 *
1292 * If the surface has a palette, the index of the closest matching color in
1293 * the palette will be returned.
1294 *
1295 * If the pixel format bpp (color depth) is less than 32-bpp then the unused
1296 * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
1297 * format the return value can be assigned to a Uint16, and similarly a Uint8
1298 * for an 8-bpp format).
1299 *
1300 * \param surface the surface to use for the pixel format and palette.
1301 * \param r the red component of the pixel in the range 0-255.
1302 * \param g the green component of the pixel in the range 0-255.
1303 * \param b the blue component of the pixel in the range 0-255.
1304 * \param a the alpha component of the pixel in the range 0-255.
1305 * \returns a pixel value.
1306 *
1307 * \since This function is available since SDL 3.0.0.
1308 *
1309 * \sa SDL_MapSurfaceRGB
1310 */
1311extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1312
1313/**
1314 * Retrieves a single pixel from a surface.
1315 *
1316 * This function prioritizes correctness over speed: it is suitable for unit
1317 * tests, but is not intended for use in a game engine.
1318 *
1319 * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
1320 * components from pixel formats with less than 8 bits per RGB component.
1321 *
1322 * \param surface the surface to read.
1323 * \param x the horizontal coordinate, 0 <= x < width.
1324 * \param y the vertical coordinate, 0 <= y < height.
1325 * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
1326 * this channel.
1327 * \param g a pointer filled in with the green channel, 0-255, or NULL to
1328 * ignore this channel.
1329 * \param b a pointer filled in with the blue channel, 0-255, or NULL to
1330 * ignore this channel.
1331 * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
1332 * ignore this channel.
1333 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1334 * for more information.
1335 *
1336 * \since This function is available since SDL 3.0.0.
1337 */
1338extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
1339
1340/**
1341 * Retrieves a single pixel from a surface.
1342 *
1343 * This function prioritizes correctness over speed: it is suitable for unit
1344 * tests, but is not intended for use in a game engine.
1345 *
1346 * \param surface the surface to read.
1347 * \param x the horizontal coordinate, 0 <= x < width.
1348 * \param y the vertical coordinate, 0 <= y < height.
1349 * \param r a pointer filled in with the red channel, normally in the range
1350 * 0-1, or NULL to ignore this channel.
1351 * \param g a pointer filled in with the green channel, normally in the range
1352 * 0-1, or NULL to ignore this channel.
1353 * \param b a pointer filled in with the blue channel, normally in the range
1354 * 0-1, or NULL to ignore this channel.
1355 * \param a a pointer filled in with the alpha channel, normally in the range
1356 * 0-1, or NULL to ignore this channel.
1357 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1358 * for more information.
1359 *
1360 * \since This function is available since SDL 3.0.0.
1361 */
1362extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a);
1363
1364/**
1365 * Writes a single pixel to a surface.
1366 *
1367 * This function prioritizes correctness over speed: it is suitable for unit
1368 * tests, but is not intended for use in a game engine.
1369 *
1370 * Like SDL_MapRGBA, this uses the entire 0..255 range when converting color
1371 * components from pixel formats with less than 8 bits per RGB component.
1372 *
1373 * \param surface the surface to write.
1374 * \param x the horizontal coordinate, 0 <= x < width.
1375 * \param y the vertical coordinate, 0 <= y < height.
1376 * \param r the red channel value, 0-255.
1377 * \param g the green channel value, 0-255.
1378 * \param b the blue channel value, 0-255.
1379 * \param a the alpha channel value, 0-255.
1380 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1381 * for more information.
1382 *
1383 * \since This function is available since SDL 3.0.0.
1384 */
1385extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1386
1387/**
1388 * Writes a single pixel to a surface.
1389 *
1390 * This function prioritizes correctness over speed: it is suitable for unit
1391 * tests, but is not intended for use in a game engine.
1392 *
1393 * \param surface the surface to write.
1394 * \param x the horizontal coordinate, 0 <= x < width.
1395 * \param y the vertical coordinate, 0 <= y < height.
1396 * \param r the red channel value, normally in the range 0-1.
1397 * \param g the green channel value, normally in the range 0-1.
1398 * \param b the blue channel value, normally in the range 0-1.
1399 * \param a the alpha channel value, normally in the range 0-1.
1400 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1401 * for more information.
1402 *
1403 * \since This function is available since SDL 3.0.0.
1404 */
1405extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a);
1406
1407/* Ends C function definitions when using C++ */
1408#ifdef __cplusplus
1409}
1410#endif
1411#include <SDL3/SDL_close_code.h>
1412
1413#endif /* SDL_surface_h_ */
Uint32 SDL_BlendMode
struct SDL_IOStream SDL_IOStream
SDL_Colorspace
Definition SDL_pixels.h:594
SDL_PixelFormat
Definition SDL_pixels.h:265
Uint32 SDL_PropertiesID
uint8_t Uint8
Definition SDL_stdinc.h:317
uint32_t Uint32
Definition SDL_stdinc.h:353
bool SDL_bool
Definition SDL_stdinc.h:301
SDL_bool SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key)
SDL_bool SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key)
SDL_bool SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, SDL_bool linear)
SDL_Surface * SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio)
SDL_bool SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
SDL_bool SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
SDL_bool SDL_LockSurface(SDL_Surface *surface)
SDL_bool SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_bool SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch)
SDL_bool SDL_SaveBMP(SDL_Surface *surface, const char *file)
void SDL_DestroySurface(SDL_Surface *surface)
SDL_bool SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
Uint32 SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
SDL_bool SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
SDL_bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
SDL_bool SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip)
SDL_bool SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
SDL_bool SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
SDL_bool SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
SDL_Surface * SDL_DuplicateSurface(SDL_Surface *surface)
SDL_bool SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
SDL_bool SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
void SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface)
SDL_bool SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace)
SDL_bool SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled)
Uint32 SDL_SurfaceFlags
Definition SDL_surface.h:52
SDL_Palette * SDL_CreateSurfacePalette(SDL_Surface *surface)
SDL_bool SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
SDL_bool SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format)
SDL_Surface ** SDL_GetSurfaceImages(SDL_Surface *surface, int *count)
SDL_Palette * SDL_GetSurfacePalette(SDL_Surface *surface)
SDL_bool SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a)
SDL_bool SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
SDL_ScaleMode
Definition SDL_surface.h:72
@ SDL_SCALEMODE_LINEAR
Definition SDL_surface.h:74
@ SDL_SCALEMODE_NEAREST
Definition SDL_surface.h:73
SDL_bool SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
SDL_FlipMode
Definition SDL_surface.h:83
@ SDL_FLIP_VERTICAL
Definition SDL_surface.h:86
@ SDL_FLIP_NONE
Definition SDL_surface.h:84
@ SDL_FLIP_HORIZONTAL
Definition SDL_surface.h:85
SDL_Colorspace SDL_GetSurfaceColorspace(SDL_Surface *surface)
void SDL_UnlockSurface(SDL_Surface *surface)
SDL_bool SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear)
SDL_bool SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
SDL_Surface * SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props)
SDL_Surface * SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode)
struct SDL_SurfaceData SDL_SurfaceData
Definition SDL_surface.h:90
SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect)
Uint32 SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
SDL_bool SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
SDL_Surface * SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch)
SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface)
SDL_bool SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
SDL_bool SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
SDL_bool SDL_SurfaceHasAlternateImages(SDL_Surface *surface)
SDL_bool SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image)
SDL_bool SDL_SurfaceHasRLE(SDL_Surface *surface)
SDL_Surface * SDL_LoadBMP(const char *file)
SDL_bool SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_bool SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a)
SDL_bool SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_bool SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
SDL_Surface * SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
SDL_SurfaceFlags flags
SDL_PixelFormat format
void * pixels
SDL_SurfaceData * internal