SDL_surface.h 32 KB

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