SDL_surface.h 58 KB

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