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 * 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 * \return 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 *
533 * \since This function is available since SDL 3.0.0.
534 *
535 * \sa SDL_BlitSurface
536 * \sa SDL_SetSurfaceClipRect
537 */
538extern DECLSPEC void SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface,
539 SDL_Rect *rect);
540
541/*
542 * Creates a new surface identical to the existing surface.
543 *
544 * The returned surface should be freed with SDL_DestroySurface().
545 *
546 * \param surface the surface to duplicate.
547 * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
548 * more information.
549 */
550extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
551
552/**
553 * Copy an existing surface to a new surface of the specified format.
554 *
555 * This function is used to optimize images for faster *repeat* blitting. This
556 * is accomplished by converting the original and storing the result as a new
557 * surface. The new, optimized surface can then be used as the source for
558 * future blits, making them faster.
559 *
560 * \param surface the existing SDL_Surface structure to convert
561 * \param format the SDL_PixelFormat structure that the new surface is
562 * optimized for
563 * \returns the new SDL_Surface structure that is created or NULL if it fails;
564 * call SDL_GetError() for more information.
565 *
566 * \since This function is available since SDL 3.0.0.
567 *
568 * \sa SDL_CreatePixelFormat
569 * \sa SDL_ConvertSurfaceFormat
570 * \sa SDL_CreateSurface
571 */
572extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface,
573 const SDL_PixelFormat *format);
574
575/**
576 * Copy an existing surface to a new surface of the specified format enum.
577 *
578 * This function operates just like SDL_ConvertSurface(), but accepts an
579 * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
580 * it might be easier to call but it doesn't have access to palette
581 * information for the destination surface, in case that would be important.
582 *
583 * \param surface the existing SDL_Surface structure to convert
584 * \param pixel_format the SDL_PixelFormatEnum that the new surface is
585 * optimized for
586 * \returns the new SDL_Surface structure that is created or NULL if it fails;
587 * call SDL_GetError() for more information.
588 *
589 * \since This function is available since SDL 3.0.0.
590 *
591 * \sa SDL_CreatePixelFormat
592 * \sa SDL_ConvertSurface
593 * \sa SDL_CreateSurface
594 */
595extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *surface,
596 Uint32 pixel_format);
597
598/**
599 * Copy a block of pixels of one format to another format.
600 *
601 * \param width the width of the block to copy, in pixels
602 * \param height the height of the block to copy, in pixels
603 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
604 * \param src a pointer to the source pixels
605 * \param src_pitch the pitch of the source pixels, in bytes
606 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
607 * \param dst a pointer to be filled in with new pixel data
608 * \param dst_pitch the pitch of the destination pixels, in bytes
609 * \returns 0 on success or a negative error code on failure; call
610 * SDL_GetError() for more information.
611 *
612 * \since This function is available since SDL 3.0.0.
613 */
614extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
615 Uint32 src_format,
616 const void *src, int src_pitch,
617 Uint32 dst_format,
618 void *dst, int dst_pitch);
619
620/**
621 * Premultiply the alpha on a block of pixels.
622 *
623 * This is safe to use with src == dst, but not for other overlapping areas.
624 *
625 * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
626 *
627 * \param width the width of the block to convert, in pixels
628 * \param height the height of the block to convert, in pixels
629 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
630 * \param src a pointer to the source pixels
631 * \param src_pitch the pitch of the source pixels, in bytes
632 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
633 * \param dst a pointer to be filled in with premultiplied pixel data
634 * \param dst_pitch the pitch of the destination pixels, in bytes
635 * \returns 0 on success or a negative error code on failure; call
636 * SDL_GetError() for more information.
637 *
638 * \since This function is available since SDL 3.0.0.
639 */
640extern DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height,
641 Uint32 src_format,
642 const void *src, int src_pitch,
643 Uint32 dst_format,
644 void *dst, int dst_pitch);
645
646/**
647 * Perform a fast fill of a rectangle with a specific color.
648 *
649 * `color` should be a pixel of the format used by the surface, and can be
650 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
651 * alpha component then the destination is simply filled with that alpha
652 * information, no blending takes place.
653 *
654 * If there is a clip rectangle set on the destination (set via
655 * SDL_SetSurfaceClipRect()), then this function will fill based on the
656 * intersection of the clip rectangle and `rect`.
657 *
658 * \param dst the SDL_Surface structure that is the drawing target
659 * \param rect the SDL_Rect structure representing the rectangle to fill, or
660 * NULL to fill the entire surface
661 * \param color the color to fill with
662 * \returns 0 on success or a negative error code on failure; call
663 * SDL_GetError() for more information.
664 *
665 * \since This function is available since SDL 3.0.0.
666 *
667 * \sa SDL_FillSurfaceRects
668 */
669extern DECLSPEC int SDLCALL SDL_FillSurfaceRect
670 (SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
671
672/**
673 * Perform a fast fill of a set of rectangles with a specific color.
674 *
675 * `color` should be a pixel of the format used by the surface, and can be
676 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
677 * alpha component then the destination is simply filled with that alpha
678 * information, no blending takes place.
679 *
680 * If there is a clip rectangle set on the destination (set via
681 * SDL_SetSurfaceClipRect()), then this function will fill based on the
682 * intersection of the clip rectangle and `rect`.
683 *
684 * \param dst the SDL_Surface structure that is the drawing target
685 * \param rects an array of SDL_Rects representing the rectangles to fill.
686 * \param count the number of rectangles in the array
687 * \param color the color to fill with
688 * \returns 0 on success or a negative error code on failure; call
689 * SDL_GetError() for more information.
690 *
691 * \since This function is available since SDL 3.0.0.
692 *
693 * \sa SDL_FillSurfaceRect
694 */
695extern DECLSPEC int SDLCALL SDL_FillSurfaceRects
696 (SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
697
698/**
699 * Performs a fast blit from the source surface to the destination surface.
700 *
701 * This assumes that the source and destination rectangles are the same size.
702 * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
703 * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
704 * `dstrect` after all clipping is performed.
705 *
706 * The blit function should not be called on a locked surface.
707 *
708 * The blit semantics for surfaces with and without blending and colorkey are
709 * defined as follows:
710 *
711 * ```c
712 * RGBA->RGB:
713 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
714 * alpha-blend (using the source alpha-channel and per-surface alpha)
715 * SDL_SRCCOLORKEY ignored.
716 * Source surface blend mode set to SDL_BLENDMODE_NONE:
717 * copy RGB.
718 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
719 * RGB values of the source color key, ignoring alpha in the
720 * comparison.
721 *
722 * RGB->RGBA:
723 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
724 * alpha-blend (using the source per-surface alpha)
725 * Source surface blend mode set to SDL_BLENDMODE_NONE:
726 * copy RGB, set destination alpha to source per-surface alpha value.
727 * both:
728 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
729 * source color key.
730 *
731 * RGBA->RGBA:
732 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
733 * alpha-blend (using the source alpha-channel and per-surface alpha)
734 * SDL_SRCCOLORKEY ignored.
735 * Source surface blend mode set to SDL_BLENDMODE_NONE:
736 * copy all of RGBA to the destination.
737 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
738 * RGB values of the source color key, ignoring alpha in the
739 * comparison.
740 *
741 * RGB->RGB:
742 * Source surface blend mode set to SDL_BLENDMODE_BLEND:
743 * alpha-blend (using the source per-surface alpha)
744 * Source surface blend mode set to SDL_BLENDMODE_NONE:
745 * copy RGB.
746 * both:
747 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
748 * source color key.
749 * ```
750 *
751 * \param src the SDL_Surface structure to be copied from
752 * \param srcrect the SDL_Rect structure representing the rectangle to be
753 * copied, or NULL to copy the entire surface
754 * \param dst the SDL_Surface structure that is the blit target
755 * \param dstrect the SDL_Rect structure representing the rectangle that is
756 * copied into
757 * \returns 0 on success or a negative error code on failure; call
758 * SDL_GetError() for more information.
759 *
760 * \since This function is available since SDL 3.0.0.
761 *
762 * \sa SDL_BlitSurface
763 */
764extern DECLSPEC int SDLCALL SDL_BlitSurface
765 (SDL_Surface *src, const SDL_Rect *srcrect,
766 SDL_Surface *dst, SDL_Rect *dstrect);
767
768/**
769 * Perform low-level surface blitting only.
770 *
771 * This is a semi-private blit function and it performs low-level surface
772 * blitting, assuming the input rectangles have already been clipped.
773 *
774 * \param src the SDL_Surface structure to be copied from
775 * \param srcrect the SDL_Rect structure representing the rectangle to be
776 * copied, or NULL to copy the entire surface
777 * \param dst the SDL_Surface structure that is the blit target
778 * \param dstrect the SDL_Rect structure representing the rectangle that is
779 * copied into
780 * \returns 0 on success or a negative error code on failure; call
781 * SDL_GetError() for more information.
782 *
783 * \since This function is available since SDL 3.0.0.
784 *
785 * \sa SDL_BlitSurface
786 */
787extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked
788 (SDL_Surface *src, SDL_Rect *srcrect,
789 SDL_Surface *dst, SDL_Rect *dstrect);
790
791
792/**
793 * Perform a fast, low quality, stretch blit between two surfaces of the same
794 * format.
795 *
796 * Please use SDL_BlitScaled() instead.
797 *
798 * \since This function is available since SDL 3.0.0.
799 */
800extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src,
801 const SDL_Rect *srcrect,
803 const SDL_Rect *dstrect);
804
805/**
806 * Perform bilinear scaling between two surfaces of the same format, 32BPP.
807 *
808 * \since This function is available since SDL 3.0.0.
809 */
810extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src,
811 const SDL_Rect *srcrect,
813 const SDL_Rect *dstrect);
814
815
816/**
817 * Perform a scaled surface copy to a destination surface.
818 *
819 * \param src the SDL_Surface structure to be copied from
820 * \param srcrect the SDL_Rect structure representing the rectangle to be
821 * copied
822 * \param dst the SDL_Surface structure that is the blit target
823 * \param dstrect the SDL_Rect structure representing the rectangle that is
824 * copied into
825 * \returns 0 on success or a negative error code on failure; call
826 * SDL_GetError() for more information.
827 *
828 * \since This function is available since SDL 3.0.0.
829 *
830 * \sa SDL_BlitScaled
831 */
832extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
833 (SDL_Surface *src, const SDL_Rect *srcrect,
834 SDL_Surface *dst, SDL_Rect *dstrect);
835
836/**
837 * Perform low-level surface scaled blitting only.
838 *
839 * This is a semi-private function and it performs low-level surface blitting,
840 * assuming the input rectangles have already been clipped.
841 *
842 * \param src the SDL_Surface structure to be copied from
843 * \param srcrect the SDL_Rect structure representing the rectangle to be
844 * copied
845 * \param dst the SDL_Surface structure that is the blit target
846 * \param dstrect the SDL_Rect structure representing the rectangle that is
847 * copied into
848 * \returns 0 on success or a negative error code on failure; call
849 * SDL_GetError() for more information.
850 *
851 * \since This function is available since SDL 3.0.0.
852 *
853 * \sa SDL_BlitScaled
854 */
855extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled
856 (SDL_Surface *src, SDL_Rect *srcrect,
857 SDL_Surface *dst, SDL_Rect *dstrect);
858
859/**
860 * Set the YUV conversion mode
861 *
862 * \since This function is available since SDL 3.0.0.
863 */
865
866/**
867 * Get the YUV conversion mode
868 *
869 * \since This function is available since SDL 3.0.0.
870 */
872
873/**
874 * Get the YUV conversion mode, returning the correct mode for the resolution
875 * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
876 *
877 * \since This function is available since SDL 3.0.0.
878 */
880
881/* Ends C function definitions when using C++ */
882#ifdef __cplusplus
883}
884#endif
885#include <SDL3/SDL_close_code.h>
886
887#endif /* SDL_surface_h_ */
SDL_BlendMode
The blend mode used in SDL_RenderTexture() and drawing operations.
Definition: SDL_blendmode.h:41
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
GLint GLint GLsizei width
Definition: SDL_opengl.h:1565
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1565
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
GLenum mode
GLenum src
GLuint64 key
GLuint color
GLboolean GLboolean GLboolean b
GLenum GLenum dst
GLboolean GLboolean g
GLfloat GLfloat GLfloat alpha
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)
void SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
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_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