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