SDL_surface.h 37 KB

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