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