SDL_surface.h 37 KB

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