SDL_surface.h 34 KB

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