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