SDL_surface.h 40 KB

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