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