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

554 lines
20 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2019 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. void *lock_data; /**< Read-only */
  72. /** clipping information */
  73. SDL_Rect clip_rect; /**< Read-only */
  74. /** info for fast blit mapping to other surfaces */
  75. struct SDL_BlitMap *map; /**< Private */
  76. /** Reference count -- used when freeing surface */
  77. int refcount; /**< Read-mostly */
  78. } SDL_Surface;
  79. /**
  80. * \brief The type of function used for surface blitting functions.
  81. */
  82. typedef int (SDLCALL *SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
  83. struct SDL_Surface * dst, SDL_Rect * dstrect);
  84. /**
  85. * \brief The formula used for converting between YUV and RGB
  86. */
  87. typedef enum
  88. {
  89. SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
  90. SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
  91. SDL_YUV_CONVERSION_BT709, /**< BT.709 */
  92. SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
  93. } SDL_YUV_CONVERSION_MODE;
  94. /**
  95. * Allocate and free an RGB surface.
  96. *
  97. * If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
  98. * If the depth is greater than 8 bits, the pixel format is set using the
  99. * flags '[RGB]mask'.
  100. *
  101. * If the function runs out of memory, it will return NULL.
  102. *
  103. * \param flags The \c flags are obsolete and should be set to 0.
  104. * \param width The width in pixels of the surface to create.
  105. * \param height The height in pixels of the surface to create.
  106. * \param depth The depth in bits of the surface to create.
  107. * \param Rmask The red mask of the surface to create.
  108. * \param Gmask The green mask of the surface to create.
  109. * \param Bmask The blue mask of the surface to create.
  110. * \param Amask The alpha mask of the surface to create.
  111. */
  112. extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
  113. (Uint32 flags, int width, int height, int depth,
  114. Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
  115. /* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
  116. extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
  117. (Uint32 flags, int width, int height, int depth, Uint32 format);
  118. extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
  119. int width,
  120. int height,
  121. int depth,
  122. int pitch,
  123. Uint32 Rmask,
  124. Uint32 Gmask,
  125. Uint32 Bmask,
  126. Uint32 Amask);
  127. extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
  128. (void *pixels, int width, int height, int depth, int pitch, Uint32 format);
  129. extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
  130. /**
  131. * \brief Set the palette used by a surface.
  132. *
  133. * \return 0, or -1 if the surface format doesn't use a palette.
  134. *
  135. * \note A single palette can be shared with many surfaces.
  136. */
  137. extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
  138. SDL_Palette * palette);
  139. /**
  140. * \brief Sets up a surface for directly accessing the pixels.
  141. *
  142. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
  143. * to and read from \c surface->pixels, using the pixel format stored in
  144. * \c surface->format. Once you are done accessing the surface, you should
  145. * use SDL_UnlockSurface() to release it.
  146. *
  147. * Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
  148. * to 0, then you can read and write to the surface at any time, and the
  149. * pixel format of the surface will not change.
  150. *
  151. * No operating system or library calls should be made between lock/unlock
  152. * pairs, as critical system locks may be held during this time.
  153. *
  154. * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
  155. *
  156. * \sa SDL_UnlockSurface()
  157. */
  158. extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
  159. /** \sa SDL_LockSurface() */
  160. extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
  161. /**
  162. * Load a surface from a seekable SDL data stream (memory or file).
  163. *
  164. * If \c freesrc is non-zero, the stream will be closed after being read.
  165. *
  166. * The new surface should be freed with SDL_FreeSurface().
  167. *
  168. * \return the new surface, or NULL if there was an error.
  169. */
  170. extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
  171. int freesrc);
  172. /**
  173. * Load a surface from a file.
  174. *
  175. * Convenience macro.
  176. */
  177. #define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
  178. /**
  179. * Save a surface to a seekable SDL data stream (memory or file).
  180. *
  181. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  182. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  183. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  184. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  185. * not supported.
  186. *
  187. * If \c freedst is non-zero, the stream will be closed after being written.
  188. *
  189. * \return 0 if successful or -1 if there was an error.
  190. */
  191. extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
  192. (SDL_Surface * surface, SDL_RWops * dst, int freedst);
  193. /**
  194. * Save a surface to a file.
  195. *
  196. * Convenience macro.
  197. */
  198. #define SDL_SaveBMP(surface, file) \
  199. SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
  200. /**
  201. * \brief Sets the RLE acceleration hint for a surface.
  202. *
  203. * \return 0 on success, or -1 if the surface is not valid
  204. *
  205. * \note If RLE is enabled, colorkey and alpha blending blits are much faster,
  206. * but the surface must be locked before directly accessing the pixels.
  207. */
  208. extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
  209. int flag);
  210. /**
  211. * \brief Sets the color key (transparent pixel) in a blittable surface.
  212. *
  213. * \param surface The surface to update
  214. * \param flag Non-zero to enable colorkey and 0 to disable colorkey
  215. * \param key The transparent pixel in the native surface format
  216. *
  217. * \return 0 on success, or -1 if the surface is not valid
  218. *
  219. * You can pass SDL_RLEACCEL to enable RLE accelerated blits.
  220. */
  221. extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
  222. int flag, Uint32 key);
  223. /**
  224. * \brief Returns whether the surface has a color key
  225. *
  226. * \return SDL_TRUE if the surface has a color key, or SDL_FALSE if the surface is NULL or has no color key
  227. */
  228. extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface);
  229. /**
  230. * \brief Gets the color key (transparent pixel) in a blittable surface.
  231. *
  232. * \param surface The surface to update
  233. * \param key A pointer filled in with the transparent pixel in the native
  234. * surface format
  235. *
  236. * \return 0 on success, or -1 if the surface is not valid or colorkey is not
  237. * enabled.
  238. */
  239. extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
  240. Uint32 * key);
  241. /**
  242. * \brief Set an additional color value used in blit operations.
  243. *
  244. * \param surface The surface to update.
  245. * \param r The red color value multiplied into blit operations.
  246. * \param g The green color value multiplied into blit operations.
  247. * \param b The blue color value multiplied into blit operations.
  248. *
  249. * \return 0 on success, or -1 if the surface is not valid.
  250. *
  251. * \sa SDL_GetSurfaceColorMod()
  252. */
  253. extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
  254. Uint8 r, Uint8 g, Uint8 b);
  255. /**
  256. * \brief Get the additional color value used in blit operations.
  257. *
  258. * \param surface The surface to query.
  259. * \param r A pointer filled in with the current red color value.
  260. * \param g A pointer filled in with the current green color value.
  261. * \param b A pointer filled in with the current blue color value.
  262. *
  263. * \return 0 on success, or -1 if the surface is not valid.
  264. *
  265. * \sa SDL_SetSurfaceColorMod()
  266. */
  267. extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
  268. Uint8 * r, Uint8 * g,
  269. Uint8 * b);
  270. /**
  271. * \brief Set an additional alpha value used in blit operations.
  272. *
  273. * \param surface The surface to update.
  274. * \param alpha The alpha value multiplied into blit operations.
  275. *
  276. * \return 0 on success, or -1 if the surface is not valid.
  277. *
  278. * \sa SDL_GetSurfaceAlphaMod()
  279. */
  280. extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
  281. Uint8 alpha);
  282. /**
  283. * \brief Get the additional alpha value used in blit operations.
  284. *
  285. * \param surface The surface to query.
  286. * \param alpha A pointer filled in with the current alpha value.
  287. *
  288. * \return 0 on success, or -1 if the surface is not valid.
  289. *
  290. * \sa SDL_SetSurfaceAlphaMod()
  291. */
  292. extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
  293. Uint8 * alpha);
  294. /**
  295. * \brief Set the blend mode used for blit operations.
  296. *
  297. * \param surface The surface to update.
  298. * \param blendMode ::SDL_BlendMode to use for blit blending.
  299. *
  300. * \return 0 on success, or -1 if the parameters are not valid.
  301. *
  302. * \sa SDL_GetSurfaceBlendMode()
  303. */
  304. extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
  305. SDL_BlendMode blendMode);
  306. /**
  307. * \brief Get the blend mode used for blit operations.
  308. *
  309. * \param surface The surface to query.
  310. * \param blendMode A pointer filled in with the current blend mode.
  311. *
  312. * \return 0 on success, or -1 if the surface is not valid.
  313. *
  314. * \sa SDL_SetSurfaceBlendMode()
  315. */
  316. extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
  317. SDL_BlendMode *blendMode);
  318. /**
  319. * Sets the clipping rectangle for the destination surface in a blit.
  320. *
  321. * If the clip rectangle is NULL, clipping will be disabled.
  322. *
  323. * If the clip rectangle doesn't intersect the surface, the function will
  324. * return SDL_FALSE and blits will be completely clipped. Otherwise the
  325. * function returns SDL_TRUE and blits to the surface will be clipped to
  326. * the intersection of the surface area and the clipping rectangle.
  327. *
  328. * Note that blits are automatically clipped to the edges of the source
  329. * and destination surfaces.
  330. */
  331. extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
  332. const SDL_Rect * rect);
  333. /**
  334. * Gets the clipping rectangle for the destination surface in a blit.
  335. *
  336. * \c rect must be a pointer to a valid rectangle which will be filled
  337. * with the correct values.
  338. */
  339. extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
  340. SDL_Rect * rect);
  341. /*
  342. * Creates a new surface identical to the existing surface
  343. */
  344. extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface);
  345. /**
  346. * Creates a new surface of the specified format, and then copies and maps
  347. * the given surface to it so the blit of the converted surface will be as
  348. * fast as possible. If this function fails, it returns NULL.
  349. *
  350. * The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
  351. * semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and
  352. * SDL will try to RLE accelerate colorkey and alpha blits in the resulting
  353. * surface.
  354. */
  355. extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
  356. (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
  357. extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
  358. (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
  359. /**
  360. * \brief Copy a block of pixels of one format to another format
  361. *
  362. * \return 0 on success, or -1 if there was an error
  363. */
  364. extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
  365. Uint32 src_format,
  366. const void * src, int src_pitch,
  367. Uint32 dst_format,
  368. void * dst, int dst_pitch);
  369. /**
  370. * Performs a fast fill of the given rectangle with \c color.
  371. *
  372. * If \c rect is NULL, the whole surface will be filled with \c color.
  373. *
  374. * The color should be a pixel of the format used by the surface, and
  375. * can be generated by the SDL_MapRGB() function.
  376. *
  377. * \return 0 on success, or -1 on error.
  378. */
  379. extern DECLSPEC int SDLCALL SDL_FillRect
  380. (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
  381. extern DECLSPEC int SDLCALL SDL_FillRects
  382. (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
  383. /**
  384. * Performs a fast blit from the source surface to the destination surface.
  385. *
  386. * This assumes that the source and destination rectangles are
  387. * the same size. If either \c srcrect or \c dstrect are NULL, the entire
  388. * surface (\c src or \c dst) is copied. The final blit rectangles are saved
  389. * in \c srcrect and \c dstrect after all clipping is performed.
  390. *
  391. * \return If the blit is successful, it returns 0, otherwise it returns -1.
  392. *
  393. * The blit function should not be called on a locked surface.
  394. *
  395. * The blit semantics for surfaces with and without blending and colorkey
  396. * are defined as follows:
  397. * \verbatim
  398. RGBA->RGB:
  399. Source surface blend mode set to SDL_BLENDMODE_BLEND:
  400. alpha-blend (using the source alpha-channel and per-surface alpha)
  401. SDL_SRCCOLORKEY ignored.
  402. Source surface blend mode set to SDL_BLENDMODE_NONE:
  403. copy RGB.
  404. if SDL_SRCCOLORKEY set, only copy the pixels matching the
  405. RGB values of the source color key, ignoring alpha in the
  406. comparison.
  407. RGB->RGBA:
  408. Source surface blend mode set to SDL_BLENDMODE_BLEND:
  409. alpha-blend (using the source per-surface alpha)
  410. Source surface blend mode set to SDL_BLENDMODE_NONE:
  411. copy RGB, set destination alpha to source per-surface alpha value.
  412. both:
  413. if SDL_SRCCOLORKEY set, only copy the pixels matching the
  414. source color key.
  415. RGBA->RGBA:
  416. Source surface blend mode set to SDL_BLENDMODE_BLEND:
  417. alpha-blend (using the source alpha-channel and per-surface alpha)
  418. SDL_SRCCOLORKEY ignored.
  419. Source surface blend mode set to SDL_BLENDMODE_NONE:
  420. copy all of RGBA to the destination.
  421. if SDL_SRCCOLORKEY set, only copy the pixels matching the
  422. RGB values of the source color key, ignoring alpha in the
  423. comparison.
  424. RGB->RGB:
  425. Source surface blend mode set to SDL_BLENDMODE_BLEND:
  426. alpha-blend (using the source per-surface alpha)
  427. Source surface blend mode set to SDL_BLENDMODE_NONE:
  428. copy RGB.
  429. both:
  430. if SDL_SRCCOLORKEY set, only copy the pixels matching the
  431. source color key.
  432. \endverbatim
  433. *
  434. * You should call SDL_BlitSurface() unless you know exactly how SDL
  435. * blitting works internally and how to use the other blit functions.
  436. */
  437. #define SDL_BlitSurface SDL_UpperBlit
  438. /**
  439. * This is the public blit function, SDL_BlitSurface(), and it performs
  440. * rectangle validation and clipping before passing it to SDL_LowerBlit()
  441. */
  442. extern DECLSPEC int SDLCALL SDL_UpperBlit
  443. (SDL_Surface * src, const SDL_Rect * srcrect,
  444. SDL_Surface * dst, SDL_Rect * dstrect);
  445. /**
  446. * This is a semi-private blit function and it performs low-level surface
  447. * blitting only.
  448. */
  449. extern DECLSPEC int SDLCALL SDL_LowerBlit
  450. (SDL_Surface * src, SDL_Rect * srcrect,
  451. SDL_Surface * dst, SDL_Rect * dstrect);
  452. /**
  453. * \brief Perform a fast, low quality, stretch blit between two surfaces of the
  454. * same pixel format.
  455. *
  456. * \note This function uses a static buffer, and is not thread-safe.
  457. */
  458. extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
  459. const SDL_Rect * srcrect,
  460. SDL_Surface * dst,
  461. const SDL_Rect * dstrect);
  462. #define SDL_BlitScaled SDL_UpperBlitScaled
  463. /**
  464. * This is the public scaled blit function, SDL_BlitScaled(), and it performs
  465. * rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
  466. */
  467. extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
  468. (SDL_Surface * src, const SDL_Rect * srcrect,
  469. SDL_Surface * dst, SDL_Rect * dstrect);
  470. /**
  471. * This is a semi-private blit function and it performs low-level surface
  472. * scaled blitting only.
  473. */
  474. extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
  475. (SDL_Surface * src, SDL_Rect * srcrect,
  476. SDL_Surface * dst, SDL_Rect * dstrect);
  477. /**
  478. * \brief Set the YUV conversion mode
  479. */
  480. extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
  481. /**
  482. * \brief Get the YUV conversion mode
  483. */
  484. extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionMode(void);
  485. /**
  486. * \brief Get the YUV conversion mode, returning the correct mode for the resolution when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
  487. */
  488. extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
  489. /* Ends C function definitions when using C++ */
  490. #ifdef __cplusplus
  491. }
  492. #endif
  493. #include "close_code.h"
  494. #endif /* SDL_surface_h_ */
  495. /* vi: set ts=4 sw=4 expandtab: */