SDL_surface.h 37 KB

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