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