SDL_surface.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategorySurface
  20. *
  21. * SDL_Surface definition and management functions.
  22. */
  23. #ifndef SDL_surface_h_
  24. #define SDL_surface_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_blendmode.h>
  28. #include <SDL3/SDL_pixels.h>
  29. #include <SDL3/SDL_properties.h>
  30. #include <SDL3/SDL_rect.h>
  31. #include <SDL3/SDL_iostream.h>
  32. #include <SDL3/SDL_begin_code.h>
  33. /* Set up for C function definitions, even when using C++ */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * The flags on an SDL_Surface.
  39. *
  40. * These are generally considered read-only.
  41. *
  42. * \since This datatype is available since SDL 3.0.0.
  43. */
  44. typedef Uint32 SDL_SurfaceFlags;
  45. #define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */
  46. #define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */
  47. #define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */
  48. #define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */
  49. /**
  50. * Evaluates to true if the surface needs to be locked before access.
  51. *
  52. * \since This macro is available since SDL 3.0.0.
  53. */
  54. #define SDL_MUSTLOCK(S) (((S)->flags & (SDL_SURFACE_LOCK_NEEDED | SDL_SURFACE_LOCKED)) == SDL_SURFACE_LOCK_NEEDED)
  55. /**
  56. * The scaling mode.
  57. *
  58. * \since This enum is available since SDL 3.0.0.
  59. */
  60. typedef enum SDL_ScaleMode
  61. {
  62. SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
  63. SDL_SCALEMODE_LINEAR, /**< linear filtering */
  64. SDL_SCALEMODE_BEST /**< anisotropic filtering */
  65. } SDL_ScaleMode;
  66. /**
  67. * The flip mode.
  68. *
  69. * \since This enum is available since SDL 3.0.0.
  70. */
  71. typedef enum SDL_FlipMode
  72. {
  73. SDL_FLIP_NONE, /**< Do not flip */
  74. SDL_FLIP_HORIZONTAL, /**< flip horizontally */
  75. SDL_FLIP_VERTICAL /**< flip vertically */
  76. } SDL_FlipMode;
  77. /* Internal surface data */
  78. typedef struct SDL_SurfaceData SDL_SurfaceData;
  79. /**
  80. * A collection of pixels used in software blitting.
  81. *
  82. * Pixels are arranged in memory in rows, with the top row first. Each row
  83. * occupies an amount of memory given by the pitch (sometimes known as the row
  84. * stride in non-SDL APIs).
  85. *
  86. * Within each row, pixels are arranged from left to right until the width is
  87. * reached. Each pixel occupies a number of bits appropriate for its format,
  88. * with most formats representing each pixel as one or more whole bytes (in
  89. * some indexed formats, instead multiple pixels are packed into each byte),
  90. * and a byte order given by the format. After encoding all pixels, any
  91. * remaining bytes to reach the pitch are used as padding to reach a desired
  92. * alignment, and have undefined contents.
  93. *
  94. * \since This struct is available since SDL 3.0.0.
  95. */
  96. typedef struct SDL_Surface
  97. {
  98. SDL_SurfaceFlags flags; /**< Read-only */
  99. SDL_PixelFormat format; /**< Read-only */
  100. int w, h; /**< Read-only */
  101. int pitch; /**< Read-only */
  102. void *pixels; /**< Read-only pointer, writable pixels if non-NULL */
  103. int refcount; /**< Application reference count, used when freeing surface */
  104. SDL_SurfaceData *internal; /**< Private */
  105. } SDL_Surface;
  106. /**
  107. * Allocate a new surface with a specific pixel format.
  108. *
  109. * \param width the width of the surface.
  110. * \param height the height of the surface.
  111. * \param format the SDL_PixelFormat for the new surface's pixel format.
  112. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  113. * call SDL_GetError() for more information.
  114. *
  115. * \since This function is available since SDL 3.0.0.
  116. *
  117. * \sa SDL_CreateSurfaceFrom
  118. * \sa SDL_DestroySurface
  119. */
  120. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
  121. /**
  122. * Allocate a new surface with a specific pixel format and existing pixel
  123. * data.
  124. *
  125. * No copy is made of the pixel data. Pixel data is not managed automatically;
  126. * you must free the surface before you free the pixel data.
  127. *
  128. * Pitch is the offset in bytes from one row of pixels to the next, e.g.
  129. * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
  130. *
  131. * You may pass NULL for pixels and 0 for pitch to create a surface that you
  132. * will fill in with valid values later.
  133. *
  134. * \param width the width of the surface.
  135. * \param height the height of the surface.
  136. * \param format the SDL_PixelFormat for the new surface's pixel format.
  137. * \param pixels a pointer to existing pixel data.
  138. * \param pitch the number of bytes between each row, including padding.
  139. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  140. * call SDL_GetError() for more information.
  141. *
  142. * \since This function is available since SDL 3.0.0.
  143. *
  144. * \sa SDL_CreateSurface
  145. * \sa SDL_DestroySurface
  146. */
  147. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
  148. /**
  149. * Free a surface.
  150. *
  151. * It is safe to pass NULL to this function.
  152. *
  153. * \param surface the SDL_Surface to free.
  154. *
  155. * \since This function is available since SDL 3.0.0.
  156. *
  157. * \sa SDL_CreateStackSurface
  158. * \sa SDL_CreateSurface
  159. * \sa SDL_CreateSurfaceFrom
  160. */
  161. extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
  162. /**
  163. * Get the properties associated with a surface.
  164. *
  165. * The following properties are understood by SDL:
  166. *
  167. * - `SDL_PROP_SURFACE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
  168. * the surface colorspace, defaults to SDL_COLORSPACE_SRGB_LINEAR for
  169. * floating point formats, SDL_COLORSPACE_HDR10 for 10-bit formats,
  170. * SDL_COLORSPACE_SRGB for other RGB surfaces and SDL_COLORSPACE_BT709_FULL
  171. * for YUV surfaces.
  172. * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  173. * surfaces, this defines the value of 100% diffuse white, with higher
  174. * values being displayed in the High Dynamic Range headroom. This defaults
  175. * to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
  176. * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
  177. * surfaces, this defines the maximum dynamic range used by the content, in
  178. * terms of the SDR white point. This defaults to 0.0, which disables tone
  179. * mapping.
  180. * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
  181. * used when compressing from a surface with high dynamic range to another
  182. * with lower dynamic range. Currently this supports "chrome", which uses
  183. * the same tone mapping that Chrome uses for HDR content, the form "*=N",
  184. * where N is a floating point scale factor applied in linear space, and
  185. * "none", which disables tone mapping. This defaults to "chrome".
  186. *
  187. * \param surface the SDL_Surface structure to query.
  188. * \returns a valid property ID on success or 0 on failure; call
  189. * SDL_GetError() for more information.
  190. *
  191. * \since This function is available since SDL 3.0.0.
  192. */
  193. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
  194. #define SDL_PROP_SURFACE_COLORSPACE_NUMBER "SDL.surface.colorspace"
  195. #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
  196. #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
  197. #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
  198. /**
  199. * Set the colorspace used by a surface.
  200. *
  201. * Setting the colorspace doesn't change the pixels, only how they are
  202. * interpreted in color operations.
  203. *
  204. * \param surface the SDL_Surface structure to update.
  205. * \param colorspace an SDL_ColorSpace value describing the surface
  206. * colorspace.
  207. * \returns 0 on success or a negative error code on failure; call
  208. * SDL_GetError() for more information.
  209. *
  210. * \since This function is available since SDL 3.0.0.
  211. *
  212. * \sa SDL_GetSurfaceColorspace
  213. */
  214. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
  215. /**
  216. * Get the colorspace used by a surface.
  217. *
  218. * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
  219. * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
  220. * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
  221. *
  222. * \param surface the SDL_Surface structure to query.
  223. * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
  224. * the surface is NULL.
  225. *
  226. * \since This function is available since SDL 3.0.0.
  227. *
  228. * \sa SDL_SetSurfaceColorspace
  229. */
  230. extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
  231. /**
  232. * Set the palette used by a surface.
  233. *
  234. * A single palette can be shared with many surfaces.
  235. *
  236. * \param surface the SDL_Surface structure to update.
  237. * \param palette the SDL_Palette structure to use.
  238. * \returns 0 on success or a negative error code on failure; call
  239. * SDL_GetError() for more information.
  240. *
  241. * \since This function is available since SDL 3.0.0.
  242. *
  243. * \sa SDL_CreatePalette
  244. * \sa SDL_GetSurfacePalette
  245. */
  246. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  247. /**
  248. * Get the palette used by a surface.
  249. *
  250. * \param surface the SDL_Surface structure to query.
  251. * \returns a pointer to the palette used by the surface, or NULL if there is
  252. * no palette used.
  253. *
  254. * \since This function is available since SDL 3.0.0.
  255. *
  256. * \sa SDL_SetSurfacePalette
  257. */
  258. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
  259. /**
  260. * Set up a surface for directly accessing the pixels.
  261. *
  262. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  263. * and read from `surface->pixels`, using the pixel format stored in
  264. * `surface->format`. Once you are done accessing the surface, you should use
  265. * SDL_UnlockSurface() to release it.
  266. *
  267. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  268. * 0, then you can read and write to the surface at any time, and the pixel
  269. * format of the surface will not change.
  270. *
  271. * \param surface the SDL_Surface structure to be locked.
  272. * \returns 0 on success or a negative error code on failure; call
  273. * SDL_GetError() for more information.
  274. *
  275. * \since This function is available since SDL 3.0.0.
  276. *
  277. * \sa SDL_MUSTLOCK
  278. * \sa SDL_UnlockSurface
  279. */
  280. extern SDL_DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
  281. /**
  282. * Release a surface after directly accessing the pixels.
  283. *
  284. * \param surface the SDL_Surface structure to be unlocked.
  285. *
  286. * \since This function is available since SDL 3.0.0.
  287. *
  288. * \sa SDL_LockSurface
  289. */
  290. extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  291. /**
  292. * Load a BMP image from a seekable SDL data stream.
  293. *
  294. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  295. * will result in a memory leak.
  296. *
  297. * \param src the data stream for the surface.
  298. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  299. * even in the case of an error.
  300. * \returns a pointer to a new SDL_Surface structure or NULL if there was an
  301. * error; call SDL_GetError() for more information.
  302. *
  303. * \since This function is available since SDL 3.0.0.
  304. *
  305. * \sa SDL_DestroySurface
  306. * \sa SDL_LoadBMP
  307. * \sa SDL_SaveBMP_IO
  308. */
  309. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio);
  310. /**
  311. * Load a BMP image from a file.
  312. *
  313. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  314. * will result in a memory leak.
  315. *
  316. * \param file the BMP file to load.
  317. * \returns a pointer to a new SDL_Surface structure or NULL if there was an
  318. * error; call SDL_GetError() for more information.
  319. *
  320. * \since This function is available since SDL 3.0.0.
  321. *
  322. * \sa SDL_DestroySurface
  323. * \sa SDL_LoadBMP_IO
  324. * \sa SDL_SaveBMP
  325. */
  326. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
  327. /**
  328. * Save a surface to a seekable SDL data stream in BMP format.
  329. *
  330. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  331. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  332. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  333. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  334. * not supported.
  335. *
  336. * \param surface the SDL_Surface structure containing the image to be saved.
  337. * \param dst a data stream to save to.
  338. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `dst` before returning,
  339. * even in the case of an error.
  340. * \returns 0 on success or a negative error code on failure; call
  341. * SDL_GetError() for more information.
  342. *
  343. * \since This function is available since SDL 3.0.0.
  344. *
  345. * \sa SDL_LoadBMP_IO
  346. * \sa SDL_SaveBMP
  347. */
  348. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio);
  349. /**
  350. * Save a surface to a file.
  351. *
  352. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  353. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  354. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  355. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  356. * not supported.
  357. *
  358. * \param surface the SDL_Surface structure containing the image to be saved.
  359. * \param file a file to save to.
  360. * \returns 0 on success or a negative error code on failure; call
  361. * SDL_GetError() for more information.
  362. *
  363. * \since This function is available since SDL 3.0.0.
  364. *
  365. * \sa SDL_LoadBMP
  366. * \sa SDL_SaveBMP_IO
  367. */
  368. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  369. /**
  370. * Set the RLE acceleration hint for a surface.
  371. *
  372. * If RLE is enabled, color key and alpha blending blits are much faster, but
  373. * the surface must be locked before directly accessing the pixels.
  374. *
  375. * \param surface the SDL_Surface structure to optimize.
  376. * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable
  377. * it.
  378. * \returns 0 on success or a negative error code on failure; call
  379. * SDL_GetError() for more information.
  380. *
  381. * \since This function is available since SDL 3.0.0.
  382. *
  383. * \sa SDL_BlitSurface
  384. * \sa SDL_LockSurface
  385. * \sa SDL_UnlockSurface
  386. */
  387. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled);
  388. /**
  389. * Returns whether the surface is RLE enabled.
  390. *
  391. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  392. *
  393. * \param surface the SDL_Surface structure to query.
  394. * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
  395. *
  396. * \since This function is available since SDL 3.0.0.
  397. *
  398. * \sa SDL_SetSurfaceRLE
  399. */
  400. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  401. /**
  402. * Set the color key (transparent pixel) in a surface.
  403. *
  404. * The color key defines a pixel value that will be treated as transparent in
  405. * a blit. For example, one can use this to specify that cyan pixels should be
  406. * considered transparent, and therefore not rendered.
  407. *
  408. * It is a pixel of the format used by the surface, as generated by
  409. * SDL_MapRGB().
  410. *
  411. * \param surface the SDL_Surface structure to update.
  412. * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color
  413. * key.
  414. * \param key the transparent pixel.
  415. * \returns 0 on success or a negative error code on failure; call
  416. * SDL_GetError() for more information.
  417. *
  418. * \since This function is available since SDL 3.0.0.
  419. *
  420. * \sa SDL_GetSurfaceColorKey
  421. * \sa SDL_SetSurfaceRLE
  422. * \sa SDL_SurfaceHasColorKey
  423. */
  424. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key);
  425. /**
  426. * Returns whether the surface has a color key.
  427. *
  428. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  429. *
  430. * \param surface the SDL_Surface structure to query.
  431. * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
  432. *
  433. * \since This function is available since SDL 3.0.0.
  434. *
  435. * \sa SDL_SetSurfaceColorKey
  436. * \sa SDL_GetSurfaceColorKey
  437. */
  438. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  439. /**
  440. * Get the color key (transparent pixel) for a surface.
  441. *
  442. * The color key is a pixel of the format used by the surface, as generated by
  443. * SDL_MapRGB().
  444. *
  445. * If the surface doesn't have color key enabled this function returns -1.
  446. *
  447. * \param surface the SDL_Surface structure to query.
  448. * \param key a pointer filled in with the transparent pixel.
  449. * \returns 0 on success or a negative error code on failure; call
  450. * SDL_GetError() for more information.
  451. *
  452. * \since This function is available since SDL 3.0.0.
  453. *
  454. * \sa SDL_SetSurfaceColorKey
  455. * \sa SDL_SurfaceHasColorKey
  456. */
  457. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  458. /**
  459. * Set an additional color value multiplied into blit operations.
  460. *
  461. * When this surface is blitted, during the blit operation each source color
  462. * channel is modulated by the appropriate color value according to the
  463. * following formula:
  464. *
  465. * `srcC = srcC * (color / 255)`
  466. *
  467. * \param surface the SDL_Surface structure to update.
  468. * \param r the red color value multiplied into blit operations.
  469. * \param g the green color value multiplied into blit operations.
  470. * \param b the blue color value multiplied into blit operations.
  471. * \returns 0 on success or a negative error code on failure; call
  472. * SDL_GetError() for more information.
  473. *
  474. * \since This function is available since SDL 3.0.0.
  475. *
  476. * \sa SDL_GetSurfaceColorMod
  477. * \sa SDL_SetSurfaceAlphaMod
  478. */
  479. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  480. /**
  481. * Get the additional color value multiplied into blit operations.
  482. *
  483. * \param surface the SDL_Surface structure to query.
  484. * \param r a pointer filled in with the current red color value.
  485. * \param g a pointer filled in with the current green color value.
  486. * \param b a pointer filled in with the current blue color value.
  487. * \returns 0 on success or a negative error code on failure; call
  488. * SDL_GetError() for more information.
  489. *
  490. * \since This function is available since SDL 3.0.0.
  491. *
  492. * \sa SDL_GetSurfaceAlphaMod
  493. * \sa SDL_SetSurfaceColorMod
  494. */
  495. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  496. /**
  497. * Set an additional alpha value used in blit operations.
  498. *
  499. * When this surface is blitted, during the blit operation the source alpha
  500. * value is modulated by this alpha value according to the following formula:
  501. *
  502. * `srcA = srcA * (alpha / 255)`
  503. *
  504. * \param surface the SDL_Surface structure to update.
  505. * \param alpha the alpha value multiplied into blit operations.
  506. * \returns 0 on success or a negative error code on failure; call
  507. * SDL_GetError() for more information.
  508. *
  509. * \since This function is available since SDL 3.0.0.
  510. *
  511. * \sa SDL_GetSurfaceAlphaMod
  512. * \sa SDL_SetSurfaceColorMod
  513. */
  514. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  515. /**
  516. * Get the additional alpha value used in blit operations.
  517. *
  518. * \param surface the SDL_Surface structure to query.
  519. * \param alpha a pointer filled in with the current alpha value.
  520. * \returns 0 on success or a negative error code on failure; call
  521. * SDL_GetError() for more information.
  522. *
  523. * \since This function is available since SDL 3.0.0.
  524. *
  525. * \sa SDL_GetSurfaceColorMod
  526. * \sa SDL_SetSurfaceAlphaMod
  527. */
  528. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  529. /**
  530. * Set the blend mode used for blit operations.
  531. *
  532. * To copy a surface to another surface (or texture) without blending with the
  533. * existing data, the blendmode of the SOURCE surface should be set to
  534. * `SDL_BLENDMODE_NONE`.
  535. *
  536. * \param surface the SDL_Surface structure to update.
  537. * \param blendMode the SDL_BlendMode to use for blit blending.
  538. * \returns 0 on success or a negative error code on failure; call
  539. * SDL_GetError() for more information.
  540. *
  541. * \since This function is available since SDL 3.0.0.
  542. *
  543. * \sa SDL_GetSurfaceBlendMode
  544. */
  545. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  546. /**
  547. * Get the blend mode used for blit operations.
  548. *
  549. * \param surface the SDL_Surface structure to query.
  550. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  551. * \returns 0 on success or a negative error code on failure; call
  552. * SDL_GetError() for more information.
  553. *
  554. * \since This function is available since SDL 3.0.0.
  555. *
  556. * \sa SDL_SetSurfaceBlendMode
  557. */
  558. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  559. /**
  560. * Set the clipping rectangle for a surface.
  561. *
  562. * When `surface` is the destination of a blit, only the area within the clip
  563. * rectangle is drawn into.
  564. *
  565. * Note that blits are automatically clipped to the edges of the source and
  566. * destination surfaces.
  567. *
  568. * \param surface the SDL_Surface structure to be clipped.
  569. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  570. * NULL to disable clipping.
  571. * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
  572. * SDL_FALSE and blits will be completely clipped.
  573. *
  574. * \since This function is available since SDL 3.0.0.
  575. *
  576. * \sa SDL_GetSurfaceClipRect
  577. */
  578. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  579. /**
  580. * Get the clipping rectangle for a surface.
  581. *
  582. * When `surface` is the destination of a blit, only the area within the clip
  583. * rectangle is drawn into.
  584. *
  585. * \param surface the SDL_Surface structure representing the surface to be
  586. * clipped.
  587. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  588. * the surface.
  589. * \returns 0 on success or a negative error code on failure; call
  590. * SDL_GetError() for more information.
  591. *
  592. * \since This function is available since SDL 3.0.0.
  593. *
  594. * \sa SDL_SetSurfaceClipRect
  595. */
  596. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  597. /**
  598. * Flip a surface vertically or horizontally.
  599. *
  600. * \param surface the surface to flip.
  601. * \param flip the direction to flip.
  602. * \returns 0 on success or a negative error code on failure; call
  603. * SDL_GetError() for more information.
  604. *
  605. * \since This function is available since SDL 3.0.0.
  606. */
  607. extern SDL_DECLSPEC int SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  608. /**
  609. * Creates a new surface identical to the existing surface.
  610. *
  611. * The returned surface should be freed with SDL_DestroySurface().
  612. *
  613. * \param surface the surface to duplicate.
  614. * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
  615. * more information.
  616. *
  617. * \since This function is available since SDL 3.0.0.
  618. *
  619. * \sa SDL_DestroySurface
  620. */
  621. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  622. /**
  623. * Copy an existing surface to a new surface of the specified format.
  624. *
  625. * This function is used to optimize images for faster *repeat* blitting. This
  626. * is accomplished by converting the original and storing the result as a new
  627. * surface. The new, optimized surface can then be used as the source for
  628. * future blits, making them faster.
  629. *
  630. * If you are converting to an indexed surface and want to map colors to a
  631. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  632. *
  633. * \param surface the existing SDL_Surface structure to convert.
  634. * \param format the new pixel format.
  635. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  636. * call SDL_GetError() for more information.
  637. *
  638. * \since This function is available since SDL 3.0.0.
  639. *
  640. * \sa SDL_ConvertSurfaceAndColorspace
  641. * \sa SDL_DestroySurface
  642. */
  643. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  644. /**
  645. * Copy an existing surface to a new surface of the specified format and
  646. * colorspace.
  647. *
  648. * This function converts an existing surface to a new format and colorspace
  649. * and returns the new surface. This will perform any pixel format and
  650. * colorspace conversion needed.
  651. *
  652. * \param surface the existing SDL_Surface structure to convert.
  653. * \param format the new pixel format.
  654. * \param palette an optional palette to use for indexed formats, may be NULL.
  655. * \param colorspace the new colorspace.
  656. * \param props an SDL_PropertiesID with additional color properties, or 0.
  657. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  658. * call SDL_GetError() for more information.
  659. *
  660. * \since This function is available since SDL 3.0.0.
  661. *
  662. * \sa SDL_ConvertSurface
  663. * \sa SDL_ConvertSurface
  664. * \sa SDL_DestroySurface
  665. */
  666. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, const SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  667. /**
  668. * Copy a block of pixels of one format to another format.
  669. *
  670. * \param width the width of the block to copy, in pixels.
  671. * \param height the height of the block to copy, in pixels.
  672. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  673. * \param src a pointer to the source pixels.
  674. * \param src_pitch the pitch of the source pixels, in bytes.
  675. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  676. * \param dst a pointer to be filled in with new pixel data.
  677. * \param dst_pitch the pitch of the destination pixels, in bytes.
  678. * \returns 0 on success or a negative error code on failure; call
  679. * SDL_GetError() for more information.
  680. *
  681. * \since This function is available since SDL 3.0.0.
  682. *
  683. * \sa SDL_ConvertPixelsAndColorspace
  684. */
  685. extern SDL_DECLSPEC int 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);
  686. /**
  687. * Copy a block of pixels of one format and colorspace to another format and
  688. * colorspace.
  689. *
  690. * \param width the width of the block to copy, in pixels.
  691. * \param height the height of the block to copy, in pixels.
  692. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  693. * \param src_colorspace an SDL_ColorSpace value describing the colorspace of
  694. * the `src` pixels.
  695. * \param src_properties an SDL_PropertiesID with additional source color
  696. * properties, or 0.
  697. * \param src a pointer to the source pixels.
  698. * \param src_pitch the pitch of the source pixels, in bytes.
  699. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  700. * \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
  701. * the `dst` pixels.
  702. * \param dst_properties an SDL_PropertiesID with additional destination color
  703. * properties, or 0.
  704. * \param dst a pointer to be filled in with new pixel data.
  705. * \param dst_pitch the pitch of the destination pixels, in bytes.
  706. * \returns 0 on success or a negative error code on failure; call
  707. * SDL_GetError() for more information.
  708. *
  709. * \since This function is available since SDL 3.0.0.
  710. *
  711. * \sa SDL_ConvertPixels
  712. */
  713. extern SDL_DECLSPEC int 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);
  714. /**
  715. * Premultiply the alpha on a block of pixels.
  716. *
  717. * This is safe to use with src == dst, but not for other overlapping areas.
  718. *
  719. * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
  720. *
  721. * \param width the width of the block to convert, in pixels.
  722. * \param height the height of the block to convert, in pixels.
  723. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  724. * \param src a pointer to the source pixels.
  725. * \param src_pitch the pitch of the source pixels, in bytes.
  726. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  727. * \param dst a pointer to be filled in with premultiplied pixel data.
  728. * \param dst_pitch the pitch of the destination pixels, in bytes.
  729. * \returns 0 on success or a negative error code on failure; call
  730. * SDL_GetError() for more information.
  731. *
  732. * \since This function is available since SDL 3.0.0.
  733. */
  734. extern SDL_DECLSPEC int 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);
  735. /**
  736. * Perform a fast fill of a rectangle with a specific color.
  737. *
  738. * `color` should be a pixel of the format used by the surface, and can be
  739. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  740. * alpha component then the destination is simply filled with that alpha
  741. * information, no blending takes place.
  742. *
  743. * If there is a clip rectangle set on the destination (set via
  744. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  745. * intersection of the clip rectangle and `rect`.
  746. *
  747. * \param dst the SDL_Surface structure that is the drawing target.
  748. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  749. * NULL to fill the entire surface.
  750. * \param color the color to fill with.
  751. * \returns 0 on success or a negative error code on failure; call
  752. * SDL_GetError() for more information.
  753. *
  754. * \since This function is available since SDL 3.0.0.
  755. *
  756. * \sa SDL_FillSurfaceRects
  757. */
  758. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  759. /**
  760. * Perform a fast fill of a set of rectangles with a specific color.
  761. *
  762. * `color` should be a pixel of the format used by the surface, and can be
  763. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  764. * alpha component then the destination is simply filled with that alpha
  765. * information, no blending takes place.
  766. *
  767. * If there is a clip rectangle set on the destination (set via
  768. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  769. * intersection of the clip rectangle and `rect`.
  770. *
  771. * \param dst the SDL_Surface structure that is the drawing target.
  772. * \param rects an array of SDL_Rects representing the rectangles to fill.
  773. * \param count the number of rectangles in the array.
  774. * \param color the color to fill with.
  775. * \returns 0 on success or a negative error code on failure; call
  776. * SDL_GetError() for more information.
  777. *
  778. * \since This function is available since SDL 3.0.0.
  779. *
  780. * \sa SDL_FillSurfaceRect
  781. */
  782. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  783. /**
  784. * Performs a fast blit from the source surface to the destination surface.
  785. *
  786. * This assumes that the source and destination rectangles are the same size.
  787. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  788. * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
  789. * `dstrect` after all clipping is performed.
  790. *
  791. * The blit function should not be called on a locked surface.
  792. *
  793. * The blit semantics for surfaces with and without blending and colorkey are
  794. * defined as follows:
  795. *
  796. * ```
  797. * RGBA->RGB:
  798. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  799. * alpha-blend (using the source alpha-channel and per-surface alpha)
  800. * SDL_SRCCOLORKEY ignored.
  801. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  802. * copy RGB.
  803. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  804. * RGB values of the source color key, ignoring alpha in the
  805. * comparison.
  806. *
  807. * RGB->RGBA:
  808. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  809. * alpha-blend (using the source per-surface alpha)
  810. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  811. * copy RGB, set destination alpha to source per-surface alpha value.
  812. * both:
  813. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  814. * source color key.
  815. *
  816. * RGBA->RGBA:
  817. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  818. * alpha-blend (using the source alpha-channel and per-surface alpha)
  819. * SDL_SRCCOLORKEY ignored.
  820. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  821. * copy all of RGBA to the destination.
  822. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  823. * RGB values of the source color key, ignoring alpha in the
  824. * comparison.
  825. *
  826. * RGB->RGB:
  827. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  828. * alpha-blend (using the source per-surface alpha)
  829. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  830. * copy RGB.
  831. * both:
  832. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  833. * source color key.
  834. * ```
  835. *
  836. * \param src the SDL_Surface structure to be copied from.
  837. * \param srcrect the SDL_Rect structure representing the rectangle to be
  838. * copied, or NULL to copy the entire surface.
  839. * \param dst the SDL_Surface structure that is the blit target.
  840. * \param dstrect the SDL_Rect structure representing the x and y position in
  841. * the destination surface. On input the width and height are
  842. * ignored (taken from srcrect), and on output this is filled
  843. * in with the actual rectangle used after clipping.
  844. * \returns 0 on success or a negative error code on failure; call
  845. * SDL_GetError() for more information.
  846. *
  847. * \threadsafety The same destination surface should not be used from two
  848. * threads at once. It is safe to use the same source surface
  849. * from multiple threads.
  850. *
  851. * \since This function is available since SDL 3.0.0.
  852. *
  853. * \sa SDL_BlitSurfaceScaled
  854. */
  855. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
  856. /**
  857. * Perform low-level surface blitting only.
  858. *
  859. * This is a semi-private blit function and it performs low-level surface
  860. * blitting, assuming the input rectangles have already been clipped.
  861. *
  862. * \param src the SDL_Surface structure to be copied from.
  863. * \param srcrect the SDL_Rect structure representing the rectangle to be
  864. * copied, or NULL to copy the entire surface.
  865. * \param dst the SDL_Surface structure that is the blit target.
  866. * \param dstrect the SDL_Rect structure representing the target rectangle in
  867. * the destination surface.
  868. * \returns 0 on success or a negative error code on failure; call
  869. * SDL_GetError() for more information.
  870. *
  871. * \threadsafety The same destination surface should not be used from two
  872. * threads at once. It is safe to use the same source surface
  873. * from multiple threads.
  874. *
  875. * \since This function is available since SDL 3.0.0.
  876. *
  877. * \sa SDL_BlitSurface
  878. */
  879. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  880. /**
  881. * Perform stretch blit between two surfaces of the same format.
  882. *
  883. * Using SDL_SCALEMODE_NEAREST: fast, low quality. Using SDL_SCALEMODE_LINEAR:
  884. * bilinear scaling, slower, better quality, only 32BPP.
  885. *
  886. * \param src the SDL_Surface structure to be copied from.
  887. * \param srcrect the SDL_Rect structure representing the rectangle to be
  888. * copied.
  889. * \param dst the SDL_Surface structure that is the blit target.
  890. * \param dstrect the SDL_Rect structure representing the target rectangle in
  891. * the destination surface.
  892. * \param scaleMode scale algorithm to be used.
  893. * \returns 0 on success or a negative error code on failure; call
  894. * SDL_GetError() for more information.
  895. *
  896. * \since This function is available since SDL 3.0.0.
  897. *
  898. * \sa SDL_BlitSurfaceScaled
  899. */
  900. extern SDL_DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  901. /**
  902. * Perform a scaled blit to a destination surface, which may be of a different
  903. * format.
  904. *
  905. * \param src the SDL_Surface structure to be copied from.
  906. * \param srcrect the SDL_Rect structure representing the rectangle to be
  907. * copied.
  908. * \param dst the SDL_Surface structure that is the blit target.
  909. * \param dstrect the SDL_Rect structure representing the target rectangle in
  910. * the destination surface, filled with the actual rectangle
  911. * used after clipping.
  912. * \param scaleMode the SDL_ScaleMode to be used.
  913. * \returns 0 on success or a negative error code on failure; call
  914. * SDL_GetError() for more information.
  915. *
  916. * \threadsafety The same destination surface should not be used from two
  917. * threads at once. It is safe to use the same source surface
  918. * from multiple threads.
  919. *
  920. * \since This function is available since SDL 3.0.0.
  921. *
  922. * \sa SDL_BlitSurface
  923. */
  924. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  925. /**
  926. * Perform low-level surface scaled blitting only.
  927. *
  928. * This is a semi-private function and it performs low-level surface blitting,
  929. * assuming the input rectangles have already been clipped.
  930. *
  931. * \param src the SDL_Surface structure to be copied from.
  932. * \param srcrect the SDL_Rect structure representing the rectangle to be
  933. * copied.
  934. * \param dst the SDL_Surface structure that is the blit target.
  935. * \param dstrect the SDL_Rect structure representing the target rectangle in
  936. * the destination surface.
  937. * \param scaleMode scale algorithm to be used.
  938. * \returns 0 on success or a negative error code on failure; call
  939. * SDL_GetError() for more information.
  940. *
  941. * \threadsafety The same destination surface should not be used from two
  942. * threads at once. It is safe to use the same source surface
  943. * from multiple threads.
  944. *
  945. * \since This function is available since SDL 3.0.0.
  946. *
  947. * \sa SDL_BlitSurfaceScaled
  948. */
  949. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  950. /**
  951. * Map an RGB triple to an opaque pixel value for a surface.
  952. *
  953. * This function maps the RGB color value to the specified pixel format and
  954. * returns the pixel value best approximating the given RGB color value for
  955. * the given pixel format.
  956. *
  957. * If the surface has a palette, the index of the closest matching color in
  958. * the palette will be returned.
  959. *
  960. * If the surface pixel format has an alpha component it will be returned as
  961. * all 1 bits (fully opaque).
  962. *
  963. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  964. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  965. * format the return value can be assigned to a Uint16, and similarly a Uint8
  966. * for an 8-bpp format).
  967. *
  968. * \param surface the surface to use for the pixel format and palette.
  969. * \param r the red component of the pixel in the range 0-255.
  970. * \param g the green component of the pixel in the range 0-255.
  971. * \param b the blue component of the pixel in the range 0-255.
  972. * \returns a pixel value.
  973. *
  974. * \since This function is available since SDL 3.0.0.
  975. *
  976. * \sa SDL_MapSurfaceRGBA
  977. */
  978. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  979. /**
  980. * Map an RGBA quadruple to a pixel value for a surface.
  981. *
  982. * This function maps the RGBA color value to the specified pixel format and
  983. * returns the pixel value best approximating the given RGBA color value for
  984. * the given pixel format.
  985. *
  986. * If the surface pixel format has no alpha component the alpha value will be
  987. * ignored (as it will be in formats with a palette).
  988. *
  989. * If the surface has a palette, the index of the closest matching color in
  990. * the palette will be returned.
  991. *
  992. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  993. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  994. * format the return value can be assigned to a Uint16, and similarly a Uint8
  995. * for an 8-bpp format).
  996. *
  997. * \param surface the surface to use for the pixel format and palette.
  998. * \param r the red component of the pixel in the range 0-255.
  999. * \param g the green component of the pixel in the range 0-255.
  1000. * \param b the blue component of the pixel in the range 0-255.
  1001. * \param a the alpha component of the pixel in the range 0-255.
  1002. * \returns a pixel value.
  1003. *
  1004. * \since This function is available since SDL 3.0.0.
  1005. *
  1006. * \sa SDL_MapSurfaceRGB
  1007. */
  1008. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1009. /**
  1010. * Retrieves a single pixel from a surface.
  1011. *
  1012. * This function prioritizes correctness over speed: it is suitable for unit
  1013. * tests, but is not intended for use in a game engine.
  1014. *
  1015. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1016. * components from pixel formats with less than 8 bits per RGB component.
  1017. *
  1018. * \param surface the surface to read.
  1019. * \param x the horizontal coordinate, 0 <= x < width.
  1020. * \param y the vertical coordinate, 0 <= y < height.
  1021. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1022. * this channel.
  1023. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1024. * ignore this channel.
  1025. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1026. * ignore this channel.
  1027. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1028. * ignore this channel.
  1029. * \returns 0 on success or a negative error code on failure; call
  1030. * SDL_GetError() for more information.
  1031. *
  1032. * \since This function is available since SDL 3.0.0.
  1033. */
  1034. extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1035. /* Ends C function definitions when using C++ */
  1036. #ifdef __cplusplus
  1037. }
  1038. #endif
  1039. #include <SDL3/SDL_close_code.h>
  1040. #endif /* SDL_surface_h_ */