SDL_surface.h 40 KB

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