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