SDL_surface.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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. * Create a palette and associate it with a surface.
  233. *
  234. * This function creates a palette compatible with the provided surface. The
  235. * palette is then returned for you to modify, and the surface will
  236. * automatically use the new palette in future operations. You do not need to
  237. * destroy the returned palette, it will be freed when the reference count
  238. * reaches 0, usually when the surface is destroyed.
  239. *
  240. * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
  241. * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
  242. * white and 1 as black. Other surfaces will get a palette initialized with
  243. * white in every entry.
  244. *
  245. * If this function is called for a surface that already has a palette, a new
  246. * palette will be created to replace it.
  247. *
  248. * \param surface the SDL_Surface structure to update.
  249. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  250. * the surface didn't have an index format); call SDL_GetError() for
  251. * more information.
  252. *
  253. * \since This function is available since SDL 3.0.0.
  254. *
  255. * \sa SDL_SetPaletteColors
  256. */
  257. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
  258. /**
  259. * Set the palette used by a surface.
  260. *
  261. * A single palette can be shared with many surfaces.
  262. *
  263. * \param surface the SDL_Surface structure to update.
  264. * \param palette the SDL_Palette structure to use.
  265. * \returns 0 on success or a negative error code on failure; call
  266. * SDL_GetError() for more information.
  267. *
  268. * \since This function is available since SDL 3.0.0.
  269. *
  270. * \sa SDL_CreatePalette
  271. * \sa SDL_GetSurfacePalette
  272. */
  273. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  274. /**
  275. * Get the palette used by a surface.
  276. *
  277. * \param surface the SDL_Surface structure to query.
  278. * \returns a pointer to the palette used by the surface, or NULL if there is
  279. * no palette used.
  280. *
  281. * \since This function is available since SDL 3.0.0.
  282. *
  283. * \sa SDL_SetSurfacePalette
  284. */
  285. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
  286. /**
  287. * Set up a surface for directly accessing the pixels.
  288. *
  289. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  290. * and read from `surface->pixels`, using the pixel format stored in
  291. * `surface->format`. Once you are done accessing the surface, you should use
  292. * SDL_UnlockSurface() to release it.
  293. *
  294. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  295. * 0, then you can read and write to the surface at any time, and the pixel
  296. * format of the surface will not change.
  297. *
  298. * \param surface the SDL_Surface structure to be locked.
  299. * \returns 0 on success or a negative error code on failure; call
  300. * SDL_GetError() for more information.
  301. *
  302. * \since This function is available since SDL 3.0.0.
  303. *
  304. * \sa SDL_MUSTLOCK
  305. * \sa SDL_UnlockSurface
  306. */
  307. extern SDL_DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
  308. /**
  309. * Release a surface after directly accessing the pixels.
  310. *
  311. * \param surface the SDL_Surface structure to be unlocked.
  312. *
  313. * \since This function is available since SDL 3.0.0.
  314. *
  315. * \sa SDL_LockSurface
  316. */
  317. extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  318. /**
  319. * Load a BMP image from a seekable SDL data stream.
  320. *
  321. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  322. * will result in a memory leak.
  323. *
  324. * \param src the data stream for the surface.
  325. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  326. * even in the case of an error.
  327. * \returns a pointer to a new SDL_Surface structure or NULL if there was an
  328. * error; call SDL_GetError() for more information.
  329. *
  330. * \since This function is available since SDL 3.0.0.
  331. *
  332. * \sa SDL_DestroySurface
  333. * \sa SDL_LoadBMP
  334. * \sa SDL_SaveBMP_IO
  335. */
  336. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio);
  337. /**
  338. * Load a BMP image from a file.
  339. *
  340. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  341. * will result in a memory leak.
  342. *
  343. * \param file the BMP file to load.
  344. * \returns a pointer to a new SDL_Surface structure or NULL if there was an
  345. * error; call SDL_GetError() for more information.
  346. *
  347. * \since This function is available since SDL 3.0.0.
  348. *
  349. * \sa SDL_DestroySurface
  350. * \sa SDL_LoadBMP_IO
  351. * \sa SDL_SaveBMP
  352. */
  353. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
  354. /**
  355. * Save a surface to a seekable SDL data stream in BMP format.
  356. *
  357. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  358. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  359. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  360. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  361. * not supported.
  362. *
  363. * \param surface the SDL_Surface structure containing the image to be saved.
  364. * \param dst a data stream to save to.
  365. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `dst` before returning,
  366. * even in the case of an error.
  367. * \returns 0 on success or a negative error code on failure; call
  368. * SDL_GetError() for more information.
  369. *
  370. * \since This function is available since SDL 3.0.0.
  371. *
  372. * \sa SDL_LoadBMP_IO
  373. * \sa SDL_SaveBMP
  374. */
  375. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio);
  376. /**
  377. * Save a surface to a file.
  378. *
  379. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  380. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  381. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  382. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  383. * not supported.
  384. *
  385. * \param surface the SDL_Surface structure containing the image to be saved.
  386. * \param file a file to save to.
  387. * \returns 0 on success or a negative error code on failure; call
  388. * SDL_GetError() for more information.
  389. *
  390. * \since This function is available since SDL 3.0.0.
  391. *
  392. * \sa SDL_LoadBMP
  393. * \sa SDL_SaveBMP_IO
  394. */
  395. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  396. /**
  397. * Set the RLE acceleration hint for a surface.
  398. *
  399. * If RLE is enabled, color key and alpha blending blits are much faster, but
  400. * the surface must be locked before directly accessing the pixels.
  401. *
  402. * \param surface the SDL_Surface structure to optimize.
  403. * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable
  404. * it.
  405. * \returns 0 on success or a negative error code on failure; call
  406. * SDL_GetError() for more information.
  407. *
  408. * \since This function is available since SDL 3.0.0.
  409. *
  410. * \sa SDL_BlitSurface
  411. * \sa SDL_LockSurface
  412. * \sa SDL_UnlockSurface
  413. */
  414. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled);
  415. /**
  416. * Returns whether the surface is RLE enabled.
  417. *
  418. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  419. *
  420. * \param surface the SDL_Surface structure to query.
  421. * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
  422. *
  423. * \since This function is available since SDL 3.0.0.
  424. *
  425. * \sa SDL_SetSurfaceRLE
  426. */
  427. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  428. /**
  429. * Set the color key (transparent pixel) in a surface.
  430. *
  431. * The color key defines a pixel value that will be treated as transparent in
  432. * a blit. For example, one can use this to specify that cyan pixels should be
  433. * considered transparent, and therefore not rendered.
  434. *
  435. * It is a pixel of the format used by the surface, as generated by
  436. * SDL_MapRGB().
  437. *
  438. * \param surface the SDL_Surface structure to update.
  439. * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color
  440. * key.
  441. * \param key the transparent pixel.
  442. * \returns 0 on success or a negative error code on failure; call
  443. * SDL_GetError() for more information.
  444. *
  445. * \since This function is available since SDL 3.0.0.
  446. *
  447. * \sa SDL_GetSurfaceColorKey
  448. * \sa SDL_SetSurfaceRLE
  449. * \sa SDL_SurfaceHasColorKey
  450. */
  451. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key);
  452. /**
  453. * Returns whether the surface has a color key.
  454. *
  455. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  456. *
  457. * \param surface the SDL_Surface structure to query.
  458. * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
  459. *
  460. * \since This function is available since SDL 3.0.0.
  461. *
  462. * \sa SDL_SetSurfaceColorKey
  463. * \sa SDL_GetSurfaceColorKey
  464. */
  465. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  466. /**
  467. * Get the color key (transparent pixel) for a surface.
  468. *
  469. * The color key is a pixel of the format used by the surface, as generated by
  470. * SDL_MapRGB().
  471. *
  472. * If the surface doesn't have color key enabled this function returns -1.
  473. *
  474. * \param surface the SDL_Surface structure to query.
  475. * \returns the transparent pixel.
  476. *
  477. * \since This function is available since SDL 3.0.0.
  478. *
  479. * \sa SDL_SetSurfaceColorKey
  480. * \sa SDL_SurfaceHasColorKey
  481. */
  482. extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface);
  483. /**
  484. * Set an additional color value multiplied into blit operations.
  485. *
  486. * When this surface is blitted, during the blit operation each source color
  487. * channel is modulated by the appropriate color value according to the
  488. * following formula:
  489. *
  490. * `srcC = srcC * (color / 255)`
  491. *
  492. * \param surface the SDL_Surface structure to update.
  493. * \param r the red color value multiplied into blit operations.
  494. * \param g the green color value multiplied into blit operations.
  495. * \param b the blue color value multiplied into blit operations.
  496. * \returns 0 on success or a negative error code on failure; call
  497. * SDL_GetError() for more information.
  498. *
  499. * \since This function is available since SDL 3.0.0.
  500. *
  501. * \sa SDL_GetSurfaceColorMod
  502. * \sa SDL_SetSurfaceAlphaMod
  503. */
  504. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  505. /**
  506. * Get the additional color value multiplied into blit operations.
  507. *
  508. * \param surface the SDL_Surface structure to query.
  509. * \param r a pointer filled in with the current red color value.
  510. * \param g a pointer filled in with the current green color value.
  511. * \param b a pointer filled in with the current blue color value.
  512. * \returns 0 on success or a negative error code on failure; call
  513. * SDL_GetError() for more information.
  514. *
  515. * \since This function is available since SDL 3.0.0.
  516. *
  517. * \sa SDL_GetSurfaceAlphaMod
  518. * \sa SDL_SetSurfaceColorMod
  519. */
  520. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  521. /**
  522. * Set an additional alpha value used in blit operations.
  523. *
  524. * When this surface is blitted, during the blit operation the source alpha
  525. * value is modulated by this alpha value according to the following formula:
  526. *
  527. * `srcA = srcA * (alpha / 255)`
  528. *
  529. * \param surface the SDL_Surface structure to update.
  530. * \param alpha the alpha value multiplied into blit operations.
  531. * \returns 0 on success or a negative error code on failure; call
  532. * SDL_GetError() for more information.
  533. *
  534. * \since This function is available since SDL 3.0.0.
  535. *
  536. * \sa SDL_GetSurfaceAlphaMod
  537. * \sa SDL_SetSurfaceColorMod
  538. */
  539. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  540. /**
  541. * Get the additional alpha value used in blit operations.
  542. *
  543. * \param surface the SDL_Surface structure to query.
  544. * \param alpha a pointer filled in with the current alpha value.
  545. * \returns 0 on success or a negative error code on failure; call
  546. * SDL_GetError() for more information.
  547. *
  548. * \since This function is available since SDL 3.0.0.
  549. *
  550. * \sa SDL_GetSurfaceColorMod
  551. * \sa SDL_SetSurfaceAlphaMod
  552. */
  553. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  554. /**
  555. * Set the blend mode used for blit operations.
  556. *
  557. * To copy a surface to another surface (or texture) without blending with the
  558. * existing data, the blendmode of the SOURCE surface should be set to
  559. * `SDL_BLENDMODE_NONE`.
  560. *
  561. * \param surface the SDL_Surface structure to update.
  562. * \param blendMode the SDL_BlendMode to use for blit blending.
  563. * \returns 0 on success or a negative error code on failure; call
  564. * SDL_GetError() for more information.
  565. *
  566. * \since This function is available since SDL 3.0.0.
  567. *
  568. * \sa SDL_GetSurfaceBlendMode
  569. */
  570. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  571. /**
  572. * Get the blend mode used for blit operations.
  573. *
  574. * \param surface the SDL_Surface structure to query.
  575. * \returns the current SDL_BlendMode.
  576. *
  577. * \since This function is available since SDL 3.0.0.
  578. *
  579. * \sa SDL_SetSurfaceBlendMode
  580. */
  581. extern SDL_DECLSPEC SDL_BlendMode SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface);
  582. /**
  583. * Set the clipping rectangle for a surface.
  584. *
  585. * When `surface` is the destination of a blit, only the area within the clip
  586. * rectangle is drawn into.
  587. *
  588. * Note that blits are automatically clipped to the edges of the source and
  589. * destination surfaces.
  590. *
  591. * \param surface the SDL_Surface structure to be clipped.
  592. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  593. * NULL to disable clipping.
  594. * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
  595. * SDL_FALSE and blits will be completely clipped.
  596. *
  597. * \since This function is available since SDL 3.0.0.
  598. *
  599. * \sa SDL_GetSurfaceClipRect
  600. */
  601. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  602. /**
  603. * Get the clipping rectangle for a surface.
  604. *
  605. * When `surface` is the destination of a blit, only the area within the clip
  606. * rectangle is drawn into.
  607. *
  608. * \param surface the SDL_Surface structure representing the surface to be
  609. * clipped.
  610. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  611. * the surface.
  612. * \returns 0 on success or a negative error code on failure; call
  613. * SDL_GetError() for more information.
  614. *
  615. * \since This function is available since SDL 3.0.0.
  616. *
  617. * \sa SDL_SetSurfaceClipRect
  618. */
  619. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  620. /**
  621. * Flip a surface vertically or horizontally.
  622. *
  623. * \param surface the surface to flip.
  624. * \param flip the direction to flip.
  625. * \returns 0 on success or a negative error code on failure; call
  626. * SDL_GetError() for more information.
  627. *
  628. * \since This function is available since SDL 3.0.0.
  629. */
  630. extern SDL_DECLSPEC int SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  631. /**
  632. * Creates a new surface identical to the existing surface.
  633. *
  634. * The returned surface should be freed with SDL_DestroySurface().
  635. *
  636. * \param surface the surface to duplicate.
  637. * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
  638. * more information.
  639. *
  640. * \since This function is available since SDL 3.0.0.
  641. *
  642. * \sa SDL_DestroySurface
  643. */
  644. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  645. /**
  646. * Copy an existing surface to a new surface of the specified format.
  647. *
  648. * This function is used to optimize images for faster *repeat* blitting. This
  649. * is accomplished by converting the original and storing the result as a new
  650. * surface. The new, optimized surface can then be used as the source for
  651. * future blits, making them faster.
  652. *
  653. * If you are converting to an indexed surface and want to map colors to a
  654. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  655. *
  656. * \param surface the existing SDL_Surface structure to convert.
  657. * \param format the new pixel format.
  658. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  659. * call SDL_GetError() for more information.
  660. *
  661. * \since This function is available since SDL 3.0.0.
  662. *
  663. * \sa SDL_ConvertSurfaceAndColorspace
  664. * \sa SDL_DestroySurface
  665. */
  666. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  667. /**
  668. * Copy an existing surface to a new surface of the specified format and
  669. * colorspace.
  670. *
  671. * This function converts an existing surface to a new format and colorspace
  672. * and returns the new surface. This will perform any pixel format and
  673. * colorspace conversion needed.
  674. *
  675. * \param surface the existing SDL_Surface structure to convert.
  676. * \param format the new pixel format.
  677. * \param palette an optional palette to use for indexed formats, may be NULL.
  678. * \param colorspace the new colorspace.
  679. * \param props an SDL_PropertiesID with additional color properties, or 0.
  680. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  681. * call SDL_GetError() for more information.
  682. *
  683. * \since This function is available since SDL 3.0.0.
  684. *
  685. * \sa SDL_ConvertSurface
  686. * \sa SDL_ConvertSurface
  687. * \sa SDL_DestroySurface
  688. */
  689. extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  690. /**
  691. * Copy a block of pixels of one format to another format.
  692. *
  693. * \param width the width of the block to copy, in pixels.
  694. * \param height the height of the block to copy, in pixels.
  695. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  696. * \param src a pointer to the source pixels.
  697. * \param src_pitch the pitch of the source pixels, in bytes.
  698. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  699. * \param dst a pointer to be filled in with new pixel data.
  700. * \param dst_pitch the pitch of the destination pixels, in bytes.
  701. * \returns 0 on success or a negative error code on failure; call
  702. * SDL_GetError() for more information.
  703. *
  704. * \since This function is available since SDL 3.0.0.
  705. *
  706. * \sa SDL_ConvertPixelsAndColorspace
  707. */
  708. 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);
  709. /**
  710. * Copy a block of pixels of one format and colorspace to another format and
  711. * colorspace.
  712. *
  713. * \param width the width of the block to copy, in pixels.
  714. * \param height the height of the block to copy, in pixels.
  715. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  716. * \param src_colorspace an SDL_ColorSpace value describing the colorspace of
  717. * the `src` pixels.
  718. * \param src_properties an SDL_PropertiesID with additional source color
  719. * properties, or 0.
  720. * \param src a pointer to the source pixels.
  721. * \param src_pitch the pitch of the source pixels, in bytes.
  722. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  723. * \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
  724. * the `dst` pixels.
  725. * \param dst_properties an SDL_PropertiesID with additional destination color
  726. * properties, or 0.
  727. * \param dst a pointer to be filled in with new 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. * \sa SDL_ConvertPixels
  735. */
  736. 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);
  737. /**
  738. * Premultiply the alpha on a block of pixels.
  739. *
  740. * This is safe to use with src == dst, but not for other overlapping areas.
  741. *
  742. * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
  743. *
  744. * \param width the width of the block to convert, in pixels.
  745. * \param height the height of the block to convert, in pixels.
  746. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  747. * \param src a pointer to the source pixels.
  748. * \param src_pitch the pitch of the source pixels, in bytes.
  749. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  750. * \param dst a pointer to be filled in with premultiplied pixel data.
  751. * \param dst_pitch the pitch of the destination pixels, in bytes.
  752. * \returns 0 on success or a negative error code on failure; call
  753. * SDL_GetError() for more information.
  754. *
  755. * \since This function is available since SDL 3.0.0.
  756. */
  757. 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);
  758. /**
  759. * Perform a fast fill of a rectangle with a specific color.
  760. *
  761. * `color` should be a pixel of the format used by the surface, and can be
  762. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  763. * alpha component then the destination is simply filled with that alpha
  764. * information, no blending takes place.
  765. *
  766. * If there is a clip rectangle set on the destination (set via
  767. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  768. * intersection of the clip rectangle and `rect`.
  769. *
  770. * \param dst the SDL_Surface structure that is the drawing target.
  771. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  772. * NULL to fill the entire surface.
  773. * \param color the color to fill with.
  774. * \returns 0 on success or a negative error code on failure; call
  775. * SDL_GetError() for more information.
  776. *
  777. * \since This function is available since SDL 3.0.0.
  778. *
  779. * \sa SDL_FillSurfaceRects
  780. */
  781. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  782. /**
  783. * Perform a fast fill of a set of rectangles with a specific color.
  784. *
  785. * `color` should be a pixel of the format used by the surface, and can be
  786. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  787. * alpha component then the destination is simply filled with that alpha
  788. * information, no blending takes place.
  789. *
  790. * If there is a clip rectangle set on the destination (set via
  791. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  792. * intersection of the clip rectangle and `rect`.
  793. *
  794. * \param dst the SDL_Surface structure that is the drawing target.
  795. * \param rects an array of SDL_Rects representing the rectangles to fill.
  796. * \param count the number of rectangles in the array.
  797. * \param color the color to fill with.
  798. * \returns 0 on success or a negative error code on failure; call
  799. * SDL_GetError() for more information.
  800. *
  801. * \since This function is available since SDL 3.0.0.
  802. *
  803. * \sa SDL_FillSurfaceRect
  804. */
  805. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  806. /**
  807. * Performs a fast blit from the source surface to the destination surface.
  808. *
  809. * This assumes that the source and destination rectangles are the same size.
  810. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  811. * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
  812. * `dstrect` after all clipping is performed.
  813. *
  814. * The blit function should not be called on a locked surface.
  815. *
  816. * The blit semantics for surfaces with and without blending and colorkey are
  817. * defined as follows:
  818. *
  819. * ```
  820. * RGBA->RGB:
  821. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  822. * alpha-blend (using the source alpha-channel and per-surface alpha)
  823. * SDL_SRCCOLORKEY ignored.
  824. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  825. * copy RGB.
  826. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  827. * RGB values of the source color key, ignoring alpha in the
  828. * comparison.
  829. *
  830. * RGB->RGBA:
  831. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  832. * alpha-blend (using the source per-surface alpha)
  833. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  834. * copy RGB, set destination alpha to source per-surface alpha value.
  835. * both:
  836. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  837. * source color key.
  838. *
  839. * RGBA->RGBA:
  840. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  841. * alpha-blend (using the source alpha-channel and per-surface alpha)
  842. * SDL_SRCCOLORKEY ignored.
  843. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  844. * copy all of RGBA to the destination.
  845. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  846. * RGB values of the source color key, ignoring alpha in the
  847. * comparison.
  848. *
  849. * RGB->RGB:
  850. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  851. * alpha-blend (using the source per-surface alpha)
  852. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  853. * copy RGB.
  854. * both:
  855. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  856. * source color key.
  857. * ```
  858. *
  859. * \param src the SDL_Surface structure to be copied from.
  860. * \param srcrect the SDL_Rect structure representing the rectangle to be
  861. * copied, or NULL to copy the entire surface.
  862. * \param dst the SDL_Surface structure that is the blit target.
  863. * \param dstrect the SDL_Rect structure representing the x and y position in
  864. * the destination surface. On input the width and height are
  865. * ignored (taken from srcrect), and on output this is filled
  866. * in with the actual rectangle used after clipping.
  867. * \returns 0 on success or a negative error code on failure; call
  868. * SDL_GetError() for more information.
  869. *
  870. * \threadsafety The same destination surface should not be used from two
  871. * threads at once. It is safe to use the same source surface
  872. * from multiple threads.
  873. *
  874. * \since This function is available since SDL 3.0.0.
  875. *
  876. * \sa SDL_BlitSurfaceScaled
  877. */
  878. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
  879. /**
  880. * Perform low-level surface blitting only.
  881. *
  882. * This is a semi-private blit function and it performs low-level surface
  883. * blitting, assuming the input rectangles have already been clipped.
  884. *
  885. * \param src the SDL_Surface structure to be copied from.
  886. * \param srcrect the SDL_Rect structure representing the rectangle to be
  887. * copied, or NULL to copy the entire surface.
  888. * \param dst the SDL_Surface structure that is the blit target.
  889. * \param dstrect the SDL_Rect structure representing the target rectangle in
  890. * the destination surface.
  891. * \returns 0 on success or a negative error code on failure; call
  892. * SDL_GetError() for more information.
  893. *
  894. * \threadsafety The same destination surface should not be used from two
  895. * threads at once. It is safe to use the same source surface
  896. * from multiple threads.
  897. *
  898. * \since This function is available since SDL 3.0.0.
  899. *
  900. * \sa SDL_BlitSurface
  901. */
  902. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  903. /**
  904. * Perform stretch blit between two surfaces of the same format.
  905. *
  906. * Using SDL_SCALEMODE_NEAREST: fast, low quality. Using SDL_SCALEMODE_LINEAR:
  907. * bilinear scaling, slower, better quality, only 32BPP.
  908. *
  909. * \param src the SDL_Surface structure to be copied from.
  910. * \param srcrect the SDL_Rect structure representing the rectangle to be
  911. * copied.
  912. * \param dst the SDL_Surface structure that is the blit target.
  913. * \param dstrect the SDL_Rect structure representing the target rectangle in
  914. * the destination surface.
  915. * \param scaleMode scale algorithm to be used.
  916. * \returns 0 on success or a negative error code on failure; call
  917. * SDL_GetError() for more information.
  918. *
  919. * \since This function is available since SDL 3.0.0.
  920. *
  921. * \sa SDL_BlitSurfaceScaled
  922. */
  923. extern SDL_DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  924. /**
  925. * Perform a scaled blit to a destination surface, which may be of a different
  926. * format.
  927. *
  928. * \param src the SDL_Surface structure to be copied from.
  929. * \param srcrect the SDL_Rect structure representing the rectangle to be
  930. * copied.
  931. * \param dst the SDL_Surface structure that is the blit target.
  932. * \param dstrect the SDL_Rect structure representing the target rectangle in
  933. * the destination surface, filled with the actual rectangle
  934. * used after clipping.
  935. * \param scaleMode the SDL_ScaleMode to be used.
  936. * \returns 0 on success or a negative error code on failure; call
  937. * SDL_GetError() for more information.
  938. *
  939. * \threadsafety The same destination surface should not be used from two
  940. * threads at once. It is safe to use the same source surface
  941. * from multiple threads.
  942. *
  943. * \since This function is available since SDL 3.0.0.
  944. *
  945. * \sa SDL_BlitSurface
  946. */
  947. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  948. /**
  949. * Perform low-level surface scaled blitting only.
  950. *
  951. * This is a semi-private function and it performs low-level surface blitting,
  952. * assuming the input rectangles have already been clipped.
  953. *
  954. * \param src the SDL_Surface structure to be copied from.
  955. * \param srcrect the SDL_Rect structure representing the rectangle to be
  956. * copied.
  957. * \param dst the SDL_Surface structure that is the blit target.
  958. * \param dstrect the SDL_Rect structure representing the target rectangle in
  959. * the destination surface.
  960. * \param scaleMode scale algorithm to be used.
  961. * \returns 0 on success or a negative error code on failure; call
  962. * SDL_GetError() for more information.
  963. *
  964. * \threadsafety The same destination surface should not be used from two
  965. * threads at once. It is safe to use the same source surface
  966. * from multiple threads.
  967. *
  968. * \since This function is available since SDL 3.0.0.
  969. *
  970. * \sa SDL_BlitSurfaceScaled
  971. */
  972. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  973. /**
  974. * Map an RGB triple to an opaque pixel value for a surface.
  975. *
  976. * This function maps the RGB color value to the specified pixel format and
  977. * returns the pixel value best approximating the given RGB color value for
  978. * the given pixel format.
  979. *
  980. * If the surface has a palette, the index of the closest matching color in
  981. * the palette will be returned.
  982. *
  983. * If the surface pixel format has an alpha component it will be returned as
  984. * all 1 bits (fully opaque).
  985. *
  986. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  987. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  988. * format the return value can be assigned to a Uint16, and similarly a Uint8
  989. * for an 8-bpp format).
  990. *
  991. * \param surface the surface to use for the pixel format and palette.
  992. * \param r the red component of the pixel in the range 0-255.
  993. * \param g the green component of the pixel in the range 0-255.
  994. * \param b the blue component of the pixel in the range 0-255.
  995. * \returns a pixel value.
  996. *
  997. * \since This function is available since SDL 3.0.0.
  998. *
  999. * \sa SDL_MapSurfaceRGBA
  1000. */
  1001. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  1002. /**
  1003. * Map an RGBA quadruple to a pixel value for a surface.
  1004. *
  1005. * This function maps the RGBA color value to the specified pixel format and
  1006. * returns the pixel value best approximating the given RGBA color value for
  1007. * the given pixel format.
  1008. *
  1009. * If the surface pixel format has no alpha component the alpha value will be
  1010. * ignored (as it will be in formats with a palette).
  1011. *
  1012. * If the surface has a palette, the index of the closest matching color in
  1013. * the palette will be returned.
  1014. *
  1015. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1016. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1017. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1018. * for an 8-bpp format).
  1019. *
  1020. * \param surface the surface to use for the pixel format and palette.
  1021. * \param r the red component of the pixel in the range 0-255.
  1022. * \param g the green component of the pixel in the range 0-255.
  1023. * \param b the blue component of the pixel in the range 0-255.
  1024. * \param a the alpha component of the pixel in the range 0-255.
  1025. * \returns a pixel value.
  1026. *
  1027. * \since This function is available since SDL 3.0.0.
  1028. *
  1029. * \sa SDL_MapSurfaceRGB
  1030. */
  1031. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1032. /**
  1033. * Retrieves a single pixel from a surface.
  1034. *
  1035. * This function prioritizes correctness over speed: it is suitable for unit
  1036. * tests, but is not intended for use in a game engine.
  1037. *
  1038. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1039. * components from pixel formats with less than 8 bits per RGB component.
  1040. *
  1041. * \param surface the surface to read.
  1042. * \param x the horizontal coordinate, 0 <= x < width.
  1043. * \param y the vertical coordinate, 0 <= y < height.
  1044. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1045. * this channel.
  1046. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1047. * ignore this channel.
  1048. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1049. * ignore this channel.
  1050. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1051. * ignore this channel.
  1052. * \returns 0 on success or a negative error code on failure; call
  1053. * SDL_GetError() for more information.
  1054. *
  1055. * \since This function is available since SDL 3.0.0.
  1056. */
  1057. extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1058. /* Ends C function definitions when using C++ */
  1059. #ifdef __cplusplus
  1060. }
  1061. #endif
  1062. #include <SDL3/SDL_close_code.h>
  1063. #endif /* SDL_surface_h_ */