SDL_surface.h 39 KB

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