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