SDL_surface.h 67 KB

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