🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

995 lines
36 KiB

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