SDL_surface.h 40 KB

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