SDL_surface.h 57 KB

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