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#ifndef SDL_INTERNAL
90
91/**
92 * A collection of pixels used in software blitting.
93 *
94 * Pixels are arranged in memory in rows, with the top row first. Each row
95 * occupies an amount of memory given by the pitch (sometimes known as the row
96 * stride in non-SDL APIs).
97 *
98 * Within each row, pixels are arranged from left to right until the width is
99 * reached. Each pixel occupies a number of bits appropriate for its format,
100 * with most formats representing each pixel as one or more whole bytes (in
101 * some indexed formats, instead multiple pixels are packed into each byte),
102 * and a byte order given by the format. After encoding all pixels, any
103 * remaining bytes to reach the pitch are used as padding to reach a desired
104 * alignment, and have undefined contents.
105 *
106 * \since This struct is available since SDL 3.0.0.
107 *
108 * \sa SDL_CreateSurface
109 * \sa SDL_DestroySurface
110 */
112{
113 SDL_SurfaceFlags flags; /**< The flags of the surface, read-only */
114 SDL_PixelFormat format; /**< The format of the surface, read-only */
115 int w; /**< The width of the surface, read-only. */
116 int h; /**< The height of the surface, read-only. */
117 int pitch; /**< The distance in bytes between rows of pixels, read-only */
118 void *pixels; /**< A pointer to the pixels of the surface, the pixels are writeable if non-NULL */
119
120 int refcount; /**< Application reference count, used when freeing surface */
121
122 void *reserved; /**< Reserved for internal use */
123};
124#endif /* !SDL_INTERNAL */
125
126typedef struct SDL_Surface SDL_Surface;
127
128/**
129 * Allocate a new surface with a specific pixel format.
130 *
131 * The pixels of the new surface are initialized to zero.
132 *
133 * \param width the width of the surface.
134 * \param height the height of the surface.
135 * \param format the SDL_PixelFormat for the new surface's pixel format.
136 * \returns the new SDL_Surface structure that is created or NULL on failure;
137 * call SDL_GetError() for more information.
138 *
139 * \since This function is available since SDL 3.0.0.
140 *
141 * \sa SDL_CreateSurfaceFrom
142 * \sa SDL_DestroySurface
143 */
144extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
145
146/**
147 * Allocate a new surface with a specific pixel format and existing pixel
148 * data.
149 *
150 * No copy is made of the pixel data. Pixel data is not managed automatically;
151 * you must free the surface before you free the pixel data.
152 *
153 * Pitch is the offset in bytes from one row of pixels to the next, e.g.
154 * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
155 *
156 * You may pass NULL for pixels and 0 for pitch to create a surface that you
157 * will fill in with valid values later.
158 *
159 * \param width the width of the surface.
160 * \param height the height of the surface.
161 * \param format the SDL_PixelFormat for the new surface's pixel format.
162 * \param pixels a pointer to existing pixel data.
163 * \param pitch the number of bytes between each row, including padding.
164 * \returns the new SDL_Surface structure that is created or NULL on failure;
165 * call SDL_GetError() for more information.
166 *
167 * \since This function is available since SDL 3.0.0.
168 *
169 * \sa SDL_CreateSurface
170 * \sa SDL_DestroySurface
171 */
172extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
173
174/**
175 * Free a surface.
176 *
177 * It is safe to pass NULL to this function.
178 *
179 * \param surface the SDL_Surface to free.
180 *
181 * \since This function is available since SDL 3.0.0.
182 *
183 * \sa SDL_CreateStackSurface
184 * \sa SDL_CreateSurface
185 * \sa SDL_CreateSurfaceFrom
186 */
187extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
188
189/**
190 * Get the properties associated with a surface.
191 *
192 * The following properties are understood by SDL:
193 *
194 * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
195 * surfaces, this defines the value of 100% diffuse white, with higher
196 * values being displayed in the High Dynamic Range headroom. This defaults
197 * to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
198 * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
199 * surfaces, this defines the maximum dynamic range used by the content, in
200 * terms of the SDR white point. This defaults to 0.0, which disables tone
201 * mapping.
202 * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
203 * used when compressing from a surface with high dynamic range to another
204 * with lower dynamic range. Currently this supports "chrome", which uses
205 * the same tone mapping that Chrome uses for HDR content, the form "*=N",
206 * where N is a floating point scale factor applied in linear space, and
207 * "none", which disables tone mapping. This defaults to "chrome".
208 *
209 * \param surface the SDL_Surface structure to query.
210 * \returns a valid property ID on success or 0 on failure; call
211 * SDL_GetError() for more information.
212 *
213 * \since This function is available since SDL 3.0.0.
214 */
215extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
216
217#define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
218#define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
219#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
220
221/**
222 * Set the colorspace used by a surface.
223 *
224 * Setting the colorspace doesn't change the pixels, only how they are
225 * interpreted in color operations.
226 *
227 * \param surface the SDL_Surface structure to update.
228 * \param colorspace an SDL_ColorSpace value describing the surface
229 * colorspace.
230 * \returns true on success or false on failure; call SDL_GetError() for more
231 * information.
232 *
233 * \since This function is available since SDL 3.0.0.
234 *
235 * \sa SDL_GetSurfaceColorspace
236 */
237extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
238
239/**
240 * Get the colorspace used by a surface.
241 *
242 * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
243 * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
244 * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
245 *
246 * \param surface the SDL_Surface structure to query.
247 * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
248 * the surface is NULL.
249 *
250 * \since This function is available since SDL 3.0.0.
251 *
252 * \sa SDL_SetSurfaceColorspace
253 */
254extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
255
256/**
257 * Create a palette and associate it with a surface.
258 *
259 * This function creates a palette compatible with the provided surface. The
260 * palette is then returned for you to modify, and the surface will
261 * automatically use the new palette in future operations. You do not need to
262 * destroy the returned palette, it will be freed when the reference count
263 * reaches 0, usually when the surface is destroyed.
264 *
265 * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
266 * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
267 * white and 1 as black. Other surfaces will get a palette initialized with
268 * white in every entry.
269 *
270 * If this function is called for a surface that already has a palette, a new
271 * palette will be created to replace it.
272 *
273 * \param surface the SDL_Surface structure to update.
274 * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
275 * the surface didn't have an index format); call SDL_GetError() for
276 * more information.
277 *
278 * \since This function is available since SDL 3.0.0.
279 *
280 * \sa SDL_SetPaletteColors
281 */
282extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
283
284/**
285 * Set the palette used by a surface.
286 *
287 * A single palette can be shared with many surfaces.
288 *
289 * \param surface the SDL_Surface structure to update.
290 * \param palette the SDL_Palette structure to use.
291 * \returns true on success or false on failure; call SDL_GetError() for more
292 * information.
293 *
294 * \since This function is available since SDL 3.0.0.
295 *
296 * \sa SDL_CreatePalette
297 * \sa SDL_GetSurfacePalette
298 */
299extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
300
301/**
302 * Get the palette used by a surface.
303 *
304 * \param surface the SDL_Surface structure to query.
305 * \returns a pointer to the palette used by the surface, or NULL if there is
306 * no palette used.
307 *
308 * \since This function is available since SDL 3.0.0.
309 *
310 * \sa SDL_SetSurfacePalette
311 */
312extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
313
314/**
315 * Add an alternate version of a surface.
316 *
317 * This function adds an alternate version of this surface, usually used for
318 * content with high DPI representations like cursors or icons. The size,
319 * format, and content do not need to match the original surface, and these
320 * alternate versions will not be updated when the original surface changes.
321 *
322 * This function adds a reference to the alternate version, so you should call
323 * SDL_DestroySurface() on the image after this call.
324 *
325 * \param surface the SDL_Surface structure to update.
326 * \param image a pointer to an alternate SDL_Surface to associate with this
327 * surface.
328 * \returns true on success or false on failure; call SDL_GetError() for more
329 * information.
330 *
331 * \since This function is available since SDL 3.0.0.
332 *
333 * \sa SDL_RemoveSurfaceAlternateImages
334 * \sa SDL_GetSurfaceImages
335 * \sa SDL_SurfaceHasAlternateImages
336 */
337extern SDL_DECLSPEC bool SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image);
338
339/**
340 * Return whether a surface has alternate versions available.
341 *
342 * \param surface the SDL_Surface structure to query.
343 * \returns true if alternate versions are available or true otherwise.
344 *
345 * \since This function is available since SDL 3.0.0.
346 *
347 * \sa SDL_AddSurfaceAlternateImage
348 * \sa SDL_RemoveSurfaceAlternateImages
349 * \sa SDL_GetSurfaceImages
350 */
351extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasAlternateImages(SDL_Surface *surface);
352
353/**
354 * Get an array including all versions of a surface.
355 *
356 * This returns all versions of a surface, with the surface being queried as
357 * the first element in the returned array.
358 *
359 * Freeing the array of surfaces does not affect the surfaces in the array.
360 * They are still referenced by the surface being queried and will be cleaned
361 * up normally.
362 *
363 * \param surface the SDL_Surface structure to query.
364 * \param count a pointer filled in with the number of surface pointers
365 * returned, may be NULL.
366 * \returns a NULL terminated array of SDL_Surface pointers or NULL on
367 * failure; call SDL_GetError() for more information. This should be
368 * freed with SDL_free() when it is no longer needed.
369 *
370 * \since This function is available since SDL 3.0.0.
371 *
372 * \sa SDL_AddSurfaceAlternateImage
373 * \sa SDL_RemoveSurfaceAlternateImages
374 * \sa SDL_SurfaceHasAlternateImages
375 */
376extern SDL_DECLSPEC SDL_Surface ** SDLCALL SDL_GetSurfaceImages(SDL_Surface *surface, int *count);
377
378/**
379 * Remove all alternate versions of a surface.
380 *
381 * This function removes a reference from all the alternative versions,
382 * destroying them if this is the last reference to them.
383 *
384 * \param surface the SDL_Surface structure to update.
385 *
386 * \since This function is available since SDL 3.0.0.
387 *
388 * \sa SDL_AddSurfaceAlternateImage
389 * \sa SDL_GetSurfaceImages
390 * \sa SDL_SurfaceHasAlternateImages
391 */
392extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface);
393
394/**
395 * Set up a surface for directly accessing the pixels.
396 *
397 * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
398 * and read from `surface->pixels`, using the pixel format stored in
399 * `surface->format`. Once you are done accessing the surface, you should use
400 * SDL_UnlockSurface() to release it.
401 *
402 * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
403 * 0, then you can read and write to the surface at any time, and the pixel
404 * format of the surface will not change.
405 *
406 * \param surface the SDL_Surface structure to be locked.
407 * \returns true on success or false on failure; call SDL_GetError() for more
408 * information.
409 *
410 * \since This function is available since SDL 3.0.0.
411 *
412 * \sa SDL_MUSTLOCK
413 * \sa SDL_UnlockSurface
414 */
415extern SDL_DECLSPEC bool SDLCALL SDL_LockSurface(SDL_Surface *surface);
416
417/**
418 * Release a surface after directly accessing the pixels.
419 *
420 * \param surface the SDL_Surface structure to be unlocked.
421 *
422 * \since This function is available since SDL 3.0.0.
423 *
424 * \sa SDL_LockSurface
425 */
426extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
427
428/**
429 * Load a BMP image from a seekable SDL data stream.
430 *
431 * The new surface should be freed with SDL_DestroySurface(). Not doing so
432 * will result in a memory leak.
433 *
434 * \param src the data stream for the surface.
435 * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
436 * in the case of an error.
437 * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
438 * SDL_GetError() for more information.
439 *
440 * \since This function is available since SDL 3.0.0.
441 *
442 * \sa SDL_DestroySurface
443 * \sa SDL_LoadBMP
444 * \sa SDL_SaveBMP_IO
445 */
446extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio);
447
448/**
449 * Load a BMP image from a file.
450 *
451 * The new surface should be freed with SDL_DestroySurface(). Not doing so
452 * will result in a memory leak.
453 *
454 * \param file the BMP file to load.
455 * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
456 * SDL_GetError() for more information.
457 *
458 * \since This function is available since SDL 3.0.0.
459 *
460 * \sa SDL_DestroySurface
461 * \sa SDL_LoadBMP_IO
462 * \sa SDL_SaveBMP
463 */
464extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
465
466/**
467 * Save a surface to a seekable SDL data stream in BMP format.
468 *
469 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
470 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
471 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
472 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
473 * not supported.
474 *
475 * \param surface the SDL_Surface structure containing the image to be saved.
476 * \param dst a data stream to save to.
477 * \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even
478 * in the case of an error.
479 * \returns true on success or false on failure; call SDL_GetError() for more
480 * information.
481 *
482 * \since This function is available since SDL 3.0.0.
483 *
484 * \sa SDL_LoadBMP_IO
485 * \sa SDL_SaveBMP
486 */
487extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
488
489/**
490 * Save a surface to a file.
491 *
492 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
493 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
494 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
495 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
496 * not supported.
497 *
498 * \param surface the SDL_Surface structure containing the image to be saved.
499 * \param file a file to save to.
500 * \returns true on success or false on failure; call SDL_GetError() for more
501 * information.
502 *
503 * \since This function is available since SDL 3.0.0.
504 *
505 * \sa SDL_LoadBMP
506 * \sa SDL_SaveBMP_IO
507 */
508extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
509
510/**
511 * Set the RLE acceleration hint for a surface.
512 *
513 * If RLE is enabled, color key and alpha blending blits are much faster, but
514 * the surface must be locked before directly accessing the pixels.
515 *
516 * \param surface the SDL_Surface structure to optimize.
517 * \param enabled true to enable RLE acceleration, false to disable it.
518 * \returns true on success or false on failure; call SDL_GetError() for more
519 * information.
520 *
521 * \since This function is available since SDL 3.0.0.
522 *
523 * \sa SDL_BlitSurface
524 * \sa SDL_LockSurface
525 * \sa SDL_UnlockSurface
526 */
527extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled);
528
529/**
530 * Returns whether the surface is RLE enabled.
531 *
532 * It is safe to pass a NULL `surface` here; it will return false.
533 *
534 * \param surface the SDL_Surface structure to query.
535 * \returns true if the surface is RLE enabled, false otherwise.
536 *
537 * \since This function is available since SDL 3.0.0.
538 *
539 * \sa SDL_SetSurfaceRLE
540 */
541extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
542
543/**
544 * Set the color key (transparent pixel) in a surface.
545 *
546 * The color key defines a pixel value that will be treated as transparent in
547 * a blit. For example, one can use this to specify that cyan pixels should be
548 * considered transparent, and therefore not rendered.
549 *
550 * It is a pixel of the format used by the surface, as generated by
551 * SDL_MapRGB().
552 *
553 * \param surface the SDL_Surface structure to update.
554 * \param enabled true to enable color key, false to disable color key.
555 * \param key the transparent pixel.
556 * \returns true on success or false on failure; call SDL_GetError() for more
557 * information.
558 *
559 * \since This function is available since SDL 3.0.0.
560 *
561 * \sa SDL_GetSurfaceColorKey
562 * \sa SDL_SetSurfaceRLE
563 * \sa SDL_SurfaceHasColorKey
564 */
565extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key);
566
567/**
568 * Returns whether the surface has a color key.
569 *
570 * It is safe to pass a NULL `surface` here; it will return false.
571 *
572 * \param surface the SDL_Surface structure to query.
573 * \returns true if the surface has a color key, false otherwise.
574 *
575 * \since This function is available since SDL 3.0.0.
576 *
577 * \sa SDL_SetSurfaceColorKey
578 * \sa SDL_GetSurfaceColorKey
579 */
580extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
581
582/**
583 * Get the color key (transparent pixel) for a surface.
584 *
585 * The color key is a pixel of the format used by the surface, as generated by
586 * SDL_MapRGB().
587 *
588 * If the surface doesn't have color key enabled this function returns false.
589 *
590 * \param surface the SDL_Surface structure to query.
591 * \param key a pointer filled in with the transparent pixel.
592 * \returns true on success or false on failure; call SDL_GetError() for more
593 * 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 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 true on success or false on failure; call SDL_GetError() for more
616 * 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 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 true on success or false on failure; call SDL_GetError() for more
634 * 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 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 true on success or false on failure; call SDL_GetError() for more
654 * 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 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 true on success or false on failure; call SDL_GetError() for more
669 * 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 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 true on success or false on failure; call SDL_GetError() for more
688 * information.
689 *
690 * \since This function is available since SDL 3.0.0.
691 *
692 * \sa SDL_GetSurfaceBlendMode
693 */
694extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
702 * information.
703 *
704 * \since This function is available since SDL 3.0.0.
705 *
706 * \sa SDL_SetSurfaceBlendMode
707 */
708extern SDL_DECLSPEC 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 true if the rectangle intersects the surface, otherwise false and
723 * 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 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 true on success or false on failure; call SDL_GetError() for more
742 * information.
743 *
744 * \since This function is available since SDL 3.0.0.
745 *
746 * \sa SDL_SetSurfaceClipRect
747 */
748extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
756 * information.
757 *
758 * \since This function is available since SDL 3.0.0.
759 */
760extern SDL_DECLSPEC 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 */
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 false on success or false on failure; call SDL_GetError() for more
864 * information.
865 *
866 * \since This function is available since SDL 3.0.0.
867 *
868 * \sa SDL_ConvertPixelsAndColorspace
869 */
870extern 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);
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 false on success or false on failure; call SDL_GetError() for more
893 * information.
894 *
895 * \since This function is available since SDL 3.0.0.
896 *
897 * \sa SDL_ConvertPixels
898 */
899extern 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);
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 true to convert from sRGB to linear space for the alpha
915 * multiplication, false to do multiplication in sRGB space.
916 * \returns true on success or false on failure; call SDL_GetError() for more
917 * information.
918 *
919 * \since This function is available since SDL 3.0.0.
920 */
921extern 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);
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 true to convert from sRGB to linear space for the alpha
930 * multiplication, false to do multiplication in sRGB space.
931 * \returns true on success or false on failure; call SDL_GetError() for more
932 * information.
933 *
934 * \since This function is available since SDL 3.0.0.
935 */
936extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, 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 true on success or false on failure; call SDL_GetError() for more
952 * information.
953 *
954 * \since This function is available since SDL 3.0.0.
955 */
956extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
975 * information.
976 *
977 * \since This function is available since SDL 3.0.0.
978 *
979 * \sa SDL_FillSurfaceRects
980 */
981extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
1000 * information.
1001 *
1002 * \since This function is available since SDL 3.0.0.
1003 *
1004 * \sa SDL_FillSurfaceRect
1005 */
1006extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
1071 * 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 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 true on success or false on failure; call SDL_GetError() for more
1096 * 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 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 true on success or false on failure; call SDL_GetError() for more
1121 * 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 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 true on success or false on failure; call SDL_GetError() for more
1147 * 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 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 true on success or false on failure; call SDL_GetError() for more
1173 * 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 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 true on success or false on failure; call SDL_GetError() for more
1203 * 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 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 true on success or false on failure; call SDL_GetError() for more
1240 * 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 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 true on success or false on failure; call SDL_GetError() for more
1334 * information.
1335 *
1336 * \since This function is available since SDL 3.0.0.
1337 */
1338extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
1358 * information.
1359 *
1360 * \since This function is available since SDL 3.0.0.
1361 */
1362extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
1381 * information.
1382 *
1383 * \since This function is available since SDL 3.0.0.
1384 */
1385extern SDL_DECLSPEC 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 true on success or false on failure; call SDL_GetError() for more
1401 * information.
1402 *
1403 * \since This function is available since SDL 3.0.0.
1404 */
1405extern SDL_DECLSPEC 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:320
uint32_t Uint32
Definition SDL_stdinc.h:356
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:52
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:72
@ SDL_SCALEMODE_LINEAR
Definition SDL_surface.h:74
@ SDL_SCALEMODE_NEAREST
Definition SDL_surface.h:73
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: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_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
void * reserved
SDL_PixelFormat format
void * pixels