SDL_surface.h 55 KB

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