SDL_surface.h 34 KB

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