SDL_surface.h 33 KB

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