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 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 * \sa SDL_CreateRGBSurfaceFrom 153 * \sa SDL_CreateRGBSurfaceWithFormat 154 * \sa SDL_FreeSurface 155 */ 156 extern 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 */ 181 extern 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 automatically; 192 * 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 */ 210 extern 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 automatically; 230 * 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 */ 245 extern 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 */ 260 extern 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 */ 272 extern 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 */ 294 extern 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 */ 303 extern 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 */ 319 extern 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 */ 347 extern 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 */ 373 extern 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 */ 386 extern 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. For example, one can use this to specify that cyan pixels should be 393 * considered transparent, and therefore not rendered. 394 * 395 * It is a pixel of the format used by the surface, as generated by 396 * SDL_MapRGB(). 397 * 398 * RLE acceleration can substantially speed up blitting of images with large 399 * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details. 400 * 401 * \param surface the SDL_Surface structure to update 402 * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key 403 * \param key the transparent pixel 404 * \returns 0 on success or a negative error code on failure; call 405 * SDL_GetError() for more information. 406 * 407 * \sa SDL_BlitSurface 408 * \sa SDL_GetColorKey 409 */ 410 extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface, 411 int flag, Uint32 key); 412 413 /** 414 * Returns whether the surface has a color key 415 * 416 * It is safe to pass a NULL `surface` here; it will return SDL_FALSE. 417 * 418 * \param surface the SDL_Surface structure to query 419 * \return SDL_TRUE if the surface has a color key, SDL_FALSE otherwise. 420 * 421 * \sa SDL_SetColorKey 422 * \sa SDL_GetColorKey 423 */ 424 extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface); 425 426 /** 427 * Get the color key (transparent pixel) for a surface. 428 * 429 * The color key is a pixel of the format used by the surface, as generated by 430 * SDL_MapRGB(). 431 * 432 * If the surface doesn't have color key enabled this function returns -1. 433 * 434 * \param surface the SDL_Surface structure to query 435 * \param key a pointer filled in with the transparent pixel 436 * \returns 0 on success or a negative error code on failure; call 437 * SDL_GetError() for more information. 438 * 439 * \sa SDL_BlitSurface 440 * \sa SDL_SetColorKey 441 */ 442 extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface, 443 Uint32 * key); 444 445 /** 446 * Set an additional color value multiplied into blit operations. 447 * 448 * When this surface is blitted, during the blit operation each source color 449 * channel is modulated by the appropriate color value according to the 450 * following formula: 451 * 452 * `srcC = srcC * (color / 255)` 453 * 454 * \param surface the SDL_Surface structure to update 455 * \param r the red color value multiplied into blit operations 456 * \param g the green color value multiplied into blit operations 457 * \param b the blue color value multiplied into blit operations 458 * \returns 0 on success or a negative error code on failure; call 459 * SDL_GetError() for more information. 460 * 461 * \sa SDL_GetSurfaceColorMod 462 * \sa SDL_SetSurfaceAlphaMod 463 */ 464 extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface, 465 Uint8 r, Uint8 g, Uint8 b); 466 467 468 /** 469 * Get the additional color value multiplied into blit operations. 470 * 471 * \param surface the SDL_Surface structure to query 472 * \param r a pointer filled in with the current red color value 473 * \param g a pointer filled in with the current green color value 474 * \param b a pointer filled in with the current blue color value 475 * \returns 0 on success or a negative error code on failure; call 476 * SDL_GetError() for more information. 477 * 478 * \sa SDL_GetSurfaceAlphaMod 479 * \sa SDL_SetSurfaceColorMod 480 */ 481 extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface, 482 Uint8 * r, Uint8 * g, 483 Uint8 * b); 484 485 /** 486 * Set an additional alpha value used in blit operations. 487 * 488 * When this surface is blitted, during the blit operation the source alpha 489 * value is modulated by this alpha value according to the following formula: 490 * 491 * `srcA = srcA * (alpha / 255)` 492 * 493 * \param surface the SDL_Surface structure to update 494 * \param alpha the alpha value multiplied into blit operations 495 * \returns 0 on success or a negative error code on failure; call 496 * SDL_GetError() for more information. 497 * 498 * \sa SDL_GetSurfaceAlphaMod 499 * \sa SDL_SetSurfaceColorMod 500 */ 501 extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface, 502 Uint8 alpha); 503 504 /** 505 * Get the additional alpha value used in blit operations. 506 * 507 * \param surface the SDL_Surface structure to query 508 * \param alpha a pointer filled in with the current alpha value 509 * \returns 0 on success or a negative error code on failure; call 510 * SDL_GetError() for more information. 511 * 512 * \sa SDL_GetSurfaceColorMod 513 * \sa SDL_SetSurfaceAlphaMod 514 */ 515 extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface, 516 Uint8 * alpha); 517 518 /** 519 * Set the blend mode used for blit operations. 520 * 521 * To copy a surface to another surface (or texture) without blending with the 522 * existing data, the blendmode of the SOURCE surface should be set to 523 * `SDL_BLENDMODE_NONE`. 524 * 525 * \param surface the SDL_Surface structure to update 526 * \param blendMode the SDL_BlendMode to use for blit blending 527 * \returns 0 on success or a negative error code on failure; call 528 * SDL_GetError() for more information. 529 * 530 * \sa SDL_GetSurfaceBlendMode 531 */ 532 extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface, 533 SDL_BlendMode blendMode); 534 535 /** 536 * Get the blend mode used for blit operations. 537 * 538 * \param surface the SDL_Surface structure to query 539 * \param blendMode a pointer filled in with the current SDL_BlendMode 540 * \returns 0 on success or a negative error code on failure; call 541 * SDL_GetError() for more information. 542 * 543 * \sa SDL_SetSurfaceBlendMode 544 */ 545 extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface, 546 SDL_BlendMode *blendMode); 547 548 /** 549 * Set the clipping rectangle for a surface. 550 * 551 * When `surface` is the destination of a blit, only the area within the clip 552 * rectangle is drawn into. 553 * 554 * Note that blits are automatically clipped to the edges of the source and 555 * destination surfaces. 556 * 557 * \param surface the SDL_Surface structure to be clipped 558 * \param rect the SDL_Rect structure representing the clipping rectangle, or 559 * NULL to disable clipping 560 * \returns SDL_TRUE if the rectangle intersects the surface, otherwise 561 * SDL_FALSE and blits will be completely clipped. 562 * 563 * \sa SDL_BlitSurface 564 * \sa SDL_GetClipRect 565 */ 566 extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface, 567 const SDL_Rect * rect); 568 569 /** 570 * Get the clipping rectangle for a surface. 571 * 572 * When `surface` is the destination of a blit, only the area within the clip 573 * rectangle is drawn into. 574 * 575 * \param surface the SDL_Surface structure representing the surface to be 576 * clipped 577 * \param rect an SDL_Rect structure filled in with the clipping rectangle for 578 * the surface 579 * 580 * \sa SDL_BlitSurface 581 * \sa SDL_SetClipRect 582 */ 583 extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface, 584 SDL_Rect * rect); 585 586 /* 587 * Creates a new surface identical to the existing surface. 588 * 589 * The returned surface should be freed with SDL_FreeSurface(). 590 * 591 * \param surface the surface to duplicate. 592 * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for 593 * more information. 594 */ 595 extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface); 596 597 /** 598 * Copy an existing surface to a new surface of the specified format. 599 * 600 * This function is used to optimize images for faster *repeat* blitting. This 601 * is accomplished by converting the original and storing the result as a new 602 * surface. The new, optimized surface can then be used as the source for 603 * future blits, making them faster. 604 * 605 * \param src the existing SDL_Surface structure to convert 606 * \param fmt the SDL_PixelFormat structure that the new surface is optimized 607 * for 608 * \param flags the flags are unused and should be set to 0; this is a 609 * leftover from SDL 1.2's API 610 * \returns the new SDL_Surface structure that is created or NULL if it fails; 611 * call SDL_GetError() for more information. 612 * 613 * \sa SDL_AllocFormat 614 * \sa SDL_ConvertSurfaceFormat 615 * \sa SDL_CreateRGBSurface 616 */ 617 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface 618 (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags); 619 620 /** 621 * Copy an existing surface to a new surface of the specified format enum. 622 * 623 * This function operates just like SDL_ConvertSurface(), but accepts an 624 * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such, 625 * it might be easier to call but it doesn't have access to palette 626 * information for the destination surface, in case that would be important. 627 * 628 * \param src the existing SDL_Surface structure to convert 629 * \param pixel_format the SDL_PixelFormatEnum that the new surface is 630 * optimized for 631 * \param flags the flags are unused and should be set to 0; this is a 632 * leftover from SDL 1.2's API 633 * \returns the new SDL_Surface structure that is created or NULL if it fails; 634 * call SDL_GetError() for more information. 635 * 636 * \sa SDL_AllocFormat 637 * \sa SDL_ConvertSurfaceFormat 638 * \sa SDL_CreateRGBSurface 639 */ 640 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat 641 (SDL_Surface * src, Uint32 pixel_format, Uint32 flags); 642 643 /** 644 * Copy a block of pixels of one format to another format. 645 * 646 * \param width the width of the block to copy, in pixels 647 * \param height the height of the block to copy, in pixels 648 * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format 649 * \param src a pointer to the source pixels 650 * \param src_pitch the pitch of the block to copy, in bytes 651 * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format 652 * \param dst a pointer to be filled in with new pixel data 653 * \param dst_pitch the pitch of the destination pixels, in bytes 654 * \returns 0 on success or a negative error code on failure; call 655 * SDL_GetError() for more information. 656 */ 657 extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, 658 Uint32 src_format, 659 const void * src, int src_pitch, 660 Uint32 dst_format, 661 void * dst, int dst_pitch); 662 663 /** 664 * Perform a fast fill of a rectangle with a specific color. 665 * 666 * `color` should be a pixel of the format used by the surface, and can be 667 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an 668 * alpha component then the destination is simply filled with that alpha 669 * information, no blending takes place. 670 * 671 * If there is a clip rectangle set on the destination (set via 672 * SDL_SetClipRect()), then this function will fill based on the intersection 673 * of the clip rectangle and `rect`. 674 * 675 * \param dst the SDL_Surface structure that is the drawing target 676 * \param rect the SDL_Rect structure representing the rectangle to fill, or 677 * NULL to fill the entire surface 678 * \param color the color to fill with 679 * \returns 0 on success or a negative error code on failure; call 680 * SDL_GetError() for more information. 681 * 682 * \sa SDL_FillRects 683 */ 684 extern DECLSPEC int SDLCALL SDL_FillRect 685 (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color); 686 687 /** 688 * Perform a fast fill of a set of rectangles with a specific color. 689 * 690 * `color` should be a pixel of the format used by the surface, and can be 691 * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an 692 * alpha component then the destination is simply filled with that alpha 693 * information, no blending takes place. 694 * 695 * If there is a clip rectangle set on the destination (set via 696 * SDL_SetClipRect()), then this function will fill based on the intersection 697 * of the clip rectangle and `rect`. 698 * 699 * \param dst the SDL_Surface structure that is the drawing target 700 * \param rects an array of SDL_Rects representing the rectangles to fill. 701 * \param count the number of rectangles in the array 702 * \param color the color to fill with 703 * \returns 0 on success or a negative error code on failure; call 704 * SDL_GetError() for more information. 705 * 706 * \sa SDL_FillRect 707 */ 708 extern DECLSPEC int SDLCALL SDL_FillRects 709 (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color); 710 711 /* !!! FIXME: merge this documentation with the wiki */ 712 /** 713 * Performs a fast blit from the source surface to the destination surface. 714 * 715 * This assumes that the source and destination rectangles are 716 * the same size. If either \c srcrect or \c dstrect are NULL, the entire 717 * surface (\c src or \c dst) is copied. The final blit rectangles are saved 718 * in \c srcrect and \c dstrect after all clipping is performed. 719 * 720 * \returns 0 if the blit is successful, otherwise it returns -1. 721 * 722 * The blit function should not be called on a locked surface. 723 * 724 * The blit semantics for surfaces with and without blending and colorkey 725 * are defined as follows: 726 * \verbatim 727 RGBA->RGB: 728 Source surface blend mode set to SDL_BLENDMODE_BLEND: 729 alpha-blend (using the source alpha-channel and per-surface alpha) 730 SDL_SRCCOLORKEY ignored. 731 Source surface blend mode set to SDL_BLENDMODE_NONE: 732 copy RGB. 733 if SDL_SRCCOLORKEY set, only copy the pixels matching the 734 RGB values of the source color key, ignoring alpha in the 735 comparison. 736 737 RGB->RGBA: 738 Source surface blend mode set to SDL_BLENDMODE_BLEND: 739 alpha-blend (using the source per-surface alpha) 740 Source surface blend mode set to SDL_BLENDMODE_NONE: 741 copy RGB, set destination alpha to source per-surface alpha value. 742 both: 743 if SDL_SRCCOLORKEY set, only copy the pixels matching the 744 source color key. 745 746 RGBA->RGBA: 747 Source surface blend mode set to SDL_BLENDMODE_BLEND: 748 alpha-blend (using the source alpha-channel and per-surface alpha) 749 SDL_SRCCOLORKEY ignored. 750 Source surface blend mode set to SDL_BLENDMODE_NONE: 751 copy all of RGBA to the destination. 752 if SDL_SRCCOLORKEY set, only copy the pixels matching the 753 RGB values of the source color key, ignoring alpha in the 754 comparison. 755 756 RGB->RGB: 757 Source surface blend mode set to SDL_BLENDMODE_BLEND: 758 alpha-blend (using the source per-surface alpha) 759 Source surface blend mode set to SDL_BLENDMODE_NONE: 760 copy RGB. 761 both: 762 if SDL_SRCCOLORKEY set, only copy the pixels matching the 763 source color key. 764 \endverbatim 765 * 766 * You should call SDL_BlitSurface() unless you know exactly how SDL 767 * blitting works internally and how to use the other blit functions. 768 */ 769 #define SDL_BlitSurface SDL_UpperBlit 770 771 /** 772 * Perform a fast blit from the source surface to the destination surface. 773 * 774 * SDL_UpperBlit() has been replaced by SDL_BlitSurface(), which is merely a 775 * macro for this function with a less confusing name. 776 * 777 * \sa SDL_BlitSurface 778 */ 779 extern DECLSPEC int SDLCALL SDL_UpperBlit 780 (SDL_Surface * src, const SDL_Rect * srcrect, 781 SDL_Surface * dst, SDL_Rect * dstrect); 782 783 /** 784 * Perform low-level surface blitting only. 785 * 786 * This is a semi-private blit function and it performs low-level surface 787 * blitting, assuming the input rectangles have already been clipped. 788 * 789 * Unless you know what you're doing, you should be using SDL_BlitSurface() 790 * instead. 791 * 792 * \param src the SDL_Surface structure to be copied from 793 * \param srcrect the SDL_Rect structure representing the rectangle to be 794 * copied, or NULL to copy the entire surface 795 * \param dst the SDL_Surface structure that is the blit target 796 * \param dstrect the SDL_Rect structure representing the rectangle that is 797 * copied into 798 * \returns 0 on success or a negative error code on failure; call 799 * SDL_GetError() for more information. 800 * 801 * \sa SDL_BlitSurface 802 */ 803 extern DECLSPEC int SDLCALL SDL_LowerBlit 804 (SDL_Surface * src, SDL_Rect * srcrect, 805 SDL_Surface * dst, SDL_Rect * dstrect); 806 807 808 /** 809 * Perform a fast, low quality, stretch blit between two surfaces of the 810 * same format. 811 * 812 * Please use SDL_BlitScaled() instead. 813 */ 814 extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src, 815 const SDL_Rect * srcrect, 816 SDL_Surface * dst, 817 const SDL_Rect * dstrect); 818 819 /** 820 * Perform bilinear scaling between two surfaces of the same format, 32BPP. 821 */ 822 extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface * src, 823 const SDL_Rect * srcrect, 824 SDL_Surface * dst, 825 const SDL_Rect * dstrect); 826 827 828 #define SDL_BlitScaled SDL_UpperBlitScaled 829 830 /** 831 * Perform a scaled surface copy to a destination surface. 832 * 833 * SDL_UpperBlitScaled() has been replaced by SDL_BlitScaled(), which is 834 * merely a macro for this function with a less confusing name. 835 * 836 * \sa SDL_BlitScaled 837 */ 838 extern DECLSPEC int SDLCALL SDL_UpperBlitScaled 839 (SDL_Surface * src, const SDL_Rect * srcrect, 840 SDL_Surface * dst, SDL_Rect * dstrect); 841 842 /** 843 * Perform low-level surface scaled blitting only. 844 * 845 * This is a semi-private function and it performs low-level surface blitting, 846 * assuming the input rectangles have already been clipped. 847 * 848 * \param src the SDL_Surface structure to be copied from 849 * \param srcrect the SDL_Rect structure representing the rectangle to be 850 * copied 851 * \param dst the SDL_Surface structure that is the blit target 852 * \param dstrect the SDL_Rect structure representing the rectangle that is 853 * copied into 854 * \returns 0 on success or a negative error code on failure; call 855 * SDL_GetError() for more information. 856 * 857 * \sa SDL_BlitScaled 858 */ 859 extern DECLSPEC int SDLCALL SDL_LowerBlitScaled 860 (SDL_Surface * src, SDL_Rect * srcrect, 861 SDL_Surface * dst, SDL_Rect * dstrect); 862 863 /** 864 * Set the YUV conversion mode 865 */ 866 extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode); 867 868 /** 869 * Get the YUV conversion mode 870 */ 871 extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionMode(void); 872 873 /** 874 * Get the YUV conversion mode, returning the correct mode for the resolution 875 * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC 876 */ 877 extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height); 878 879 /* Ends C function definitions when using C++ */ 880 #ifdef __cplusplus 881 } 882 #endif 883 #include "close_code.h" 884 885 #endif /* SDL_surface_h_ */ 886 887 /* vi: set ts=4 sw=4 expandtab: */ 888