SDL_surface.h 58 KB

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