SDL_surface.h 69 KB

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