SDL_surface.h 56 KB

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