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