SDL_surface.h 36 KB

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