SDL_surface.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  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. * - `SDL_PROP_SURFACE_HOTSPOT_X_NUMBER`: the hotspot pixel offset from the
  204. * left edge of the image, if this surface is being used as a cursor.
  205. * - `SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`: the hotspot pixel offset from the
  206. * top edge of the image, if this surface is being used as a cursor.
  207. *
  208. * \param surface the SDL_Surface structure to query.
  209. * \returns a valid property ID on success or 0 on failure; call
  210. * SDL_GetError() for more information.
  211. *
  212. * \since This function is available since SDL 3.2.0.
  213. */
  214. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
  215. #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
  216. #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
  217. #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
  218. #define SDL_PROP_SURFACE_HOTSPOT_X_NUMBER "SDL.surface.hotspot.x"
  219. #define SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER "SDL.surface.hotspot.y"
  220. /**
  221. * Set the colorspace used by a surface.
  222. *
  223. * Setting the colorspace doesn't change the pixels, only how they are
  224. * interpreted in color operations.
  225. *
  226. * \param surface the SDL_Surface structure to update.
  227. * \param colorspace an SDL_Colorspace value describing the surface
  228. * colorspace.
  229. * \returns true on success or false on failure; call SDL_GetError() for more
  230. * information.
  231. *
  232. * \since This function is available since SDL 3.2.0.
  233. *
  234. * \sa SDL_GetSurfaceColorspace
  235. */
  236. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
  237. /**
  238. * Get the colorspace used by a surface.
  239. *
  240. * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
  241. * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
  242. * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
  243. *
  244. * \param surface the SDL_Surface structure to query.
  245. * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
  246. * the surface is NULL.
  247. *
  248. * \since This function is available since SDL 3.2.0.
  249. *
  250. * \sa SDL_SetSurfaceColorspace
  251. */
  252. extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
  253. /**
  254. * Create a palette and associate it with a surface.
  255. *
  256. * This function creates a palette compatible with the provided surface. The
  257. * palette is then returned for you to modify, and the surface will
  258. * automatically use the new palette in future operations. You do not need to
  259. * destroy the returned palette, it will be freed when the reference count
  260. * reaches 0, usually when the surface is destroyed.
  261. *
  262. * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
  263. * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
  264. * white and 1 as black. Other surfaces will get a palette initialized with
  265. * white in every entry.
  266. *
  267. * If this function is called for a surface that already has a palette, a new
  268. * palette will be created to replace it.
  269. *
  270. * \param surface the SDL_Surface structure to update.
  271. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  272. * the surface didn't have an index format); call SDL_GetError() for
  273. * more information.
  274. *
  275. * \since This function is available since SDL 3.2.0.
  276. *
  277. * \sa SDL_SetPaletteColors
  278. */
  279. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
  280. /**
  281. * Set the palette used by a surface.
  282. *
  283. * A single palette can be shared with many surfaces.
  284. *
  285. * \param surface the SDL_Surface structure to update.
  286. * \param palette the SDL_Palette structure to use.
  287. * \returns true on success or false on failure; call SDL_GetError() for more
  288. * information.
  289. *
  290. * \since This function is available since SDL 3.2.0.
  291. *
  292. * \sa SDL_CreatePalette
  293. * \sa SDL_GetSurfacePalette
  294. */
  295. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  296. /**
  297. * Get the palette used by a surface.
  298. *
  299. * \param surface the SDL_Surface structure to query.
  300. * \returns a pointer to the palette used by the surface, or NULL if there is
  301. * no palette used.
  302. *
  303. * \since This function is available since SDL 3.2.0.
  304. *
  305. * \sa SDL_SetSurfacePalette
  306. */
  307. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
  308. /**
  309. * Add an alternate version of a surface.
  310. *
  311. * This function adds an alternate version of this surface, usually used for
  312. * content with high DPI representations like cursors or icons. The size,
  313. * format, and content do not need to match the original surface, and these
  314. * alternate versions will not be updated when the original surface changes.
  315. *
  316. * This function adds a reference to the alternate version, so you should call
  317. * SDL_DestroySurface() on the image after this call.
  318. *
  319. * \param surface the SDL_Surface structure to update.
  320. * \param image a pointer to an alternate SDL_Surface to associate with this
  321. * surface.
  322. * \returns true on success or false on failure; call SDL_GetError() for more
  323. * information.
  324. *
  325. * \since This function is available since SDL 3.2.0.
  326. *
  327. * \sa SDL_RemoveSurfaceAlternateImages
  328. * \sa SDL_GetSurfaceImages
  329. * \sa SDL_SurfaceHasAlternateImages
  330. */
  331. extern SDL_DECLSPEC bool SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image);
  332. /**
  333. * Return whether a surface has alternate versions available.
  334. *
  335. * \param surface the SDL_Surface structure to query.
  336. * \returns true if alternate versions are available or false otherwise.
  337. *
  338. * \since This function is available since SDL 3.2.0.
  339. *
  340. * \sa SDL_AddSurfaceAlternateImage
  341. * \sa SDL_RemoveSurfaceAlternateImages
  342. * \sa SDL_GetSurfaceImages
  343. */
  344. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasAlternateImages(SDL_Surface *surface);
  345. /**
  346. * Get an array including all versions of a surface.
  347. *
  348. * This returns all versions of a surface, with the surface being queried as
  349. * the first element in the returned array.
  350. *
  351. * Freeing the array of surfaces does not affect the surfaces in the array.
  352. * They are still referenced by the surface being queried and will be cleaned
  353. * up normally.
  354. *
  355. * \param surface the SDL_Surface structure to query.
  356. * \param count a pointer filled in with the number of surface pointers
  357. * returned, may be NULL.
  358. * \returns a NULL terminated array of SDL_Surface pointers or NULL on
  359. * failure; call SDL_GetError() for more information. This should be
  360. * freed with SDL_free() when it is no longer needed.
  361. *
  362. * \since This function is available since SDL 3.2.0.
  363. *
  364. * \sa SDL_AddSurfaceAlternateImage
  365. * \sa SDL_RemoveSurfaceAlternateImages
  366. * \sa SDL_SurfaceHasAlternateImages
  367. */
  368. extern SDL_DECLSPEC SDL_Surface ** SDLCALL SDL_GetSurfaceImages(SDL_Surface *surface, int *count);
  369. /**
  370. * Remove all alternate versions of a surface.
  371. *
  372. * This function removes a reference from all the alternative versions,
  373. * destroying them if this is the last reference to them.
  374. *
  375. * \param surface the SDL_Surface structure to update.
  376. *
  377. * \since This function is available since SDL 3.2.0.
  378. *
  379. * \sa SDL_AddSurfaceAlternateImage
  380. * \sa SDL_GetSurfaceImages
  381. * \sa SDL_SurfaceHasAlternateImages
  382. */
  383. extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface);
  384. /**
  385. * Set up a surface for directly accessing the pixels.
  386. *
  387. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  388. * and read from `surface->pixels`, using the pixel format stored in
  389. * `surface->format`. Once you are done accessing the surface, you should use
  390. * SDL_UnlockSurface() to release it.
  391. *
  392. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  393. * 0, then you can read and write to the surface at any time, and the pixel
  394. * format of the surface will not change.
  395. *
  396. * \param surface the SDL_Surface structure to be locked.
  397. * \returns true on success or false on failure; call SDL_GetError() for more
  398. * information.
  399. *
  400. * \since This function is available since SDL 3.2.0.
  401. *
  402. * \sa SDL_MUSTLOCK
  403. * \sa SDL_UnlockSurface
  404. */
  405. extern SDL_DECLSPEC bool SDLCALL SDL_LockSurface(SDL_Surface *surface);
  406. /**
  407. * Release a surface after directly accessing the pixels.
  408. *
  409. * \param surface the SDL_Surface structure to be unlocked.
  410. *
  411. * \since This function is available since SDL 3.2.0.
  412. *
  413. * \sa SDL_LockSurface
  414. */
  415. extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  416. /**
  417. * Load a BMP image from a seekable SDL data stream.
  418. *
  419. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  420. * will result in a memory leak.
  421. *
  422. * \param src the data stream for the surface.
  423. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  424. * in the case of an error.
  425. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  426. * SDL_GetError() for more information.
  427. *
  428. * \since This function is available since SDL 3.2.0.
  429. *
  430. * \sa SDL_DestroySurface
  431. * \sa SDL_LoadBMP
  432. * \sa SDL_SaveBMP_IO
  433. */
  434. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio);
  435. /**
  436. * Load a BMP image from a file.
  437. *
  438. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  439. * will result in a memory leak.
  440. *
  441. * \param file the BMP file to load.
  442. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  443. * SDL_GetError() for more information.
  444. *
  445. * \since This function is available since SDL 3.2.0.
  446. *
  447. * \sa SDL_DestroySurface
  448. * \sa SDL_LoadBMP_IO
  449. * \sa SDL_SaveBMP
  450. */
  451. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
  452. /**
  453. * Save a surface to a seekable SDL data stream in BMP format.
  454. *
  455. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  456. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  457. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  458. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  459. * not supported.
  460. *
  461. * \param surface the SDL_Surface structure containing the image to be saved.
  462. * \param dst a data stream to save to.
  463. * \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even
  464. * in the case of an error.
  465. * \returns true on success or false on failure; call SDL_GetError() for more
  466. * information.
  467. *
  468. * \since This function is available since SDL 3.2.0.
  469. *
  470. * \sa SDL_LoadBMP_IO
  471. * \sa SDL_SaveBMP
  472. */
  473. extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
  474. /**
  475. * Save a surface to a file.
  476. *
  477. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  478. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  479. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  480. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  481. * not supported.
  482. *
  483. * \param surface the SDL_Surface structure containing the image to be saved.
  484. * \param file a file to save to.
  485. * \returns true on success or false on failure; call SDL_GetError() for more
  486. * information.
  487. *
  488. * \since This function is available since SDL 3.2.0.
  489. *
  490. * \sa SDL_LoadBMP
  491. * \sa SDL_SaveBMP_IO
  492. */
  493. extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  494. /**
  495. * Set the RLE acceleration hint for a surface.
  496. *
  497. * If RLE is enabled, color key and alpha blending blits are much faster, but
  498. * the surface must be locked before directly accessing the pixels.
  499. *
  500. * \param surface the SDL_Surface structure to optimize.
  501. * \param enabled true to enable RLE acceleration, false to disable it.
  502. * \returns true on success or false on failure; call SDL_GetError() for more
  503. * information.
  504. *
  505. * \since This function is available since SDL 3.2.0.
  506. *
  507. * \sa SDL_BlitSurface
  508. * \sa SDL_LockSurface
  509. * \sa SDL_UnlockSurface
  510. */
  511. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled);
  512. /**
  513. * Returns whether the surface is RLE enabled.
  514. *
  515. * It is safe to pass a NULL `surface` here; it will return false.
  516. *
  517. * \param surface the SDL_Surface structure to query.
  518. * \returns true if the surface is RLE enabled, false otherwise.
  519. *
  520. * \since This function is available since SDL 3.2.0.
  521. *
  522. * \sa SDL_SetSurfaceRLE
  523. */
  524. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  525. /**
  526. * Set the color key (transparent pixel) in a surface.
  527. *
  528. * The color key defines a pixel value that will be treated as transparent in
  529. * a blit. For example, one can use this to specify that cyan pixels should be
  530. * considered transparent, and therefore not rendered.
  531. *
  532. * It is a pixel of the format used by the surface, as generated by
  533. * SDL_MapRGB().
  534. *
  535. * \param surface the SDL_Surface structure to update.
  536. * \param enabled true to enable color key, false to disable color key.
  537. * \param key the transparent pixel.
  538. * \returns true on success or false on failure; call SDL_GetError() for more
  539. * information.
  540. *
  541. * \since This function is available since SDL 3.2.0.
  542. *
  543. * \sa SDL_GetSurfaceColorKey
  544. * \sa SDL_SetSurfaceRLE
  545. * \sa SDL_SurfaceHasColorKey
  546. */
  547. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key);
  548. /**
  549. * Returns whether the surface has a color key.
  550. *
  551. * It is safe to pass a NULL `surface` here; it will return false.
  552. *
  553. * \param surface the SDL_Surface structure to query.
  554. * \returns true if the surface has a color key, false otherwise.
  555. *
  556. * \since This function is available since SDL 3.2.0.
  557. *
  558. * \sa SDL_SetSurfaceColorKey
  559. * \sa SDL_GetSurfaceColorKey
  560. */
  561. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  562. /**
  563. * Get the color key (transparent pixel) for a surface.
  564. *
  565. * The color key is a pixel of the format used by the surface, as generated by
  566. * SDL_MapRGB().
  567. *
  568. * If the surface doesn't have color key enabled this function returns false.
  569. *
  570. * \param surface the SDL_Surface structure to query.
  571. * \param key a pointer filled in with the transparent pixel.
  572. * \returns true on success or false on failure; call SDL_GetError() for more
  573. * information.
  574. *
  575. * \since This function is available since SDL 3.2.0.
  576. *
  577. * \sa SDL_SetSurfaceColorKey
  578. * \sa SDL_SurfaceHasColorKey
  579. */
  580. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  581. /**
  582. * Set an additional color value multiplied into blit operations.
  583. *
  584. * When this surface is blitted, during the blit operation each source color
  585. * channel is modulated by the appropriate color value according to the
  586. * following formula:
  587. *
  588. * `srcC = srcC * (color / 255)`
  589. *
  590. * \param surface the SDL_Surface structure to update.
  591. * \param r the red color value multiplied into blit operations.
  592. * \param g the green color value multiplied into blit operations.
  593. * \param b the blue color value multiplied into blit operations.
  594. * \returns true on success or false on failure; call SDL_GetError() for more
  595. * information.
  596. *
  597. * \since This function is available since SDL 3.2.0.
  598. *
  599. * \sa SDL_GetSurfaceColorMod
  600. * \sa SDL_SetSurfaceAlphaMod
  601. */
  602. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  603. /**
  604. * Get the additional color value multiplied into blit operations.
  605. *
  606. * \param surface the SDL_Surface structure to query.
  607. * \param r a pointer filled in with the current red color value.
  608. * \param g a pointer filled in with the current green color value.
  609. * \param b a pointer filled in with the current blue color value.
  610. * \returns true on success or false on failure; call SDL_GetError() for more
  611. * information.
  612. *
  613. * \since This function is available since SDL 3.2.0.
  614. *
  615. * \sa SDL_GetSurfaceAlphaMod
  616. * \sa SDL_SetSurfaceColorMod
  617. */
  618. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  619. /**
  620. * Set an additional alpha value used in blit operations.
  621. *
  622. * When this surface is blitted, during the blit operation the source alpha
  623. * value is modulated by this alpha value according to the following formula:
  624. *
  625. * `srcA = srcA * (alpha / 255)`
  626. *
  627. * \param surface the SDL_Surface structure to update.
  628. * \param alpha the alpha value multiplied into blit operations.
  629. * \returns true on success or false on failure; call SDL_GetError() for more
  630. * information.
  631. *
  632. * \since This function is available since SDL 3.2.0.
  633. *
  634. * \sa SDL_GetSurfaceAlphaMod
  635. * \sa SDL_SetSurfaceColorMod
  636. */
  637. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  638. /**
  639. * Get the additional alpha value used in blit operations.
  640. *
  641. * \param surface the SDL_Surface structure to query.
  642. * \param alpha a pointer filled in with the current alpha value.
  643. * \returns true on success or false on failure; call SDL_GetError() for more
  644. * information.
  645. *
  646. * \since This function is available since SDL 3.2.0.
  647. *
  648. * \sa SDL_GetSurfaceColorMod
  649. * \sa SDL_SetSurfaceAlphaMod
  650. */
  651. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  652. /**
  653. * Set the blend mode used for blit operations.
  654. *
  655. * To copy a surface to another surface (or texture) without blending with the
  656. * existing data, the blendmode of the SOURCE surface should be set to
  657. * `SDL_BLENDMODE_NONE`.
  658. *
  659. * \param surface the SDL_Surface structure to update.
  660. * \param blendMode the SDL_BlendMode to use for blit blending.
  661. * \returns true on success or false on failure; call SDL_GetError() for more
  662. * information.
  663. *
  664. * \since This function is available since SDL 3.2.0.
  665. *
  666. * \sa SDL_GetSurfaceBlendMode
  667. */
  668. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  669. /**
  670. * Get the blend mode used for blit operations.
  671. *
  672. * \param surface the SDL_Surface structure to query.
  673. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  674. * \returns true on success or false on failure; call SDL_GetError() for more
  675. * information.
  676. *
  677. * \since This function is available since SDL 3.2.0.
  678. *
  679. * \sa SDL_SetSurfaceBlendMode
  680. */
  681. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  682. /**
  683. * Set the clipping rectangle for a surface.
  684. *
  685. * When `surface` is the destination of a blit, only the area within the clip
  686. * rectangle is drawn into.
  687. *
  688. * Note that blits are automatically clipped to the edges of the source and
  689. * destination surfaces.
  690. *
  691. * \param surface the SDL_Surface structure to be clipped.
  692. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  693. * NULL to disable clipping.
  694. * \returns true if the rectangle intersects the surface, otherwise false and
  695. * blits will be completely clipped.
  696. *
  697. * \since This function is available since SDL 3.2.0.
  698. *
  699. * \sa SDL_GetSurfaceClipRect
  700. */
  701. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  702. /**
  703. * Get the clipping rectangle for a surface.
  704. *
  705. * When `surface` is the destination of a blit, only the area within the clip
  706. * rectangle is drawn into.
  707. *
  708. * \param surface the SDL_Surface structure representing the surface to be
  709. * clipped.
  710. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  711. * the surface.
  712. * \returns true on success or false on failure; call SDL_GetError() for more
  713. * information.
  714. *
  715. * \since This function is available since SDL 3.2.0.
  716. *
  717. * \sa SDL_SetSurfaceClipRect
  718. */
  719. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  720. /**
  721. * Flip a surface vertically or horizontally.
  722. *
  723. * \param surface the surface to flip.
  724. * \param flip the direction to flip.
  725. * \returns true on success or false on failure; call SDL_GetError() for more
  726. * information.
  727. *
  728. * \since This function is available since SDL 3.2.0.
  729. */
  730. extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  731. /**
  732. * Creates a new surface identical to the existing surface.
  733. *
  734. * If the original surface has alternate images, the new surface will have a
  735. * reference to them as well.
  736. *
  737. * The returned surface should be freed with SDL_DestroySurface().
  738. *
  739. * \param surface the surface to duplicate.
  740. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  741. * more information.
  742. *
  743. * \since This function is available since SDL 3.2.0.
  744. *
  745. * \sa SDL_DestroySurface
  746. */
  747. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  748. /**
  749. * Creates a new surface identical to the existing surface, scaled to the
  750. * desired size.
  751. *
  752. * The returned surface should be freed with SDL_DestroySurface().
  753. *
  754. * \param surface the surface to duplicate and scale.
  755. * \param width the width of the new surface.
  756. * \param height the height of the new surface.
  757. * \param scaleMode the SDL_ScaleMode to be used.
  758. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  759. * more information.
  760. *
  761. * \since This function is available since SDL 3.2.0.
  762. *
  763. * \sa SDL_DestroySurface
  764. */
  765. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode);
  766. /**
  767. * Copy an existing surface to a new surface of the specified format.
  768. *
  769. * This function is used to optimize images for faster *repeat* blitting. This
  770. * is accomplished by converting the original and storing the result as a new
  771. * surface. The new, optimized surface can then be used as the source for
  772. * future blits, making them faster.
  773. *
  774. * If you are converting to an indexed surface and want to map colors to a
  775. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  776. *
  777. * If the original surface has alternate images, the new surface will have a
  778. * reference to them as well.
  779. *
  780. * \param surface the existing SDL_Surface structure to convert.
  781. * \param format the new pixel format.
  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.2.0.
  786. *
  787. * \sa SDL_ConvertSurfaceAndColorspace
  788. * \sa SDL_DestroySurface
  789. */
  790. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  791. /**
  792. * Copy an existing surface to a new surface of the specified format and
  793. * colorspace.
  794. *
  795. * This function converts an existing surface to a new format and colorspace
  796. * and returns the new surface. This will perform any pixel format and
  797. * colorspace conversion needed.
  798. *
  799. * If the original surface has alternate images, the new surface will have a
  800. * reference to them as well.
  801. *
  802. * \param surface the existing SDL_Surface structure to convert.
  803. * \param format the new pixel format.
  804. * \param palette an optional palette to use for indexed formats, may be NULL.
  805. * \param colorspace the new colorspace.
  806. * \param props an SDL_PropertiesID with additional color properties, or 0.
  807. * \returns the new SDL_Surface structure that is created or NULL on failure;
  808. * call SDL_GetError() for more information.
  809. *
  810. * \since This function is available since SDL 3.2.0.
  811. *
  812. * \sa SDL_ConvertSurface
  813. * \sa SDL_DestroySurface
  814. */
  815. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  816. /**
  817. * Copy a block of pixels of one format to another format.
  818. *
  819. * \param width the width of the block to copy, in pixels.
  820. * \param height the height of the block to copy, in pixels.
  821. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  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 a pointer to be filled in with new pixel data.
  826. * \param dst_pitch the pitch of the destination pixels, in bytes.
  827. * \returns true on success or false on failure; call SDL_GetError() for more
  828. * information.
  829. *
  830. * \since This function is available since SDL 3.2.0.
  831. *
  832. * \sa SDL_ConvertPixelsAndColorspace
  833. */
  834. 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);
  835. /**
  836. * Copy a block of pixels of one format and colorspace to another format and
  837. * colorspace.
  838. *
  839. * \param width the width of the block to copy, in pixels.
  840. * \param height the height of the block to copy, in pixels.
  841. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  842. * \param src_colorspace an SDL_Colorspace value describing the colorspace of
  843. * the `src` pixels.
  844. * \param src_properties an SDL_PropertiesID with additional source color
  845. * properties, or 0.
  846. * \param src a pointer to the source pixels.
  847. * \param src_pitch the pitch of the source pixels, in bytes.
  848. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  849. * \param dst_colorspace an SDL_Colorspace value describing the colorspace of
  850. * the `dst` pixels.
  851. * \param dst_properties an SDL_PropertiesID with additional destination color
  852. * properties, or 0.
  853. * \param dst a pointer to be filled in with new pixel data.
  854. * \param dst_pitch the pitch of the destination pixels, in bytes.
  855. * \returns true on success or false on failure; call SDL_GetError() for more
  856. * information.
  857. *
  858. * \since This function is available since SDL 3.2.0.
  859. *
  860. * \sa SDL_ConvertPixels
  861. */
  862. 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);
  863. /**
  864. * Premultiply the alpha on a block of pixels.
  865. *
  866. * This is safe to use with src == dst, but not for other overlapping areas.
  867. *
  868. * \param width the width of the block to convert, in pixels.
  869. * \param height the height of the block to convert, in pixels.
  870. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  871. * \param src a pointer to the source pixels.
  872. * \param src_pitch the pitch of the source pixels, in bytes.
  873. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  874. * \param dst a pointer to be filled in with premultiplied pixel data.
  875. * \param dst_pitch the pitch of the destination pixels, in bytes.
  876. * \param linear true to convert from sRGB to linear space for the alpha
  877. * multiplication, false to do multiplication in sRGB space.
  878. * \returns true on success or false on failure; call SDL_GetError() for more
  879. * information.
  880. *
  881. * \since This function is available since SDL 3.2.0.
  882. */
  883. 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);
  884. /**
  885. * Premultiply the alpha in a surface.
  886. *
  887. * This is safe to use with src == dst, but not for other overlapping areas.
  888. *
  889. * \param surface the surface to modify.
  890. * \param linear true to convert from sRGB to linear space for the alpha
  891. * multiplication, false to do multiplication in sRGB space.
  892. * \returns true on success or false on failure; call SDL_GetError() for more
  893. * information.
  894. *
  895. * \since This function is available since SDL 3.2.0.
  896. */
  897. extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, bool linear);
  898. /**
  899. * Clear a surface with a specific color, with floating point precision.
  900. *
  901. * This function handles all surface formats, and ignores any clip rectangle.
  902. *
  903. * If the surface is YUV, the color is assumed to be in the sRGB colorspace,
  904. * otherwise the color is assumed to be in the colorspace of the suface.
  905. *
  906. * \param surface the SDL_Surface to clear.
  907. * \param r the red component of the pixel, normally in the range 0-1.
  908. * \param g the green component of the pixel, normally in the range 0-1.
  909. * \param b the blue component of the pixel, normally in the range 0-1.
  910. * \param a the alpha component of the pixel, normally in the range 0-1.
  911. * \returns true on success or false on failure; call SDL_GetError() for more
  912. * information.
  913. *
  914. * \since This function is available since SDL 3.2.0.
  915. */
  916. extern SDL_DECLSPEC bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a);
  917. /**
  918. * Perform a fast fill of a rectangle 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 rect the SDL_Rect structure representing the rectangle to fill, or
  931. * NULL to fill the entire surface.
  932. * \param color the color to fill with.
  933. * \returns true on success or false on failure; call SDL_GetError() for more
  934. * information.
  935. *
  936. * \since This function is available since SDL 3.2.0.
  937. *
  938. * \sa SDL_FillSurfaceRects
  939. */
  940. extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  941. /**
  942. * Perform a fast fill of a set of rectangles with a specific color.
  943. *
  944. * `color` should be a pixel of the format used by the surface, and can be
  945. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  946. * alpha component then the destination is simply filled with that alpha
  947. * information, no blending takes place.
  948. *
  949. * If there is a clip rectangle set on the destination (set via
  950. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  951. * intersection of the clip rectangle and `rect`.
  952. *
  953. * \param dst the SDL_Surface structure that is the drawing target.
  954. * \param rects an array of SDL_Rects representing the rectangles to fill.
  955. * \param count the number of rectangles in the array.
  956. * \param color the color to fill with.
  957. * \returns true on success or false on failure; call SDL_GetError() for more
  958. * information.
  959. *
  960. * \since This function is available since SDL 3.2.0.
  961. *
  962. * \sa SDL_FillSurfaceRect
  963. */
  964. extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  965. /**
  966. * Performs a fast blit from the source surface to the destination surface
  967. * with clipping.
  968. *
  969. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  970. * `dst`) is copied while ensuring clipping to `dst->clip_rect`.
  971. *
  972. * The final blit rectangles are saved in `srcrect` and `dstrect` after all
  973. * clipping is performed.
  974. *
  975. * The blit function should not be called on a locked surface.
  976. *
  977. * The blit semantics for surfaces with and without blending and colorkey are
  978. * defined as follows:
  979. *
  980. * ```
  981. * RGBA->RGB:
  982. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  983. * alpha-blend (using the source alpha-channel and per-surface alpha)
  984. * SDL_SRCCOLORKEY ignored.
  985. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  986. * copy RGB.
  987. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  988. * RGB values of the source color key, ignoring alpha in the
  989. * comparison.
  990. *
  991. * RGB->RGBA:
  992. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  993. * alpha-blend (using the source per-surface alpha)
  994. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  995. * copy RGB, set destination alpha to source per-surface alpha value.
  996. * both:
  997. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  998. * source color key.
  999. *
  1000. * RGBA->RGBA:
  1001. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1002. * alpha-blend (using the source alpha-channel and per-surface alpha)
  1003. * SDL_SRCCOLORKEY ignored.
  1004. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1005. * copy all of RGBA to the destination.
  1006. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1007. * RGB values of the source color key, ignoring alpha in the
  1008. * comparison.
  1009. *
  1010. * RGB->RGB:
  1011. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1012. * alpha-blend (using the source per-surface alpha)
  1013. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1014. * copy RGB.
  1015. * both:
  1016. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1017. * source color key.
  1018. * ```
  1019. *
  1020. * \param src the SDL_Surface structure to be copied from.
  1021. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1022. * copied, or NULL to copy the entire surface.
  1023. * \param dst the SDL_Surface structure that is the blit target.
  1024. * \param dstrect the SDL_Rect structure representing the x and y position in
  1025. * the destination surface, or NULL for (0,0). The width and
  1026. * height are ignored, and are copied from `srcrect`. If you
  1027. * want a specific width and height, you should use
  1028. * SDL_BlitSurfaceScaled().
  1029. * \returns true on success or false on failure; call SDL_GetError() for more
  1030. * information.
  1031. *
  1032. * \threadsafety The same destination surface should not be used from two
  1033. * threads at once. It is safe to use the same source surface
  1034. * from multiple threads.
  1035. *
  1036. * \since This function is available since SDL 3.2.0.
  1037. *
  1038. * \sa SDL_BlitSurfaceScaled
  1039. */
  1040. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1041. /**
  1042. * Perform low-level surface blitting only.
  1043. *
  1044. * This is a semi-private blit function and it performs low-level surface
  1045. * blitting, assuming the input rectangles have already been clipped.
  1046. *
  1047. * \param src the SDL_Surface structure to be copied from.
  1048. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1049. * copied, may not be NULL.
  1050. * \param dst the SDL_Surface structure that is the blit target.
  1051. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1052. * the destination surface, may not be NULL.
  1053. * \returns true on success or false on failure; call SDL_GetError() for more
  1054. * information.
  1055. *
  1056. * \threadsafety The same destination surface should not be used from two
  1057. * threads at once. It is safe to use the same source surface
  1058. * from multiple threads.
  1059. *
  1060. * \since This function is available since SDL 3.2.0.
  1061. *
  1062. * \sa SDL_BlitSurface
  1063. */
  1064. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1065. /**
  1066. * Perform a scaled blit to a destination surface, which may be of a different
  1067. * format.
  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, or NULL to copy the entire surface.
  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, or NULL to fill the entire
  1075. * destination surface.
  1076. * \param scaleMode the SDL_ScaleMode to be used.
  1077. * \returns true on success or false on failure; call SDL_GetError() for more
  1078. * information.
  1079. *
  1080. * \threadsafety The same destination surface should not be used from two
  1081. * threads at once. It is safe to use the same source surface
  1082. * from multiple threads.
  1083. *
  1084. * \since This function is available since SDL 3.2.0.
  1085. *
  1086. * \sa SDL_BlitSurface
  1087. */
  1088. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1089. /**
  1090. * Perform low-level surface scaled blitting only.
  1091. *
  1092. * This is a semi-private function and it performs low-level surface blitting,
  1093. * assuming the input rectangles have already been clipped.
  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, may not be NULL.
  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, may not be NULL.
  1101. * \param scaleMode the SDL_ScaleMode to be used.
  1102. * \returns true on success or false on failure; call SDL_GetError() for more
  1103. * information.
  1104. *
  1105. * \threadsafety The same destination surface should not be used from two
  1106. * threads at once. It is safe to use the same source surface
  1107. * from multiple threads.
  1108. *
  1109. * \since This function is available since SDL 3.2.0.
  1110. *
  1111. * \sa SDL_BlitSurfaceScaled
  1112. */
  1113. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1114. /**
  1115. * Perform a stretched pixel copy from one surface to another.
  1116. *
  1117. * \param src the SDL_Surface structure to be copied from.
  1118. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1119. * copied, may not be NULL.
  1120. * \param dst the SDL_Surface structure that is the blit target.
  1121. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1122. * the destination surface, may not be NULL.
  1123. * \param scaleMode the SDL_ScaleMode to be used.
  1124. * \returns true on success or false on failure; call SDL_GetError() for more
  1125. * information.
  1126. *
  1127. * \threadsafety The same destination surface should not be used from two
  1128. * threads at once. It is safe to use the same source surface
  1129. * from multiple threads.
  1130. *
  1131. * \since This function is available since SDL 3.4.0.
  1132. *
  1133. * \sa SDL_BlitSurfaceScaled
  1134. */
  1135. extern SDL_DECLSPEC bool SDLCALL SDL_StretchSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1136. /**
  1137. * Perform a tiled blit to a destination surface, which may be of a different
  1138. * format.
  1139. *
  1140. * The pixels in `srcrect` will be repeated as many times as needed to
  1141. * completely fill `dstrect`.
  1142. *
  1143. * \param src the SDL_Surface structure to be copied from.
  1144. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1145. * copied, or NULL to copy the entire surface.
  1146. * \param dst the SDL_Surface structure that is the blit target.
  1147. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1148. * the destination surface, or NULL to fill the entire surface.
  1149. * \returns true on success or false on failure; call SDL_GetError() for more
  1150. * information.
  1151. *
  1152. * \threadsafety The same destination surface should not be used from two
  1153. * threads at once. It is safe to use the same source surface
  1154. * from multiple threads.
  1155. *
  1156. * \since This function is available since SDL 3.2.0.
  1157. *
  1158. * \sa SDL_BlitSurface
  1159. */
  1160. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1161. /**
  1162. * Perform a scaled and tiled blit to a destination surface, which may be of a
  1163. * different format.
  1164. *
  1165. * The pixels in `srcrect` will be scaled and repeated as many times as needed
  1166. * to completely fill `dstrect`.
  1167. *
  1168. * \param src the SDL_Surface structure to be copied from.
  1169. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1170. * copied, or NULL to copy the entire surface.
  1171. * \param scale the scale used to transform srcrect into the destination
  1172. * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
  1173. * 64x64 tiles.
  1174. * \param scaleMode scale algorithm to be used.
  1175. * \param dst the SDL_Surface structure that is the blit target.
  1176. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1177. * the destination surface, or NULL to fill the entire surface.
  1178. * \returns true on success or false on failure; call SDL_GetError() for more
  1179. * information.
  1180. *
  1181. * \threadsafety The same destination surface should not be used from two
  1182. * threads at once. It is safe to use the same source surface
  1183. * from multiple threads.
  1184. *
  1185. * \since This function is available since SDL 3.2.0.
  1186. *
  1187. * \sa SDL_BlitSurface
  1188. */
  1189. 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);
  1190. /**
  1191. * Perform a scaled blit using the 9-grid algorithm to a destination surface,
  1192. * which may be of a different format.
  1193. *
  1194. * The pixels in the source surface are split into a 3x3 grid, using the
  1195. * different corner sizes for each corner, and the sides and center making up
  1196. * the remaining pixels. The corners are then scaled using `scale` and fit
  1197. * into the corners of the destination rectangle. The sides and center are
  1198. * then stretched into place to cover the remaining destination rectangle.
  1199. *
  1200. * \param src the SDL_Surface structure to be copied from.
  1201. * \param srcrect the SDL_Rect structure representing the rectangle to be used
  1202. * for the 9-grid, or NULL to use the entire surface.
  1203. * \param left_width the width, in pixels, of the left corners in `srcrect`.
  1204. * \param right_width the width, in pixels, of the right corners in `srcrect`.
  1205. * \param top_height the height, in pixels, of the top corners in `srcrect`.
  1206. * \param bottom_height the height, in pixels, of the bottom corners in
  1207. * `srcrect`.
  1208. * \param scale the scale used to transform the corner of `srcrect` into the
  1209. * corner of `dstrect`, or 0.0f for an unscaled blit.
  1210. * \param scaleMode scale algorithm to be used.
  1211. * \param dst the SDL_Surface structure that is the blit target.
  1212. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1213. * the destination surface, or NULL to fill the entire surface.
  1214. * \returns true on success or false on failure; call SDL_GetError() for more
  1215. * information.
  1216. *
  1217. * \threadsafety The same destination surface should not be used from two
  1218. * threads at once. It is safe to use the same source surface
  1219. * from multiple threads.
  1220. *
  1221. * \since This function is available since SDL 3.2.0.
  1222. *
  1223. * \sa SDL_BlitSurface
  1224. */
  1225. 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);
  1226. /**
  1227. * Map an RGB triple to an opaque pixel value for a surface.
  1228. *
  1229. * This function maps the RGB color value to the specified pixel format and
  1230. * returns the pixel value best approximating the given RGB color value for
  1231. * the given pixel format.
  1232. *
  1233. * If the surface has a palette, the index of the closest matching color in
  1234. * the palette will be returned.
  1235. *
  1236. * If the surface pixel format has an alpha component it will be returned as
  1237. * all 1 bits (fully opaque).
  1238. *
  1239. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1240. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1241. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1242. * for an 8-bpp format).
  1243. *
  1244. * \param surface the surface to use for the pixel format and palette.
  1245. * \param r the red component of the pixel in the range 0-255.
  1246. * \param g the green component of the pixel in the range 0-255.
  1247. * \param b the blue component of the pixel in the range 0-255.
  1248. * \returns a pixel value.
  1249. *
  1250. * \since This function is available since SDL 3.2.0.
  1251. *
  1252. * \sa SDL_MapSurfaceRGBA
  1253. */
  1254. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  1255. /**
  1256. * Map an RGBA quadruple to a pixel value for a surface.
  1257. *
  1258. * This function maps the RGBA color value to the specified pixel format and
  1259. * returns the pixel value best approximating the given RGBA color value for
  1260. * the given pixel format.
  1261. *
  1262. * If the surface pixel format has no alpha component the alpha value will be
  1263. * ignored (as it will be in formats with a palette).
  1264. *
  1265. * If the surface has a palette, the index of the closest matching color in
  1266. * the palette will be returned.
  1267. *
  1268. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1269. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1270. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1271. * for an 8-bpp format).
  1272. *
  1273. * \param surface the surface to use for the pixel format and palette.
  1274. * \param r the red component of the pixel in the range 0-255.
  1275. * \param g the green component of the pixel in the range 0-255.
  1276. * \param b the blue component of the pixel in the range 0-255.
  1277. * \param a the alpha component of the pixel in the range 0-255.
  1278. * \returns a pixel value.
  1279. *
  1280. * \since This function is available since SDL 3.2.0.
  1281. *
  1282. * \sa SDL_MapSurfaceRGB
  1283. */
  1284. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1285. /**
  1286. * Retrieves a single pixel from a surface.
  1287. *
  1288. * This function prioritizes correctness over speed: it is suitable for unit
  1289. * tests, but is not intended for use in a game engine.
  1290. *
  1291. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1292. * components from pixel formats with less than 8 bits per RGB component.
  1293. *
  1294. * \param surface the surface to read.
  1295. * \param x the horizontal coordinate, 0 <= x < width.
  1296. * \param y the vertical coordinate, 0 <= y < height.
  1297. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1298. * this channel.
  1299. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1300. * ignore this channel.
  1301. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1302. * ignore this channel.
  1303. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1304. * ignore this channel.
  1305. * \returns true on success or false on failure; call SDL_GetError() for more
  1306. * information.
  1307. *
  1308. * \since This function is available since SDL 3.2.0.
  1309. */
  1310. extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1311. /**
  1312. * Retrieves a single pixel from a surface.
  1313. *
  1314. * This function prioritizes correctness over speed: it is suitable for unit
  1315. * tests, but is not intended for use in a game engine.
  1316. *
  1317. * \param surface the surface to read.
  1318. * \param x the horizontal coordinate, 0 <= x < width.
  1319. * \param y the vertical coordinate, 0 <= y < height.
  1320. * \param r a pointer filled in with the red channel, normally in the range
  1321. * 0-1, or NULL to ignore this channel.
  1322. * \param g a pointer filled in with the green channel, normally in the range
  1323. * 0-1, or NULL to ignore this channel.
  1324. * \param b a pointer filled in with the blue channel, normally in the range
  1325. * 0-1, or NULL to ignore this channel.
  1326. * \param a a pointer filled in with the alpha channel, normally in the range
  1327. * 0-1, or NULL to ignore this channel.
  1328. * \returns true on success or false on failure; call SDL_GetError() for more
  1329. * information.
  1330. *
  1331. * \since This function is available since SDL 3.2.0.
  1332. */
  1333. extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a);
  1334. /**
  1335. * Writes a single pixel to a surface.
  1336. *
  1337. * This function prioritizes correctness over speed: it is suitable for unit
  1338. * tests, but is not intended for use in a game engine.
  1339. *
  1340. * Like SDL_MapRGBA, this uses the entire 0..255 range when converting color
  1341. * components from pixel formats with less than 8 bits per RGB component.
  1342. *
  1343. * \param surface the surface to write.
  1344. * \param x the horizontal coordinate, 0 <= x < width.
  1345. * \param y the vertical coordinate, 0 <= y < height.
  1346. * \param r the red channel value, 0-255.
  1347. * \param g the green channel value, 0-255.
  1348. * \param b the blue channel value, 0-255.
  1349. * \param a the alpha channel value, 0-255.
  1350. * \returns true on success or false on failure; call SDL_GetError() for more
  1351. * information.
  1352. *
  1353. * \since This function is available since SDL 3.2.0.
  1354. */
  1355. extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1356. /**
  1357. * Writes a single pixel to a surface.
  1358. *
  1359. * This function prioritizes correctness over speed: it is suitable for unit
  1360. * tests, but is not intended for use in a game engine.
  1361. *
  1362. * \param surface the surface to write.
  1363. * \param x the horizontal coordinate, 0 <= x < width.
  1364. * \param y the vertical coordinate, 0 <= y < height.
  1365. * \param r the red channel value, normally in the range 0-1.
  1366. * \param g the green channel value, normally in the range 0-1.
  1367. * \param b the blue channel value, normally in the range 0-1.
  1368. * \param a the alpha channel value, normally in the range 0-1.
  1369. * \returns true on success or false on failure; call SDL_GetError() for more
  1370. * information.
  1371. *
  1372. * \since This function is available since SDL 3.2.0.
  1373. */
  1374. extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a);
  1375. /* Ends C function definitions when using C++ */
  1376. #ifdef __cplusplus
  1377. }
  1378. #endif
  1379. #include <SDL3/SDL_close_code.h>
  1380. #endif /* SDL_surface_h_ */