getting stuff working on windows again
[vg.git] / dep / sdl / include / SDL_surface.h
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 "SDL_stdinc.h"
32 #include "SDL_pixels.h"
33 #include "SDL_rect.h"
34 #include "SDL_blendmode.h"
35 #include "SDL_rwops.h"
36
37 #include "begin_code.h"
38 /* Set up for C function definitions, even when using C++ */
39 #ifdef __cplusplus
40 extern "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
64 typedef 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 */
72 typedef 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 */
97 } SDL_Surface;
98
99 /**
100 * \brief The type of function used for surface blitting functions.
101 */
102 typedef 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 */
108 typedef enum
109 {
110 SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
111 SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
112 SDL_YUV_CONVERSION_BT709, /**< BT.709 */
113 SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
114 } SDL_YUV_CONVERSION_MODE;
115
116 /**
117 * Allocate a new RGB surface.
118 *
119 * If `depth` is 4 or 8 bits, an empty palette is allocated for the surface.
120 * If `depth` is greater than 8 bits, the pixel format is set using the
121 * [RGBA]mask parameters.
122 *
123 * The [RGBA]mask parameters are the bitmasks used to extract that color from
124 * a pixel. For instance, `Rmask` being 0xFF000000 means the red data is
125 * stored in the most significant byte. Using zeros for the RGB masks sets a
126 * default value, based on the depth. For example:
127 *
128 * ```c++
129 * SDL_CreateRGBSurface(0,w,h,32,0,0,0,0);
130 * ```
131 *
132 * However, using zero for the Amask results in an Amask of 0.
133 *
134 * By default surfaces with an alpha mask are set up for blending as with:
135 *
136 * ```c++
137 * SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)
138 * ```
139 *
140 * You can change this by calling SDL_SetSurfaceBlendMode() and selecting a
141 * different `blendMode`.
142 *
143 * \param flags the flags are unused and should be set to 0
144 * \param width the width of the surface
145 * \param height the height of the surface
146 * \param depth the depth of the surface in bits
147 * \param Rmask the red mask for the pixels
148 * \param Gmask the green mask for the pixels
149 * \param Bmask the blue mask for the pixels
150 * \param Amask the alpha mask for the pixels
151 * \returns the new SDL_Surface structure that is created or NULL if it fails;
152 * call SDL_GetError() for more information.
153 *
154 * \since This function is available since SDL 2.0.0.
155 *
156 * \sa SDL_CreateRGBSurfaceFrom
157 * \sa SDL_CreateRGBSurfaceWithFormat
158 * \sa SDL_FreeSurface
159 */
160 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
161 (Uint32 flags, int width, int height, int depth,
162 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
163
164
165 /* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
166
167 /**
168 * Allocate a new RGB surface with a specific pixel format.
169 *
170 * This function operates mostly like SDL_CreateRGBSurface(), except instead
171 * of providing pixel color masks, you provide it with a predefined format
172 * from SDL_PixelFormatEnum.
173 *
174 * \param flags the flags are unused and should be set to 0
175 * \param width the width of the surface
176 * \param height the height of the surface
177 * \param depth the depth of the surface in bits
178 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
179 * \returns the new SDL_Surface structure that is created or NULL if it fails;
180 * call SDL_GetError() for more information.
181 *
182 * \since This function is available since SDL 2.0.5.
183 *
184 * \sa SDL_CreateRGBSurface
185 * \sa SDL_CreateRGBSurfaceFrom
186 * \sa SDL_FreeSurface
187 */
188 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
189 (Uint32 flags, int width, int height, int depth, Uint32 format);
190
191 /**
192 * Allocate a new RGB surface with existing pixel data.
193 *
194 * This function operates mostly like SDL_CreateRGBSurface(), except it does
195 * not allocate memory for the pixel data, instead the caller provides an
196 * existing buffer of data for the surface to use.
197 *
198 * No copy is made of the pixel data. Pixel data is not managed automatically;
199 * you must free the surface before you free the pixel data.
200 *
201 * \param pixels a pointer to existing pixel data
202 * \param width the width of the surface
203 * \param height the height of the surface
204 * \param depth the depth of the surface in bits
205 * \param pitch the pitch of the surface in bytes
206 * \param Rmask the red mask for the pixels
207 * \param Gmask the green mask for the pixels
208 * \param Bmask the blue mask for the pixels
209 * \param Amask the alpha mask for the pixels
210 * \returns the new SDL_Surface structure that is created or NULL if it fails;
211 * call SDL_GetError() for more information.
212 *
213 * \since This function is available since SDL 2.0.0.
214 *
215 * \sa SDL_CreateRGBSurface
216 * \sa SDL_CreateRGBSurfaceWithFormat
217 * \sa SDL_FreeSurface
218 */
219 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
220 int width,
221 int height,
222 int depth,
223 int pitch,
224 Uint32 Rmask,
225 Uint32 Gmask,
226 Uint32 Bmask,
227 Uint32 Amask);
228
229 /* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
230
231 /**
232 * Allocate a new RGB surface with with a specific pixel format and existing
233 * pixel data.
234 *
235 * This function operates mostly like SDL_CreateRGBSurfaceFrom(), except
236 * instead of providing pixel color masks, you provide it with a predefined
237 * format from SDL_PixelFormatEnum.
238 *
239 * No copy is made of the pixel data. Pixel data is not managed automatically;
240 * you must free the surface before you free the pixel data.
241 *
242 * \param pixels a pointer to existing pixel data
243 * \param width the width of the surface
244 * \param height the height of the surface
245 * \param depth the depth of the surface in bits
246 * \param pitch the pitch of the surface in bytes
247 * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
248 * \returns the new SDL_Surface structure that is created or NULL if it fails;
249 * call SDL_GetError() for more information.
250 *
251 * \since This function is available since SDL 2.0.5.
252 *
253 * \sa SDL_CreateRGBSurfaceFrom
254 * \sa SDL_CreateRGBSurfaceWithFormat
255 * \sa SDL_FreeSurface
256 */
257 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
258 (void *pixels, int width, int height, int depth, int pitch, Uint32 format);
259
260 /**
261 * Free an RGB surface.
262 *
263 * It is safe to pass NULL to this function.
264 *
265 * \param surface the SDL_Surface to free.
266 *
267 * \since This function is available since SDL 2.0.0.
268 *
269 * \sa SDL_CreateRGBSurface
270 * \sa SDL_CreateRGBSurfaceFrom
271 * \sa SDL_LoadBMP
272 * \sa SDL_LoadBMP_RW
273 */
274 extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
275
276 /**
277 * Set the palette used by a surface.
278 *
279 * A single palette can be shared with many surfaces.
280 *
281 * \param surface the SDL_Surface structure to update
282 * \param palette the SDL_Palette structure to use
283 * \returns 0 on success or a negative error code on failure; call
284 * SDL_GetError() for more information.
285 *
286 * \since This function is available since SDL 2.0.0.
287 */
288 extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
289 SDL_Palette * palette);
290
291 /**
292 * Set up a surface for directly accessing the pixels.
293 *
294 * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
295 * and read from `surface->pixels`, using the pixel format stored in
296 * `surface->format`. Once you are done accessing the surface, you should use
297 * SDL_UnlockSurface() to release it.
298 *
299 * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
300 * 0, then you can read and write to the surface at any time, and the pixel
301 * format of the surface will not change.
302 *
303 * \param surface the SDL_Surface structure to be locked
304 * \returns 0 on success or a negative error code on failure; call
305 * SDL_GetError() for more information.
306 *
307 * \since This function is available since SDL 2.0.0.
308 *
309 * \sa SDL_MUSTLOCK
310 * \sa SDL_UnlockSurface
311 */
312 extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
313
314 /**
315 * Release a surface after directly accessing the pixels.
316 *
317 * \param surface the SDL_Surface structure to be unlocked
318 *
319 * \since This function is available since SDL 2.0.0.
320 *
321 * \sa SDL_LockSurface
322 */
323 extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
324
325 /**
326 * Load a BMP image from a seekable SDL data stream.
327 *
328 * The new surface should be freed with SDL_FreeSurface(). Not doing so will
329 * result in a memory leak.
330 *
331 * src is an open SDL_RWops buffer, typically loaded with SDL_RWFromFile.
332 * Alternitavely, you might also use the macro SDL_LoadBMP to load a bitmap
333 * from a file, convert it to an SDL_Surface and then close the file.
334 *
335 * \param src the data stream for the surface
336 * \param freesrc non-zero to close the stream after being read
337 * \returns a pointer to a new SDL_Surface structure or NULL if there was an
338 * error; call SDL_GetError() for more information.
339 *
340 * \since This function is available since SDL 2.0.0.
341 *
342 * \sa SDL_FreeSurface
343 * \sa SDL_RWFromFile
344 * \sa SDL_LoadBMP
345 * \sa SDL_SaveBMP_RW
346 */
347 extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
348 int freesrc);
349
350 /**
351 * Load a surface from a file.
352 *
353 * Convenience macro.
354 */
355 #define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
356
357 /**
358 * Save a surface to a seekable SDL data stream in BMP format.
359 *
360 * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
361 * BMP directly. Other RGB formats with 8-bit or higher get converted to a
362 * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
363 * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
364 * not supported.
365 *
366 * \param surface the SDL_Surface structure containing the image to be saved
367 * \param dst a data stream to save to
368 * \param freedst non-zero to close the stream after being written
369 * \returns 0 on success or a negative error code on failure; call
370 * SDL_GetError() for more information.
371 *
372 * \since This function is available since SDL 2.0.0.
373 *
374 * \sa SDL_LoadBMP_RW
375 * \sa SDL_SaveBMP
376 */
377 extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
378 (SDL_Surface * surface, SDL_RWops * dst, int freedst);
379
380 /**
381 * Save a surface to a file.
382 *
383 * Convenience macro.
384 */
385 #define SDL_SaveBMP(surface, file) \
386 SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
387
388 /**
389 * Set the RLE acceleration hint for a surface.
390 *
391 * If RLE is enabled, color key and alpha blending blits are much faster, but
392 * the surface must be locked before directly accessing the pixels.
393 *
394 * \param surface the SDL_Surface structure to optimize
395 * \param flag 0 to disable, non-zero to enable RLE acceleration
396 * \returns 0 on success or a negative error code on failure; call
397 * SDL_GetError() for more information.
398 *
399 * \since This function is available since SDL 2.0.0.
400 *
401 * \sa SDL_BlitSurface
402 * \sa SDL_LockSurface
403 * \sa SDL_UnlockSurface
404 */
405 extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
406 int flag);
407
408 /**
409 * Returns whether the surface is RLE enabled
410 *
411 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
412 *
413 * \param surface the SDL_Surface structure to query
414 * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
415 *
416 * \since This function is available since SDL 2.0.14.
417 *
418 * \sa SDL_SetSurfaceRLE
419 */
420 extern DECLSPEC SDL_bool SDLCALL SDL_HasSurfaceRLE(SDL_Surface * surface);
421
422 /**
423 * Set the color key (transparent pixel) in a surface.
424 *
425 * The color key defines a pixel value that will be treated as transparent in
426 * a blit. For example, one can use this to specify that cyan pixels should be
427 * considered transparent, and therefore not rendered.
428 *
429 * It is a pixel of the format used by the surface, as generated by
430 * SDL_MapRGB().
431 *
432 * RLE acceleration can substantially speed up blitting of images with large
433 * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details.
434 *
435 * \param surface the SDL_Surface structure to update
436 * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key
437 * \param key the transparent pixel
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 2.0.0.
442 *
443 * \sa SDL_BlitSurface
444 * \sa SDL_GetColorKey
445 */
446 extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
447 int flag, Uint32 key);
448
449 /**
450 * Returns whether the surface has a color key
451 *
452 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
453 *
454 * \param surface the SDL_Surface structure to query
455 * \return SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
456 *
457 * \since This function is available since SDL 2.0.9.
458 *
459 * \sa SDL_SetColorKey
460 * \sa SDL_GetColorKey
461 */
462 extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface);
463
464 /**
465 * Get the color key (transparent pixel) for a surface.
466 *
467 * The color key is a pixel of the format used by the surface, as generated by
468 * SDL_MapRGB().
469 *
470 * If the surface doesn't have color key enabled this function returns -1.
471 *
472 * \param surface the SDL_Surface structure to query
473 * \param key a pointer filled in with the transparent pixel
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 2.0.0.
478 *
479 * \sa SDL_BlitSurface
480 * \sa SDL_SetColorKey
481 */
482 extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
483 Uint32 * key);
484
485 /**
486 * Set an additional color value multiplied into blit operations.
487 *
488 * When this surface is blitted, during the blit operation each source color
489 * channel is modulated by the appropriate color value according to the
490 * following formula:
491 *
492 * `srcC = srcC * (color / 255)`
493 *
494 * \param surface the SDL_Surface structure to update
495 * \param r the red color value multiplied into blit operations
496 * \param g the green color value multiplied into blit operations
497 * \param b the blue color value multiplied into blit operations
498 * \returns 0 on success or a negative error code on failure; call
499 * SDL_GetError() for more information.
500 *
501 * \since This function is available since SDL 2.0.0.
502 *
503 * \sa SDL_GetSurfaceColorMod
504 * \sa SDL_SetSurfaceAlphaMod
505 */
506 extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
507 Uint8 r, Uint8 g, Uint8 b);
508
509
510 /**
511 * Get the additional color value multiplied into blit operations.
512 *
513 * \param surface the SDL_Surface structure to query
514 * \param r a pointer filled in with the current red color value
515 * \param g a pointer filled in with the current green color value
516 * \param b a pointer filled in with the current blue color value
517 * \returns 0 on success or a negative error code on failure; call
518 * SDL_GetError() for more information.
519 *
520 * \since This function is available since SDL 2.0.0.
521 *
522 * \sa SDL_GetSurfaceAlphaMod
523 * \sa SDL_SetSurfaceColorMod
524 */
525 extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
526 Uint8 * r, Uint8 * g,
527 Uint8 * b);
528
529 /**
530 * Set an additional alpha value used in blit operations.
531 *
532 * When this surface is blitted, during the blit operation the source alpha
533 * value is modulated by this alpha value according to the following formula:
534 *
535 * `srcA = srcA * (alpha / 255)`
536 *
537 * \param surface the SDL_Surface structure to update
538 * \param alpha the alpha value multiplied into blit operations
539 * \returns 0 on success or a negative error code on failure; call
540 * SDL_GetError() for more information.
541 *
542 * \since This function is available since SDL 2.0.0.
543 *
544 * \sa SDL_GetSurfaceAlphaMod
545 * \sa SDL_SetSurfaceColorMod
546 */
547 extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
548 Uint8 alpha);
549
550 /**
551 * Get the additional alpha value used in blit operations.
552 *
553 * \param surface the SDL_Surface structure to query
554 * \param alpha a pointer filled in with the current alpha value
555 * \returns 0 on success or a negative error code on failure; call
556 * SDL_GetError() for more information.
557 *
558 * \since This function is available since SDL 2.0.0.
559 *
560 * \sa SDL_GetSurfaceColorMod
561 * \sa SDL_SetSurfaceAlphaMod
562 */
563 extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
564 Uint8 * alpha);
565
566 /**
567 * Set the blend mode used for blit operations.
568 *
569 * To copy a surface to another surface (or texture) without blending with the
570 * existing data, the blendmode of the SOURCE surface should be set to
571 * `SDL_BLENDMODE_NONE`.
572 *
573 * \param surface the SDL_Surface structure to update
574 * \param blendMode the SDL_BlendMode to use for blit blending
575 * \returns 0 on success or a negative error code on failure; call
576 * SDL_GetError() for more information.
577 *
578 * \since This function is available since SDL 2.0.0.
579 *
580 * \sa SDL_GetSurfaceBlendMode
581 */
582 extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
583 SDL_BlendMode blendMode);
584
585 /**
586 * Get the blend mode used for blit operations.
587 *
588 * \param surface the SDL_Surface structure to query
589 * \param blendMode a pointer filled in with the current SDL_BlendMode
590 * \returns 0 on success or a negative error code on failure; call
591 * SDL_GetError() for more information.
592 *
593 * \since This function is available since SDL 2.0.0.
594 *
595 * \sa SDL_SetSurfaceBlendMode
596 */
597 extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
598 SDL_BlendMode *blendMode);
599
600 /**
601 * Set the clipping rectangle for a surface.
602 *
603 * When `surface` is the destination of a blit, only the area within the clip
604 * rectangle is drawn into.
605 *
606 * Note that blits are automatically clipped to the edges of the source and
607 * destination surfaces.
608 *
609 * \param surface the SDL_Surface structure to be clipped
610 * \param rect the SDL_Rect structure representing the clipping rectangle, or
611 * NULL to disable clipping
612 * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
613 * SDL_FALSE and blits will be completely clipped.
614 *
615 * \since This function is available since SDL 2.0.0.
616 *
617 * \sa SDL_BlitSurface
618 * \sa SDL_GetClipRect
619 */
620 extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
621 const SDL_Rect * rect);
622
623 /**
624 * Get the clipping rectangle for a surface.
625 *
626 * When `surface` is the destination of a blit, only the area within the clip
627 * rectangle is drawn into.
628 *
629 * \param surface the SDL_Surface structure representing the surface to be
630 * clipped
631 * \param rect an SDL_Rect structure filled in with the clipping rectangle for
632 * the surface
633 *
634 * \since This function is available since SDL 2.0.0.
635 *
636 * \sa SDL_BlitSurface
637 * \sa SDL_SetClipRect
638 */
639 extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
640 SDL_Rect * rect);
641
642 /*
643 * Creates a new surface identical to the existing surface.
644 *
645 * The returned surface should be freed with SDL_FreeSurface().
646 *
647 * \param surface the surface to duplicate.
648 * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
649 * more information.
650 */
651 extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface);
652
653 /**
654 * Copy an existing surface to a new surface of the specified format.
655 *
656 * This function is used to optimize images for faster *repeat* blitting. This
657 * is accomplished by converting the original and storing the result as a new
658 * surface. The new, optimized surface can then be used as the source for
659 * future blits, making them faster.
660 *
661 * \param src the existing SDL_Surface structure to convert
662 * \param fmt the SDL_PixelFormat structure that the new surface is optimized
663 * for
664 * \param flags the flags are unused and should be set to 0; this is a
665 * leftover from SDL 1.2's API
666 * \returns the new SDL_Surface structure that is created or NULL if it fails;
667 * call SDL_GetError() for more information.
668 *
669 * \since This function is available since SDL 2.0.0.
670 *
671 * \sa SDL_AllocFormat
672 * \sa SDL_ConvertSurfaceFormat
673 * \sa SDL_CreateRGBSurface
674 */
675 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
676 (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
677
678 /**
679 * Copy an existing surface to a new surface of the specified format enum.
680 *
681 * This function operates just like SDL_ConvertSurface(), but accepts an
682 * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
683 * it might be easier to call but it doesn't have access to palette
684 * information for the destination surface, in case that would be important.
685 *
686 * \param src the existing SDL_Surface structure to convert
687 * \param pixel_format the SDL_PixelFormatEnum that the new surface is
688 * optimized for
689 * \param flags the flags are unused and should be set to 0; this is a
690 * leftover from SDL 1.2's API
691 * \returns the new SDL_Surface structure that is created or NULL if it fails;
692 * call SDL_GetError() for more information.
693 *
694 * \since This function is available since SDL 2.0.0.
695 *
696 * \sa SDL_AllocFormat
697 * \sa SDL_ConvertSurface
698 * \sa SDL_CreateRGBSurface
699 */
700 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
701 (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
702
703 /**
704 * Copy a block of pixels of one format to another format.
705 *
706 * \param width the width of the block to copy, in pixels
707 * \param height the height of the block to copy, in pixels
708 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
709 * \param src a pointer to the source pixels
710 * \param src_pitch the pitch of the source pixels, in bytes
711 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
712 * \param dst a pointer to be filled in with new pixel data
713 * \param dst_pitch the pitch of the destination pixels, in bytes
714 * \returns 0 on success or a negative error code on failure; call
715 * SDL_GetError() for more information.
716 *
717 * \since This function is available since SDL 2.0.0.
718 */
719 extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
720 Uint32 src_format,
721 const void * src, int src_pitch,
722 Uint32 dst_format,
723 void * dst, int dst_pitch);
724
725 /**
726 * Premultiply the alpha on a block of pixels.
727 *
728 * This is safe to use with src == dst, but not for other overlapping areas.
729 *
730 * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
731 *
732 * \param width the width of the block to convert, in pixels
733 * \param height the height of the block to convert, in pixels
734 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
735 * \param src a pointer to the source pixels
736 * \param src_pitch the pitch of the source pixels, in bytes
737 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
738 * \param dst a pointer to be filled in with premultiplied pixel data
739 * \param dst_pitch the pitch of the destination pixels, in bytes
740 * \returns 0 on success or a negative error code on failure; call
741 * SDL_GetError() for more information.
742 *
743 * \since This function is available since SDL 2.0.18.
744 */
745 extern DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height,
746 Uint32 src_format,
747 const void * src, int src_pitch,
748 Uint32 dst_format,
749 void * dst, int dst_pitch);
750
751 /**
752 * Perform a fast fill of a rectangle with a specific color.
753 *
754 * `color` should be a pixel of the format used by the surface, and can be
755 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
756 * alpha component then the destination is simply filled with that alpha
757 * information, no blending takes place.
758 *
759 * If there is a clip rectangle set on the destination (set via
760 * SDL_SetClipRect()), then this function will fill based on the intersection
761 * of the clip rectangle and `rect`.
762 *
763 * \param dst the SDL_Surface structure that is the drawing target
764 * \param rect the SDL_Rect structure representing the rectangle to fill, or
765 * NULL to fill the entire surface
766 * \param color the color to fill with
767 * \returns 0 on success or a negative error code on failure; call
768 * SDL_GetError() for more information.
769 *
770 * \since This function is available since SDL 2.0.0.
771 *
772 * \sa SDL_FillRects
773 */
774 extern DECLSPEC int SDLCALL SDL_FillRect
775 (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
776
777 /**
778 * Perform a fast fill of a set of rectangles with a specific color.
779 *
780 * `color` should be a pixel of the format used by the surface, and can be
781 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
782 * alpha component then the destination is simply filled with that alpha
783 * information, no blending takes place.
784 *
785 * If there is a clip rectangle set on the destination (set via
786 * SDL_SetClipRect()), then this function will fill based on the intersection
787 * of the clip rectangle and `rect`.
788 *
789 * \param dst the SDL_Surface structure that is the drawing target
790 * \param rects an array of SDL_Rects representing the rectangles to fill.
791 * \param count the number of rectangles in the array
792 * \param color the color to fill with
793 * \returns 0 on success or a negative error code on failure; call
794 * SDL_GetError() for more information.
795 *
796 * \since This function is available since SDL 2.0.0.
797 *
798 * \sa SDL_FillRect
799 */
800 extern DECLSPEC int SDLCALL SDL_FillRects
801 (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
802
803 /* !!! FIXME: merge this documentation with the wiki */
804 /**
805 * Performs a fast blit from the source surface to the destination surface.
806 *
807 * This assumes that the source and destination rectangles are
808 * the same size. If either \c srcrect or \c dstrect are NULL, the entire
809 * surface (\c src or \c dst) is copied. The final blit rectangles are saved
810 * in \c srcrect and \c dstrect after all clipping is performed.
811 *
812 * \returns 0 if the blit is successful, otherwise it returns -1.
813 *
814 * The blit function should not be called on a locked surface.
815 *
816 * The blit semantics for surfaces with and without blending and colorkey
817 * are defined as follows:
818 * \verbatim
819 RGBA->RGB:
820 Source surface blend mode set to SDL_BLENDMODE_BLEND:
821 alpha-blend (using the source alpha-channel and per-surface alpha)
822 SDL_SRCCOLORKEY ignored.
823 Source surface blend mode set to SDL_BLENDMODE_NONE:
824 copy RGB.
825 if SDL_SRCCOLORKEY set, only copy the pixels matching the
826 RGB values of the source color key, ignoring alpha in the
827 comparison.
828
829 RGB->RGBA:
830 Source surface blend mode set to SDL_BLENDMODE_BLEND:
831 alpha-blend (using the source per-surface alpha)
832 Source surface blend mode set to SDL_BLENDMODE_NONE:
833 copy RGB, set destination alpha to source per-surface alpha value.
834 both:
835 if SDL_SRCCOLORKEY set, only copy the pixels matching the
836 source color key.
837
838 RGBA->RGBA:
839 Source surface blend mode set to SDL_BLENDMODE_BLEND:
840 alpha-blend (using the source alpha-channel and per-surface alpha)
841 SDL_SRCCOLORKEY ignored.
842 Source surface blend mode set to SDL_BLENDMODE_NONE:
843 copy all of RGBA to the destination.
844 if SDL_SRCCOLORKEY set, only copy the pixels matching the
845 RGB values of the source color key, ignoring alpha in the
846 comparison.
847
848 RGB->RGB:
849 Source surface blend mode set to SDL_BLENDMODE_BLEND:
850 alpha-blend (using the source per-surface alpha)
851 Source surface blend mode set to SDL_BLENDMODE_NONE:
852 copy RGB.
853 both:
854 if SDL_SRCCOLORKEY set, only copy the pixels matching the
855 source color key.
856 \endverbatim
857 *
858 * You should call SDL_BlitSurface() unless you know exactly how SDL
859 * blitting works internally and how to use the other blit functions.
860 */
861 #define SDL_BlitSurface SDL_UpperBlit
862
863 /**
864 * Perform a fast blit from the source surface to the destination surface.
865 *
866 * SDL_UpperBlit() has been replaced by SDL_BlitSurface(), which is merely a
867 * macro for this function with a less confusing name.
868 *
869 * \since This function is available since SDL 2.0.0.
870 *
871 * \sa SDL_BlitSurface
872 */
873 extern DECLSPEC int SDLCALL SDL_UpperBlit
874 (SDL_Surface * src, const SDL_Rect * srcrect,
875 SDL_Surface * dst, SDL_Rect * dstrect);
876
877 /**
878 * Perform low-level surface blitting only.
879 *
880 * This is a semi-private blit function and it performs low-level surface
881 * blitting, assuming the input rectangles have already been clipped.
882 *
883 * Unless you know what you're doing, you should be using SDL_BlitSurface()
884 * instead.
885 *
886 * \param src the SDL_Surface structure to be copied from
887 * \param srcrect the SDL_Rect structure representing the rectangle to be
888 * copied, or NULL to copy the entire surface
889 * \param dst the SDL_Surface structure that is the blit target
890 * \param dstrect the SDL_Rect structure representing the rectangle that is
891 * copied into
892 * \returns 0 on success or a negative error code on failure; call
893 * SDL_GetError() for more information.
894 *
895 * \since This function is available since SDL 2.0.0.
896 *
897 * \sa SDL_BlitSurface
898 */
899 extern DECLSPEC int SDLCALL SDL_LowerBlit
900 (SDL_Surface * src, SDL_Rect * srcrect,
901 SDL_Surface * dst, SDL_Rect * dstrect);
902
903
904 /**
905 * Perform a fast, low quality, stretch blit between two surfaces of the same
906 * format.
907 *
908 * Please use SDL_BlitScaled() instead.
909 *
910 * \since This function is available since SDL 2.0.0.
911 */
912 extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
913 const SDL_Rect * srcrect,
914 SDL_Surface * dst,
915 const SDL_Rect * dstrect);
916
917 /**
918 * Perform bilinear scaling between two surfaces of the same format, 32BPP.
919 *
920 * \since This function is available since SDL 2.0.16.
921 */
922 extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface * src,
923 const SDL_Rect * srcrect,
924 SDL_Surface * dst,
925 const SDL_Rect * dstrect);
926
927
928 #define SDL_BlitScaled SDL_UpperBlitScaled
929
930 /**
931 * Perform a scaled surface copy to a destination surface.
932 *
933 * SDL_UpperBlitScaled() has been replaced by SDL_BlitScaled(), which is
934 * merely a macro for this function with a less confusing name.
935 *
936 * \since This function is available since SDL 2.0.0.
937 *
938 * \sa SDL_BlitScaled
939 */
940 extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
941 (SDL_Surface * src, const SDL_Rect * srcrect,
942 SDL_Surface * dst, SDL_Rect * dstrect);
943
944 /**
945 * Perform low-level surface scaled blitting only.
946 *
947 * This is a semi-private function and it performs low-level surface blitting,
948 * assuming the input rectangles have already been clipped.
949 *
950 * \param src the SDL_Surface structure to be copied from
951 * \param srcrect the SDL_Rect structure representing the rectangle to be
952 * copied
953 * \param dst the SDL_Surface structure that is the blit target
954 * \param dstrect the SDL_Rect structure representing the rectangle that is
955 * copied into
956 * \returns 0 on success or a negative error code on failure; call
957 * SDL_GetError() for more information.
958 *
959 * \since This function is available since SDL 2.0.0.
960 *
961 * \sa SDL_BlitScaled
962 */
963 extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
964 (SDL_Surface * src, SDL_Rect * srcrect,
965 SDL_Surface * dst, SDL_Rect * dstrect);
966
967 /**
968 * Set the YUV conversion mode
969 *
970 * \since This function is available since SDL 2.0.8.
971 */
972 extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
973
974 /**
975 * Get the YUV conversion mode
976 *
977 * \since This function is available since SDL 2.0.8.
978 */
979 extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionMode(void);
980
981 /**
982 * Get the YUV conversion mode, returning the correct mode for the resolution
983 * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
984 *
985 * \since This function is available since SDL 2.0.8.
986 */
987 extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
988
989 /* Ends C function definitions when using C++ */
990 #ifdef __cplusplus
991 }
992 #endif
993 #include "close_code.h"
994
995 #endif /* SDL_surface_h_ */
996
997 /* vi: set ts=4 sw=4 expandtab: */