SDL_surface.h 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategorySurface
  20. *
  21. * SDL surfaces are buffers of pixels in system RAM. These are useful for
  22. * passing around and manipulating images that are not stored in GPU memory.
  23. *
  24. * SDL_Surface makes serious efforts to manage images in various formats, and
  25. * provides a reasonable toolbox for transforming the data, including copying
  26. * between surfaces, filling rectangles in the image data, etc.
  27. *
  28. * There is also a simple .bmp loader, SDL_LoadBMP(), a simple .png loader,
  29. * SDL_LoadPNG(), and a simple .jpg loader, SDL_LoadJPG(). SDL itself does not
  30. * provide loaders for other file formats, but there are several excellent
  31. * external libraries that do, including its own satellite library,
  32. * [SDL_image](https://wiki.libsdl.org/SDL3_image)
  33. * .
  34. *
  35. * In general these functions are thread-safe in that they can be called on
  36. * different threads with different surfaces. You should not try to modify any
  37. * surface from two threads simultaneously.
  38. */
  39. #ifndef SDL_surface_h_
  40. #define SDL_surface_h_
  41. #include <SDL3/SDL_stdinc.h>
  42. #include <SDL3/SDL_error.h>
  43. #include <SDL3/SDL_blendmode.h>
  44. #include <SDL3/SDL_pixels.h>
  45. #include <SDL3/SDL_properties.h>
  46. #include <SDL3/SDL_rect.h>
  47. #include <SDL3/SDL_iostream.h>
  48. #include <SDL3/SDL_begin_code.h>
  49. /* Set up for C function definitions, even when using C++ */
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53. /**
  54. * The flags on an SDL_Surface.
  55. *
  56. * These are generally considered read-only.
  57. *
  58. * \since This datatype is available since SDL 3.2.0.
  59. */
  60. typedef Uint32 SDL_SurfaceFlags;
  61. #define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */
  62. #define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */
  63. #define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */
  64. #define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */
  65. /**
  66. * Evaluates to true if the surface needs to be locked before access.
  67. *
  68. * \since This macro is available since SDL 3.2.0.
  69. */
  70. #define SDL_MUSTLOCK(S) (((S)->flags & SDL_SURFACE_LOCK_NEEDED) == SDL_SURFACE_LOCK_NEEDED)
  71. /**
  72. * The scaling mode.
  73. *
  74. * \since This enum is available since SDL 3.2.0.
  75. */
  76. typedef enum SDL_ScaleMode
  77. {
  78. SDL_SCALEMODE_INVALID = -1,
  79. SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
  80. SDL_SCALEMODE_LINEAR, /**< linear filtering */
  81. SDL_SCALEMODE_PIXELART /**< nearest pixel sampling with improved scaling for pixel art, available since SDL 3.4.0 */
  82. } SDL_ScaleMode;
  83. /**
  84. * The flip mode.
  85. *
  86. * \since This enum is available since SDL 3.2.0.
  87. */
  88. typedef enum SDL_FlipMode
  89. {
  90. SDL_FLIP_NONE, /**< Do not flip */
  91. SDL_FLIP_HORIZONTAL, /**< flip horizontally */
  92. SDL_FLIP_VERTICAL, /**< flip vertically */
  93. SDL_FLIP_HORIZONTAL_AND_VERTICAL = (SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL) /**< flip horizontally and vertically (not a diagonal flip) */
  94. } SDL_FlipMode;
  95. #ifndef SDL_INTERNAL
  96. /**
  97. * A collection of pixels used in software blitting.
  98. *
  99. * Pixels are arranged in memory in rows, with the top row first. Each row
  100. * occupies an amount of memory given by the pitch (sometimes known as the row
  101. * stride in non-SDL APIs).
  102. *
  103. * Within each row, pixels are arranged from left to right until the width is
  104. * reached. Each pixel occupies a number of bits appropriate for its format,
  105. * with most formats representing each pixel as one or more whole bytes (in
  106. * some indexed formats, instead multiple pixels are packed into each byte),
  107. * and a byte order given by the format. After encoding all pixels, any
  108. * remaining bytes to reach the pitch are used as padding to reach a desired
  109. * alignment, and have undefined contents.
  110. *
  111. * When a surface holds YUV format data, the planes are assumed to be
  112. * contiguous without padding between them, e.g. a 32x32 surface in NV12
  113. * format with a pitch of 32 would consist of 32x32 bytes of Y plane followed
  114. * by 32x16 bytes of UV plane.
  115. *
  116. * When a surface holds MJPG format data, pixels points at the compressed JPEG
  117. * image and pitch is the length of that data.
  118. *
  119. * \since This struct is available since SDL 3.2.0.
  120. *
  121. * \sa SDL_CreateSurface
  122. * \sa SDL_DestroySurface
  123. */
  124. struct SDL_Surface
  125. {
  126. SDL_SurfaceFlags flags; /**< The flags of the surface, read-only */
  127. SDL_PixelFormat format; /**< The format of the surface, read-only */
  128. int w; /**< The width of the surface, read-only. */
  129. int h; /**< The height of the surface, read-only. */
  130. int pitch; /**< The distance in bytes between rows of pixels, read-only */
  131. void *pixels; /**< A pointer to the pixels of the surface, the pixels are writeable if non-NULL */
  132. int refcount; /**< Application reference count, used when freeing surface */
  133. void *reserved; /**< Reserved for internal use */
  134. };
  135. #endif /* !SDL_INTERNAL */
  136. typedef struct SDL_Surface SDL_Surface;
  137. /**
  138. * Allocate a new surface with a specific pixel format.
  139. *
  140. * The pixels of the new surface are initialized to zero.
  141. *
  142. * \param width the width of the surface.
  143. * \param height the height of the surface.
  144. * \param format the SDL_PixelFormat for the new surface's pixel format.
  145. * \returns the new SDL_Surface structure that is created or NULL on failure;
  146. * call SDL_GetError() for more information.
  147. *
  148. * \threadsafety It is safe to call this function from any thread.
  149. *
  150. * \since This function is available since SDL 3.2.0.
  151. *
  152. * \sa SDL_CreateSurfaceFrom
  153. * \sa SDL_DestroySurface
  154. */
  155. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
  156. /**
  157. * Allocate a new surface with a specific pixel format and existing pixel
  158. * data.
  159. *
  160. * No copy is made of the pixel data. Pixel data is not managed automatically;
  161. * you must free the surface before you free the pixel data.
  162. *
  163. * Pitch is the offset in bytes from one row of pixels to the next, e.g.
  164. * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
  165. *
  166. * You may pass NULL for pixels and 0 for pitch to create a surface that you
  167. * will fill in with valid values later.
  168. *
  169. * \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, PNG or JPEG 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, PNG or JPEG 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. * Load a JPEG image from a seekable SDL data stream.
  690. *
  691. * This is intended as a convenience function for loading images from trusted
  692. * sources. If you want to load arbitrary images you should use libjpeg or
  693. * another image loading library designed with security in mind.
  694. *
  695. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  696. * will result in a memory leak.
  697. *
  698. * \param src the data stream for the surface.
  699. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  700. * in the case of an error.
  701. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  702. * SDL_GetError() for more information.
  703. *
  704. * \threadsafety It is safe to call this function from any thread.
  705. *
  706. * \since This function is available since SDL 3.6.0.
  707. *
  708. * \sa SDL_DestroySurface
  709. * \sa SDL_LoadJPG
  710. */
  711. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadJPG_IO(SDL_IOStream *src, bool closeio);
  712. /**
  713. * Load a JPEG image from a file.
  714. *
  715. * This is intended as a convenience function for loading images from trusted
  716. * sources. If you want to load arbitrary images you should use libjpeg or
  717. * another image loading library designed with security in mind.
  718. *
  719. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  720. * will result in a memory leak.
  721. *
  722. * \param file the JPG file to load.
  723. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  724. * SDL_GetError() for more information.
  725. *
  726. * \threadsafety It is safe to call this function from any thread.
  727. *
  728. * \since This function is available since SDL 3.6.0.
  729. *
  730. * \sa SDL_DestroySurface
  731. * \sa SDL_LoadJPG_IO
  732. */
  733. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadJPG(const char *file);
  734. /**
  735. * Set the RLE acceleration hint for a surface.
  736. *
  737. * If RLE is enabled, color key and alpha blending blits are much faster, but
  738. * the surface must be locked before directly accessing the pixels.
  739. *
  740. * \param surface the SDL_Surface structure to optimize.
  741. * \param enabled true to enable RLE acceleration, false to disable it.
  742. * \returns true on success or false on failure; call SDL_GetError() for more
  743. * information.
  744. *
  745. * \threadsafety This function can be called on different threads with
  746. * different surfaces.
  747. *
  748. * \since This function is available since SDL 3.2.0.
  749. *
  750. * \sa SDL_BlitSurface
  751. * \sa SDL_LockSurface
  752. * \sa SDL_UnlockSurface
  753. */
  754. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled);
  755. /**
  756. * Returns whether the surface is RLE enabled.
  757. *
  758. * It is safe to pass a NULL `surface` here; it will return false.
  759. *
  760. * \param surface the SDL_Surface structure to query.
  761. * \returns true if the surface is RLE enabled, false otherwise.
  762. *
  763. * \threadsafety It is safe to call this function from any thread.
  764. *
  765. * \since This function is available since SDL 3.2.0.
  766. *
  767. * \sa SDL_SetSurfaceRLE
  768. */
  769. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  770. /**
  771. * Set the color key (transparent pixel) in a surface.
  772. *
  773. * The color key defines a pixel value that will be treated as transparent in
  774. * a blit. For example, one can use this to specify that cyan pixels should be
  775. * considered transparent, and therefore not rendered.
  776. *
  777. * It is a pixel of the format used by the surface, as generated by
  778. * SDL_MapRGB().
  779. *
  780. * \param surface the SDL_Surface structure to update.
  781. * \param enabled true to enable color key, false to disable color key.
  782. * \param key the transparent pixel.
  783. * \returns true on success or false on failure; call SDL_GetError() for more
  784. * information.
  785. *
  786. * \threadsafety This function can be called on different threads with
  787. * different surfaces.
  788. *
  789. * \since This function is available since SDL 3.2.0.
  790. *
  791. * \sa SDL_GetSurfaceColorKey
  792. * \sa SDL_SetSurfaceRLE
  793. * \sa SDL_SurfaceHasColorKey
  794. */
  795. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key);
  796. /**
  797. * Returns whether the surface has a color key.
  798. *
  799. * It is safe to pass a NULL `surface` here; it will return false.
  800. *
  801. * \param surface the SDL_Surface structure to query.
  802. * \returns true if the surface has a color key, false otherwise.
  803. *
  804. * \threadsafety It is safe to call this function from any thread.
  805. *
  806. * \since This function is available since SDL 3.2.0.
  807. *
  808. * \sa SDL_SetSurfaceColorKey
  809. * \sa SDL_GetSurfaceColorKey
  810. */
  811. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  812. /**
  813. * Get the color key (transparent pixel) for a surface.
  814. *
  815. * The color key is a pixel of the format used by the surface, as generated by
  816. * SDL_MapRGB().
  817. *
  818. * If the surface doesn't have color key enabled this function returns false.
  819. *
  820. * \param surface the SDL_Surface structure to query.
  821. * \param key a pointer filled in with the transparent pixel.
  822. * \returns true on success or false on failure; call SDL_GetError() for more
  823. * information.
  824. *
  825. * \threadsafety It is safe to call this function from any thread.
  826. *
  827. * \since This function is available since SDL 3.2.0.
  828. *
  829. * \sa SDL_SetSurfaceColorKey
  830. * \sa SDL_SurfaceHasColorKey
  831. */
  832. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  833. /**
  834. * Set an additional color value multiplied into blit operations.
  835. *
  836. * When this surface is blitted, during the blit operation each source color
  837. * channel is modulated by the appropriate color value according to the
  838. * following formula:
  839. *
  840. * `srcC = srcC * (color / 255)`
  841. *
  842. * \param surface the SDL_Surface structure to update.
  843. * \param r the red color value multiplied into blit operations.
  844. * \param g the green color value multiplied into blit operations.
  845. * \param b the blue color value multiplied into blit operations.
  846. * \returns true on success or false on failure; call SDL_GetError() for more
  847. * information.
  848. *
  849. * \threadsafety This function can be called on different threads with
  850. * different surfaces.
  851. *
  852. * \since This function is available since SDL 3.2.0.
  853. *
  854. * \sa SDL_GetSurfaceColorMod
  855. * \sa SDL_SetSurfaceAlphaMod
  856. */
  857. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  858. /**
  859. * Get the additional color value multiplied into blit operations.
  860. *
  861. * \param surface the SDL_Surface structure to query.
  862. * \param r a pointer filled in with the current red color value.
  863. * \param g a pointer filled in with the current green color value.
  864. * \param b a pointer filled in with the current blue color value.
  865. * \returns true on success or false on failure; call SDL_GetError() for more
  866. * information.
  867. *
  868. * \threadsafety This function can be called on different threads with
  869. * different surfaces.
  870. *
  871. * \since This function is available since SDL 3.2.0.
  872. *
  873. * \sa SDL_GetSurfaceAlphaMod
  874. * \sa SDL_SetSurfaceColorMod
  875. */
  876. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  877. /**
  878. * Set an additional alpha value used in blit operations.
  879. *
  880. * When this surface is blitted, during the blit operation the source alpha
  881. * value is modulated by this alpha value according to the following formula:
  882. *
  883. * `srcA = srcA * (alpha / 255)`
  884. *
  885. * \param surface the SDL_Surface structure to update.
  886. * \param alpha the alpha value multiplied into blit operations.
  887. * \returns true on success or false on failure; call SDL_GetError() for more
  888. * information.
  889. *
  890. * \threadsafety This function can be called on different threads with
  891. * different surfaces.
  892. *
  893. * \since This function is available since SDL 3.2.0.
  894. *
  895. * \sa SDL_GetSurfaceAlphaMod
  896. * \sa SDL_SetSurfaceColorMod
  897. */
  898. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  899. /**
  900. * Get the additional alpha value used in blit operations.
  901. *
  902. * \param surface the SDL_Surface structure to query.
  903. * \param alpha a pointer filled in with the current alpha value.
  904. * \returns true on success or false on failure; call SDL_GetError() for more
  905. * information.
  906. *
  907. * \threadsafety It is safe to call this function from any thread.
  908. *
  909. * \since This function is available since SDL 3.2.0.
  910. *
  911. * \sa SDL_GetSurfaceColorMod
  912. * \sa SDL_SetSurfaceAlphaMod
  913. */
  914. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  915. /**
  916. * Set the blend mode used for blit operations.
  917. *
  918. * To copy a surface to another surface (or texture) without blending with the
  919. * existing data, the blendmode of the SOURCE surface should be set to
  920. * `SDL_BLENDMODE_NONE`.
  921. *
  922. * \param surface the SDL_Surface structure to update.
  923. * \param blendMode the SDL_BlendMode to use for blit blending.
  924. * \returns true on success or false on failure; call SDL_GetError() for more
  925. * information.
  926. *
  927. * \threadsafety This function can be called on different threads with
  928. * different surfaces.
  929. *
  930. * \since This function is available since SDL 3.2.0.
  931. *
  932. * \sa SDL_GetSurfaceBlendMode
  933. */
  934. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  935. /**
  936. * Get the blend mode used for blit operations.
  937. *
  938. * \param surface the SDL_Surface structure to query.
  939. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  940. * \returns true on success or false on failure; call SDL_GetError() for more
  941. * information.
  942. *
  943. * \threadsafety It is safe to call this function from any thread.
  944. *
  945. * \since This function is available since SDL 3.2.0.
  946. *
  947. * \sa SDL_SetSurfaceBlendMode
  948. */
  949. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  950. /**
  951. * Set the clipping rectangle for a surface.
  952. *
  953. * When `surface` is the destination of a blit, only the area within the clip
  954. * rectangle is drawn into.
  955. *
  956. * Note that blits are automatically clipped to the edges of the source and
  957. * destination surfaces.
  958. *
  959. * \param surface the SDL_Surface structure to be clipped.
  960. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  961. * NULL to disable clipping.
  962. * \returns true if the rectangle intersects the surface, otherwise false and
  963. * blits will be completely clipped.
  964. *
  965. * \threadsafety This function can be called on different threads with
  966. * different surfaces.
  967. *
  968. * \since This function is available since SDL 3.2.0.
  969. *
  970. * \sa SDL_GetSurfaceClipRect
  971. */
  972. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  973. /**
  974. * Get the clipping rectangle for a surface.
  975. *
  976. * When `surface` is the destination of a blit, only the area within the clip
  977. * rectangle is drawn into.
  978. *
  979. * \param surface the SDL_Surface structure representing the surface to be
  980. * clipped.
  981. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  982. * the surface.
  983. * \returns true on success or false on failure; call SDL_GetError() for more
  984. * information.
  985. *
  986. * \threadsafety This function can be called on different threads with
  987. * different surfaces.
  988. *
  989. * \since This function is available since SDL 3.2.0.
  990. *
  991. * \sa SDL_SetSurfaceClipRect
  992. */
  993. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  994. /**
  995. * Flip a surface vertically or horizontally.
  996. *
  997. * \param surface the surface to flip.
  998. * \param flip the direction to flip.
  999. * \returns true on success or false on failure; call SDL_GetError() for more
  1000. * 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. extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  1008. /**
  1009. * Return a copy of a surface rotated clockwise a number of degrees.
  1010. *
  1011. * The angle of rotation can be negative for counter-clockwise rotation.
  1012. *
  1013. * When the rotation isn't a multiple of 90 degrees, the resulting surface is
  1014. * larger than the original, with the background filled in with the colorkey,
  1015. * if available, or RGBA 255/255/255/0 if not.
  1016. *
  1017. * If `surface` has the SDL_PROP_SURFACE_ROTATION_FLOAT property set on it,
  1018. * the new copy will have the adjusted value set: if the rotation property is
  1019. * 90 and `angle` was 30, the new surface will have a property value of 60
  1020. * (that is: to be upright vs gravity, this surface needs to rotate 60 more
  1021. * degrees). However, note that further rotations on the new surface in this
  1022. * example will produce unexpected results, since the image will have resized
  1023. * and padded to accommodate the not-90 degree angle.
  1024. *
  1025. * \param surface the surface to rotate.
  1026. * \param angle the rotation angle, in degrees.
  1027. * \returns a rotated copy of the surface or NULL on failure; call
  1028. * SDL_GetError() for more information.
  1029. *
  1030. * \threadsafety This function can be called on different threads with
  1031. * different surfaces.
  1032. *
  1033. * \since This function is available since SDL 3.4.0.
  1034. */
  1035. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RotateSurface(SDL_Surface *surface, float angle);
  1036. /**
  1037. * Creates a new surface identical to the existing surface.
  1038. *
  1039. * If the original surface has alternate images, the new surface will have a
  1040. * reference to them as well.
  1041. *
  1042. * The returned surface should be freed with SDL_DestroySurface().
  1043. *
  1044. * \param surface the surface to duplicate.
  1045. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  1046. * more information.
  1047. *
  1048. * \threadsafety This function can be called on different threads with
  1049. * different surfaces.
  1050. *
  1051. * \since This function is available since SDL 3.2.0.
  1052. *
  1053. * \sa SDL_DestroySurface
  1054. */
  1055. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  1056. /**
  1057. * Creates a new surface identical to the existing surface, scaled to the
  1058. * desired size.
  1059. *
  1060. * The returned surface should be freed with SDL_DestroySurface().
  1061. *
  1062. * \param surface the surface to duplicate and scale.
  1063. * \param width the width of the new surface.
  1064. * \param height the height of the new surface.
  1065. * \param scaleMode the SDL_ScaleMode to be used.
  1066. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  1067. * more information.
  1068. *
  1069. * \threadsafety This function can be called on different threads with
  1070. * different surfaces.
  1071. *
  1072. * \since This function is available since SDL 3.2.0.
  1073. *
  1074. * \sa SDL_DestroySurface
  1075. */
  1076. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode);
  1077. /**
  1078. * Copy an existing surface to a new surface of the specified format.
  1079. *
  1080. * This function is used to optimize images for faster *repeat* blitting. This
  1081. * is accomplished by converting the original and storing the result as a new
  1082. * surface. The new, optimized surface can then be used as the source for
  1083. * future blits, making them faster.
  1084. *
  1085. * If you are converting to an indexed surface and want to map colors to a
  1086. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  1087. *
  1088. * If the original surface has alternate images, the new surface will have a
  1089. * reference to them as well.
  1090. *
  1091. * \param surface the existing SDL_Surface structure to convert.
  1092. * \param format the new pixel format.
  1093. * \returns the new SDL_Surface structure that is created or NULL on failure;
  1094. * call SDL_GetError() for more information.
  1095. *
  1096. * \threadsafety This function can be called on different threads with
  1097. * different surfaces.
  1098. *
  1099. * \since This function is available since SDL 3.2.0.
  1100. *
  1101. * \sa SDL_ConvertSurfaceAndColorspace
  1102. * \sa SDL_DestroySurface
  1103. */
  1104. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  1105. /**
  1106. * Copy an existing surface to a new surface of the specified format and
  1107. * colorspace.
  1108. *
  1109. * This function converts an existing surface to a new format and colorspace
  1110. * and returns the new surface. This will perform any pixel format and
  1111. * colorspace conversion needed.
  1112. *
  1113. * If the original surface has alternate images, the new surface will have a
  1114. * reference to them as well.
  1115. *
  1116. * \param surface the existing SDL_Surface structure to convert.
  1117. * \param format the new pixel format.
  1118. * \param palette an optional palette to use for indexed formats, may be NULL.
  1119. * \param colorspace the new colorspace.
  1120. * \param props an SDL_PropertiesID with additional color properties, or 0.
  1121. * \returns the new SDL_Surface structure that is created or NULL on failure;
  1122. * call SDL_GetError() for more information.
  1123. *
  1124. * \threadsafety This function can be called on different threads with
  1125. * different surfaces.
  1126. *
  1127. * \since This function is available since SDL 3.2.0.
  1128. *
  1129. * \sa SDL_ConvertSurface
  1130. * \sa SDL_DestroySurface
  1131. */
  1132. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  1133. /**
  1134. * Copy a block of pixels of one format to another format.
  1135. *
  1136. * \param width the width of the block to copy, in pixels.
  1137. * \param height the height of the block to copy, in pixels.
  1138. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  1139. * \param src a pointer to the source pixels.
  1140. * \param src_pitch the pitch of the source pixels, in bytes.
  1141. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  1142. * \param dst a pointer to be filled in with new pixel data.
  1143. * \param dst_pitch the pitch of the destination pixels, in bytes.
  1144. * \returns true on success or false on failure; call SDL_GetError() for more
  1145. * information.
  1146. *
  1147. * \threadsafety The same destination pixels should not be used from two
  1148. * threads at once. It is safe to use the same source pixels
  1149. * from multiple threads.
  1150. *
  1151. * \since This function is available since SDL 3.2.0.
  1152. *
  1153. * \sa SDL_ConvertPixelsAndColorspace
  1154. */
  1155. 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);
  1156. /**
  1157. * Copy a block of pixels of one format and colorspace to another format and
  1158. * colorspace.
  1159. *
  1160. * \param width the width of the block to copy, in pixels.
  1161. * \param height the height of the block to copy, in pixels.
  1162. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  1163. * \param src_colorspace an SDL_Colorspace value describing the colorspace of
  1164. * the `src` pixels.
  1165. * \param src_properties an SDL_PropertiesID with additional source color
  1166. * properties, or 0.
  1167. * \param src a pointer to the source pixels.
  1168. * \param src_pitch the pitch of the source pixels, in bytes.
  1169. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  1170. * \param dst_colorspace an SDL_Colorspace value describing the colorspace of
  1171. * the `dst` pixels.
  1172. * \param dst_properties an SDL_PropertiesID with additional destination color
  1173. * properties, or 0.
  1174. * \param dst a pointer to be filled in with new pixel data.
  1175. * \param dst_pitch the pitch of the destination pixels, in bytes.
  1176. * \returns true on success or false on failure; call SDL_GetError() for more
  1177. * information.
  1178. *
  1179. * \threadsafety The same destination pixels should not be used from two
  1180. * threads at once. It is safe to use the same source pixels
  1181. * from multiple threads.
  1182. *
  1183. * \since This function is available since SDL 3.2.0.
  1184. *
  1185. * \sa SDL_ConvertPixels
  1186. */
  1187. 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);
  1188. /**
  1189. * Premultiply the alpha on a block of pixels.
  1190. *
  1191. * This is safe to use with src == dst, but not for other overlapping areas.
  1192. *
  1193. * \param width the width of the block to convert, in pixels.
  1194. * \param height the height of the block to convert, in pixels.
  1195. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  1196. * \param src a pointer to the source pixels.
  1197. * \param src_pitch the pitch of the source pixels, in bytes.
  1198. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  1199. * \param dst a pointer to be filled in with premultiplied pixel data.
  1200. * \param dst_pitch the pitch of the destination pixels, in bytes.
  1201. * \param linear true to convert from sRGB to linear space for the alpha
  1202. * multiplication, false to do multiplication in sRGB space.
  1203. * \returns true on success or false on failure; call SDL_GetError() for more
  1204. * information.
  1205. *
  1206. * \threadsafety The same destination pixels should not be used from two
  1207. * threads at once. It is safe to use the same source pixels
  1208. * from multiple threads.
  1209. *
  1210. * \since This function is available since SDL 3.2.0.
  1211. */
  1212. 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);
  1213. /**
  1214. * Premultiply the alpha in a surface.
  1215. *
  1216. * This is safe to use with src == dst, but not for other overlapping areas.
  1217. *
  1218. * \param surface the surface to modify.
  1219. * \param linear true to convert from sRGB to linear space for the alpha
  1220. * multiplication, false to do multiplication in sRGB space.
  1221. * \returns true on success or false on failure; call SDL_GetError() for more
  1222. * information.
  1223. *
  1224. * \threadsafety This function can be called on different threads with
  1225. * different surfaces.
  1226. *
  1227. * \since This function is available since SDL 3.2.0.
  1228. */
  1229. extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, bool linear);
  1230. /**
  1231. * Clear a surface with a specific color, with floating point precision.
  1232. *
  1233. * This function handles all surface formats, and ignores any clip rectangle.
  1234. *
  1235. * If the surface is YUV, the color is assumed to be in the sRGB colorspace,
  1236. * otherwise the color is assumed to be in the colorspace of the surface.
  1237. *
  1238. * \param surface the SDL_Surface to clear.
  1239. * \param r the red component of the pixel, normally in the range 0-1.
  1240. * \param g the green component of the pixel, normally in the range 0-1.
  1241. * \param b the blue component of the pixel, normally in the range 0-1.
  1242. * \param a the alpha component of the pixel, normally in the range 0-1.
  1243. * \returns true on success or false on failure; call SDL_GetError() for more
  1244. * information.
  1245. *
  1246. * \threadsafety This function can be called on different threads with
  1247. * different surfaces.
  1248. *
  1249. * \since This function is available since SDL 3.2.0.
  1250. */
  1251. extern SDL_DECLSPEC bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a);
  1252. /**
  1253. * Perform a fast fill of a rectangle with a specific color.
  1254. *
  1255. * `color` should be a pixel of the format used by the surface, and can be
  1256. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  1257. * alpha component then the destination is simply filled with that alpha
  1258. * information, no blending takes place.
  1259. *
  1260. * If there is a clip rectangle set on the destination (set via
  1261. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  1262. * intersection of the clip rectangle and `rect`.
  1263. *
  1264. * \param dst the SDL_Surface structure that is the drawing target.
  1265. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  1266. * NULL to fill the entire surface.
  1267. * \param color the color to fill with.
  1268. * \returns true on success or false on failure; call SDL_GetError() for more
  1269. * information.
  1270. *
  1271. * \threadsafety This function can be called on different threads with
  1272. * different surfaces.
  1273. *
  1274. * \since This function is available since SDL 3.2.0.
  1275. *
  1276. * \sa SDL_FillSurfaceRects
  1277. */
  1278. extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  1279. /**
  1280. * Perform a fast fill of a set of rectangles with a specific color.
  1281. *
  1282. * `color` should be a pixel of the format used by the surface, and can be
  1283. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  1284. * alpha component then the destination is simply filled with that alpha
  1285. * information, no blending takes place.
  1286. *
  1287. * If there is a clip rectangle set on the destination (set via
  1288. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  1289. * intersection of the clip rectangle and `rect`.
  1290. *
  1291. * \param dst the SDL_Surface structure that is the drawing target.
  1292. * \param rects an array of SDL_Rects representing the rectangles to fill.
  1293. * \param count the number of rectangles in the array.
  1294. * \param color the color to fill with.
  1295. * \returns true on success or false on failure; call SDL_GetError() for more
  1296. * information.
  1297. *
  1298. * \threadsafety This function can be called on different threads with
  1299. * different surfaces.
  1300. *
  1301. * \since This function is available since SDL 3.2.0.
  1302. *
  1303. * \sa SDL_FillSurfaceRect
  1304. */
  1305. extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  1306. /**
  1307. * Performs a fast blit from the source surface to the destination surface
  1308. * with clipping.
  1309. *
  1310. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  1311. * `dst`) is copied while ensuring clipping to `dst->clip_rect`.
  1312. *
  1313. * The blit function should not be called on a locked surface.
  1314. *
  1315. * The blit semantics for surfaces with and without blending and colorkey are
  1316. * defined as follows:
  1317. *
  1318. * ```
  1319. * RGBA->RGB:
  1320. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1321. * alpha-blend (using the source alpha-channel and per-surface alpha)
  1322. * SDL_SRCCOLORKEY ignored.
  1323. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1324. * copy RGB.
  1325. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1326. * RGB values of the source color key, ignoring alpha in the
  1327. * comparison.
  1328. *
  1329. * RGB->RGBA:
  1330. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1331. * alpha-blend (using the source per-surface alpha)
  1332. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1333. * copy RGB, set destination alpha to source per-surface alpha value.
  1334. * both:
  1335. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1336. * source color key.
  1337. *
  1338. * RGBA->RGBA:
  1339. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1340. * alpha-blend (using the source alpha-channel and per-surface alpha)
  1341. * SDL_SRCCOLORKEY ignored.
  1342. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1343. * copy all of RGBA to the destination.
  1344. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1345. * RGB values of the source color key, ignoring alpha in the
  1346. * comparison.
  1347. *
  1348. * RGB->RGB:
  1349. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1350. * alpha-blend (using the source per-surface alpha)
  1351. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1352. * copy RGB.
  1353. * both:
  1354. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1355. * source color key.
  1356. * ```
  1357. *
  1358. * \param src the SDL_Surface structure to be copied from.
  1359. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1360. * copied, or NULL to copy the entire surface.
  1361. * \param dst the SDL_Surface structure that is the blit target.
  1362. * \param dstrect the SDL_Rect structure representing the x and y position in
  1363. * the destination surface, or NULL for (0,0). The width and
  1364. * height are ignored, and are copied from `srcrect`. If you
  1365. * want a specific width and height, you should use
  1366. * SDL_BlitSurfaceScaled().
  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_BlitSurfaceScaled
  1376. */
  1377. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1378. /**
  1379. * Perform low-level surface blitting only.
  1380. *
  1381. * This is a semi-private blit function and it performs low-level surface
  1382. * blitting, 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. * \returns true on success or false on failure; call SDL_GetError() for more
  1391. * information.
  1392. *
  1393. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1394. * at any given time.
  1395. *
  1396. * \since This function is available since SDL 3.2.0.
  1397. *
  1398. * \sa SDL_BlitSurface
  1399. */
  1400. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1401. /**
  1402. * Perform a scaled blit to a destination surface, which may be of a different
  1403. * format.
  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.2.0.
  1420. *
  1421. * \sa SDL_BlitSurface
  1422. */
  1423. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1424. /**
  1425. * Perform low-level surface scaled blitting only.
  1426. *
  1427. * This is a semi-private function and it performs low-level surface blitting,
  1428. * assuming the input rectangles have already been clipped.
  1429. *
  1430. * \param src the SDL_Surface structure to be copied from.
  1431. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1432. * copied, may not be NULL.
  1433. * \param dst the SDL_Surface structure that is the blit target.
  1434. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1435. * the destination surface, may not be NULL.
  1436. * \param scaleMode the SDL_ScaleMode to be used.
  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_BlitSurfaceScaled
  1446. */
  1447. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1448. /**
  1449. * Perform a stretched pixel copy from one surface to another.
  1450. *
  1451. * \param src the SDL_Surface structure to be copied from.
  1452. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1453. * copied, or NULL to copy the entire surface.
  1454. * \param dst the SDL_Surface structure that is the blit target.
  1455. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1456. * the destination surface, or NULL to fill the entire
  1457. * destination surface.
  1458. * \param scaleMode the SDL_ScaleMode to be used.
  1459. * \returns true on success or false on failure; call SDL_GetError() for more
  1460. * information.
  1461. *
  1462. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1463. * at any given time.
  1464. *
  1465. * \since This function is available since SDL 3.4.0.
  1466. *
  1467. * \sa SDL_BlitSurfaceScaled
  1468. */
  1469. extern SDL_DECLSPEC bool SDLCALL SDL_StretchSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1470. /**
  1471. * Perform a tiled blit to a destination surface, which may be of a different
  1472. * format.
  1473. *
  1474. * The pixels in `srcrect` will be repeated as many times as needed to
  1475. * completely fill `dstrect`.
  1476. *
  1477. * \param src the SDL_Surface structure to be copied from.
  1478. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1479. * copied, or NULL to copy the entire surface.
  1480. * \param dst the SDL_Surface structure that is the blit target.
  1481. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1482. * the destination surface, or NULL to fill the entire surface.
  1483. * \returns true on success or false on failure; call SDL_GetError() for more
  1484. * information.
  1485. *
  1486. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1487. * at any given time.
  1488. *
  1489. * \since This function is available since SDL 3.2.0.
  1490. *
  1491. * \sa SDL_BlitSurface
  1492. */
  1493. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1494. /**
  1495. * Perform a scaled and tiled blit to a destination surface, which may be of a
  1496. * different format.
  1497. *
  1498. * The pixels in `srcrect` will be scaled and repeated as many times as needed
  1499. * to completely fill `dstrect`.
  1500. *
  1501. * \param src the SDL_Surface structure to be copied from.
  1502. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1503. * copied, or NULL to copy the entire surface.
  1504. * \param scale the scale used to transform srcrect into the destination
  1505. * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
  1506. * 64x64 tiles.
  1507. * \param scaleMode scale algorithm to be used.
  1508. * \param dst the SDL_Surface structure that is the blit target.
  1509. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1510. * the destination surface, or NULL to fill the entire surface.
  1511. * \returns true on success or false on failure; call SDL_GetError() for more
  1512. * information.
  1513. *
  1514. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1515. * at any given time.
  1516. *
  1517. * \since This function is available since SDL 3.2.0.
  1518. *
  1519. * \sa SDL_BlitSurface
  1520. */
  1521. 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);
  1522. /**
  1523. * Perform a scaled blit using the 9-grid algorithm to a destination surface,
  1524. * which may be of a different format.
  1525. *
  1526. * The pixels in the source surface are split into a 3x3 grid, using the
  1527. * different corner sizes for each corner, and the sides and center making up
  1528. * the remaining pixels. The corners are then scaled using `scale` and fit
  1529. * into the corners of the destination rectangle. The sides and center are
  1530. * then stretched into place to cover the remaining destination rectangle.
  1531. *
  1532. * \param src the SDL_Surface structure to be copied from.
  1533. * \param srcrect the SDL_Rect structure representing the rectangle to be used
  1534. * for the 9-grid, or NULL to use the entire surface.
  1535. * \param left_width the width, in pixels, of the left corners in `srcrect`.
  1536. * \param right_width the width, in pixels, of the right corners in `srcrect`.
  1537. * \param top_height the height, in pixels, of the top corners in `srcrect`.
  1538. * \param bottom_height the height, in pixels, of the bottom corners in
  1539. * `srcrect`.
  1540. * \param scale the scale used to transform the corner of `srcrect` into the
  1541. * corner of `dstrect`, or 0.0f for an unscaled blit.
  1542. * \param scaleMode scale algorithm to be used.
  1543. * \param dst the SDL_Surface structure that is the blit target.
  1544. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1545. * the destination surface, or NULL to fill the entire surface.
  1546. * \returns true on success or false on failure; call SDL_GetError() for more
  1547. * information.
  1548. *
  1549. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1550. * at any given time.
  1551. *
  1552. * \since This function is available since SDL 3.2.0.
  1553. *
  1554. * \sa SDL_BlitSurface
  1555. */
  1556. 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);
  1557. /**
  1558. * Map an RGB triple to an opaque pixel value for a surface.
  1559. *
  1560. * This function maps the RGB color value to the specified pixel format and
  1561. * returns the pixel value best approximating the given RGB color value for
  1562. * the given pixel format.
  1563. *
  1564. * If the surface has a palette, the index of the closest matching color in
  1565. * the palette will be returned.
  1566. *
  1567. * If the surface pixel format has an alpha component it will be returned as
  1568. * all 1 bits (fully opaque).
  1569. *
  1570. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1571. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1572. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1573. * for an 8-bpp format).
  1574. *
  1575. * \param surface the surface to use for the pixel format and palette.
  1576. * \param r the red component of the pixel in the range 0-255.
  1577. * \param g the green component of the pixel in the range 0-255.
  1578. * \param b the blue component of the pixel in the range 0-255.
  1579. * \returns a pixel value.
  1580. *
  1581. * \threadsafety This function can be called on different threads with
  1582. * different surfaces.
  1583. *
  1584. * \since This function is available since SDL 3.2.0.
  1585. *
  1586. * \sa SDL_MapSurfaceRGBA
  1587. */
  1588. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  1589. /**
  1590. * Map an RGBA quadruple to a pixel value for a surface.
  1591. *
  1592. * This function maps the RGBA color value to the specified pixel format and
  1593. * returns the pixel value best approximating the given RGBA color value for
  1594. * the given pixel format.
  1595. *
  1596. * If the surface pixel format has no alpha component the alpha value will be
  1597. * ignored (as it will be in formats with a palette).
  1598. *
  1599. * If the surface has a palette, the index of the closest matching color in
  1600. * the palette will be returned.
  1601. *
  1602. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1603. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1604. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1605. * for an 8-bpp format).
  1606. *
  1607. * \param surface the surface to use for the pixel format and palette.
  1608. * \param r the red component of the pixel in the range 0-255.
  1609. * \param g the green component of the pixel in the range 0-255.
  1610. * \param b the blue component of the pixel in the range 0-255.
  1611. * \param a the alpha component of the pixel in the range 0-255.
  1612. * \returns a pixel value.
  1613. *
  1614. * \threadsafety This function can be called on different threads with
  1615. * different surfaces.
  1616. *
  1617. * \since This function is available since SDL 3.2.0.
  1618. *
  1619. * \sa SDL_MapSurfaceRGB
  1620. */
  1621. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1622. /**
  1623. * Retrieves a single pixel from a surface.
  1624. *
  1625. * This function prioritizes correctness over speed: it is suitable for unit
  1626. * tests, but is not intended for use in a game engine.
  1627. *
  1628. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1629. * components from pixel formats with less than 8 bits per RGB component.
  1630. *
  1631. * \param surface the surface to read.
  1632. * \param x the horizontal coordinate, 0 <= x < width.
  1633. * \param y the vertical coordinate, 0 <= y < height.
  1634. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1635. * this channel.
  1636. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1637. * ignore this channel.
  1638. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1639. * ignore this channel.
  1640. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1641. * ignore this channel.
  1642. * \returns true on success or false on failure; call SDL_GetError() for more
  1643. * information.
  1644. *
  1645. * \threadsafety This function can be called on different threads with
  1646. * different surfaces.
  1647. *
  1648. * \since This function is available since SDL 3.2.0.
  1649. */
  1650. extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1651. /**
  1652. * Retrieves a single pixel from a surface.
  1653. *
  1654. * This function prioritizes correctness over speed: it is suitable for unit
  1655. * tests, but is not intended for use in a game engine.
  1656. *
  1657. * \param surface the surface to read.
  1658. * \param x the horizontal coordinate, 0 <= x < width.
  1659. * \param y the vertical coordinate, 0 <= y < height.
  1660. * \param r a pointer filled in with the red channel, normally in the range
  1661. * 0-1, or NULL to ignore this channel.
  1662. * \param g a pointer filled in with the green channel, normally in the range
  1663. * 0-1, or NULL to ignore this channel.
  1664. * \param b a pointer filled in with the blue channel, normally in the range
  1665. * 0-1, or NULL to ignore this channel.
  1666. * \param a a pointer filled in with the alpha channel, normally in the range
  1667. * 0-1, or NULL to ignore this channel.
  1668. * \returns true on success or false on failure; call SDL_GetError() for more
  1669. * information.
  1670. *
  1671. * \threadsafety This function can be called on different threads with
  1672. * different surfaces.
  1673. *
  1674. * \since This function is available since SDL 3.2.0.
  1675. */
  1676. extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a);
  1677. /**
  1678. * Writes a single pixel to a surface.
  1679. *
  1680. * This function prioritizes correctness over speed: it is suitable for unit
  1681. * tests, but is not intended for use in a game engine.
  1682. *
  1683. * Like SDL_MapRGBA, this uses the entire 0..255 range when converting color
  1684. * components from pixel formats with less than 8 bits per RGB component.
  1685. *
  1686. * \param surface the surface to write.
  1687. * \param x the horizontal coordinate, 0 <= x < width.
  1688. * \param y the vertical coordinate, 0 <= y < height.
  1689. * \param r the red channel value, 0-255.
  1690. * \param g the green channel value, 0-255.
  1691. * \param b the blue channel value, 0-255.
  1692. * \param a the alpha channel value, 0-255.
  1693. * \returns true on success or false on failure; call SDL_GetError() for more
  1694. * information.
  1695. *
  1696. * \threadsafety This function can be called on different threads with
  1697. * different surfaces.
  1698. *
  1699. * \since This function is available since SDL 3.2.0.
  1700. */
  1701. extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1702. /**
  1703. * Writes a single pixel to a surface.
  1704. *
  1705. * This function prioritizes correctness over speed: it is suitable for unit
  1706. * tests, but is not intended for use in a game engine.
  1707. *
  1708. * \param surface the surface to write.
  1709. * \param x the horizontal coordinate, 0 <= x < width.
  1710. * \param y the vertical coordinate, 0 <= y < height.
  1711. * \param r the red channel value, normally in the range 0-1.
  1712. * \param g the green channel value, normally in the range 0-1.
  1713. * \param b the blue channel value, normally in the range 0-1.
  1714. * \param a the alpha channel value, normally in the range 0-1.
  1715. * \returns true on success or false on failure; call SDL_GetError() for more
  1716. * information.
  1717. *
  1718. * \threadsafety This function can be called on different threads with
  1719. * different surfaces.
  1720. *
  1721. * \since This function is available since SDL 3.2.0.
  1722. */
  1723. extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a);
  1724. /* Ends C function definitions when using C++ */
  1725. #ifdef __cplusplus
  1726. }
  1727. #endif
  1728. #include <SDL3/SDL_close_code.h>
  1729. #endif /* SDL_surface_h_ */