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