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