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