SDL_surface.h 71 KB

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