SDL 3.0
SDL_surface.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 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 * \file SDL_surface.h
24 *
25 * \brief Header file for ::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_pixels.h>
33#include <SDL3/SDL_rect.h>
34#include <SDL3/SDL_blendmode.h>
35#include <SDL3/SDL_rwops.h>
36
37#include <SDL3/SDL_begin_code.h>
38/* Set up for C function definitions, even when using C++ */
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * \name Surface flags
45 *
46 * These are the currently supported flags for the ::SDL_Surface.
47 *
48 * \internal
49 * Used internally (read-only).
50 */
51/* @{ */
52#define SDL_SWSURFACE 0 /**< Just here for compatibility */
53#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
54#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
55#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
56#define SDL_SIMD_ALIGNED 0x00000008 /**< Surface uses aligned memory */
57/* @} *//* Surface flags */
58
59/**
60 * Evaluates to true if the surface needs to be locked before access.
61 */
62#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
63
64typedef struct SDL_BlitMap SDL_BlitMap; /* this is an opaque type. */
65
66/**
67 * \brief A collection of pixels used in software blitting.
68 *
69 * \note This structure should be treated as read-only, except for \c pixels,
70 * which, if not NULL, contains the raw pixel data for the surface.
71 */
72typedef struct SDL_Surface
73{
74 Uint32 flags; /**< Read-only */
75 SDL_PixelFormat *format; /**< Read-only */
76 int w, h; /**< Read-only */
77 int pitch; /**< Read-only */
78 void *pixels; /**< Read-write */
79
80 /** Application data associated with the surface */
81 void *userdata; /**< Read-write */
82
83 /** information needed for surfaces requiring locks */
84 int locked; /**< Read-only */
85
86 /** list of BlitMap that hold a reference to this surface */
87 void *list_blitmap; /**< Private */
88
89 /** clipping information */
90 SDL_Rect clip_rect; /**< Read-only */
91
92 /** info for fast blit mapping to other surfaces */
93 SDL_BlitMap *map; /**< Private */
94
95 /** Reference count -- used when freeing surface */
96 int refcount; /**< Read-mostly */
98
99/**
100 * \brief The type of function used for surface blitting functions.
101 */
102typedef int (SDLCALL *SDL_blit) (struct SDL_Surface *src, const SDL_Rect *srcrect,
103 struct SDL_Surface *dst, const SDL_Rect *dstrect);
104
105/**
106 * \brief The formula used for converting between YUV and RGB
107 */
108typedef enum
109{
110 SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
111 SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
113 SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
115
116/**
117 * Allocate a new RGB surface with a specific pixel format.
118 *
119 * \param width the width of the surface
120 * \param height the height of the surface
121 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
122 * \returns the new SDL_Surface structure that is created or NULL if it fails;
123 * call SDL_GetError() for more information.
124 *
125 * \since This function is available since SDL 3.0.0.
126 *
127 * \sa SDL_CreateSurfaceFrom
128 * \sa SDL_DestroySurface
129 */
130extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface
131 (int width, int height, Uint32 format);
132
133/**
134 * Allocate a new RGB surface with with a specific pixel format and existing
135 * pixel data.
136 *
137 * No copy is made of the pixel data. Pixel data is not managed automatically;
138 * you must free the surface before you free the pixel data.
139 *
140 * You may pass NULL for pixels and 0 for pitch to create a surface that you
141 * will fill in with valid values later.
142 *
143 * \param pixels a pointer to existing pixel data
144 * \param width the width of the surface
145 * \param height the height of the surface
146 * \param pitch the pitch of the surface in bytes
147 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
148 * \returns the new SDL_Surface structure that is created or NULL if it fails;
149 * call SDL_GetError() for more information.
150 *
151 * \since This function is available since SDL 3.0.0.
152 *
153 * \sa SDL_CreateSurface
154 * \sa SDL_DestroySurface
155 */
156extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom
157 (void *pixels, int width, int height, int pitch, Uint32 format);
158
159/**
160 * Free an RGB surface.
161 *
162 * It is safe to pass NULL to this function.
163 *
164 * \param surface the SDL_Surface to free.
165 *
166 * \since This function is available since SDL 3.0.0.
167 *
168 * \sa SDL_CreateSurface
169 * \sa SDL_CreateSurfaceFrom
170 * \sa SDL_LoadBMP
171 * \sa SDL_LoadBMP_RW
172 */
173extern DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
174
175/**
176 * Set the palette used by a surface.
177 *
178 * A single palette can be shared with many surfaces.
179 *
180 * \param surface the SDL_Surface structure to update
181 * \param palette the SDL_Palette structure to use
182 * \returns 0 on success or a negative error code on failure; call
183 * SDL_GetError() for more information.
184 *
185 * \since This function is available since SDL 3.0.0.
186 */
187extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface,
188 SDL_Palette *palette);
189
190/**
191 * Set up a surface for directly accessing the pixels.
192 *
193 * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
194 * and read from `surface->pixels`, using the pixel format stored in
195 * `surface->format`. Once you are done accessing the surface, you should use
196 * SDL_UnlockSurface() to release it.
197 *
198 * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
199 * 0, then you can read and write to the surface at any time, and the pixel
200 * format of the surface will not change.
201 *
202 * \param surface the SDL_Surface structure to be locked
203 * \returns 0 on success or a negative error code on failure; call
204 * SDL_GetError() for more information.
205 *
206 * \since This function is available since SDL 3.0.0.
207 *
208 * \sa SDL_MUSTLOCK
209 * \sa SDL_UnlockSurface
210 */
211extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
212
213/**
214 * Release a surface after directly accessing the pixels.
215 *
216 * \param surface the SDL_Surface structure to be unlocked
217 *
218 * \since This function is available since SDL 3.0.0.
219 *
220 * \sa SDL_LockSurface
221 */
222extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
223
224/**
225 * Load a BMP image from a seekable SDL data stream.
226 *
227 * The new surface should be freed with SDL_DestroySurface(). Not doing so
228 * will result in a memory leak.
229 *
230 * \param src the data stream for the surface
231 * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
232 * even in the case of an error
233 * \returns a pointer to a new SDL_Surface structure or NULL if there was an
234 * error; call SDL_GetError() for more information.
235 *
236 * \since This function is available since SDL 3.0.0.
237 *
238 * \sa SDL_DestroySurface
239 * \sa SDL_LoadBMP
240 * \sa SDL_SaveBMP_RW
241 */
242extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc);
243
244/**
245 * Load a BMP image from a file.
246 *
247 * The new surface should be freed with SDL_DestroySurface(). Not doing so
248 * will result in a memory leak.
249 *
250 * \param file the BMP file to load
251 * \returns a pointer to a new SDL_Surface structure or NULL if there was an
252 * error; call SDL_GetError() for more information.
253 *
254 * \since This function is available since SDL 3.0.0.
255 *
256 * \sa SDL_DestroySurface
257 * \sa SDL_LoadBMP_RW
258 * \sa SDL_SaveBMP
259 */
260extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
261
262/**
263 * Save a surface to a seekable SDL data stream in BMP format.
264 *
265 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
266 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
267 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
268 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
269 * not supported.
270 *
271 * \param surface the SDL_Surface structure containing the image to be saved
272 * \param dst a data stream to save to
273 * \param freedst non-zero to close the stream after being written
274 * \returns 0 on success or a negative error code on failure; call
275 * SDL_GetError() for more information.
276 *
277 * \since This function is available since SDL 3.0.0.
278 *
279 * \sa SDL_LoadBMP_RW
280 * \sa SDL_SaveBMP
281 */
282extern DECLSPEC int SDLCALL SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst);
283
284/**
285 * Save a surface to a file.
286 *
287 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
288 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
289 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
290 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
291 * not supported.
292 *
293 * \param surface the SDL_Surface structure containing the image to be saved
294 * \param file a file to save to
295 * \returns 0 on success or a negative error code on failure; call
296 * SDL_GetError() for more information.
297 *
298 * \since This function is available since SDL 3.0.0.
299 *
300 * \sa SDL_LoadBMP
301 * \sa SDL_SaveBMP_RW
302 */
303extern DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
304
305/**
306 * Set the RLE acceleration hint for a surface.
307 *
308 * If RLE is enabled, color key and alpha blending blits are much faster, but
309 * the surface must be locked before directly accessing the pixels.
310 *
311 * \param surface the SDL_Surface structure to optimize
312 * \param flag 0 to disable, non-zero to enable RLE acceleration
313 * \returns 0 on success or a negative error code on failure; call
314 * SDL_GetError() for more information.
315 *
316 * \since This function is available since SDL 3.0.0.
317 *
318 * \sa SDL_BlitSurface
319 * \sa SDL_LockSurface
320 * \sa SDL_UnlockSurface
321 */
322extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface,
323 int flag);
324
325/**
326 * Returns whether the surface is RLE enabled
327 *
328 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
329 *
330 * \param surface the SDL_Surface structure to query
331 * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
332 *
333 * \since This function is available since SDL 3.0.0.
334 *
335 * \sa SDL_SetSurfaceRLE
336 */
337extern DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
338
339/**
340 * Set the color key (transparent pixel) in a surface.
341 *
342 * The color key defines a pixel value that will be treated as transparent in
343 * a blit. For example, one can use this to specify that cyan pixels should be
344 * considered transparent, and therefore not rendered.
345 *
346 * It is a pixel of the format used by the surface, as generated by
347 * SDL_MapRGB().
348 *
349 * RLE acceleration can substantially speed up blitting of images with large
350 * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details.
351 *
352 * \param surface the SDL_Surface structure to update
353 * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key
354 * \param key the transparent pixel
355 * \returns 0 on success or a negative error code on failure; call
356 * SDL_GetError() for more information.
357 *
358 * \since This function is available since SDL 3.0.0.
359 *
360 * \sa SDL_BlitSurface
361 * \sa SDL_GetSurfaceColorKey
362 */
363extern DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface,
364 int flag, Uint32 key);
365
366/**
367 * Returns whether the surface has a color key
368 *
369 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
370 *
371 * \param surface the SDL_Surface structure to query
372 * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
373 *
374 * \since This function is available since SDL 3.0.0.
375 *
376 * \sa SDL_SetSurfaceColorKey
377 * \sa SDL_GetSurfaceColorKey
378 */
379extern DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
380
381/**
382 * Get the color key (transparent pixel) for a surface.
383 *
384 * The color key is a pixel of the format used by the surface, as generated by
385 * SDL_MapRGB().
386 *
387 * If the surface doesn't have color key enabled this function returns -1.
388 *
389 * \param surface the SDL_Surface structure to query
390 * \param key a pointer filled in with the transparent pixel
391 * \returns 0 on success or a negative error code on failure; call
392 * SDL_GetError() for more information.
393 *
394 * \since This function is available since SDL 3.0.0.
395 *
396 * \sa SDL_BlitSurface
397 * \sa SDL_SetSurfaceColorKey
398 */
399extern DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface,
400 Uint32 *key);
401
402/**
403 * Set an additional color value multiplied into blit operations.
404 *
405 * When this surface is blitted, during the blit operation each source color
406 * channel is modulated by the appropriate color value according to the
407 * following formula:
408 *
409 * `srcC = srcC * (color / 255)`
410 *
411 * \param surface the SDL_Surface structure to update
412 * \param r the red color value multiplied into blit operations
413 * \param g the green color value multiplied into blit operations
414 * \param b the blue color value multiplied into blit operations
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_GetSurfaceColorMod
421 * \sa SDL_SetSurfaceAlphaMod
422 */
423extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface,
424 Uint8 r, Uint8 g, Uint8 b);
425
426
427/**
428 * Get the additional color value multiplied into blit operations.
429 *
430 * \param surface the SDL_Surface structure to query
431 * \param r a pointer filled in with the current red color value
432 * \param g a pointer filled in with the current green color value
433 * \param b a pointer filled in with the current blue color value
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_GetSurfaceAlphaMod
440 * \sa SDL_SetSurfaceColorMod
441 */
442extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface,
443 Uint8 *r, Uint8 *g,
444 Uint8 *b);
445
446/**
447 * Set an additional alpha value used in blit operations.
448 *
449 * When this surface is blitted, during the blit operation the source alpha
450 * value is modulated by this alpha value according to the following formula:
451 *
452 * `srcA = srcA * (alpha / 255)`
453 *
454 * \param surface the SDL_Surface structure to update
455 * \param alpha the alpha value multiplied into blit operations
456 * \returns 0 on success or a negative error code on failure; call
457 * SDL_GetError() for more information.
458 *
459 * \since This function is available since SDL 3.0.0.
460 *
461 * \sa SDL_GetSurfaceAlphaMod
462 * \sa SDL_SetSurfaceColorMod
463 */
464extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface,
465 Uint8 alpha);
466
467/**
468 * Get the additional alpha value used in blit operations.
469 *
470 * \param surface the SDL_Surface structure to query
471 * \param alpha a pointer filled in with the current alpha value
472 * \returns 0 on success or a negative error code on failure; call
473 * SDL_GetError() for more information.
474 *
475 * \since This function is available since SDL 3.0.0.
476 *
477 * \sa SDL_GetSurfaceColorMod
478 * \sa SDL_SetSurfaceAlphaMod
479 */
480extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface,
481 Uint8 *alpha);
482
483/**
484 * Set the blend mode used for blit operations.
485 *
486 * To copy a surface to another surface (or texture) without blending with the
487 * existing data, the blendmode of the SOURCE surface should be set to
488 * `SDL_BLENDMODE_NONE`.
489 *
490 * \param surface the SDL_Surface structure to update
491 * \param blendMode the SDL_BlendMode to use for blit blending
492 * \returns 0 on success or a negative error code on failure; call
493 * SDL_GetError() for more information.
494 *
495 * \since This function is available since SDL 3.0.0.
496 *
497 * \sa SDL_GetSurfaceBlendMode
498 */
499extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface,
500 SDL_BlendMode blendMode);
501
502/**
503 * Get the blend mode used for blit operations.
504 *
505 * \param surface the SDL_Surface structure to query
506 * \param blendMode a pointer filled in with the current SDL_BlendMode
507 * \returns 0 on success or a negative error code on failure; call
508 * SDL_GetError() for more information.
509 *
510 * \since This function is available since SDL 3.0.0.
511 *
512 * \sa SDL_SetSurfaceBlendMode
513 */
514extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface,
515 SDL_BlendMode *blendMode);
516
517/**
518 * Set the clipping rectangle for a surface.
519 *
520 * When `surface` is the destination of a blit, only the area within the clip
521 * rectangle is drawn into.
522 *
523 * Note that blits are automatically clipped to the edges of the source and
524 * destination surfaces.
525 *
526 * \param surface the SDL_Surface structure to be clipped
527 * \param rect the SDL_Rect structure representing the clipping rectangle, or
528 * NULL to disable clipping
529 * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
530 * SDL_FALSE and blits will be completely clipped.
531 *
532 * \since This function is available since SDL 3.0.0.
533 *
534 * \sa SDL_BlitSurface
535 * \sa SDL_GetSurfaceClipRect
536 */
537extern DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface,
538 const SDL_Rect *rect);
539
540/**
541 * Get the clipping rectangle for a surface.
542 *
543 * When `surface` is the destination of a blit, only the area within the clip
544 * rectangle is drawn into.
545 *
546 * \param surface the SDL_Surface structure representing the surface to be
547 * clipped
548 * \param rect an SDL_Rect structure filled in with the clipping rectangle for
549 * the surface
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_BlitSurface
556 * \sa SDL_SetSurfaceClipRect
557 */
558extern DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface,
559 SDL_Rect *rect);
560
561/*
562 * Creates a new surface identical to the existing surface.
563 *
564 * The returned surface should be freed with SDL_DestroySurface().
565 *
566 * \param surface the surface to duplicate.
567 * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
568 * more information.
569 *
570 * \since This function is available since SDL 3.0.0.
571 */
572extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
573
574/**
575 * Copy an existing surface to a new surface of the specified format.
576 *
577 * This function is used to optimize images for faster *repeat* blitting. This
578 * is accomplished by converting the original and storing the result as a new
579 * surface. The new, optimized surface can then be used as the source for
580 * future blits, making them faster.
581 *
582 * \param surface the existing SDL_Surface structure to convert
583 * \param format the SDL_PixelFormat structure that the new surface is
584 * optimized for
585 * \returns the new SDL_Surface structure that is created or NULL if it fails;
586 * call SDL_GetError() for more information.
587 *
588 * \since This function is available since SDL 3.0.0.
589 *
590 * \sa SDL_CreatePixelFormat
591 * \sa SDL_ConvertSurfaceFormat
592 * \sa SDL_CreateSurface
593 */
594extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface,
595 const SDL_PixelFormat *format);
596
597/**
598 * Copy an existing surface to a new surface of the specified format enum.
599 *
600 * This function operates just like SDL_ConvertSurface(), but accepts an
601 * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
602 * it might be easier to call but it doesn't have access to palette
603 * information for the destination surface, in case that would be important.
604 *
605 * \param surface the existing SDL_Surface structure to convert
606 * \param pixel_format the SDL_PixelFormatEnum that the new surface is
607 * optimized for
608 * \returns the new SDL_Surface structure that is created or NULL if it fails;
609 * call SDL_GetError() for more information.
610 *
611 * \since This function is available since SDL 3.0.0.
612 *
613 * \sa SDL_CreatePixelFormat
614 * \sa SDL_ConvertSurface
615 * \sa SDL_CreateSurface
616 */
617extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *surface,
618 Uint32 pixel_format);
619
620/**
621 * Copy a block of pixels of one format to another format.
622 *
623 * \param width the width of the block to copy, in pixels
624 * \param height the height of the block to copy, in pixels
625 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
626 * \param src a pointer to the source pixels
627 * \param src_pitch the pitch of the source pixels, in bytes
628 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
629 * \param dst a pointer to be filled in with new pixel data
630 * \param dst_pitch the pitch of the destination pixels, in bytes
631 * \returns 0 on success or a negative error code on failure; call
632 * SDL_GetError() for more information.
633 *
634 * \since This function is available since SDL 3.0.0.
635 */
636extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
637 Uint32 src_format,
638 const void *src, int src_pitch,
639 Uint32 dst_format,
640 void *dst, int dst_pitch);
641
642/**
643 * Premultiply the alpha on a block of pixels.
644 *
645 * This is safe to use with src == dst, but not for other overlapping areas.
646 *
647 * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
648 *
649 * \param width the width of the block to convert, in pixels
650 * \param height the height of the block to convert, in pixels
651 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
652 * \param src a pointer to the source pixels
653 * \param src_pitch the pitch of the source pixels, in bytes
654 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
655 * \param dst a pointer to be filled in with premultiplied pixel data
656 * \param dst_pitch the pitch of the destination pixels, in bytes
657 * \returns 0 on success or a negative error code on failure; call
658 * SDL_GetError() for more information.
659 *
660 * \since This function is available since SDL 3.0.0.
661 */
662extern DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height,
663 Uint32 src_format,
664 const void *src, int src_pitch,
665 Uint32 dst_format,
666 void *dst, int dst_pitch);
667
668/**
669 * Perform a fast fill of a rectangle with a specific color.
670 *
671 * `color` should be a pixel of the format used by the surface, and can be
672 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
673 * alpha component then the destination is simply filled with that alpha
674 * information, no blending takes place.
675 *
676 * If there is a clip rectangle set on the destination (set via
677 * SDL_SetSurfaceClipRect()), then this function will fill based on the
678 * intersection of the clip rectangle and `rect`.
679 *
680 * \param dst the SDL_Surface structure that is the drawing target
681 * \param rect the SDL_Rect structure representing the rectangle to fill, or
682 * NULL to fill the entire surface
683 * \param color the color to fill with
684 * \returns 0 on success or a negative error code on failure; call
685 * SDL_GetError() for more information.
686 *
687 * \since This function is available since SDL 3.0.0.
688 *
689 * \sa SDL_FillSurfaceRects
690 */
691extern DECLSPEC int SDLCALL SDL_FillSurfaceRect
692 (SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
693
694/**
695 * Perform a fast fill of a set of rectangles with a specific color.
696 *
697 * `color` should be a pixel of the format used by the surface, and can be
698 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
699 * alpha component then the destination is simply filled with that alpha
700 * information, no blending takes place.
701 *
702 * If there is a clip rectangle set on the destination (set via
703 * SDL_SetSurfaceClipRect()), then this function will fill based on the
704 * intersection of the clip rectangle and `rect`.
705 *
706 * \param dst the SDL_Surface structure that is the drawing target
707 * \param rects an array of SDL_Rects representing the rectangles to fill.
708 * \param count the number of rectangles in the array
709 * \param color the color to fill with
710 * \returns 0 on success or a negative error code on failure; call
711 * SDL_GetError() for more information.
712 *
713 * \since This function is available since SDL 3.0.0.
714 *
715 * \sa SDL_FillSurfaceRect
716 */
717extern DECLSPEC int SDLCALL SDL_FillSurfaceRects
718 (SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
719
720/**
721 * Performs a fast blit from the source surface to the destination surface.
722 *
723 * This assumes that the source and destination rectangles are the same size.
724 * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
725 * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
726 * `dstrect` after all clipping is performed.
727 *
728 * The blit function should not be called on a locked surface.
729 *
730 * The blit semantics for surfaces with and without blending and colorkey are
731 * defined as follows:
732 *
733 * ```c
734 * RGBA->RGB:
735 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
736 * alpha-blend (using the source alpha-channel and per-surface alpha)
737 * SDL_SRCCOLORKEY ignored.
738 * Source surface blend mode set to SDL_BLENDMODE_NONE:
739 * copy RGB.
740 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
741 * RGB values of the source color key, ignoring alpha in the
742 * comparison.
743 *
744 * RGB->RGBA:
745 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
746 * alpha-blend (using the source per-surface alpha)
747 * Source surface blend mode set to SDL_BLENDMODE_NONE:
748 * copy RGB, set destination alpha to source per-surface alpha value.
749 * both:
750 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
751 * source color key.
752 *
753 * RGBA->RGBA:
754 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
755 * alpha-blend (using the source alpha-channel and per-surface alpha)
756 * SDL_SRCCOLORKEY ignored.
757 * Source surface blend mode set to SDL_BLENDMODE_NONE:
758 * copy all of RGBA to the destination.
759 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
760 * RGB values of the source color key, ignoring alpha in the
761 * comparison.
762 *
763 * RGB->RGB:
764 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
765 * alpha-blend (using the source per-surface alpha)
766 * Source surface blend mode set to SDL_BLENDMODE_NONE:
767 * copy RGB.
768 * both:
769 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
770 * source color key.
771 * ```
772 *
773 * \param src the SDL_Surface structure to be copied from
774 * \param srcrect the SDL_Rect structure representing the rectangle to be
775 * copied, or NULL to copy the entire surface
776 * \param dst the SDL_Surface structure that is the blit target
777 * \param dstrect the SDL_Rect structure representing the target rectangle in
778 * the destination surface, filled with the actual rectangle
779 * used after clipping
780 * \returns 0 on success or a negative error code on failure; call
781 * SDL_GetError() for more information.
782 *
783 * \since This function is available since SDL 3.0.0.
784 *
785 * \sa SDL_BlitSurface
786 */
787extern DECLSPEC int SDLCALL SDL_BlitSurface
788 (SDL_Surface *src, const SDL_Rect *srcrect,
789 SDL_Surface *dst, SDL_Rect *dstrect);
790
791/**
792 * Perform low-level surface blitting only.
793 *
794 * This is a semi-private blit function and it performs low-level surface
795 * blitting, assuming the input rectangles have already been clipped.
796 *
797 * \param src the SDL_Surface structure to be copied from
798 * \param srcrect the SDL_Rect structure representing the rectangle to be
799 * copied, or NULL to copy the entire surface
800 * \param dst the SDL_Surface structure that is the blit target
801 * \param dstrect the SDL_Rect structure representing the target rectangle in
802 * the destination surface
803 * \returns 0 on success or a negative error code on failure; call
804 * SDL_GetError() for more information.
805 *
806 * \since This function is available since SDL 3.0.0.
807 *
808 * \sa SDL_BlitSurface
809 */
810extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked
811 (SDL_Surface *src, const SDL_Rect *srcrect,
812 SDL_Surface *dst, const SDL_Rect *dstrect);
813
814
815/**
816 * Perform a fast, low quality, stretch blit between two surfaces of the same
817 * format.
818 *
819 * **WARNING**: Please use SDL_BlitSurfaceScaled() instead.
820 *
821 * \param src the SDL_Surface structure to be copied from
822 * \param srcrect the SDL_Rect structure representing the rectangle to be
823 * copied
824 * \param dst the SDL_Surface structure that is the blit target
825 * \param dstrect the SDL_Rect structure representing the target rectangle in
826 * the destination surface
827 * \returns 0 on success or a negative error code on failure; call
828 * SDL_GetError() for more information.
829 *
830 * \since This function is available since SDL 3.0.0.
831 */
832extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src,
833 const SDL_Rect *srcrect,
834 SDL_Surface *dst,
835 const SDL_Rect *dstrect);
836
837/**
838 * Perform bilinear scaling between two surfaces of the same format, 32BPP.
839 *
840 * \param src the SDL_Surface structure to be copied from
841 * \param srcrect the SDL_Rect structure representing the rectangle to be
842 * copied
843 * \param dst the SDL_Surface structure that is the blit target
844 * \param dstrect the SDL_Rect structure representing the target rectangle in
845 * the destination surface
846 * \returns 0 on success or a negative error code on failure; call
847 * SDL_GetError() for more information.
848 *
849 * \since This function is available since SDL 3.0.0.
850 */
851extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src,
852 const SDL_Rect *srcrect,
853 SDL_Surface *dst,
854 const SDL_Rect *dstrect);
855
856
857/**
858 * Perform a scaled surface copy to a destination surface.
859 *
860 * \param src the SDL_Surface structure to be copied from
861 * \param srcrect the SDL_Rect structure representing the rectangle to be
862 * copied
863 * \param dst the SDL_Surface structure that is the blit target
864 * \param dstrect the SDL_Rect structure representing the target rectangle in
865 * the destination surface, filled with the actual rectangle
866 * used after clipping
867 * \returns 0 on success or a negative error code on failure; call
868 * SDL_GetError() for more information.
869 *
870 * \since This function is available since SDL 3.0.0.
871 */
872extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
873 (SDL_Surface *src, const SDL_Rect *srcrect,
874 SDL_Surface *dst, SDL_Rect *dstrect);
875
876/**
877 * Perform low-level surface scaled blitting only.
878 *
879 * This is a semi-private function and it performs low-level surface blitting,
880 * assuming the input rectangles have already been clipped.
881 *
882 * \param src the SDL_Surface structure to be copied from
883 * \param srcrect the SDL_Rect structure representing the rectangle to be
884 * copied
885 * \param dst the SDL_Surface structure that is the blit target
886 * \param dstrect the SDL_Rect structure representing the target rectangle in
887 * the destination surface
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_BlitSurfaceScaled
894 */
895extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled
896 (SDL_Surface *src, const SDL_Rect *srcrect,
897 SDL_Surface *dst, const SDL_Rect *dstrect);
898
899/**
900 * Set the YUV conversion mode
901 *
902 * \param mode YUV conversion mode
903 *
904 * \since This function is available since SDL 3.0.0.
905 */
906extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
907
908/**
909 * Get the YUV conversion mode
910 *
911 * \returns YUV conversion mode
912 *
913 * \since This function is available since SDL 3.0.0.
914 */
916
917/**
918 * Get the YUV conversion mode, returning the correct mode for the resolution
919 * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
920 *
921 * \param width width
922 * \param height height
923 * \returns YUV conversion mode
924 *
925 * \since This function is available since SDL 3.0.0.
926 */
927extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
928
929/* Ends C function definitions when using C++ */
930#ifdef __cplusplus
931}
932#endif
933#include <SDL3/SDL_close_code.h>
934
935#endif /* SDL_surface_h_ */
Header file declaring the SDL_BlendMode enumeration.
SDL_BlendMode
The blend mode used in SDL_RenderTexture() and drawing operations.
Definition: SDL_blendmode.h:41
Header for the enumerated pixel format definitions.
Header file for SDL_rect definition and management functions.
This is a general header that includes C language support.
uint8_t Uint8
Definition: SDL_stdinc.h:147
SDL_bool
Definition: SDL_stdinc.h:130
uint32_t Uint32
Definition: SDL_stdinc.h:171
SDL_YUV_CONVERSION_MODE
The formula used for converting between YUV and RGB.
Definition: SDL_surface.h:109
@ SDL_YUV_CONVERSION_BT601
Definition: SDL_surface.h:111
@ SDL_YUV_CONVERSION_JPEG
Definition: SDL_surface.h:110
@ SDL_YUV_CONVERSION_BT709
Definition: SDL_surface.h:112
@ SDL_YUV_CONVERSION_AUTOMATIC
Definition: SDL_surface.h:113
int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
int(* SDL_blit)(struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect)
The type of function used for surface blitting functions.
Definition: SDL_surface.h:102
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
void SDL_DestroySurface(SDL_Surface *surface)
SDL_Surface * SDL_ConvertSurfaceFormat(SDL_Surface *surface, Uint32 pixel_format)
SDL_Surface * SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitch, Uint32 format)
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)
SDL_Surface * SDL_DuplicateSurface(SDL_Surface *surface)
int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
int SDL_LockSurface(SDL_Surface *surface)
int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
int SDL_PremultiplyAlpha(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)
struct SDL_BlitMap SDL_BlitMap
Definition: SDL_surface.h:64
int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
int SDL_SetSurfaceColorKey(SDL_Surface *surface, int flag, Uint32 key)
SDL_Surface * SDL_CreateSurface(int width, int height, Uint32 format)
int SDL_SaveBMP(SDL_Surface *surface, const char *file)
void SDL_UnlockSurface(SDL_Surface *surface)
int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect)
int SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
SDL_Surface * SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc)
int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface)
int SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
int SDL_SoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode(void)
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_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
void SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution(int width, int height)
int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
A collection of pixels used in software blitting.
Definition: SDL_surface.h:73
SDL_PixelFormat * format
Definition: SDL_surface.h:75
void * list_blitmap
Definition: SDL_surface.h:87
Uint32 flags
Definition: SDL_surface.h:74
SDL_Rect clip_rect
Definition: SDL_surface.h:90
void * pixels
Definition: SDL_surface.h:78
SDL_BlitMap * map
Definition: SDL_surface.h:93
void * userdata
Definition: SDL_surface.h:81