SDL_surface.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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 <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_blendmode.h>
  27. #include <SDL3/SDL_pixels.h>
  28. #include <SDL3/SDL_properties.h>
  29. #include <SDL3/SDL_rect.h>
  30. #include <SDL3/SDL_rwops.h>
  31. #include <SDL3/SDL_begin_code.h>
  32. /* Set up for C function definitions, even when using C++ */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /**
  37. * \name Surface flags
  38. *
  39. * These are the currently supported flags for the ::SDL_Surface.
  40. *
  41. * \internal
  42. * Used internally (read-only).
  43. */
  44. /* @{ */
  45. #define SDL_SWSURFACE 0 /**< Just here for compatibility */
  46. #define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
  47. #define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
  48. #define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
  49. #define SDL_SIMD_ALIGNED 0x00000008 /**< Surface uses aligned memory */
  50. #define SDL_SURFACE_USES_PROPERTIES 0x00000010 /**< Surface uses properties */
  51. /* @} *//* Surface flags */
  52. /**
  53. * Evaluates to true if the surface needs to be locked before access.
  54. */
  55. #define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
  56. typedef struct SDL_BlitMap SDL_BlitMap; /* this is an opaque type. */
  57. /**
  58. * The scaling mode
  59. */
  60. typedef enum
  61. {
  62. SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
  63. SDL_SCALEMODE_LINEAR, /**< linear filtering */
  64. SDL_SCALEMODE_BEST /**< anisotropic filtering */
  65. } SDL_ScaleMode;
  66. /**
  67. * The flip mode
  68. */
  69. typedef enum
  70. {
  71. SDL_FLIP_NONE, /**< Do not flip */
  72. SDL_FLIP_HORIZONTAL, /**< flip horizontally */
  73. SDL_FLIP_VERTICAL /**< flip vertically */
  74. } SDL_FlipMode;
  75. /**
  76. * A collection of pixels used in software blitting.
  77. *
  78. * Pixels are arranged in memory in rows, with the top row first.
  79. * Each row occupies an amount of memory given by the pitch (sometimes
  80. * known as the row stride in non-SDL APIs).
  81. *
  82. * Within each row, pixels are arranged from left to right until the
  83. * width is reached.
  84. * Each pixel occupies a number of bits appropriate for its format, with
  85. * most formats representing each pixel as one or more whole bytes
  86. * (in some indexed formats, instead multiple pixels are packed into
  87. * each byte), and a byte order given by the format.
  88. * After encoding all pixels, any remaining bytes to reach the pitch are
  89. * used as padding to reach a desired alignment, and have undefined contents.
  90. *
  91. * \note This structure should be treated as read-only, except for \c pixels,
  92. * which, if not NULL, contains the raw pixel data for the surface.
  93. * \sa SDL_CreateSurfaceFrom
  94. */
  95. typedef struct SDL_Surface
  96. {
  97. Uint32 flags; /**< Read-only */
  98. SDL_PixelFormat *format; /**< Read-only */
  99. int w, h; /**< Read-only */
  100. int pitch; /**< Read-only */
  101. void *pixels; /**< Read-write */
  102. void *reserved; /**< Private */
  103. /** information needed for surfaces requiring locks */
  104. int locked; /**< Read-only */
  105. /** list of BlitMap that hold a reference to this surface */
  106. void *list_blitmap; /**< Private */
  107. /** clipping information */
  108. SDL_Rect clip_rect; /**< Read-only */
  109. /** info for fast blit mapping to other surfaces */
  110. SDL_BlitMap *map; /**< Private */
  111. /** Reference count -- used when freeing surface */
  112. int refcount; /**< Read-mostly */
  113. } SDL_Surface;
  114. /**
  115. * The type of function used for surface blitting functions.
  116. */
  117. typedef int (SDLCALL *SDL_blit) (struct SDL_Surface *src, const SDL_Rect *srcrect,
  118. struct SDL_Surface *dst, const SDL_Rect *dstrect);
  119. /**
  120. * The formula used for converting between YUV and RGB
  121. */
  122. typedef enum
  123. {
  124. SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
  125. SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
  126. SDL_YUV_CONVERSION_BT709, /**< BT.709 */
  127. SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
  128. } SDL_YUV_CONVERSION_MODE;
  129. /**
  130. * Allocate a new RGB surface with a specific pixel format.
  131. *
  132. * \param width the width of the surface
  133. * \param height the height of the surface
  134. * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
  135. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  136. * call SDL_GetError() for more information.
  137. *
  138. * \since This function is available since SDL 3.0.0.
  139. *
  140. * \sa SDL_CreateSurfaceFrom
  141. * \sa SDL_DestroySurface
  142. */
  143. extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface
  144. (int width, int height, Uint32 format);
  145. /**
  146. * Allocate a new RGB surface with a specific pixel format and existing pixel
  147. * data.
  148. *
  149. * No copy is made of the pixel data. Pixel data is not managed automatically;
  150. * you must free the surface before you free the pixel data.
  151. *
  152. * Pitch is the offset in bytes from one row of pixels to the next, e.g.
  153. * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
  154. *
  155. * You may pass NULL for pixels and 0 for pitch to create a surface that you
  156. * will fill in with valid values later.
  157. *
  158. * \param pixels a pointer to existing pixel data
  159. * \param width the width of the surface
  160. * \param height the height of the surface
  161. * \param pitch the pitch of the surface in bytes
  162. * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
  163. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  164. * call SDL_GetError() for more information.
  165. *
  166. * \since This function is available since SDL 3.0.0.
  167. *
  168. * \sa SDL_CreateSurface
  169. * \sa SDL_DestroySurface
  170. */
  171. extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom
  172. (void *pixels, int width, int height, int pitch, Uint32 format);
  173. /**
  174. * Free an RGB surface.
  175. *
  176. * It is safe to pass NULL to this function.
  177. *
  178. * \param surface the SDL_Surface to free.
  179. *
  180. * \since This function is available since SDL 3.0.0.
  181. *
  182. * \sa SDL_CreateSurface
  183. * \sa SDL_CreateSurfaceFrom
  184. * \sa SDL_LoadBMP
  185. * \sa SDL_LoadBMP_RW
  186. */
  187. extern DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
  188. /**
  189. * Get the properties associated with a surface.
  190. *
  191. * The following properties are understood by SDL:
  192. *
  193. * - `SDL_PROP_SURFACE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
  194. * the surface colorspace, defaults to SDL_COLORSPACE_SCRGB for floating
  195. * point formats, SDL_COLORSPACE_HDR10 for 10-bit formats,
  196. * SDL_COLORSPACE_SRGB for other RGB surfaces and SDL_COLORSPACE_BT709_FULL
  197. * for YUV textures.
  198. * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
  199. * used when converting between different colorspaces. Currently this
  200. * supports the form "*=N", where N is a floating point scale factor applied
  201. * in linear space.
  202. *
  203. * \param surface the SDL_Surface structure to query
  204. * \returns a valid property ID on success or 0 on failure; call
  205. * SDL_GetError() for more information.
  206. *
  207. * \since This function is available since SDL 3.0.0.
  208. *
  209. * \sa SDL_GetProperty
  210. * \sa SDL_SetProperty
  211. */
  212. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
  213. #define SDL_PROP_SURFACE_COLORSPACE_NUMBER "SDL.surface.colorspace"
  214. #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
  215. /**
  216. * Set the colorspace used by a surface.
  217. *
  218. * Setting the colorspace doesn't change the pixels, only how they are
  219. * interpreted in color operations.
  220. *
  221. * \param surface the SDL_Surface structure to update
  222. * \param colorspace an SDL_ColorSpace value describing the surface colorspace
  223. * \returns 0 on success or a negative error code on failure; call
  224. * SDL_GetError() for more information.
  225. *
  226. * \since This function is available since SDL 3.0.0.
  227. */
  228. extern DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
  229. /**
  230. * Get the colorspace used by a surface.
  231. *
  232. * The colorspace defaults to SDL_COLORSPACE_SCRGB for floating point formats,
  233. * SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for other RGB
  234. * surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
  235. *
  236. * \param surface the SDL_Surface structure to query
  237. * \param colorspace a pointer filled in with an SDL_ColorSpace value
  238. * describing the surface colorspace
  239. * \returns 0 on success or a negative error code on failure; call
  240. * SDL_GetError() for more information.
  241. *
  242. * \since This function is available since SDL 3.0.0.
  243. */
  244. extern DECLSPEC int SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace *colorspace);
  245. /**
  246. * Set the palette used by a surface.
  247. *
  248. * A single palette can be shared with many surfaces.
  249. *
  250. * \param surface the SDL_Surface structure to update
  251. * \param palette the SDL_Palette structure to use
  252. * \returns 0 on success or a negative error code on failure; call
  253. * SDL_GetError() for more information.
  254. *
  255. * \since This function is available since SDL 3.0.0.
  256. */
  257. extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  258. /**
  259. * Set up a surface for directly accessing the pixels.
  260. *
  261. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  262. * and read from `surface->pixels`, using the pixel format stored in
  263. * `surface->format`. Once you are done accessing the surface, you should use
  264. * SDL_UnlockSurface() to release it.
  265. *
  266. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  267. * 0, then you can read and write to the surface at any time, and the pixel
  268. * format of the surface will not change.
  269. *
  270. * \param surface the SDL_Surface structure to be locked
  271. * \returns 0 on success or a negative error code on failure; call
  272. * SDL_GetError() for more information.
  273. *
  274. * \since This function is available since SDL 3.0.0.
  275. *
  276. * \sa SDL_MUSTLOCK
  277. * \sa SDL_UnlockSurface
  278. */
  279. extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
  280. /**
  281. * Release a surface after directly accessing the pixels.
  282. *
  283. * \param surface the SDL_Surface structure to be unlocked
  284. *
  285. * \since This function is available since SDL 3.0.0.
  286. *
  287. * \sa SDL_LockSurface
  288. */
  289. extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  290. /**
  291. * Load a BMP image from a seekable SDL data stream.
  292. *
  293. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  294. * will result in a memory leak.
  295. *
  296. * \param src the data stream for the surface
  297. * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
  298. * even in the case of an error
  299. * \returns a pointer to a new SDL_Surface structure or NULL if there was an
  300. * error; call SDL_GetError() for more information.
  301. *
  302. * \since This function is available since SDL 3.0.0.
  303. *
  304. * \sa SDL_DestroySurface
  305. * \sa SDL_LoadBMP
  306. * \sa SDL_SaveBMP_RW
  307. */
  308. extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc);
  309. /**
  310. * Load a BMP image from a file.
  311. *
  312. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  313. * will result in a memory leak.
  314. *
  315. * \param file the BMP file to load
  316. * \returns a pointer to a new SDL_Surface structure or NULL if there was an
  317. * error; call SDL_GetError() for more information.
  318. *
  319. * \since This function is available since SDL 3.0.0.
  320. *
  321. * \sa SDL_DestroySurface
  322. * \sa SDL_LoadBMP_RW
  323. * \sa SDL_SaveBMP
  324. */
  325. extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
  326. /**
  327. * Save a surface to a seekable SDL data stream in BMP format.
  328. *
  329. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  330. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  331. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  332. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  333. * not supported.
  334. *
  335. * \param surface the SDL_Surface structure containing the image to be saved
  336. * \param dst a data stream to save to
  337. * \param freedst if SDL_TRUE, calls SDL_RWclose() on `dst` before returning,
  338. * even in the case of an error
  339. * \returns 0 on success or a negative error code on failure; call
  340. * SDL_GetError() for more information.
  341. *
  342. * \since This function is available since SDL 3.0.0.
  343. *
  344. * \sa SDL_LoadBMP_RW
  345. * \sa SDL_SaveBMP
  346. */
  347. extern DECLSPEC int SDLCALL SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, SDL_bool freedst);
  348. /**
  349. * Save a surface to a file.
  350. *
  351. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  352. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  353. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  354. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  355. * not supported.
  356. *
  357. * \param surface the SDL_Surface structure containing the image to be saved
  358. * \param file a file to save to
  359. * \returns 0 on success or a negative error code on failure; call
  360. * SDL_GetError() for more information.
  361. *
  362. * \since This function is available since SDL 3.0.0.
  363. *
  364. * \sa SDL_LoadBMP
  365. * \sa SDL_SaveBMP_RW
  366. */
  367. extern DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  368. /**
  369. * Set the RLE acceleration hint for a surface.
  370. *
  371. * If RLE is enabled, color key and alpha blending blits are much faster, but
  372. * the surface must be locked before directly accessing the pixels.
  373. *
  374. * \param surface the SDL_Surface structure to optimize
  375. * \param flag 0 to disable, non-zero to enable RLE acceleration
  376. * \returns 0 on success or a negative error code on failure; call
  377. * SDL_GetError() for more information.
  378. *
  379. * \since This function is available since SDL 3.0.0.
  380. *
  381. * \sa SDL_BlitSurface
  382. * \sa SDL_LockSurface
  383. * \sa SDL_UnlockSurface
  384. */
  385. extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, int flag);
  386. /**
  387. * Returns whether the surface is RLE enabled
  388. *
  389. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  390. *
  391. * \param surface the SDL_Surface structure to query
  392. * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
  393. *
  394. * \since This function is available since SDL 3.0.0.
  395. *
  396. * \sa SDL_SetSurfaceRLE
  397. */
  398. extern DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  399. /**
  400. * Set the color key (transparent pixel) in a surface.
  401. *
  402. * The color key defines a pixel value that will be treated as transparent in
  403. * a blit. For example, one can use this to specify that cyan pixels should be
  404. * considered transparent, and therefore not rendered.
  405. *
  406. * It is a pixel of the format used by the surface, as generated by
  407. * SDL_MapRGB().
  408. *
  409. * RLE acceleration can substantially speed up blitting of images with large
  410. * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details.
  411. *
  412. * \param surface the SDL_Surface structure to update
  413. * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key
  414. * \param key the transparent pixel
  415. * \returns 0 on success or a negative error code on failure; call
  416. * SDL_GetError() for more information.
  417. *
  418. * \since This function is available since SDL 3.0.0.
  419. *
  420. * \sa SDL_BlitSurface
  421. * \sa SDL_GetSurfaceColorKey
  422. */
  423. extern DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, int flag, Uint32 key);
  424. /**
  425. * Returns whether the surface has a color key
  426. *
  427. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  428. *
  429. * \param surface the SDL_Surface structure to query
  430. * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
  431. *
  432. * \since This function is available since SDL 3.0.0.
  433. *
  434. * \sa SDL_SetSurfaceColorKey
  435. * \sa SDL_GetSurfaceColorKey
  436. */
  437. extern DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  438. /**
  439. * Get the color key (transparent pixel) for a surface.
  440. *
  441. * The color key is a pixel of the format used by the surface, as generated by
  442. * SDL_MapRGB().
  443. *
  444. * If the surface doesn't have color key enabled this function returns -1.
  445. *
  446. * \param surface the SDL_Surface structure to query
  447. * \param key a pointer filled in with the transparent pixel
  448. * \returns 0 on success or a negative error code on failure; call
  449. * SDL_GetError() for more information.
  450. *
  451. * \since This function is available since SDL 3.0.0.
  452. *
  453. * \sa SDL_BlitSurface
  454. * \sa SDL_SetSurfaceColorKey
  455. */
  456. extern DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  457. /**
  458. * Set an additional color value multiplied into blit operations.
  459. *
  460. * When this surface is blitted, during the blit operation each source color
  461. * channel is modulated by the appropriate color value according to the
  462. * following formula:
  463. *
  464. * `srcC = srcC * (color / 255)`
  465. *
  466. * \param surface the SDL_Surface structure to update
  467. * \param r the red color value multiplied into blit operations
  468. * \param g the green color value multiplied into blit operations
  469. * \param b the blue color value multiplied into blit operations
  470. * \returns 0 on success or a negative error code on failure; call
  471. * SDL_GetError() for more information.
  472. *
  473. * \since This function is available since SDL 3.0.0.
  474. *
  475. * \sa SDL_GetSurfaceColorMod
  476. * \sa SDL_SetSurfaceAlphaMod
  477. */
  478. extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  479. /**
  480. * Get the additional color value multiplied into blit operations.
  481. *
  482. * \param surface the SDL_Surface structure to query
  483. * \param r a pointer filled in with the current red color value
  484. * \param g a pointer filled in with the current green color value
  485. * \param b a pointer filled in with the current blue color value
  486. * \returns 0 on success or a negative error code on failure; call
  487. * SDL_GetError() for more information.
  488. *
  489. * \since This function is available since SDL 3.0.0.
  490. *
  491. * \sa SDL_GetSurfaceAlphaMod
  492. * \sa SDL_SetSurfaceColorMod
  493. */
  494. extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  495. /**
  496. * Set an additional alpha value used in blit operations.
  497. *
  498. * When this surface is blitted, during the blit operation the source alpha
  499. * value is modulated by this alpha value according to the following formula:
  500. *
  501. * `srcA = srcA * (alpha / 255)`
  502. *
  503. * \param surface the SDL_Surface structure to update
  504. * \param alpha the alpha value multiplied into blit operations
  505. * \returns 0 on success or a negative error code on failure; call
  506. * SDL_GetError() for more information.
  507. *
  508. * \since This function is available since SDL 3.0.0.
  509. *
  510. * \sa SDL_GetSurfaceAlphaMod
  511. * \sa SDL_SetSurfaceColorMod
  512. */
  513. extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  514. /**
  515. * Get the additional alpha value used in blit operations.
  516. *
  517. * \param surface the SDL_Surface structure to query
  518. * \param alpha a pointer filled in with the current alpha value
  519. * \returns 0 on success or a negative error code on failure; call
  520. * SDL_GetError() for more information.
  521. *
  522. * \since This function is available since SDL 3.0.0.
  523. *
  524. * \sa SDL_GetSurfaceColorMod
  525. * \sa SDL_SetSurfaceAlphaMod
  526. */
  527. extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  528. /**
  529. * Set the blend mode used for blit operations.
  530. *
  531. * To copy a surface to another surface (or texture) without blending with the
  532. * existing data, the blendmode of the SOURCE surface should be set to
  533. * `SDL_BLENDMODE_NONE`.
  534. *
  535. * \param surface the SDL_Surface structure to update
  536. * \param blendMode the SDL_BlendMode to use for blit blending
  537. * \returns 0 on success or a negative error code on failure; call
  538. * SDL_GetError() for more information.
  539. *
  540. * \since This function is available since SDL 3.0.0.
  541. *
  542. * \sa SDL_GetSurfaceBlendMode
  543. */
  544. extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  545. /**
  546. * Get the blend mode used for blit operations.
  547. *
  548. * \param surface the SDL_Surface structure to query
  549. * \param blendMode a pointer filled in with the current SDL_BlendMode
  550. * \returns 0 on success or a negative error code on failure; call
  551. * SDL_GetError() for more information.
  552. *
  553. * \since This function is available since SDL 3.0.0.
  554. *
  555. * \sa SDL_SetSurfaceBlendMode
  556. */
  557. extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  558. /**
  559. * Set the clipping rectangle for a surface.
  560. *
  561. * When `surface` is the destination of a blit, only the area within the clip
  562. * rectangle is drawn into.
  563. *
  564. * Note that blits are automatically clipped to the edges of the source and
  565. * destination surfaces.
  566. *
  567. * \param surface the SDL_Surface structure to be clipped
  568. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  569. * NULL to disable clipping
  570. * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
  571. * SDL_FALSE and blits will be completely clipped.
  572. *
  573. * \since This function is available since SDL 3.0.0.
  574. *
  575. * \sa SDL_BlitSurface
  576. * \sa SDL_GetSurfaceClipRect
  577. */
  578. extern DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  579. /**
  580. * Get the clipping rectangle for a surface.
  581. *
  582. * When `surface` is the destination of a blit, only the area within the clip
  583. * rectangle is drawn into.
  584. *
  585. * \param surface the SDL_Surface structure representing the surface to be
  586. * clipped
  587. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  588. * the surface
  589. * \returns 0 on success or a negative error code on failure; call
  590. * SDL_GetError() for more information.
  591. *
  592. * \since This function is available since SDL 3.0.0.
  593. *
  594. * \sa SDL_BlitSurface
  595. * \sa SDL_SetSurfaceClipRect
  596. */
  597. extern DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  598. /*
  599. * Flip a surface vertically or horizontally.
  600. *
  601. * \param surface the surface to flip
  602. * \param flip the direction to flip
  603. * \returns 0 on success or a negative error code on failure; call
  604. * SDL_GetError() for more information.
  605. *
  606. * \since This function is available since SDL 3.0.0.
  607. */
  608. extern DECLSPEC int SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  609. /*
  610. * Creates a new surface identical to the existing surface.
  611. *
  612. * The returned surface should be freed with SDL_DestroySurface().
  613. *
  614. * \param surface the surface to duplicate.
  615. * \returns a copy of the surface, or NULL on failure; call SDL_GetError() for
  616. * more information.
  617. *
  618. * \since This function is available since SDL 3.0.0.
  619. */
  620. extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  621. /**
  622. * Copy an existing surface to a new surface of the specified format.
  623. *
  624. * This function is used to optimize images for faster *repeat* blitting. This
  625. * is accomplished by converting the original and storing the result as a new
  626. * surface. The new, optimized surface can then be used as the source for
  627. * future blits, making them faster.
  628. *
  629. * \param surface the existing SDL_Surface structure to convert
  630. * \param format the SDL_PixelFormat structure that the new surface is
  631. * optimized for
  632. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  633. * call SDL_GetError() for more information.
  634. *
  635. * \since This function is available since SDL 3.0.0.
  636. *
  637. * \sa SDL_CreatePixelFormat
  638. * \sa SDL_ConvertSurfaceFormat
  639. * \sa SDL_CreateSurface
  640. */
  641. extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format);
  642. /**
  643. * Copy an existing surface to a new surface of the specified format.
  644. *
  645. * This function operates just like SDL_ConvertSurface(), but accepts an
  646. * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
  647. * it might be easier to call but it doesn't have access to palette
  648. * information for the destination surface, in case that would be important.
  649. *
  650. * \param surface the existing SDL_Surface structure to convert
  651. * \param pixel_format the new pixel format
  652. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  653. * call SDL_GetError() for more information.
  654. *
  655. * \since This function is available since SDL 3.0.0.
  656. *
  657. * \sa SDL_CreatePixelFormat
  658. * \sa SDL_ConvertSurface
  659. * \sa SDL_CreateSurface
  660. */
  661. extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *surface, Uint32 pixel_format);
  662. /**
  663. * Copy an existing surface to a new surface of the specified format and
  664. * colorspace.
  665. *
  666. * This function converts an existing surface to a new format and colorspace
  667. * and returns the new surface. This will perform any pixel format and
  668. * colorspace conversion needed.
  669. *
  670. * \param surface the existing SDL_Surface structure to convert
  671. * \param pixel_format the new pixel format
  672. * \param colorspace the new colorspace
  673. * \returns the new SDL_Surface structure that is created or NULL if it fails;
  674. * call SDL_GetError() for more information.
  675. *
  676. * \since This function is available since SDL 3.0.0.
  677. *
  678. * \sa SDL_CreatePixelFormat
  679. * \sa SDL_ConvertSurface
  680. * \sa SDL_CreateSurface
  681. */
  682. extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormatAndColorspace(SDL_Surface *surface, Uint32 pixel_format, SDL_Colorspace colorspace);
  683. /**
  684. * Copy a block of pixels of one format to another format.
  685. *
  686. * \param width the width of the block to copy, in pixels
  687. * \param height the height of the block to copy, in pixels
  688. * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
  689. * \param src a pointer to the source pixels
  690. * \param src_pitch the pitch of the source pixels, in bytes
  691. * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
  692. * \param dst a pointer to be filled in with new pixel data
  693. * \param dst_pitch the pitch of the destination pixels, in bytes
  694. * \returns 0 on success or a negative error code on failure; call
  695. * SDL_GetError() for more information.
  696. *
  697. * \since This function is available since SDL 3.0.0.
  698. */
  699. extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
  700. /**
  701. * Copy a block of pixels of one format and colorspace to another format and
  702. * colorspace.
  703. *
  704. * \param width the width of the block to copy, in pixels
  705. * \param height the height of the block to copy, in pixels
  706. * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
  707. * \param src_colorspace an SDL_ColorSpace value describing the colorspace of
  708. * the `src` pixels
  709. * \param src a pointer to the source pixels
  710. * \param src_pitch the pitch of the source pixels, in bytes
  711. * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
  712. * \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
  713. * the `dst` pixels
  714. * \param dst a pointer to be filled in with new pixel data
  715. * \param dst_pitch the pitch of the destination pixels, in bytes
  716. * \returns 0 on success or a negative error code on failure; call
  717. * SDL_GetError() for more information.
  718. *
  719. * \since This function is available since SDL 3.0.0.
  720. */
  721. extern DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, Uint32 src_format, SDL_Colorspace src_colorspace, const void *src, int src_pitch, Uint32 dst_format, SDL_Colorspace dst_colorspace, void *dst, int dst_pitch);
  722. /**
  723. * Premultiply the alpha on a block of pixels.
  724. *
  725. * This is safe to use with src == dst, but not for other overlapping areas.
  726. *
  727. * This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888.
  728. *
  729. * \param width the width of the block to convert, in pixels
  730. * \param height the height of the block to convert, in pixels
  731. * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format
  732. * \param src a pointer to the source pixels
  733. * \param src_pitch the pitch of the source pixels, in bytes
  734. * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format
  735. * \param dst a pointer to be filled in with premultiplied pixel data
  736. * \param dst_pitch the pitch of the destination pixels, in bytes
  737. * \returns 0 on success or a negative error code on failure; call
  738. * SDL_GetError() for more information.
  739. *
  740. * \since This function is available since SDL 3.0.0.
  741. */
  742. extern DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
  743. /**
  744. * Perform a fast fill of a rectangle with a specific color.
  745. *
  746. * `color` should be a pixel of the format used by the surface, and can be
  747. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  748. * alpha component then the destination is simply filled with that alpha
  749. * information, no blending takes place.
  750. *
  751. * If there is a clip rectangle set on the destination (set via
  752. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  753. * intersection of the clip rectangle and `rect`.
  754. *
  755. * \param dst the SDL_Surface structure that is the drawing target
  756. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  757. * NULL to fill the entire surface
  758. * \param color the color to fill with
  759. * \returns 0 on success or a negative error code on failure; call
  760. * SDL_GetError() for more information.
  761. *
  762. * \since This function is available since SDL 3.0.0.
  763. *
  764. * \sa SDL_FillSurfaceRects
  765. */
  766. extern DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  767. /**
  768. * Perform a fast fill of a set of rectangles with a specific color.
  769. *
  770. * `color` should be a pixel of the format used by the surface, and can be
  771. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  772. * alpha component then the destination is simply filled with that alpha
  773. * information, no blending takes place.
  774. *
  775. * If there is a clip rectangle set on the destination (set via
  776. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  777. * intersection of the clip rectangle and `rect`.
  778. *
  779. * \param dst the SDL_Surface structure that is the drawing target
  780. * \param rects an array of SDL_Rects representing the rectangles to fill.
  781. * \param count the number of rectangles in the array
  782. * \param color the color to fill with
  783. * \returns 0 on success or a negative error code on failure; call
  784. * SDL_GetError() for more information.
  785. *
  786. * \since This function is available since SDL 3.0.0.
  787. *
  788. * \sa SDL_FillSurfaceRect
  789. */
  790. extern DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  791. /**
  792. * Performs a fast blit from the source surface to the destination surface.
  793. *
  794. * This assumes that the source and destination rectangles are the same size.
  795. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  796. * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
  797. * `dstrect` after all clipping is performed.
  798. *
  799. * The blit function should not be called on a locked surface.
  800. *
  801. * The blit semantics for surfaces with and without blending and colorkey are
  802. * defined as follows:
  803. *
  804. * ```c
  805. * RGBA->RGB:
  806. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  807. * alpha-blend (using the source alpha-channel and per-surface alpha)
  808. * SDL_SRCCOLORKEY ignored.
  809. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  810. * copy RGB.
  811. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  812. * RGB values of the source color key, ignoring alpha in the
  813. * comparison.
  814. *
  815. * RGB->RGBA:
  816. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  817. * alpha-blend (using the source per-surface alpha)
  818. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  819. * copy RGB, set destination alpha to source per-surface alpha value.
  820. * both:
  821. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  822. * source color key.
  823. *
  824. * RGBA->RGBA:
  825. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  826. * alpha-blend (using the source alpha-channel and per-surface alpha)
  827. * SDL_SRCCOLORKEY ignored.
  828. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  829. * copy all of RGBA to the destination.
  830. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  831. * RGB values of the source color key, ignoring alpha in the
  832. * comparison.
  833. *
  834. * RGB->RGB:
  835. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  836. * alpha-blend (using the source per-surface alpha)
  837. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  838. * copy RGB.
  839. * both:
  840. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  841. * source color key.
  842. * ```
  843. *
  844. * \param src the SDL_Surface structure to be copied from
  845. * \param srcrect the SDL_Rect structure representing the rectangle to be
  846. * copied, or NULL to copy the entire surface
  847. * \param dst the SDL_Surface structure that is the blit target
  848. * \param dstrect the SDL_Rect structure representing the x and y position in
  849. * the destination surface. On input the width and height are
  850. * ignored (taken from srcrect), and on output this is filled
  851. * in with the actual rectangle used after clipping.
  852. * \returns 0 on success or a negative error code on failure; call
  853. * SDL_GetError() for more information.
  854. *
  855. * \since This function is available since SDL 3.0.0.
  856. *
  857. * \sa SDL_BlitSurfaceScaled
  858. */
  859. extern DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
  860. /**
  861. * Perform low-level surface blitting only.
  862. *
  863. * This is a semi-private blit function and it performs low-level surface
  864. * blitting, assuming the input rectangles have already been clipped.
  865. *
  866. * \param src the SDL_Surface structure to be copied from
  867. * \param srcrect the SDL_Rect structure representing the rectangle to be
  868. * copied, or NULL to copy the entire surface
  869. * \param dst the SDL_Surface structure that is the blit target
  870. * \param dstrect the SDL_Rect structure representing the target rectangle in
  871. * the destination surface
  872. * \returns 0 on success or a negative error code on failure; call
  873. * SDL_GetError() for more information.
  874. *
  875. * \since This function is available since SDL 3.0.0.
  876. *
  877. * \sa SDL_BlitSurface
  878. */
  879. extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  880. /**
  881. * Perform stretch blit between two surfaces of the same format.
  882. *
  883. * Using SDL_SCALEMODE_NEAREST: fast, low quality. Using SDL_SCALEMODE_LINEAR:
  884. * bilinear scaling, slower, better quality, only 32BPP.
  885. *
  886. * \param src the SDL_Surface structure to be copied from
  887. * \param srcrect the SDL_Rect structure representing the rectangle to be
  888. * copied
  889. * \param dst the SDL_Surface structure that is the blit target
  890. * \param dstrect the SDL_Rect structure representing the target rectangle in
  891. * the destination surface
  892. * \param scaleMode scale algorithm to be used
  893. * \returns 0 on success or a negative error code on failure; call
  894. * SDL_GetError() for more information.
  895. *
  896. * \since This function is available since SDL 3.0.0.
  897. *
  898. * \sa SDL_BlitSurfaceScaled
  899. */
  900. extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  901. /**
  902. * Perform a scaled surface copy to a destination surface.
  903. *
  904. * \param src the SDL_Surface structure to be copied from
  905. * \param srcrect the SDL_Rect structure representing the rectangle to be
  906. * copied
  907. * \param dst the SDL_Surface structure that is the blit target
  908. * \param dstrect the SDL_Rect structure representing the target rectangle in
  909. * the destination surface, filled with the actual rectangle
  910. * used after clipping
  911. * \param scaleMode scale algorithm to be used
  912. * \returns 0 on success or a negative error code on failure; call
  913. * SDL_GetError() for more information.
  914. *
  915. * \since This function is available since SDL 3.0.0.
  916. *
  917. * \sa SDL_BlitSurface
  918. */
  919. extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  920. /**
  921. * Perform low-level surface scaled blitting only.
  922. *
  923. * This is a semi-private function and it performs low-level surface blitting,
  924. * assuming the input rectangles have already been clipped.
  925. *
  926. * \param src the SDL_Surface structure to be copied from
  927. * \param srcrect the SDL_Rect structure representing the rectangle to be
  928. * copied
  929. * \param dst the SDL_Surface structure that is the blit target
  930. * \param dstrect the SDL_Rect structure representing the target rectangle in
  931. * the destination surface
  932. * \param scaleMode scale algorithm to be used
  933. * \returns 0 on success or a negative error code on failure; call
  934. * SDL_GetError() for more information.
  935. *
  936. * \since This function is available since SDL 3.0.0.
  937. *
  938. * \sa SDL_BlitSurfaceScaled
  939. */
  940. extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  941. /**
  942. * Retrieves a single pixel from a surface.
  943. *
  944. * This function prioritizes correctness over speed: it is suitable for unit
  945. * tests, but is not intended for use in a game engine.
  946. *
  947. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  948. * components from pixel formats with less than 8 bits per RGB component.
  949. *
  950. * \param surface the surface to read
  951. * \param x the horizontal coordinate, 0 <= x < width
  952. * \param y the vertical coordinate, 0 <= y < height
  953. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  954. * this channel
  955. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  956. * ignore this channel
  957. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  958. * ignore this channel
  959. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  960. * ignore this channel
  961. * \returns 0 on success or a negative error code on failure; call
  962. * SDL_GetError() for more information.
  963. *
  964. * \since This function is available since SDL 3.0.0.
  965. */
  966. extern DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  967. /**
  968. * Set the YUV conversion mode
  969. *
  970. * \param mode YUV conversion mode
  971. *
  972. * \since This function is available since SDL 3.0.0.
  973. */
  974. extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
  975. /**
  976. * Get the YUV conversion mode
  977. *
  978. * \returns YUV conversion mode
  979. *
  980. * \since This function is available since SDL 3.0.0.
  981. */
  982. extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionMode(void);
  983. /**
  984. * Get the YUV conversion mode, returning the correct mode for the resolution
  985. * when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
  986. *
  987. * \param width width
  988. * \param height height
  989. * \returns YUV conversion mode
  990. *
  991. * \since This function is available since SDL 3.0.0.
  992. */
  993. extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
  994. /* Ends C function definitions when using C++ */
  995. #ifdef __cplusplus
  996. }
  997. #endif
  998. #include <SDL3/SDL_close_code.h>
  999. #endif /* SDL_surface_h_ */