🛠️🐜 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.

997 lines
36 KiB

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