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