| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 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 | * # CategorySurface |
| 24 | * |
| 25 | * SDL surfaces are buffers of pixels in system RAM. These are useful for |
| 26 | * passing around and manipulating images that are not stored in GPU memory. |
| 27 | * |
| 28 | * SDL_Surface makes serious efforts to manage images in various formats, and |
| 29 | * provides a reasonable toolbox for transforming the data, including copying |
| 30 | * between surfaces, filling rectangles in the image data, etc. |
| 31 | * |
| 32 | * There is also a simple .bmp loader, SDL_LoadBMP(). SDL itself does not |
| 33 | * provide loaders for various other file formats, but there are several |
| 34 | * excellent external libraries that do, including its own satellite library, |
| 35 | * SDL_image: |
| 36 | * |
| 37 | * https://github.com/libsdl-org/SDL_image |
| 38 | */ |
| 39 | |
| 40 | #ifndef SDL_surface_h_ |
| 41 | #define SDL_surface_h_ |
| 42 | |
| 43 | #include <SDL3/SDL_stdinc.h> |
| 44 | #include <SDL3/SDL_error.h> |
| 45 | #include <SDL3/SDL_blendmode.h> |
| 46 | #include <SDL3/SDL_pixels.h> |
| 47 | #include <SDL3/SDL_properties.h> |
| 48 | #include <SDL3/SDL_rect.h> |
| 49 | #include <SDL3/SDL_iostream.h> |
| 50 | |
| 51 | #include <SDL3/SDL_begin_code.h> |
| 52 | /* Set up for C function definitions, even when using C++ */ |
| 53 | #ifdef __cplusplus |
| 54 | extern "C" { |
| 55 | #endif |
| 56 | |
| 57 | /** |
| 58 | * The flags on an SDL_Surface. |
| 59 | * |
| 60 | * These are generally considered read-only. |
| 61 | * |
| 62 | * \since This datatype is available since SDL 3.2.0. |
| 63 | */ |
| 64 | typedef Uint32 SDL_SurfaceFlags; |
| 65 | |
| 66 | #define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */ |
| 67 | #define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */ |
| 68 | #define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */ |
| 69 | #define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */ |
| 70 | |
| 71 | /** |
| 72 | * Evaluates to true if the surface needs to be locked before access. |
| 73 | * |
| 74 | * \since This macro is available since SDL 3.2.0. |
| 75 | */ |
| 76 | #define SDL_MUSTLOCK(S) (((S)->flags & SDL_SURFACE_LOCK_NEEDED) == SDL_SURFACE_LOCK_NEEDED) |
| 77 | |
| 78 | /** |
| 79 | * The scaling mode. |
| 80 | * |
| 81 | * \since This enum is available since SDL 3.2.0. |
| 82 | */ |
| 83 | typedef enum SDL_ScaleMode |
| 84 | { |
| 85 | SDL_SCALEMODE_INVALID = -1, |
| 86 | SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */ |
| 87 | SDL_SCALEMODE_LINEAR, /**< linear filtering */ |
| 88 | SDL_SCALEMODE_PIXELART /**< nearest pixel sampling with improved scaling for pixel art */ |
| 89 | } SDL_ScaleMode; |
| 90 | |
| 91 | /** |
| 92 | * The flip mode. |
| 93 | * |
| 94 | * \since This enum is available since SDL 3.2.0. |
| 95 | */ |
| 96 | typedef enum SDL_FlipMode |
| 97 | { |
| 98 | SDL_FLIP_NONE, /**< Do not flip */ |
| 99 | SDL_FLIP_HORIZONTAL, /**< flip horizontally */ |
| 100 | SDL_FLIP_VERTICAL /**< flip vertically */ |
| 101 | } SDL_FlipMode; |
| 102 | |
| 103 | #ifndef SDL_INTERNAL |
| 104 | |
| 105 | /** |
| 106 | * A collection of pixels used in software blitting. |
| 107 | * |
| 108 | * Pixels are arranged in memory in rows, with the top row first. Each row |
| 109 | * occupies an amount of memory given by the pitch (sometimes known as the row |
| 110 | * stride in non-SDL APIs). |
| 111 | * |
| 112 | * Within each row, pixels are arranged from left to right until the width is |
| 113 | * reached. Each pixel occupies a number of bits appropriate for its format, |
| 114 | * with most formats representing each pixel as one or more whole bytes (in |
| 115 | * some indexed formats, instead multiple pixels are packed into each byte), |
| 116 | * and a byte order given by the format. After encoding all pixels, any |
| 117 | * remaining bytes to reach the pitch are used as padding to reach a desired |
| 118 | * alignment, and have undefined contents. |
| 119 | * |
| 120 | * When a surface holds YUV format data, the planes are assumed to be |
| 121 | * contiguous without padding between them, e.g. a 32x32 surface in NV12 |
| 122 | * format with a pitch of 32 would consist of 32x32 bytes of Y plane followed |
| 123 | * by 32x16 bytes of UV plane. |
| 124 | * |
| 125 | * When a surface holds MJPG format data, pixels points at the compressed JPEG |
| 126 | * image and pitch is the length of that data. |
| 127 | * |
| 128 | * \since This struct is available since SDL 3.2.0. |
| 129 | * |
| 130 | * \sa SDL_CreateSurface |
| 131 | * \sa SDL_DestroySurface |
| 132 | */ |
| 133 | struct SDL_Surface |
| 134 | { |
| 135 | SDL_SurfaceFlags flags; /**< The flags of the surface, read-only */ |
| 136 | SDL_PixelFormat format; /**< The format of the surface, read-only */ |
| 137 | int w; /**< The width of the surface, read-only. */ |
| 138 | int h; /**< The height of the surface, read-only. */ |
| 139 | int pitch; /**< The distance in bytes between rows of pixels, read-only */ |
| 140 | void *pixels; /**< A pointer to the pixels of the surface, the pixels are writeable if non-NULL */ |
| 141 | |
| 142 | int refcount; /**< Application reference count, used when freeing surface */ |
| 143 | |
| 144 | void *reserved; /**< Reserved for internal use */ |
| 145 | }; |
| 146 | #endif /* !SDL_INTERNAL */ |
| 147 | |
| 148 | typedef struct SDL_Surface SDL_Surface; |
| 149 | |
| 150 | /** |
| 151 | * Allocate a new surface with a specific pixel format. |
| 152 | * |
| 153 | * The pixels of the new surface are initialized to zero. |
| 154 | * |
| 155 | * \param width the width of the surface. |
| 156 | * \param height the height of the surface. |
| 157 | * \param format the SDL_PixelFormat for the new surface's pixel format. |
| 158 | * \returns the new SDL_Surface structure that is created or NULL on failure; |
| 159 | * call SDL_GetError() for more information. |
| 160 | * |
| 161 | * \threadsafety It is safe to call this function from any thread. |
| 162 | * |
| 163 | * \since This function is available since SDL 3.2.0. |
| 164 | * |
| 165 | * \sa SDL_CreateSurfaceFrom |
| 166 | * \sa SDL_DestroySurface |
| 167 | */ |
| 168 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format); |
| 169 | |
| 170 | /** |
| 171 | * Allocate a new surface with a specific pixel format and existing pixel |
| 172 | * data. |
| 173 | * |
| 174 | * No copy is made of the pixel data. Pixel data is not managed automatically; |
| 175 | * you must free the surface before you free the pixel data. |
| 176 | * |
| 177 | * Pitch is the offset in bytes from one row of pixels to the next, e.g. |
| 178 | * `width*4` for `SDL_PIXELFORMAT_RGBA8888`. |
| 179 | * |
| 180 | * You may pass NULL for pixels and 0 for pitch to create a surface that you |
| 181 | * will fill in with valid values later. |
| 182 | * |
| 183 | * \param width the width of the surface. |
| 184 | * \param height the height of the surface. |
| 185 | * \param format the SDL_PixelFormat for the new surface's pixel format. |
| 186 | * \param pixels a pointer to existing pixel data. |
| 187 | * \param pitch the number of bytes between each row, including padding. |
| 188 | * \returns the new SDL_Surface structure that is created or NULL on failure; |
| 189 | * call SDL_GetError() for more information. |
| 190 | * |
| 191 | * \threadsafety It is safe to call this function from any thread. |
| 192 | * |
| 193 | * \since This function is available since SDL 3.2.0. |
| 194 | * |
| 195 | * \sa SDL_CreateSurface |
| 196 | * \sa SDL_DestroySurface |
| 197 | */ |
| 198 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch); |
| 199 | |
| 200 | /** |
| 201 | * Free a surface. |
| 202 | * |
| 203 | * It is safe to pass NULL to this function. |
| 204 | * |
| 205 | * \param surface the SDL_Surface to free. |
| 206 | * |
| 207 | * \threadsafety No other thread should be using the surface when it is freed. |
| 208 | * |
| 209 | * \since This function is available since SDL 3.2.0. |
| 210 | * |
| 211 | * \sa SDL_CreateSurface |
| 212 | * \sa SDL_CreateSurfaceFrom |
| 213 | */ |
| 214 | extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface); |
| 215 | |
| 216 | /** |
| 217 | * Get the properties associated with a surface. |
| 218 | * |
| 219 | * The following properties are understood by SDL: |
| 220 | * |
| 221 | * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point |
| 222 | * surfaces, this defines the value of 100% diffuse white, with higher |
| 223 | * values being displayed in the High Dynamic Range headroom. This defaults |
| 224 | * to 203 for HDR10 surfaces and 1.0 for floating point surfaces. |
| 225 | * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point |
| 226 | * surfaces, this defines the maximum dynamic range used by the content, in |
| 227 | * terms of the SDR white point. This defaults to 0.0, which disables tone |
| 228 | * mapping. |
| 229 | * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator |
| 230 | * used when compressing from a surface with high dynamic range to another |
| 231 | * with lower dynamic range. Currently this supports "chrome", which uses |
| 232 | * the same tone mapping that Chrome uses for HDR content, the form "*=N", |
| 233 | * where N is a floating point scale factor applied in linear space, and |
| 234 | * "none", which disables tone mapping. This defaults to "chrome". |
| 235 | * - `SDL_PROP_SURFACE_HOTSPOT_X_NUMBER`: the hotspot pixel offset from the |
| 236 | * left edge of the image, if this surface is being used as a cursor. |
| 237 | * - `SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`: the hotspot pixel offset from the |
| 238 | * top edge of the image, if this surface is being used as a cursor. |
| 239 | * |
| 240 | * \param surface the SDL_Surface structure to query. |
| 241 | * \returns a valid property ID on success or 0 on failure; call |
| 242 | * SDL_GetError() for more information. |
| 243 | * |
| 244 | * \threadsafety It is safe to call this function from any thread. |
| 245 | * |
| 246 | * \since This function is available since SDL 3.2.0. |
| 247 | */ |
| 248 | extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface); |
| 249 | |
| 250 | #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point" |
| 251 | #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom" |
| 252 | #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap" |
| 253 | #define SDL_PROP_SURFACE_HOTSPOT_X_NUMBER "SDL.surface.hotspot.x" |
| 254 | #define SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER "SDL.surface.hotspot.y" |
| 255 | |
| 256 | /** |
| 257 | * Set the colorspace used by a surface. |
| 258 | * |
| 259 | * Setting the colorspace doesn't change the pixels, only how they are |
| 260 | * interpreted in color operations. |
| 261 | * |
| 262 | * \param surface the SDL_Surface structure to update. |
| 263 | * \param colorspace an SDL_Colorspace value describing the surface |
| 264 | * colorspace. |
| 265 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 266 | * information. |
| 267 | * |
| 268 | * \threadsafety This function is not thread safe. |
| 269 | * |
| 270 | * \since This function is available since SDL 3.2.0. |
| 271 | * |
| 272 | * \sa SDL_GetSurfaceColorspace |
| 273 | */ |
| 274 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace); |
| 275 | |
| 276 | /** |
| 277 | * Get the colorspace used by a surface. |
| 278 | * |
| 279 | * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point |
| 280 | * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for |
| 281 | * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures. |
| 282 | * |
| 283 | * \param surface the SDL_Surface structure to query. |
| 284 | * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if |
| 285 | * the surface is NULL. |
| 286 | * |
| 287 | * \threadsafety This function is not thread safe. |
| 288 | * |
| 289 | * \since This function is available since SDL 3.2.0. |
| 290 | * |
| 291 | * \sa SDL_SetSurfaceColorspace |
| 292 | */ |
| 293 | extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface); |
| 294 | |
| 295 | /** |
| 296 | * Create a palette and associate it with a surface. |
| 297 | * |
| 298 | * This function creates a palette compatible with the provided surface. The |
| 299 | * palette is then returned for you to modify, and the surface will |
| 300 | * automatically use the new palette in future operations. You do not need to |
| 301 | * destroy the returned palette, it will be freed when the reference count |
| 302 | * reaches 0, usually when the surface is destroyed. |
| 303 | * |
| 304 | * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or |
| 305 | * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as |
| 306 | * white and 1 as black. Other surfaces will get a palette initialized with |
| 307 | * white in every entry. |
| 308 | * |
| 309 | * If this function is called for a surface that already has a palette, a new |
| 310 | * palette will be created to replace it. |
| 311 | * |
| 312 | * \param surface the SDL_Surface structure to update. |
| 313 | * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if |
| 314 | * the surface didn't have an index format); call SDL_GetError() for |
| 315 | * more information. |
| 316 | * |
| 317 | * \threadsafety This function is not thread safe. |
| 318 | * |
| 319 | * \since This function is available since SDL 3.2.0. |
| 320 | * |
| 321 | * \sa SDL_SetPaletteColors |
| 322 | */ |
| 323 | extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface); |
| 324 | |
| 325 | /** |
| 326 | * Set the palette used by a surface. |
| 327 | * |
| 328 | * A single palette can be shared with many surfaces. |
| 329 | * |
| 330 | * \param surface the SDL_Surface structure to update. |
| 331 | * \param palette the SDL_Palette structure to use. |
| 332 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 333 | * information. |
| 334 | * |
| 335 | * \threadsafety This function is not thread safe. |
| 336 | * |
| 337 | * \since This function is available since SDL 3.2.0. |
| 338 | * |
| 339 | * \sa SDL_CreatePalette |
| 340 | * \sa SDL_GetSurfacePalette |
| 341 | */ |
| 342 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette); |
| 343 | |
| 344 | /** |
| 345 | * Get the palette used by a surface. |
| 346 | * |
| 347 | * \param surface the SDL_Surface structure to query. |
| 348 | * \returns a pointer to the palette used by the surface, or NULL if there is |
| 349 | * no palette used. |
| 350 | * |
| 351 | * \threadsafety It is safe to call this function from any thread. |
| 352 | * |
| 353 | * \since This function is available since SDL 3.2.0. |
| 354 | * |
| 355 | * \sa SDL_SetSurfacePalette |
| 356 | */ |
| 357 | extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface); |
| 358 | |
| 359 | /** |
| 360 | * Add an alternate version of a surface. |
| 361 | * |
| 362 | * This function adds an alternate version of this surface, usually used for |
| 363 | * content with high DPI representations like cursors or icons. The size, |
| 364 | * format, and content do not need to match the original surface, and these |
| 365 | * alternate versions will not be updated when the original surface changes. |
| 366 | * |
| 367 | * This function adds a reference to the alternate version, so you should call |
| 368 | * SDL_DestroySurface() on the image after this call. |
| 369 | * |
| 370 | * \param surface the SDL_Surface structure to update. |
| 371 | * \param image a pointer to an alternate SDL_Surface to associate with this |
| 372 | * surface. |
| 373 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 374 | * information. |
| 375 | * |
| 376 | * \threadsafety This function is not thread safe. |
| 377 | * |
| 378 | * \since This function is available since SDL 3.2.0. |
| 379 | * |
| 380 | * \sa SDL_RemoveSurfaceAlternateImages |
| 381 | * \sa SDL_GetSurfaceImages |
| 382 | * \sa SDL_SurfaceHasAlternateImages |
| 383 | */ |
| 384 | extern SDL_DECLSPEC bool SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image); |
| 385 | |
| 386 | /** |
| 387 | * Return whether a surface has alternate versions available. |
| 388 | * |
| 389 | * \param surface the SDL_Surface structure to query. |
| 390 | * \returns true if alternate versions are available or false otherwise. |
| 391 | * |
| 392 | * \threadsafety It is safe to call this function from any thread. |
| 393 | * |
| 394 | * \since This function is available since SDL 3.2.0. |
| 395 | * |
| 396 | * \sa SDL_AddSurfaceAlternateImage |
| 397 | * \sa SDL_RemoveSurfaceAlternateImages |
| 398 | * \sa SDL_GetSurfaceImages |
| 399 | */ |
| 400 | extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasAlternateImages(SDL_Surface *surface); |
| 401 | |
| 402 | /** |
| 403 | * Get an array including all versions of a surface. |
| 404 | * |
| 405 | * This returns all versions of a surface, with the surface being queried as |
| 406 | * the first element in the returned array. |
| 407 | * |
| 408 | * Freeing the array of surfaces does not affect the surfaces in the array. |
| 409 | * They are still referenced by the surface being queried and will be cleaned |
| 410 | * up normally. |
| 411 | * |
| 412 | * \param surface the SDL_Surface structure to query. |
| 413 | * \param count a pointer filled in with the number of surface pointers |
| 414 | * returned, may be NULL. |
| 415 | * \returns a NULL terminated array of SDL_Surface pointers or NULL on |
| 416 | * failure; call SDL_GetError() for more information. This should be |
| 417 | * freed with SDL_free() when it is no longer needed. |
| 418 | * |
| 419 | * \threadsafety This function is not thread safe. |
| 420 | * |
| 421 | * \since This function is available since SDL 3.2.0. |
| 422 | * |
| 423 | * \sa SDL_AddSurfaceAlternateImage |
| 424 | * \sa SDL_RemoveSurfaceAlternateImages |
| 425 | * \sa SDL_SurfaceHasAlternateImages |
| 426 | */ |
| 427 | extern SDL_DECLSPEC SDL_Surface ** SDLCALL SDL_GetSurfaceImages(SDL_Surface *surface, int *count); |
| 428 | |
| 429 | /** |
| 430 | * Remove all alternate versions of a surface. |
| 431 | * |
| 432 | * This function removes a reference from all the alternative versions, |
| 433 | * destroying them if this is the last reference to them. |
| 434 | * |
| 435 | * \param surface the SDL_Surface structure to update. |
| 436 | * |
| 437 | * \threadsafety This function is not thread safe. |
| 438 | * |
| 439 | * \since This function is available since SDL 3.2.0. |
| 440 | * |
| 441 | * \sa SDL_AddSurfaceAlternateImage |
| 442 | * \sa SDL_GetSurfaceImages |
| 443 | * \sa SDL_SurfaceHasAlternateImages |
| 444 | */ |
| 445 | extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface); |
| 446 | |
| 447 | /** |
| 448 | * Set up a surface for directly accessing the pixels. |
| 449 | * |
| 450 | * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to |
| 451 | * and read from `surface->pixels`, using the pixel format stored in |
| 452 | * `surface->format`. Once you are done accessing the surface, you should use |
| 453 | * SDL_UnlockSurface() to release it. |
| 454 | * |
| 455 | * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to |
| 456 | * 0, then you can read and write to the surface at any time, and the pixel |
| 457 | * format of the surface will not change. |
| 458 | * |
| 459 | * \param surface the SDL_Surface structure to be locked. |
| 460 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 461 | * information. |
| 462 | * |
| 463 | * \threadsafety This function is not thread safe. The locking referred to by |
| 464 | * this function is making the pixels available for direct |
| 465 | * access, not thread-safe locking. |
| 466 | * |
| 467 | * \since This function is available since SDL 3.2.0. |
| 468 | * |
| 469 | * \sa SDL_MUSTLOCK |
| 470 | * \sa SDL_UnlockSurface |
| 471 | */ |
| 472 | extern SDL_DECLSPEC bool SDLCALL SDL_LockSurface(SDL_Surface *surface); |
| 473 | |
| 474 | /** |
| 475 | * Release a surface after directly accessing the pixels. |
| 476 | * |
| 477 | * \param surface the SDL_Surface structure to be unlocked. |
| 478 | * |
| 479 | * \threadsafety This function is not thread safe. The locking referred to by |
| 480 | * this function is making the pixels available for direct |
| 481 | * access, not thread-safe locking. |
| 482 | * |
| 483 | * \since This function is available since SDL 3.2.0. |
| 484 | * |
| 485 | * \sa SDL_LockSurface |
| 486 | */ |
| 487 | extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface); |
| 488 | |
| 489 | /** |
| 490 | * Load a BMP image from a seekable SDL data stream. |
| 491 | * |
| 492 | * The new surface should be freed with SDL_DestroySurface(). Not doing so |
| 493 | * will result in a memory leak. |
| 494 | * |
| 495 | * \param src the data stream for the surface. |
| 496 | * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even |
| 497 | * in the case of an error. |
| 498 | * \returns a pointer to a new SDL_Surface structure or NULL on failure; call |
| 499 | * SDL_GetError() for more information. |
| 500 | * |
| 501 | * \threadsafety It is safe to call this function from any thread. |
| 502 | * |
| 503 | * \since This function is available since SDL 3.2.0. |
| 504 | * |
| 505 | * \sa SDL_DestroySurface |
| 506 | * \sa SDL_LoadBMP |
| 507 | * \sa SDL_SaveBMP_IO |
| 508 | */ |
| 509 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio); |
| 510 | |
| 511 | /** |
| 512 | * Load a BMP image from a file. |
| 513 | * |
| 514 | * The new surface should be freed with SDL_DestroySurface(). Not doing so |
| 515 | * will result in a memory leak. |
| 516 | * |
| 517 | * \param file the BMP file to load. |
| 518 | * \returns a pointer to a new SDL_Surface structure or NULL on failure; call |
| 519 | * SDL_GetError() for more information. |
| 520 | * |
| 521 | * \threadsafety It is safe to call this function from any thread. |
| 522 | * |
| 523 | * \since This function is available since SDL 3.2.0. |
| 524 | * |
| 525 | * \sa SDL_DestroySurface |
| 526 | * \sa SDL_LoadBMP_IO |
| 527 | * \sa SDL_SaveBMP |
| 528 | */ |
| 529 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file); |
| 530 | |
| 531 | /** |
| 532 | * Save a surface to a seekable SDL data stream in BMP format. |
| 533 | * |
| 534 | * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the |
| 535 | * BMP directly. Other RGB formats with 8-bit or higher get converted to a |
| 536 | * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit |
| 537 | * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are |
| 538 | * not supported. |
| 539 | * |
| 540 | * \param surface the SDL_Surface structure containing the image to be saved. |
| 541 | * \param dst a data stream to save to. |
| 542 | * \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even |
| 543 | * in the case of an error. |
| 544 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 545 | * information. |
| 546 | * |
| 547 | * \threadsafety This function is not thread safe. |
| 548 | * |
| 549 | * \since This function is available since SDL 3.2.0. |
| 550 | * |
| 551 | * \sa SDL_LoadBMP_IO |
| 552 | * \sa SDL_SaveBMP |
| 553 | */ |
| 554 | extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio); |
| 555 | |
| 556 | /** |
| 557 | * Save a surface to a file. |
| 558 | * |
| 559 | * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the |
| 560 | * BMP directly. Other RGB formats with 8-bit or higher get converted to a |
| 561 | * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit |
| 562 | * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are |
| 563 | * not supported. |
| 564 | * |
| 565 | * \param surface the SDL_Surface structure containing the image to be saved. |
| 566 | * \param file a file to save to. |
| 567 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 568 | * information. |
| 569 | * |
| 570 | * \threadsafety This function is not thread safe. |
| 571 | * |
| 572 | * \since This function is available since SDL 3.2.0. |
| 573 | * |
| 574 | * \sa SDL_LoadBMP |
| 575 | * \sa SDL_SaveBMP_IO |
| 576 | */ |
| 577 | extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file); |
| 578 | |
| 579 | /** |
| 580 | * Set the RLE acceleration hint for a surface. |
| 581 | * |
| 582 | * If RLE is enabled, color key and alpha blending blits are much faster, but |
| 583 | * the surface must be locked before directly accessing the pixels. |
| 584 | * |
| 585 | * \param surface the SDL_Surface structure to optimize. |
| 586 | * \param enabled true to enable RLE acceleration, false to disable it. |
| 587 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 588 | * information. |
| 589 | * |
| 590 | * \threadsafety This function is not thread safe. |
| 591 | * |
| 592 | * \since This function is available since SDL 3.2.0. |
| 593 | * |
| 594 | * \sa SDL_BlitSurface |
| 595 | * \sa SDL_LockSurface |
| 596 | * \sa SDL_UnlockSurface |
| 597 | */ |
| 598 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled); |
| 599 | |
| 600 | /** |
| 601 | * Returns whether the surface is RLE enabled. |
| 602 | * |
| 603 | * It is safe to pass a NULL `surface` here; it will return false. |
| 604 | * |
| 605 | * \param surface the SDL_Surface structure to query. |
| 606 | * \returns true if the surface is RLE enabled, false otherwise. |
| 607 | * |
| 608 | * \threadsafety It is safe to call this function from any thread. |
| 609 | * |
| 610 | * \since This function is available since SDL 3.2.0. |
| 611 | * |
| 612 | * \sa SDL_SetSurfaceRLE |
| 613 | */ |
| 614 | extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface); |
| 615 | |
| 616 | /** |
| 617 | * Set the color key (transparent pixel) in a surface. |
| 618 | * |
| 619 | * The color key defines a pixel value that will be treated as transparent in |
| 620 | * a blit. For example, one can use this to specify that cyan pixels should be |
| 621 | * considered transparent, and therefore not rendered. |
| 622 | * |
| 623 | * It is a pixel of the format used by the surface, as generated by |
| 624 | * SDL_MapRGB(). |
| 625 | * |
| 626 | * \param surface the SDL_Surface structure to update. |
| 627 | * \param enabled true to enable color key, false to disable color key. |
| 628 | * \param key the transparent pixel. |
| 629 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 630 | * information. |
| 631 | * |
| 632 | * \threadsafety This function is not thread safe. |
| 633 | * |
| 634 | * \since This function is available since SDL 3.2.0. |
| 635 | * |
| 636 | * \sa SDL_GetSurfaceColorKey |
| 637 | * \sa SDL_SetSurfaceRLE |
| 638 | * \sa SDL_SurfaceHasColorKey |
| 639 | */ |
| 640 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key); |
| 641 | |
| 642 | /** |
| 643 | * Returns whether the surface has a color key. |
| 644 | * |
| 645 | * It is safe to pass a NULL `surface` here; it will return false. |
| 646 | * |
| 647 | * \param surface the SDL_Surface structure to query. |
| 648 | * \returns true if the surface has a color key, false otherwise. |
| 649 | * |
| 650 | * \threadsafety It is safe to call this function from any thread. |
| 651 | * |
| 652 | * \since This function is available since SDL 3.2.0. |
| 653 | * |
| 654 | * \sa SDL_SetSurfaceColorKey |
| 655 | * \sa SDL_GetSurfaceColorKey |
| 656 | */ |
| 657 | extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface); |
| 658 | |
| 659 | /** |
| 660 | * Get the color key (transparent pixel) for a surface. |
| 661 | * |
| 662 | * The color key is a pixel of the format used by the surface, as generated by |
| 663 | * SDL_MapRGB(). |
| 664 | * |
| 665 | * If the surface doesn't have color key enabled this function returns false. |
| 666 | * |
| 667 | * \param surface the SDL_Surface structure to query. |
| 668 | * \param key a pointer filled in with the transparent pixel. |
| 669 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 670 | * information. |
| 671 | * |
| 672 | * \threadsafety It is safe to call this function from any thread. |
| 673 | * |
| 674 | * \since This function is available since SDL 3.2.0. |
| 675 | * |
| 676 | * \sa SDL_SetSurfaceColorKey |
| 677 | * \sa SDL_SurfaceHasColorKey |
| 678 | */ |
| 679 | extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key); |
| 680 | |
| 681 | /** |
| 682 | * Set an additional color value multiplied into blit operations. |
| 683 | * |
| 684 | * When this surface is blitted, during the blit operation each source color |
| 685 | * channel is modulated by the appropriate color value according to the |
| 686 | * following formula: |
| 687 | * |
| 688 | * `srcC = srcC * (color / 255)` |
| 689 | * |
| 690 | * \param surface the SDL_Surface structure to update. |
| 691 | * \param r the red color value multiplied into blit operations. |
| 692 | * \param g the green color value multiplied into blit operations. |
| 693 | * \param b the blue color value multiplied into blit operations. |
| 694 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 695 | * information. |
| 696 | * |
| 697 | * \threadsafety This function is not thread safe. |
| 698 | * |
| 699 | * \since This function is available since SDL 3.2.0. |
| 700 | * |
| 701 | * \sa SDL_GetSurfaceColorMod |
| 702 | * \sa SDL_SetSurfaceAlphaMod |
| 703 | */ |
| 704 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b); |
| 705 | |
| 706 | |
| 707 | /** |
| 708 | * Get the additional color value multiplied into blit operations. |
| 709 | * |
| 710 | * \param surface the SDL_Surface structure to query. |
| 711 | * \param r a pointer filled in with the current red color value. |
| 712 | * \param g a pointer filled in with the current green color value. |
| 713 | * \param b a pointer filled in with the current blue color value. |
| 714 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 715 | * information. |
| 716 | * |
| 717 | * \threadsafety This function is not thread safe. |
| 718 | * |
| 719 | * \since This function is available since SDL 3.2.0. |
| 720 | * |
| 721 | * \sa SDL_GetSurfaceAlphaMod |
| 722 | * \sa SDL_SetSurfaceColorMod |
| 723 | */ |
| 724 | extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b); |
| 725 | |
| 726 | /** |
| 727 | * Set an additional alpha value used in blit operations. |
| 728 | * |
| 729 | * When this surface is blitted, during the blit operation the source alpha |
| 730 | * value is modulated by this alpha value according to the following formula: |
| 731 | * |
| 732 | * `srcA = srcA * (alpha / 255)` |
| 733 | * |
| 734 | * \param surface the SDL_Surface structure to update. |
| 735 | * \param alpha the alpha value multiplied into blit operations. |
| 736 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 737 | * information. |
| 738 | * |
| 739 | * \threadsafety This function is not thread safe. |
| 740 | * |
| 741 | * \since This function is available since SDL 3.2.0. |
| 742 | * |
| 743 | * \sa SDL_GetSurfaceAlphaMod |
| 744 | * \sa SDL_SetSurfaceColorMod |
| 745 | */ |
| 746 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha); |
| 747 | |
| 748 | /** |
| 749 | * Get the additional alpha value used in blit operations. |
| 750 | * |
| 751 | * \param surface the SDL_Surface structure to query. |
| 752 | * \param alpha a pointer filled in with the current alpha value. |
| 753 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 754 | * information. |
| 755 | * |
| 756 | * \threadsafety It is safe to call this function from any thread. |
| 757 | * |
| 758 | * \since This function is available since SDL 3.2.0. |
| 759 | * |
| 760 | * \sa SDL_GetSurfaceColorMod |
| 761 | * \sa SDL_SetSurfaceAlphaMod |
| 762 | */ |
| 763 | extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha); |
| 764 | |
| 765 | /** |
| 766 | * Set the blend mode used for blit operations. |
| 767 | * |
| 768 | * To copy a surface to another surface (or texture) without blending with the |
| 769 | * existing data, the blendmode of the SOURCE surface should be set to |
| 770 | * `SDL_BLENDMODE_NONE`. |
| 771 | * |
| 772 | * \param surface the SDL_Surface structure to update. |
| 773 | * \param blendMode the SDL_BlendMode to use for blit blending. |
| 774 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 775 | * information. |
| 776 | * |
| 777 | * \threadsafety This function is not thread safe. |
| 778 | * |
| 779 | * \since This function is available since SDL 3.2.0. |
| 780 | * |
| 781 | * \sa SDL_GetSurfaceBlendMode |
| 782 | */ |
| 783 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode); |
| 784 | |
| 785 | /** |
| 786 | * Get the blend mode used for blit operations. |
| 787 | * |
| 788 | * \param surface the SDL_Surface structure to query. |
| 789 | * \param blendMode a pointer filled in with the current SDL_BlendMode. |
| 790 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 791 | * information. |
| 792 | * |
| 793 | * \threadsafety It is safe to call this function from any thread. |
| 794 | * |
| 795 | * \since This function is available since SDL 3.2.0. |
| 796 | * |
| 797 | * \sa SDL_SetSurfaceBlendMode |
| 798 | */ |
| 799 | extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode); |
| 800 | |
| 801 | /** |
| 802 | * Set the clipping rectangle for a surface. |
| 803 | * |
| 804 | * When `surface` is the destination of a blit, only the area within the clip |
| 805 | * rectangle is drawn into. |
| 806 | * |
| 807 | * Note that blits are automatically clipped to the edges of the source and |
| 808 | * destination surfaces. |
| 809 | * |
| 810 | * \param surface the SDL_Surface structure to be clipped. |
| 811 | * \param rect the SDL_Rect structure representing the clipping rectangle, or |
| 812 | * NULL to disable clipping. |
| 813 | * \returns true if the rectangle intersects the surface, otherwise false and |
| 814 | * blits will be completely clipped. |
| 815 | * |
| 816 | * \threadsafety This function is not thread safe. |
| 817 | * |
| 818 | * \since This function is available since SDL 3.2.0. |
| 819 | * |
| 820 | * \sa SDL_GetSurfaceClipRect |
| 821 | */ |
| 822 | extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect); |
| 823 | |
| 824 | /** |
| 825 | * Get the clipping rectangle for a surface. |
| 826 | * |
| 827 | * When `surface` is the destination of a blit, only the area within the clip |
| 828 | * rectangle is drawn into. |
| 829 | * |
| 830 | * \param surface the SDL_Surface structure representing the surface to be |
| 831 | * clipped. |
| 832 | * \param rect an SDL_Rect structure filled in with the clipping rectangle for |
| 833 | * the surface. |
| 834 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 835 | * information. |
| 836 | * |
| 837 | * \threadsafety This function is not thread safe. |
| 838 | * |
| 839 | * \since This function is available since SDL 3.2.0. |
| 840 | * |
| 841 | * \sa SDL_SetSurfaceClipRect |
| 842 | */ |
| 843 | extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect); |
| 844 | |
| 845 | /** |
| 846 | * Flip a surface vertically or horizontally. |
| 847 | * |
| 848 | * \param surface the surface to flip. |
| 849 | * \param flip the direction to flip. |
| 850 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 851 | * information. |
| 852 | * |
| 853 | * \threadsafety This function is not thread safe. |
| 854 | * |
| 855 | * \since This function is available since SDL 3.2.0. |
| 856 | */ |
| 857 | extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip); |
| 858 | |
| 859 | /** |
| 860 | * Creates a new surface identical to the existing surface. |
| 861 | * |
| 862 | * If the original surface has alternate images, the new surface will have a |
| 863 | * reference to them as well. |
| 864 | * |
| 865 | * The returned surface should be freed with SDL_DestroySurface(). |
| 866 | * |
| 867 | * \param surface the surface to duplicate. |
| 868 | * \returns a copy of the surface or NULL on failure; call SDL_GetError() for |
| 869 | * more information. |
| 870 | * |
| 871 | * \threadsafety This function is not thread safe. |
| 872 | * |
| 873 | * \since This function is available since SDL 3.2.0. |
| 874 | * |
| 875 | * \sa SDL_DestroySurface |
| 876 | */ |
| 877 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface); |
| 878 | |
| 879 | /** |
| 880 | * Creates a new surface identical to the existing surface, scaled to the |
| 881 | * desired size. |
| 882 | * |
| 883 | * The returned surface should be freed with SDL_DestroySurface(). |
| 884 | * |
| 885 | * \param surface the surface to duplicate and scale. |
| 886 | * \param width the width of the new surface. |
| 887 | * \param height the height of the new surface. |
| 888 | * \param scaleMode the SDL_ScaleMode to be used. |
| 889 | * \returns a copy of the surface or NULL on failure; call SDL_GetError() for |
| 890 | * more information. |
| 891 | * |
| 892 | * \threadsafety This function is not thread safe. |
| 893 | * |
| 894 | * \since This function is available since SDL 3.2.0. |
| 895 | * |
| 896 | * \sa SDL_DestroySurface |
| 897 | */ |
| 898 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode); |
| 899 | |
| 900 | /** |
| 901 | * Copy an existing surface to a new surface of the specified format. |
| 902 | * |
| 903 | * This function is used to optimize images for faster *repeat* blitting. This |
| 904 | * is accomplished by converting the original and storing the result as a new |
| 905 | * surface. The new, optimized surface can then be used as the source for |
| 906 | * future blits, making them faster. |
| 907 | * |
| 908 | * If you are converting to an indexed surface and want to map colors to a |
| 909 | * palette, you can use SDL_ConvertSurfaceAndColorspace() instead. |
| 910 | * |
| 911 | * If the original surface has alternate images, the new surface will have a |
| 912 | * reference to them as well. |
| 913 | * |
| 914 | * \param surface the existing SDL_Surface structure to convert. |
| 915 | * \param format the new pixel format. |
| 916 | * \returns the new SDL_Surface structure that is created or NULL on failure; |
| 917 | * call SDL_GetError() for more information. |
| 918 | * |
| 919 | * \threadsafety This function is not thread safe. |
| 920 | * |
| 921 | * \since This function is available since SDL 3.2.0. |
| 922 | * |
| 923 | * \sa SDL_ConvertSurfaceAndColorspace |
| 924 | * \sa SDL_DestroySurface |
| 925 | */ |
| 926 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format); |
| 927 | |
| 928 | /** |
| 929 | * Copy an existing surface to a new surface of the specified format and |
| 930 | * colorspace. |
| 931 | * |
| 932 | * This function converts an existing surface to a new format and colorspace |
| 933 | * and returns the new surface. This will perform any pixel format and |
| 934 | * colorspace conversion needed. |
| 935 | * |
| 936 | * If the original surface has alternate images, the new surface will have a |
| 937 | * reference to them as well. |
| 938 | * |
| 939 | * \param surface the existing SDL_Surface structure to convert. |
| 940 | * \param format the new pixel format. |
| 941 | * \param palette an optional palette to use for indexed formats, may be NULL. |
| 942 | * \param colorspace the new colorspace. |
| 943 | * \param props an SDL_PropertiesID with additional color properties, or 0. |
| 944 | * \returns the new SDL_Surface structure that is created or NULL on failure; |
| 945 | * call SDL_GetError() for more information. |
| 946 | * |
| 947 | * \threadsafety This function is not thread safe. |
| 948 | * |
| 949 | * \since This function is available since SDL 3.2.0. |
| 950 | * |
| 951 | * \sa SDL_ConvertSurface |
| 952 | * \sa SDL_DestroySurface |
| 953 | */ |
| 954 | extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props); |
| 955 | |
| 956 | /** |
| 957 | * Copy a block of pixels of one format to another format. |
| 958 | * |
| 959 | * \param width the width of the block to copy, in pixels. |
| 960 | * \param height the height of the block to copy, in pixels. |
| 961 | * \param src_format an SDL_PixelFormat value of the `src` pixels format. |
| 962 | * \param src a pointer to the source pixels. |
| 963 | * \param src_pitch the pitch of the source pixels, in bytes. |
| 964 | * \param dst_format an SDL_PixelFormat value of the `dst` pixels format. |
| 965 | * \param dst a pointer to be filled in with new pixel data. |
| 966 | * \param dst_pitch the pitch of the destination pixels, in bytes. |
| 967 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 968 | * information. |
| 969 | * |
| 970 | * \threadsafety The same destination pixels should not be used from two |
| 971 | * threads at once. It is safe to use the same source pixels |
| 972 | * from multiple threads. |
| 973 | * |
| 974 | * \since This function is available since SDL 3.2.0. |
| 975 | * |
| 976 | * \sa SDL_ConvertPixelsAndColorspace |
| 977 | */ |
| 978 | extern SDL_DECLSPEC bool SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch); |
| 979 | |
| 980 | /** |
| 981 | * Copy a block of pixels of one format and colorspace to another format and |
| 982 | * colorspace. |
| 983 | * |
| 984 | * \param width the width of the block to copy, in pixels. |
| 985 | * \param height the height of the block to copy, in pixels. |
| 986 | * \param src_format an SDL_PixelFormat value of the `src` pixels format. |
| 987 | * \param src_colorspace an SDL_Colorspace value describing the colorspace of |
| 988 | * the `src` pixels. |
| 989 | * \param src_properties an SDL_PropertiesID with additional source color |
| 990 | * properties, or 0. |
| 991 | * \param src a pointer to the source pixels. |
| 992 | * \param src_pitch the pitch of the source pixels, in bytes. |
| 993 | * \param dst_format an SDL_PixelFormat value of the `dst` pixels format. |
| 994 | * \param dst_colorspace an SDL_Colorspace value describing the colorspace of |
| 995 | * the `dst` pixels. |
| 996 | * \param dst_properties an SDL_PropertiesID with additional destination color |
| 997 | * properties, or 0. |
| 998 | * \param dst a pointer to be filled in with new pixel data. |
| 999 | * \param dst_pitch the pitch of the destination pixels, in bytes. |
| 1000 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1001 | * information. |
| 1002 | * |
| 1003 | * \threadsafety The same destination pixels should not be used from two |
| 1004 | * threads at once. It is safe to use the same source pixels |
| 1005 | * from multiple threads. |
| 1006 | * |
| 1007 | * \since This function is available since SDL 3.2.0. |
| 1008 | * |
| 1009 | * \sa SDL_ConvertPixels |
| 1010 | */ |
| 1011 | extern SDL_DECLSPEC bool SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); |
| 1012 | |
| 1013 | /** |
| 1014 | * Premultiply the alpha on a block of pixels. |
| 1015 | * |
| 1016 | * This is safe to use with src == dst, but not for other overlapping areas. |
| 1017 | * |
| 1018 | * \param width the width of the block to convert, in pixels. |
| 1019 | * \param height the height of the block to convert, in pixels. |
| 1020 | * \param src_format an SDL_PixelFormat value of the `src` pixels format. |
| 1021 | * \param src a pointer to the source pixels. |
| 1022 | * \param src_pitch the pitch of the source pixels, in bytes. |
| 1023 | * \param dst_format an SDL_PixelFormat value of the `dst` pixels format. |
| 1024 | * \param dst a pointer to be filled in with premultiplied pixel data. |
| 1025 | * \param dst_pitch the pitch of the destination pixels, in bytes. |
| 1026 | * \param linear true to convert from sRGB to linear space for the alpha |
| 1027 | * multiplication, false to do multiplication in sRGB space. |
| 1028 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1029 | * information. |
| 1030 | * |
| 1031 | * \threadsafety The same destination pixels should not be used from two |
| 1032 | * threads at once. It is safe to use the same source pixels |
| 1033 | * from multiple threads. |
| 1034 | * |
| 1035 | * \since This function is available since SDL 3.2.0. |
| 1036 | */ |
| 1037 | extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, bool linear); |
| 1038 | |
| 1039 | /** |
| 1040 | * Premultiply the alpha in a surface. |
| 1041 | * |
| 1042 | * This is safe to use with src == dst, but not for other overlapping areas. |
| 1043 | * |
| 1044 | * \param surface the surface to modify. |
| 1045 | * \param linear true to convert from sRGB to linear space for the alpha |
| 1046 | * multiplication, false to do multiplication in sRGB space. |
| 1047 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1048 | * information. |
| 1049 | * |
| 1050 | * \threadsafety This function is not thread safe. |
| 1051 | * |
| 1052 | * \since This function is available since SDL 3.2.0. |
| 1053 | */ |
| 1054 | extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, bool linear); |
| 1055 | |
| 1056 | /** |
| 1057 | * Clear a surface with a specific color, with floating point precision. |
| 1058 | * |
| 1059 | * This function handles all surface formats, and ignores any clip rectangle. |
| 1060 | * |
| 1061 | * If the surface is YUV, the color is assumed to be in the sRGB colorspace, |
| 1062 | * otherwise the color is assumed to be in the colorspace of the suface. |
| 1063 | * |
| 1064 | * \param surface the SDL_Surface to clear. |
| 1065 | * \param r the red component of the pixel, normally in the range 0-1. |
| 1066 | * \param g the green component of the pixel, normally in the range 0-1. |
| 1067 | * \param b the blue component of the pixel, normally in the range 0-1. |
| 1068 | * \param a the alpha component of the pixel, normally in the range 0-1. |
| 1069 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1070 | * information. |
| 1071 | * |
| 1072 | * \threadsafety This function is not thread safe. |
| 1073 | * |
| 1074 | * \since This function is available since SDL 3.2.0. |
| 1075 | */ |
| 1076 | extern SDL_DECLSPEC bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a); |
| 1077 | |
| 1078 | /** |
| 1079 | * Perform a fast fill of a rectangle with a specific color. |
| 1080 | * |
| 1081 | * `color` should be a pixel of the format used by the surface, and can be |
| 1082 | * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an |
| 1083 | * alpha component then the destination is simply filled with that alpha |
| 1084 | * information, no blending takes place. |
| 1085 | * |
| 1086 | * If there is a clip rectangle set on the destination (set via |
| 1087 | * SDL_SetSurfaceClipRect()), then this function will fill based on the |
| 1088 | * intersection of the clip rectangle and `rect`. |
| 1089 | * |
| 1090 | * \param dst the SDL_Surface structure that is the drawing target. |
| 1091 | * \param rect the SDL_Rect structure representing the rectangle to fill, or |
| 1092 | * NULL to fill the entire surface. |
| 1093 | * \param color the color to fill with. |
| 1094 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1095 | * information. |
| 1096 | * |
| 1097 | * \threadsafety This function is not thread safe. |
| 1098 | * |
| 1099 | * \since This function is available since SDL 3.2.0. |
| 1100 | * |
| 1101 | * \sa SDL_FillSurfaceRects |
| 1102 | */ |
| 1103 | extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color); |
| 1104 | |
| 1105 | /** |
| 1106 | * Perform a fast fill of a set of rectangles with a specific color. |
| 1107 | * |
| 1108 | * `color` should be a pixel of the format used by the surface, and can be |
| 1109 | * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an |
| 1110 | * alpha component then the destination is simply filled with that alpha |
| 1111 | * information, no blending takes place. |
| 1112 | * |
| 1113 | * If there is a clip rectangle set on the destination (set via |
| 1114 | * SDL_SetSurfaceClipRect()), then this function will fill based on the |
| 1115 | * intersection of the clip rectangle and `rect`. |
| 1116 | * |
| 1117 | * \param dst the SDL_Surface structure that is the drawing target. |
| 1118 | * \param rects an array of SDL_Rects representing the rectangles to fill. |
| 1119 | * \param count the number of rectangles in the array. |
| 1120 | * \param color the color to fill with. |
| 1121 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1122 | * information. |
| 1123 | * |
| 1124 | * \threadsafety This function is not thread safe. |
| 1125 | * |
| 1126 | * \since This function is available since SDL 3.2.0. |
| 1127 | * |
| 1128 | * \sa SDL_FillSurfaceRect |
| 1129 | */ |
| 1130 | extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color); |
| 1131 | |
| 1132 | /** |
| 1133 | * Performs a fast blit from the source surface to the destination surface |
| 1134 | * with clipping. |
| 1135 | * |
| 1136 | * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or |
| 1137 | * `dst`) is copied while ensuring clipping to `dst->clip_rect`. |
| 1138 | * |
| 1139 | * The final blit rectangles are saved in `srcrect` and `dstrect` after all |
| 1140 | * clipping is performed. |
| 1141 | * |
| 1142 | * The blit function should not be called on a locked surface. |
| 1143 | * |
| 1144 | * The blit semantics for surfaces with and without blending and colorkey are |
| 1145 | * defined as follows: |
| 1146 | * |
| 1147 | * ``` |
| 1148 | * RGBA->RGB: |
| 1149 | * Source surface blend mode set to SDL_BLENDMODE_BLEND: |
| 1150 | * alpha-blend (using the source alpha-channel and per-surface alpha) |
| 1151 | * SDL_SRCCOLORKEY ignored. |
| 1152 | * Source surface blend mode set to SDL_BLENDMODE_NONE: |
| 1153 | * copy RGB. |
| 1154 | * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the |
| 1155 | * RGB values of the source color key, ignoring alpha in the |
| 1156 | * comparison. |
| 1157 | * |
| 1158 | * RGB->RGBA: |
| 1159 | * Source surface blend mode set to SDL_BLENDMODE_BLEND: |
| 1160 | * alpha-blend (using the source per-surface alpha) |
| 1161 | * Source surface blend mode set to SDL_BLENDMODE_NONE: |
| 1162 | * copy RGB, set destination alpha to source per-surface alpha value. |
| 1163 | * both: |
| 1164 | * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the |
| 1165 | * source color key. |
| 1166 | * |
| 1167 | * RGBA->RGBA: |
| 1168 | * Source surface blend mode set to SDL_BLENDMODE_BLEND: |
| 1169 | * alpha-blend (using the source alpha-channel and per-surface alpha) |
| 1170 | * SDL_SRCCOLORKEY ignored. |
| 1171 | * Source surface blend mode set to SDL_BLENDMODE_NONE: |
| 1172 | * copy all of RGBA to the destination. |
| 1173 | * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the |
| 1174 | * RGB values of the source color key, ignoring alpha in the |
| 1175 | * comparison. |
| 1176 | * |
| 1177 | * RGB->RGB: |
| 1178 | * Source surface blend mode set to SDL_BLENDMODE_BLEND: |
| 1179 | * alpha-blend (using the source per-surface alpha) |
| 1180 | * Source surface blend mode set to SDL_BLENDMODE_NONE: |
| 1181 | * copy RGB. |
| 1182 | * both: |
| 1183 | * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the |
| 1184 | * source color key. |
| 1185 | * ``` |
| 1186 | * |
| 1187 | * \param src the SDL_Surface structure to be copied from. |
| 1188 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1189 | * copied, or NULL to copy the entire surface. |
| 1190 | * \param dst the SDL_Surface structure that is the blit target. |
| 1191 | * \param dstrect the SDL_Rect structure representing the x and y position in |
| 1192 | * the destination surface, or NULL for (0,0). The width and |
| 1193 | * height are ignored, and are copied from `srcrect`. If you |
| 1194 | * want a specific width and height, you should use |
| 1195 | * SDL_BlitSurfaceScaled(). |
| 1196 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1197 | * information. |
| 1198 | * |
| 1199 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1200 | * at any given time. |
| 1201 | * |
| 1202 | * \since This function is available since SDL 3.2.0. |
| 1203 | * |
| 1204 | * \sa SDL_BlitSurfaceScaled |
| 1205 | */ |
| 1206 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); |
| 1207 | |
| 1208 | /** |
| 1209 | * Perform low-level surface blitting only. |
| 1210 | * |
| 1211 | * This is a semi-private blit function and it performs low-level surface |
| 1212 | * blitting, assuming the input rectangles have already been clipped. |
| 1213 | * |
| 1214 | * \param src the SDL_Surface structure to be copied from. |
| 1215 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1216 | * copied, may not be NULL. |
| 1217 | * \param dst the SDL_Surface structure that is the blit target. |
| 1218 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1219 | * the destination surface, may not be NULL. |
| 1220 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1221 | * information. |
| 1222 | * |
| 1223 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1224 | * at any given time. |
| 1225 | * |
| 1226 | * \since This function is available since SDL 3.2.0. |
| 1227 | * |
| 1228 | * \sa SDL_BlitSurface |
| 1229 | */ |
| 1230 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); |
| 1231 | |
| 1232 | /** |
| 1233 | * Perform a scaled blit to a destination surface, which may be of a different |
| 1234 | * format. |
| 1235 | * |
| 1236 | * \param src the SDL_Surface structure to be copied from. |
| 1237 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1238 | * copied, or NULL to copy the entire surface. |
| 1239 | * \param dst the SDL_Surface structure that is the blit target. |
| 1240 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1241 | * the destination surface, or NULL to fill the entire |
| 1242 | * destination surface. |
| 1243 | * \param scaleMode the SDL_ScaleMode to be used. |
| 1244 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1245 | * information. |
| 1246 | * |
| 1247 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1248 | * at any given time. |
| 1249 | * |
| 1250 | * \since This function is available since SDL 3.2.0. |
| 1251 | * |
| 1252 | * \sa SDL_BlitSurface |
| 1253 | */ |
| 1254 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); |
| 1255 | |
| 1256 | /** |
| 1257 | * Perform low-level surface scaled blitting only. |
| 1258 | * |
| 1259 | * This is a semi-private function and it performs low-level surface blitting, |
| 1260 | * assuming the input rectangles have already been clipped. |
| 1261 | * |
| 1262 | * \param src the SDL_Surface structure to be copied from. |
| 1263 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1264 | * copied, may not be NULL. |
| 1265 | * \param dst the SDL_Surface structure that is the blit target. |
| 1266 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1267 | * the destination surface, may not be NULL. |
| 1268 | * \param scaleMode the SDL_ScaleMode to be used. |
| 1269 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1270 | * information. |
| 1271 | * |
| 1272 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1273 | * at any given time. |
| 1274 | * |
| 1275 | * \since This function is available since SDL 3.2.0. |
| 1276 | * |
| 1277 | * \sa SDL_BlitSurfaceScaled |
| 1278 | */ |
| 1279 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); |
| 1280 | |
| 1281 | /** |
| 1282 | * Perform a stretched pixel copy from one surface to another. |
| 1283 | * |
| 1284 | * \param src the SDL_Surface structure to be copied from. |
| 1285 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1286 | * copied, may not be NULL. |
| 1287 | * \param dst the SDL_Surface structure that is the blit target. |
| 1288 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1289 | * the destination surface, may not be NULL. |
| 1290 | * \param scaleMode the SDL_ScaleMode to be used. |
| 1291 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1292 | * information. |
| 1293 | * |
| 1294 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1295 | * at any given time. |
| 1296 | * |
| 1297 | * \since This function is available since SDL 3.4.0. |
| 1298 | * |
| 1299 | * \sa SDL_BlitSurfaceScaled |
| 1300 | */ |
| 1301 | extern SDL_DECLSPEC bool SDLCALL SDL_StretchSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); |
| 1302 | |
| 1303 | /** |
| 1304 | * Perform a tiled blit to a destination surface, which may be of a different |
| 1305 | * format. |
| 1306 | * |
| 1307 | * The pixels in `srcrect` will be repeated as many times as needed to |
| 1308 | * completely fill `dstrect`. |
| 1309 | * |
| 1310 | * \param src the SDL_Surface structure to be copied from. |
| 1311 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1312 | * copied, or NULL to copy the entire surface. |
| 1313 | * \param dst the SDL_Surface structure that is the blit target. |
| 1314 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1315 | * the destination surface, or NULL to fill the entire surface. |
| 1316 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1317 | * information. |
| 1318 | * |
| 1319 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1320 | * at any given time. |
| 1321 | * |
| 1322 | * \since This function is available since SDL 3.2.0. |
| 1323 | * |
| 1324 | * \sa SDL_BlitSurface |
| 1325 | */ |
| 1326 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); |
| 1327 | |
| 1328 | /** |
| 1329 | * Perform a scaled and tiled blit to a destination surface, which may be of a |
| 1330 | * different format. |
| 1331 | * |
| 1332 | * The pixels in `srcrect` will be scaled and repeated as many times as needed |
| 1333 | * to completely fill `dstrect`. |
| 1334 | * |
| 1335 | * \param src the SDL_Surface structure to be copied from. |
| 1336 | * \param srcrect the SDL_Rect structure representing the rectangle to be |
| 1337 | * copied, or NULL to copy the entire surface. |
| 1338 | * \param scale the scale used to transform srcrect into the destination |
| 1339 | * rectangle, e.g. a 32x32 texture with a scale of 2 would fill |
| 1340 | * 64x64 tiles. |
| 1341 | * \param scaleMode scale algorithm to be used. |
| 1342 | * \param dst the SDL_Surface structure that is the blit target. |
| 1343 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1344 | * the destination surface, or NULL to fill the entire surface. |
| 1345 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1346 | * information. |
| 1347 | * |
| 1348 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1349 | * at any given time. |
| 1350 | * |
| 1351 | * \since This function is available since SDL 3.2.0. |
| 1352 | * |
| 1353 | * \sa SDL_BlitSurface |
| 1354 | */ |
| 1355 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect); |
| 1356 | |
| 1357 | /** |
| 1358 | * Perform a scaled blit using the 9-grid algorithm to a destination surface, |
| 1359 | * which may be of a different format. |
| 1360 | * |
| 1361 | * The pixels in the source surface are split into a 3x3 grid, using the |
| 1362 | * different corner sizes for each corner, and the sides and center making up |
| 1363 | * the remaining pixels. The corners are then scaled using `scale` and fit |
| 1364 | * into the corners of the destination rectangle. The sides and center are |
| 1365 | * then stretched into place to cover the remaining destination rectangle. |
| 1366 | * |
| 1367 | * \param src the SDL_Surface structure to be copied from. |
| 1368 | * \param srcrect the SDL_Rect structure representing the rectangle to be used |
| 1369 | * for the 9-grid, or NULL to use the entire surface. |
| 1370 | * \param left_width the width, in pixels, of the left corners in `srcrect`. |
| 1371 | * \param right_width the width, in pixels, of the right corners in `srcrect`. |
| 1372 | * \param top_height the height, in pixels, of the top corners in `srcrect`. |
| 1373 | * \param bottom_height the height, in pixels, of the bottom corners in |
| 1374 | * `srcrect`. |
| 1375 | * \param scale the scale used to transform the corner of `srcrect` into the |
| 1376 | * corner of `dstrect`, or 0.0f for an unscaled blit. |
| 1377 | * \param scaleMode scale algorithm to be used. |
| 1378 | * \param dst the SDL_Surface structure that is the blit target. |
| 1379 | * \param dstrect the SDL_Rect structure representing the target rectangle in |
| 1380 | * the destination surface, or NULL to fill the entire surface. |
| 1381 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1382 | * information. |
| 1383 | * |
| 1384 | * \threadsafety Only one thread should be using the `src` and `dst` surfaces |
| 1385 | * at any given time. |
| 1386 | * |
| 1387 | * \since This function is available since SDL 3.2.0. |
| 1388 | * |
| 1389 | * \sa SDL_BlitSurface |
| 1390 | */ |
| 1391 | extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect); |
| 1392 | |
| 1393 | /** |
| 1394 | * Map an RGB triple to an opaque pixel value for a surface. |
| 1395 | * |
| 1396 | * This function maps the RGB color value to the specified pixel format and |
| 1397 | * returns the pixel value best approximating the given RGB color value for |
| 1398 | * the given pixel format. |
| 1399 | * |
| 1400 | * If the surface has a palette, the index of the closest matching color in |
| 1401 | * the palette will be returned. |
| 1402 | * |
| 1403 | * If the surface pixel format has an alpha component it will be returned as |
| 1404 | * all 1 bits (fully opaque). |
| 1405 | * |
| 1406 | * If the pixel format bpp (color depth) is less than 32-bpp then the unused |
| 1407 | * upper bits of the return value can safely be ignored (e.g., with a 16-bpp |
| 1408 | * format the return value can be assigned to a Uint16, and similarly a Uint8 |
| 1409 | * for an 8-bpp format). |
| 1410 | * |
| 1411 | * \param surface the surface to use for the pixel format and palette. |
| 1412 | * \param r the red component of the pixel in the range 0-255. |
| 1413 | * \param g the green component of the pixel in the range 0-255. |
| 1414 | * \param b the blue component of the pixel in the range 0-255. |
| 1415 | * \returns a pixel value. |
| 1416 | * |
| 1417 | * \threadsafety It is safe to call this function from any thread. |
| 1418 | * |
| 1419 | * \since This function is available since SDL 3.2.0. |
| 1420 | * |
| 1421 | * \sa SDL_MapSurfaceRGBA |
| 1422 | */ |
| 1423 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b); |
| 1424 | |
| 1425 | /** |
| 1426 | * Map an RGBA quadruple to a pixel value for a surface. |
| 1427 | * |
| 1428 | * This function maps the RGBA color value to the specified pixel format and |
| 1429 | * returns the pixel value best approximating the given RGBA color value for |
| 1430 | * the given pixel format. |
| 1431 | * |
| 1432 | * If the surface pixel format has no alpha component the alpha value will be |
| 1433 | * ignored (as it will be in formats with a palette). |
| 1434 | * |
| 1435 | * If the surface has a palette, the index of the closest matching color in |
| 1436 | * the palette will be returned. |
| 1437 | * |
| 1438 | * If the pixel format bpp (color depth) is less than 32-bpp then the unused |
| 1439 | * upper bits of the return value can safely be ignored (e.g., with a 16-bpp |
| 1440 | * format the return value can be assigned to a Uint16, and similarly a Uint8 |
| 1441 | * for an 8-bpp format). |
| 1442 | * |
| 1443 | * \param surface the surface to use for the pixel format and palette. |
| 1444 | * \param r the red component of the pixel in the range 0-255. |
| 1445 | * \param g the green component of the pixel in the range 0-255. |
| 1446 | * \param b the blue component of the pixel in the range 0-255. |
| 1447 | * \param a the alpha component of the pixel in the range 0-255. |
| 1448 | * \returns a pixel value. |
| 1449 | * |
| 1450 | * \threadsafety It is safe to call this function from any thread. |
| 1451 | * |
| 1452 | * \since This function is available since SDL 3.2.0. |
| 1453 | * |
| 1454 | * \sa SDL_MapSurfaceRGB |
| 1455 | */ |
| 1456 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a); |
| 1457 | |
| 1458 | /** |
| 1459 | * Retrieves a single pixel from a surface. |
| 1460 | * |
| 1461 | * This function prioritizes correctness over speed: it is suitable for unit |
| 1462 | * tests, but is not intended for use in a game engine. |
| 1463 | * |
| 1464 | * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color |
| 1465 | * components from pixel formats with less than 8 bits per RGB component. |
| 1466 | * |
| 1467 | * \param surface the surface to read. |
| 1468 | * \param x the horizontal coordinate, 0 <= x < width. |
| 1469 | * \param y the vertical coordinate, 0 <= y < height. |
| 1470 | * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore |
| 1471 | * this channel. |
| 1472 | * \param g a pointer filled in with the green channel, 0-255, or NULL to |
| 1473 | * ignore this channel. |
| 1474 | * \param b a pointer filled in with the blue channel, 0-255, or NULL to |
| 1475 | * ignore this channel. |
| 1476 | * \param a a pointer filled in with the alpha channel, 0-255, or NULL to |
| 1477 | * ignore this channel. |
| 1478 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1479 | * information. |
| 1480 | * |
| 1481 | * \threadsafety This function is not thread safe. |
| 1482 | * |
| 1483 | * \since This function is available since SDL 3.2.0. |
| 1484 | */ |
| 1485 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); |
| 1486 | |
| 1487 | /** |
| 1488 | * Retrieves a single pixel from a surface. |
| 1489 | * |
| 1490 | * This function prioritizes correctness over speed: it is suitable for unit |
| 1491 | * tests, but is not intended for use in a game engine. |
| 1492 | * |
| 1493 | * \param surface the surface to read. |
| 1494 | * \param x the horizontal coordinate, 0 <= x < width. |
| 1495 | * \param y the vertical coordinate, 0 <= y < height. |
| 1496 | * \param r a pointer filled in with the red channel, normally in the range |
| 1497 | * 0-1, or NULL to ignore this channel. |
| 1498 | * \param g a pointer filled in with the green channel, normally in the range |
| 1499 | * 0-1, or NULL to ignore this channel. |
| 1500 | * \param b a pointer filled in with the blue channel, normally in the range |
| 1501 | * 0-1, or NULL to ignore this channel. |
| 1502 | * \param a a pointer filled in with the alpha channel, normally in the range |
| 1503 | * 0-1, or NULL to ignore this channel. |
| 1504 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1505 | * information. |
| 1506 | * |
| 1507 | * \threadsafety This function is not thread safe. |
| 1508 | * |
| 1509 | * \since This function is available since SDL 3.2.0. |
| 1510 | */ |
| 1511 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a); |
| 1512 | |
| 1513 | /** |
| 1514 | * Writes a single pixel to a surface. |
| 1515 | * |
| 1516 | * This function prioritizes correctness over speed: it is suitable for unit |
| 1517 | * tests, but is not intended for use in a game engine. |
| 1518 | * |
| 1519 | * Like SDL_MapRGBA, this uses the entire 0..255 range when converting color |
| 1520 | * components from pixel formats with less than 8 bits per RGB component. |
| 1521 | * |
| 1522 | * \param surface the surface to write. |
| 1523 | * \param x the horizontal coordinate, 0 <= x < width. |
| 1524 | * \param y the vertical coordinate, 0 <= y < height. |
| 1525 | * \param r the red channel value, 0-255. |
| 1526 | * \param g the green channel value, 0-255. |
| 1527 | * \param b the blue channel value, 0-255. |
| 1528 | * \param a the alpha channel value, 0-255. |
| 1529 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1530 | * information. |
| 1531 | * |
| 1532 | * \threadsafety This function is not thread safe. |
| 1533 | * |
| 1534 | * \since This function is available since SDL 3.2.0. |
| 1535 | */ |
| 1536 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a); |
| 1537 | |
| 1538 | /** |
| 1539 | * Writes a single pixel to a surface. |
| 1540 | * |
| 1541 | * This function prioritizes correctness over speed: it is suitable for unit |
| 1542 | * tests, but is not intended for use in a game engine. |
| 1543 | * |
| 1544 | * \param surface the surface to write. |
| 1545 | * \param x the horizontal coordinate, 0 <= x < width. |
| 1546 | * \param y the vertical coordinate, 0 <= y < height. |
| 1547 | * \param r the red channel value, normally in the range 0-1. |
| 1548 | * \param g the green channel value, normally in the range 0-1. |
| 1549 | * \param b the blue channel value, normally in the range 0-1. |
| 1550 | * \param a the alpha channel value, normally in the range 0-1. |
| 1551 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 1552 | * information. |
| 1553 | * |
| 1554 | * \threadsafety This function is not thread safe. |
| 1555 | * |
| 1556 | * \since This function is available since SDL 3.2.0. |
| 1557 | */ |
| 1558 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a); |
| 1559 | |
| 1560 | /* Ends C function definitions when using C++ */ |
| 1561 | #ifdef __cplusplus |
| 1562 | } |
| 1563 | #endif |
| 1564 | #include <SDL3/SDL_close_code.h> |
| 1565 | |
| 1566 | #endif /* SDL_surface_h_ */ |
| 1567 | |