SDL_surface.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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. * # CategorySurface
  20. *
  21. * 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_error.h>
  27. #include <SDL3/SDL_blendmode.h>
  28. #include <SDL3/SDL_pixels.h>
  29. #include <SDL3/SDL_properties.h>
  30. #include <SDL3/SDL_rect.h>
  31. #include <SDL3/SDL_iostream.h>
  32. #include <SDL3/SDL_begin_code.h>
  33. /* Set up for C function definitions, even when using C++ */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * The flags on an SDL_Surface.
  39. *
  40. * These are generally considered read-only.
  41. *
  42. * \since This datatype is available since SDL 3.0.0.
  43. */
  44. typedef Uint32 SDL_SurfaceFlags;
  45. #define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */
  46. #define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */
  47. #define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */
  48. #define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */
  49. /**
  50. * Evaluates to true if the surface needs to be locked before access.
  51. *
  52. * \since This macro is available since SDL 3.0.0.
  53. */
  54. #define SDL_MUSTLOCK(S) ((((S)->flags & SDL_SURFACE_LOCK_NEEDED)) == SDL_SURFACE_LOCK_NEEDED)
  55. /**
  56. * The scaling mode.
  57. *
  58. * \since This enum is available since SDL 3.0.0.
  59. */
  60. typedef enum SDL_ScaleMode
  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. * \since This enum is available since SDL 3.0.0.
  70. */
  71. typedef enum SDL_FlipMode
  72. {
  73. SDL_FLIP_NONE, /**< Do not flip */
  74. SDL_FLIP_HORIZONTAL, /**< flip horizontally */
  75. SDL_FLIP_VERTICAL /**< flip vertically */
  76. } SDL_FlipMode;
  77. /* Internal surface data */
  78. typedef struct SDL_SurfaceData SDL_SurfaceData;
  79. /**
  80. * A collection of pixels used in software blitting.
  81. *
  82. * Pixels are arranged in memory in rows, with the top row first. Each row
  83. * occupies an amount of memory given by the pitch (sometimes known as the row
  84. * stride in non-SDL APIs).
  85. *
  86. * Within each row, pixels are arranged from left to right until the width is
  87. * reached. Each pixel occupies a number of bits appropriate for its format,
  88. * with most formats representing each pixel as one or more whole bytes (in
  89. * some indexed formats, instead multiple pixels are packed into each byte),
  90. * and a byte order given by the format. After encoding all pixels, any
  91. * remaining bytes to reach the pitch are used as padding to reach a desired
  92. * alignment, and have undefined contents.
  93. *
  94. * \since This struct is available since SDL 3.0.0.
  95. */
  96. typedef struct SDL_Surface
  97. {
  98. SDL_SurfaceFlags flags; /**< Read-only */
  99. SDL_PixelFormat format; /**< Read-only */
  100. int w, h; /**< Read-only */
  101. int pitch; /**< Read-only */
  102. void *pixels; /**< Read-only pointer, writable pixels if non-NULL */
  103. int refcount; /**< Application reference count, used when freeing surface */
  104. SDL_SurfaceData *internal; /**< Private */
  105. } SDL_Surface;
  106. /**
  107. * Allocate a new surface with a specific pixel format.
  108. *
  109. * \param width the width of the surface.
  110. * \param height the height of the surface.
  111. * \param format the SDL_PixelFormat for the new surface's pixel format.
  112. * \returns the new SDL_Surface structure that is created or NULL on failure;
  113. * call SDL_GetError() for more information.
  114. *
  115. * \since This function is available since SDL 3.0.0.
  116. *
  117. * \sa SDL_CreateSurfaceFrom
  118. * \sa SDL_DestroySurface
  119. */
  120. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
  121. /**
  122. * Allocate a new surface with a specific pixel format and existing pixel
  123. * data.
  124. *
  125. * No copy is made of the pixel data. Pixel data is not managed automatically;
  126. * you must free the surface before you free the pixel data.
  127. *
  128. * Pitch is the offset in bytes from one row of pixels to the next, e.g.
  129. * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
  130. *
  131. * You may pass NULL for pixels and 0 for pitch to create a surface that you
  132. * will fill in with valid values later.
  133. *
  134. * \param width the width of the surface.
  135. * \param height the height of the surface.
  136. * \param format the SDL_PixelFormat for the new surface's pixel format.
  137. * \param pixels a pointer to existing pixel data.
  138. * \param pitch the number of bytes between each row, including padding.
  139. * \returns the new SDL_Surface structure that is created or NULL on failure;
  140. * call SDL_GetError() for more information.
  141. *
  142. * \since This function is available since SDL 3.0.0.
  143. *
  144. * \sa SDL_CreateSurface
  145. * \sa SDL_DestroySurface
  146. */
  147. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
  148. /**
  149. * Free a surface.
  150. *
  151. * It is safe to pass NULL to this function.
  152. *
  153. * \param surface the SDL_Surface to free.
  154. *
  155. * \since This function is available since SDL 3.0.0.
  156. *
  157. * \sa SDL_CreateStackSurface
  158. * \sa SDL_CreateSurface
  159. * \sa SDL_CreateSurfaceFrom
  160. */
  161. extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
  162. /**
  163. * Get the properties associated with a surface.
  164. *
  165. * The following properties are understood by SDL:
  166. *
  167. * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  168. * surfaces, this defines the value of 100% diffuse white, with higher
  169. * values being displayed in the High Dynamic Range headroom. This defaults
  170. * to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
  171. * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
  172. * surfaces, this defines the maximum dynamic range used by the content, in
  173. * terms of the SDR white point. This defaults to 0.0, which disables tone
  174. * mapping.
  175. * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
  176. * used when compressing from a surface with high dynamic range to another
  177. * with lower dynamic range. Currently this supports "chrome", which uses
  178. * the same tone mapping that Chrome uses for HDR content, the form "*=N",
  179. * where N is a floating point scale factor applied in linear space, and
  180. * "none", which disables tone mapping. This defaults to "chrome".
  181. *
  182. * \param surface the SDL_Surface structure to query.
  183. * \returns a valid property ID on success or 0 on failure; call
  184. * SDL_GetError() for more information.
  185. *
  186. * \since This function is available since SDL 3.0.0.
  187. */
  188. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
  189. #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
  190. #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
  191. #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
  192. /**
  193. * Set the colorspace used by a surface.
  194. *
  195. * Setting the colorspace doesn't change the pixels, only how they are
  196. * interpreted in color operations.
  197. *
  198. * \param surface the SDL_Surface structure to update.
  199. * \param colorspace an SDL_ColorSpace value describing the surface
  200. * colorspace.
  201. * \returns 0 on success or a negative error code on failure; call
  202. * SDL_GetError() for more information.
  203. *
  204. * \since This function is available since SDL 3.0.0.
  205. *
  206. * \sa SDL_GetSurfaceColorspace
  207. */
  208. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
  209. /**
  210. * Get the colorspace used by a surface.
  211. *
  212. * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
  213. * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
  214. * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
  215. *
  216. * \param surface the SDL_Surface structure to query.
  217. * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
  218. * the surface is NULL.
  219. *
  220. * \since This function is available since SDL 3.0.0.
  221. *
  222. * \sa SDL_SetSurfaceColorspace
  223. */
  224. extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
  225. /**
  226. * Create a palette and associate it with a surface.
  227. *
  228. * This function creates a palette compatible with the provided surface. The
  229. * palette is then returned for you to modify, and the surface will
  230. * automatically use the new palette in future operations. You do not need to
  231. * destroy the returned palette, it will be freed when the reference count
  232. * reaches 0, usually when the surface is destroyed.
  233. *
  234. * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
  235. * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
  236. * white and 1 as black. Other surfaces will get a palette initialized with
  237. * white in every entry.
  238. *
  239. * If this function is called for a surface that already has a palette, a new
  240. * palette will be created to replace it.
  241. *
  242. * \param surface the SDL_Surface structure to update.
  243. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  244. * the surface didn't have an index format); call SDL_GetError() for
  245. * more information.
  246. *
  247. * \since This function is available since SDL 3.0.0.
  248. *
  249. * \sa SDL_SetPaletteColors
  250. */
  251. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
  252. /**
  253. * Set the palette used by a surface.
  254. *
  255. * A single palette can be shared with many surfaces.
  256. *
  257. * \param surface the SDL_Surface structure to update.
  258. * \param palette the SDL_Palette structure to use.
  259. * \returns 0 on success or a negative error code on failure; call
  260. * SDL_GetError() for more information.
  261. *
  262. * \since This function is available since SDL 3.0.0.
  263. *
  264. * \sa SDL_CreatePalette
  265. * \sa SDL_GetSurfacePalette
  266. */
  267. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  268. /**
  269. * Get the palette used by a surface.
  270. *
  271. * \param surface the SDL_Surface structure to query.
  272. * \returns a pointer to the palette used by the surface, or NULL if there is
  273. * no palette used.
  274. *
  275. * \since This function is available since SDL 3.0.0.
  276. *
  277. * \sa SDL_SetSurfacePalette
  278. */
  279. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
  280. /**
  281. * Set up a surface for directly accessing the pixels.
  282. *
  283. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  284. * and read from `surface->pixels`, using the pixel format stored in
  285. * `surface->format`. Once you are done accessing the surface, you should use
  286. * SDL_UnlockSurface() to release it.
  287. *
  288. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  289. * 0, then you can read and write to the surface at any time, and the pixel
  290. * format of the surface will not change.
  291. *
  292. * \param surface the SDL_Surface structure to be locked.
  293. * \returns 0 on success or a negative error code on failure; call
  294. * SDL_GetError() for more information.
  295. *
  296. * \since This function is available since SDL 3.0.0.
  297. *
  298. * \sa SDL_MUSTLOCK
  299. * \sa SDL_UnlockSurface
  300. */
  301. extern SDL_DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
  302. /**
  303. * Release a surface after directly accessing the pixels.
  304. *
  305. * \param surface the SDL_Surface structure to be unlocked.
  306. *
  307. * \since This function is available since SDL 3.0.0.
  308. *
  309. * \sa SDL_LockSurface
  310. */
  311. extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  312. /**
  313. * Load a BMP image from a seekable SDL data stream.
  314. *
  315. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  316. * will result in a memory leak.
  317. *
  318. * \param src the data stream for the surface.
  319. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  320. * even in the case of an error.
  321. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  322. * SDL_GetError() for more information.
  323. *
  324. * \since This function is available since SDL 3.0.0.
  325. *
  326. * \sa SDL_DestroySurface
  327. * \sa SDL_LoadBMP
  328. * \sa SDL_SaveBMP_IO
  329. */
  330. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio);
  331. /**
  332. * Load a BMP image from a file.
  333. *
  334. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  335. * will result in a memory leak.
  336. *
  337. * \param file the BMP file to load.
  338. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  339. * SDL_GetError() for more information.
  340. *
  341. * \since This function is available since SDL 3.0.0.
  342. *
  343. * \sa SDL_DestroySurface
  344. * \sa SDL_LoadBMP_IO
  345. * \sa SDL_SaveBMP
  346. */
  347. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
  348. /**
  349. * Save a surface to a seekable SDL data stream in BMP format.
  350. *
  351. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  352. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  353. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  354. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  355. * not supported.
  356. *
  357. * \param surface the SDL_Surface structure containing the image to be saved.
  358. * \param dst a data stream to save to.
  359. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `dst` before returning,
  360. * even in the case of an error.
  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_IO
  367. * \sa SDL_SaveBMP
  368. */
  369. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio);
  370. /**
  371. * Save a surface to a file.
  372. *
  373. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  374. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  375. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  376. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  377. * not supported.
  378. *
  379. * \param surface the SDL_Surface structure containing the image to be saved.
  380. * \param file a file to save to.
  381. * \returns 0 on success or a negative error code on failure; call
  382. * SDL_GetError() for more information.
  383. *
  384. * \since This function is available since SDL 3.0.0.
  385. *
  386. * \sa SDL_LoadBMP
  387. * \sa SDL_SaveBMP_IO
  388. */
  389. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  390. /**
  391. * Set the RLE acceleration hint for a surface.
  392. *
  393. * If RLE is enabled, color key and alpha blending blits are much faster, but
  394. * the surface must be locked before directly accessing the pixels.
  395. *
  396. * \param surface the SDL_Surface structure to optimize.
  397. * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable
  398. * it.
  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_LockSurface
  406. * \sa SDL_UnlockSurface
  407. */
  408. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled);
  409. /**
  410. * Returns whether the surface is RLE enabled.
  411. *
  412. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  413. *
  414. * \param surface the SDL_Surface structure to query.
  415. * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
  416. *
  417. * \since This function is available since SDL 3.0.0.
  418. *
  419. * \sa SDL_SetSurfaceRLE
  420. */
  421. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  422. /**
  423. * Set the color key (transparent pixel) in a surface.
  424. *
  425. * The color key defines a pixel value that will be treated as transparent in
  426. * a blit. For example, one can use this to specify that cyan pixels should be
  427. * considered transparent, and therefore not rendered.
  428. *
  429. * It is a pixel of the format used by the surface, as generated by
  430. * SDL_MapRGB().
  431. *
  432. * \param surface the SDL_Surface structure to update.
  433. * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color
  434. * key.
  435. * \param key the transparent pixel.
  436. * \returns 0 on success or a negative error code on failure; call
  437. * SDL_GetError() for more information.
  438. *
  439. * \since This function is available since SDL 3.0.0.
  440. *
  441. * \sa SDL_GetSurfaceColorKey
  442. * \sa SDL_SetSurfaceRLE
  443. * \sa SDL_SurfaceHasColorKey
  444. */
  445. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key);
  446. /**
  447. * Returns whether the surface has a color key.
  448. *
  449. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  450. *
  451. * \param surface the SDL_Surface structure to query.
  452. * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
  453. *
  454. * \since This function is available since SDL 3.0.0.
  455. *
  456. * \sa SDL_SetSurfaceColorKey
  457. * \sa SDL_GetSurfaceColorKey
  458. */
  459. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  460. /**
  461. * Get the color key (transparent pixel) for a surface.
  462. *
  463. * The color key is a pixel of the format used by the surface, as generated by
  464. * SDL_MapRGB().
  465. *
  466. * If the surface doesn't have color key enabled this function returns -1.
  467. *
  468. * \param surface the SDL_Surface structure to query.
  469. * \param key a pointer filled in with the transparent pixel.
  470. * \returns 0 on success or a negative error code on failure; call
  471. * SDL_GetError() for more information.
  472. *
  473. * \since This function is available since SDL 3.0.0.
  474. *
  475. * \sa SDL_SetSurfaceColorKey
  476. * \sa SDL_SurfaceHasColorKey
  477. */
  478. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  479. /**
  480. * Set an additional color value multiplied into blit operations.
  481. *
  482. * When this surface is blitted, during the blit operation each source color
  483. * channel is modulated by the appropriate color value according to the
  484. * following formula:
  485. *
  486. * `srcC = srcC * (color / 255)`
  487. *
  488. * \param surface the SDL_Surface structure to update.
  489. * \param r the red color value multiplied into blit operations.
  490. * \param g the green color value multiplied into blit operations.
  491. * \param b the blue color value multiplied into blit operations.
  492. * \returns 0 on success or a negative error code on failure; call
  493. * SDL_GetError() for more information.
  494. *
  495. * \since This function is available since SDL 3.0.0.
  496. *
  497. * \sa SDL_GetSurfaceColorMod
  498. * \sa SDL_SetSurfaceAlphaMod
  499. */
  500. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  501. /**
  502. * Get the additional color value multiplied into blit operations.
  503. *
  504. * \param surface the SDL_Surface structure to query.
  505. * \param r a pointer filled in with the current red color value.
  506. * \param g a pointer filled in with the current green color value.
  507. * \param b a pointer filled in with the current blue color value.
  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_GetSurfaceAlphaMod
  514. * \sa SDL_SetSurfaceColorMod
  515. */
  516. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  517. /**
  518. * Set an additional alpha value used in blit operations.
  519. *
  520. * When this surface is blitted, during the blit operation the source alpha
  521. * value is modulated by this alpha value according to the following formula:
  522. *
  523. * `srcA = srcA * (alpha / 255)`
  524. *
  525. * \param surface the SDL_Surface structure to update.
  526. * \param alpha the alpha value multiplied into blit operations.
  527. * \returns 0 on success or a negative error code on failure; call
  528. * SDL_GetError() for more information.
  529. *
  530. * \since This function is available since SDL 3.0.0.
  531. *
  532. * \sa SDL_GetSurfaceAlphaMod
  533. * \sa SDL_SetSurfaceColorMod
  534. */
  535. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  536. /**
  537. * Get the additional alpha value used in blit operations.
  538. *
  539. * \param surface the SDL_Surface structure to query.
  540. * \param alpha a pointer filled in with the current alpha value.
  541. * \returns 0 on success or a negative error code on failure; call
  542. * SDL_GetError() for more information.
  543. *
  544. * \since This function is available since SDL 3.0.0.
  545. *
  546. * \sa SDL_GetSurfaceColorMod
  547. * \sa SDL_SetSurfaceAlphaMod
  548. */
  549. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  550. /**
  551. * Set the blend mode used for blit operations.
  552. *
  553. * To copy a surface to another surface (or texture) without blending with the
  554. * existing data, the blendmode of the SOURCE surface should be set to
  555. * `SDL_BLENDMODE_NONE`.
  556. *
  557. * \param surface the SDL_Surface structure to update.
  558. * \param blendMode the SDL_BlendMode to use for blit blending.
  559. * \returns 0 on success or a negative error code on failure; call
  560. * SDL_GetError() for more information.
  561. *
  562. * \since This function is available since SDL 3.0.0.
  563. *
  564. * \sa SDL_GetSurfaceBlendMode
  565. */
  566. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  567. /**
  568. * Get the blend mode used for blit operations.
  569. *
  570. * \param surface the SDL_Surface structure to query.
  571. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  572. * \returns 0 on success or a negative error code on failure; call
  573. * SDL_GetError() for more information.
  574. *
  575. * \since This function is available since SDL 3.0.0.
  576. *
  577. * \sa SDL_SetSurfaceBlendMode
  578. */
  579. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  580. /**
  581. * Set the clipping rectangle for a surface.
  582. *
  583. * When `surface` is the destination of a blit, only the area within the clip
  584. * rectangle is drawn into.
  585. *
  586. * Note that blits are automatically clipped to the edges of the source and
  587. * destination surfaces.
  588. *
  589. * \param surface the SDL_Surface structure to be clipped.
  590. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  591. * NULL to disable clipping.
  592. * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
  593. * SDL_FALSE and blits will be completely clipped.
  594. *
  595. * \since This function is available since SDL 3.0.0.
  596. *
  597. * \sa SDL_GetSurfaceClipRect
  598. */
  599. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  600. /**
  601. * Get the clipping rectangle for a surface.
  602. *
  603. * When `surface` is the destination of a blit, only the area within the clip
  604. * rectangle is drawn into.
  605. *
  606. * \param surface the SDL_Surface structure representing the surface to be
  607. * clipped.
  608. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  609. * the surface.
  610. * \returns 0 on success or a negative error code on failure; call
  611. * SDL_GetError() for more information.
  612. *
  613. * \since This function is available since SDL 3.0.0.
  614. *
  615. * \sa SDL_SetSurfaceClipRect
  616. */
  617. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  618. /**
  619. * Flip a surface vertically or horizontally.
  620. *
  621. * \param surface the surface to flip.
  622. * \param flip the direction to flip.
  623. * \returns 0 on success or a negative error code on failure; call
  624. * SDL_GetError() for more information.
  625. *
  626. * \since This function is available since SDL 3.0.0.
  627. */
  628. extern SDL_DECLSPEC int SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  629. /**
  630. * Creates a new surface identical to the existing surface.
  631. *
  632. * The returned surface should be freed with SDL_DestroySurface().
  633. *
  634. * \param surface the surface to duplicate.
  635. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  636. * more information.
  637. *
  638. * \since This function is available since SDL 3.0.0.
  639. *
  640. * \sa SDL_DestroySurface
  641. */
  642. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  643. /**
  644. * Copy an existing surface to a new surface of the specified format.
  645. *
  646. * This function is used to optimize images for faster *repeat* blitting. This
  647. * is accomplished by converting the original and storing the result as a new
  648. * surface. The new, optimized surface can then be used as the source for
  649. * future blits, making them faster.
  650. *
  651. * If you are converting to an indexed surface and want to map colors to a
  652. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  653. *
  654. * \param surface the existing SDL_Surface structure to convert.
  655. * \param format the new pixel format.
  656. * \returns the new SDL_Surface structure that is created or NULL on failure;
  657. * call SDL_GetError() for more information.
  658. *
  659. * \since This function is available since SDL 3.0.0.
  660. *
  661. * \sa SDL_ConvertSurfaceAndColorspace
  662. * \sa SDL_DestroySurface
  663. */
  664. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  665. /**
  666. * Copy an existing surface to a new surface of the specified format and
  667. * colorspace.
  668. *
  669. * This function converts an existing surface to a new format and colorspace
  670. * and returns the new surface. This will perform any pixel format and
  671. * colorspace conversion needed.
  672. *
  673. * \param surface the existing SDL_Surface structure to convert.
  674. * \param format the new pixel format.
  675. * \param palette an optional palette to use for indexed formats, may be NULL.
  676. * \param colorspace the new colorspace.
  677. * \param props an SDL_PropertiesID with additional color properties, or 0.
  678. * \returns the new SDL_Surface structure that is created or NULL on failure;
  679. * call SDL_GetError() for more information.
  680. *
  681. * \since This function is available since SDL 3.0.0.
  682. *
  683. * \sa SDL_ConvertSurface
  684. * \sa SDL_ConvertSurface
  685. * \sa SDL_DestroySurface
  686. */
  687. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  688. /**
  689. * Copy a block of pixels of one format to another format.
  690. *
  691. * \param width the width of the block to copy, in pixels.
  692. * \param height the height of the block to copy, in pixels.
  693. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  694. * \param src a pointer to the source pixels.
  695. * \param src_pitch the pitch of the source pixels, in bytes.
  696. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  697. * \param dst a pointer to be filled in with new pixel data.
  698. * \param dst_pitch the pitch of the destination pixels, in bytes.
  699. * \returns 0 on success or a negative error code on failure; call
  700. * SDL_GetError() for more information.
  701. *
  702. * \since This function is available since SDL 3.0.0.
  703. *
  704. * \sa SDL_ConvertPixelsAndColorspace
  705. */
  706. extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch);
  707. /**
  708. * Copy a block of pixels of one format and colorspace to another format and
  709. * colorspace.
  710. *
  711. * \param width the width of the block to copy, in pixels.
  712. * \param height the height of the block to copy, in pixels.
  713. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  714. * \param src_colorspace an SDL_ColorSpace value describing the colorspace of
  715. * the `src` pixels.
  716. * \param src_properties an SDL_PropertiesID with additional source color
  717. * properties, or 0.
  718. * \param src a pointer to the source pixels.
  719. * \param src_pitch the pitch of the source pixels, in bytes.
  720. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  721. * \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
  722. * the `dst` pixels.
  723. * \param dst_properties an SDL_PropertiesID with additional destination color
  724. * properties, or 0.
  725. * \param dst a pointer to be filled in with new pixel data.
  726. * \param dst_pitch the pitch of the destination pixels, in bytes.
  727. * \returns 0 on success or a negative error code on failure; call
  728. * SDL_GetError() for more information.
  729. *
  730. * \since This function is available since SDL 3.0.0.
  731. *
  732. * \sa SDL_ConvertPixels
  733. */
  734. extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
  735. /**
  736. * Premultiply the alpha on a block of pixels.
  737. *
  738. * This is safe to use with src == dst, but not for other overlapping areas.
  739. *
  740. * \param width the width of the block to convert, in pixels.
  741. * \param height the height of the block to convert, in pixels.
  742. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  743. * \param src a pointer to the source pixels.
  744. * \param src_pitch the pitch of the source pixels, in bytes.
  745. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  746. * \param dst a pointer to be filled in with premultiplied pixel data.
  747. * \param dst_pitch the pitch of the destination pixels, in bytes.
  748. * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha
  749. * multiplication, SDL_FALSE to do multiplication in sRGB space.
  750. * \returns 0 on success or a negative error code on failure; call
  751. * SDL_GetError() for more information.
  752. *
  753. * \since This function is available since SDL 3.0.0.
  754. */
  755. extern SDL_DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, SDL_bool linear);
  756. /**
  757. * Premultiply the alpha in a surface.
  758. *
  759. * This is safe to use with src == dst, but not for other overlapping areas.
  760. *
  761. * \param surface the surface to modify.
  762. * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha
  763. * multiplication, SDL_FALSE to do multiplication in sRGB space.
  764. * \returns 0 on success or a negative error code on failure; call
  765. * SDL_GetError() for more information.
  766. *
  767. * \since This function is available since SDL 3.0.0.
  768. */
  769. extern SDL_DECLSPEC int SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear);
  770. /**
  771. * Clear a surface with a specific color, with floating point precision.
  772. *
  773. * This function handles all surface formats, and ignores any clip rectangle.
  774. *
  775. * If the surface is YUV, the color is assumed to be in the sRGB colorspace,
  776. * otherwise the color is assumed to be in the colorspace of the suface.
  777. *
  778. * \param surface the SDL_Surface to clear.
  779. * \param r the red component of the pixel, normally in the range 0-1.
  780. * \param g the green component of the pixel, normally in the range 0-1.
  781. * \param b the blue component of the pixel, normally in the range 0-1.
  782. * \param a the alpha component of the pixel, normally in the range 0-1.
  783. * \returns 0 on success or a negative error code on failure; call
  784. * SDL_GetError() for more information.
  785. *
  786. * \since This function is available since SDL 3.0.0.
  787. */
  788. extern SDL_DECLSPEC int SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a);
  789. /**
  790. * Perform a fast fill of a rectangle with a specific color.
  791. *
  792. * `color` should be a pixel of the format used by the surface, and can be
  793. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  794. * alpha component then the destination is simply filled with that alpha
  795. * information, no blending takes place.
  796. *
  797. * If there is a clip rectangle set on the destination (set via
  798. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  799. * intersection of the clip rectangle and `rect`.
  800. *
  801. * \param dst the SDL_Surface structure that is the drawing target.
  802. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  803. * NULL to fill the entire surface.
  804. * \param color the color to fill with.
  805. * \returns 0 on success or a negative error code on failure; call
  806. * SDL_GetError() for more information.
  807. *
  808. * \since This function is available since SDL 3.0.0.
  809. *
  810. * \sa SDL_FillSurfaceRects
  811. */
  812. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  813. /**
  814. * Perform a fast fill of a set of rectangles with a specific color.
  815. *
  816. * `color` should be a pixel of the format used by the surface, and can be
  817. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  818. * alpha component then the destination is simply filled with that alpha
  819. * information, no blending takes place.
  820. *
  821. * If there is a clip rectangle set on the destination (set via
  822. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  823. * intersection of the clip rectangle and `rect`.
  824. *
  825. * \param dst the SDL_Surface structure that is the drawing target.
  826. * \param rects an array of SDL_Rects representing the rectangles to fill.
  827. * \param count the number of rectangles in the array.
  828. * \param color the color to fill with.
  829. * \returns 0 on success or a negative error code on failure; call
  830. * SDL_GetError() for more information.
  831. *
  832. * \since This function is available since SDL 3.0.0.
  833. *
  834. * \sa SDL_FillSurfaceRect
  835. */
  836. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  837. /**
  838. * Performs a fast blit from the source surface to the destination surface.
  839. *
  840. * This assumes that the source and destination rectangles are the same size.
  841. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  842. * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
  843. * `dstrect` after all clipping is performed.
  844. *
  845. * The blit function should not be called on a locked surface.
  846. *
  847. * The blit semantics for surfaces with and without blending and colorkey are
  848. * defined as follows:
  849. *
  850. * ```
  851. * RGBA->RGB:
  852. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  853. * alpha-blend (using the source alpha-channel and per-surface alpha)
  854. * SDL_SRCCOLORKEY ignored.
  855. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  856. * copy RGB.
  857. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  858. * RGB values of the source color key, ignoring alpha in the
  859. * comparison.
  860. *
  861. * RGB->RGBA:
  862. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  863. * alpha-blend (using the source per-surface alpha)
  864. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  865. * copy RGB, set destination alpha to source per-surface alpha value.
  866. * both:
  867. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  868. * source color key.
  869. *
  870. * RGBA->RGBA:
  871. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  872. * alpha-blend (using the source alpha-channel and per-surface alpha)
  873. * SDL_SRCCOLORKEY ignored.
  874. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  875. * copy all of RGBA to the destination.
  876. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  877. * RGB values of the source color key, ignoring alpha in the
  878. * comparison.
  879. *
  880. * RGB->RGB:
  881. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  882. * alpha-blend (using the source per-surface alpha)
  883. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  884. * copy RGB.
  885. * both:
  886. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  887. * source color key.
  888. * ```
  889. *
  890. * \param src the SDL_Surface structure to be copied from.
  891. * \param srcrect the SDL_Rect structure representing the rectangle to be
  892. * copied, or NULL to copy the entire surface.
  893. * \param dst the SDL_Surface structure that is the blit target.
  894. * \param dstrect the SDL_Rect structure representing the x and y position in
  895. * the destination surface, or NULL for (0,0). The width and
  896. * height are ignored, and are copied from `srcrect`. If you
  897. * want a specific width and height, you should use
  898. * SDL_BlitSurfaceScaled().
  899. * \returns 0 on success or a negative error code on failure; call
  900. * SDL_GetError() for more information.
  901. *
  902. * \threadsafety The same destination surface should not be used from two
  903. * threads at once. It is safe to use the same source surface
  904. * from multiple threads.
  905. *
  906. * \since This function is available since SDL 3.0.0.
  907. *
  908. * \sa SDL_BlitSurfaceScaled
  909. */
  910. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  911. /**
  912. * Perform low-level surface blitting only.
  913. *
  914. * This is a semi-private blit function and it performs low-level surface
  915. * blitting, assuming the input rectangles have already been clipped.
  916. *
  917. * \param src the SDL_Surface structure to be copied from.
  918. * \param srcrect the SDL_Rect structure representing the rectangle to be
  919. * copied, may not be NULL.
  920. * \param dst the SDL_Surface structure that is the blit target.
  921. * \param dstrect the SDL_Rect structure representing the target rectangle in
  922. * the destination surface, may not be NULL.
  923. * \returns 0 on success or a negative error code on failure; call
  924. * SDL_GetError() for more information.
  925. *
  926. * \threadsafety The same destination surface should not be used from two
  927. * threads at once. It is safe to use the same source surface
  928. * from multiple threads.
  929. *
  930. * \since This function is available since SDL 3.0.0.
  931. *
  932. * \sa SDL_BlitSurface
  933. */
  934. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  935. /**
  936. * Perform a scaled blit to a destination surface, which may be of a different
  937. * format.
  938. *
  939. * \param src the SDL_Surface structure to be copied from.
  940. * \param srcrect the SDL_Rect structure representing the rectangle to be
  941. * copied, or NULL to copy the entire surface.
  942. * \param dst the SDL_Surface structure that is the blit target.
  943. * \param dstrect the SDL_Rect structure representing the target rectangle in
  944. * the destination surface, or NULL to fill the entire
  945. * destination surface.
  946. * \param scaleMode the SDL_ScaleMode to be used.
  947. * \returns 0 on success or a negative error code on failure; call
  948. * SDL_GetError() for more information.
  949. *
  950. * \threadsafety The same destination surface should not be used from two
  951. * threads at once. It is safe to use the same source surface
  952. * from multiple threads.
  953. *
  954. * \since This function is available since SDL 3.0.0.
  955. *
  956. * \sa SDL_BlitSurface
  957. */
  958. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  959. /**
  960. * Perform low-level surface scaled blitting only.
  961. *
  962. * This is a semi-private function and it performs low-level surface blitting,
  963. * assuming the input rectangles have already been clipped.
  964. *
  965. * \param src the SDL_Surface structure to be copied from.
  966. * \param srcrect the SDL_Rect structure representing the rectangle to be
  967. * copied, may not be NULL.
  968. * \param dst the SDL_Surface structure that is the blit target.
  969. * \param dstrect the SDL_Rect structure representing the target rectangle in
  970. * the destination surface, may not be NULL.
  971. * \param scaleMode scale algorithm to be used.
  972. * \returns 0 on success or a negative error code on failure; call
  973. * SDL_GetError() for more information.
  974. *
  975. * \threadsafety The same destination surface should not be used from two
  976. * threads at once. It is safe to use the same source surface
  977. * from multiple threads.
  978. *
  979. * \since This function is available since SDL 3.0.0.
  980. *
  981. * \sa SDL_BlitSurfaceScaled
  982. */
  983. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  984. /**
  985. * Perform a tiled blit to a destination surface, which may be of a different
  986. * format.
  987. *
  988. * The pixels in `srcrect` will be repeated as many times as needed to
  989. * completely fill `dstrect`.
  990. *
  991. * \param src the SDL_Surface structure to be copied from.
  992. * \param srcrect the SDL_Rect structure representing the rectangle to be
  993. * copied, or NULL to copy the entire surface.
  994. * \param dst the SDL_Surface structure that is the blit target.
  995. * \param dstrect the SDL_Rect structure representing the target rectangle in
  996. * the destination surface, or NULL to fill the entire surface.
  997. * \returns 0 on success or a negative error code on failure; call
  998. * SDL_GetError() for more information.
  999. *
  1000. * \threadsafety The same destination surface should not be used from two
  1001. * threads at once. It is safe to use the same source surface
  1002. * from multiple threads.
  1003. *
  1004. * \since This function is available since SDL 3.0.0.
  1005. *
  1006. * \sa SDL_BlitSurface
  1007. */
  1008. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1009. /**
  1010. * Perform a scaled and tiled blit to a destination surface, which may be of a
  1011. * different format.
  1012. *
  1013. * The pixels in `srcrect` will be scaled and repeated as many times as needed
  1014. * to completely fill `dstrect`.
  1015. *
  1016. * \param src the SDL_Surface structure to be copied from.
  1017. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1018. * copied, or NULL to copy the entire surface.
  1019. * \param scale the scale used to transform srcrect into the destination
  1020. * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
  1021. * 64x64 tiles.
  1022. * \param scaleMode scale algorithm to be used.
  1023. * \param dst the SDL_Surface structure that is the blit target.
  1024. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1025. * the destination surface, or NULL to fill the entire surface.
  1026. * \returns 0 on success or a negative error code on failure; call
  1027. * SDL_GetError() for more information.
  1028. *
  1029. * \threadsafety The same destination surface should not be used from two
  1030. * threads at once. It is safe to use the same source surface
  1031. * from multiple threads.
  1032. *
  1033. * \since This function is available since SDL 3.0.0.
  1034. *
  1035. * \sa SDL_BlitSurface
  1036. */
  1037. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect);
  1038. /**
  1039. * Perform a scaled blit using the 9-grid algorithm to a destination surface,
  1040. * which may be of a different format.
  1041. *
  1042. * The pixels in the source surface are split into a 3x3 grid, using the
  1043. * corner size for each corner, and the sides and center making up the
  1044. * remaining pixels. The corners are then scaled using `scale` and fit into
  1045. * the corners of the destination rectangle. The sides and center are then
  1046. * stretched into place to cover the remaining destination rectangle.
  1047. *
  1048. * \param src the SDL_Surface structure to be copied from.
  1049. * \param srcrect the SDL_Rect structure representing the rectangle to be used
  1050. * for the 9-grid, or NULL to use the entire surface.
  1051. * \param corner_size the size, in pixels, of the corner in `srcrect`.
  1052. * \param scale the scale used to transform the corner of `srcrect` into the
  1053. * corner of `dstrect`, or 0.0f for an unscaled blit.
  1054. * \param scaleMode scale algorithm to be used.
  1055. * \param dst the SDL_Surface structure that is the blit target.
  1056. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1057. * the destination surface, or NULL to fill the entire surface.
  1058. * \returns 0 on success or a negative error code on failure; call
  1059. * SDL_GetError() for more information.
  1060. *
  1061. * \threadsafety The same destination surface should not be used from two
  1062. * threads at once. It is safe to use the same source surface
  1063. * from multiple threads.
  1064. *
  1065. * \since This function is available since SDL 3.0.0.
  1066. *
  1067. * \sa SDL_BlitSurface
  1068. */
  1069. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int corner_size, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect);
  1070. /**
  1071. * Map an RGB triple to an opaque pixel value for a surface.
  1072. *
  1073. * This function maps the RGB color value to the specified pixel format and
  1074. * returns the pixel value best approximating the given RGB color value for
  1075. * the given pixel format.
  1076. *
  1077. * If the surface has a palette, the index of the closest matching color in
  1078. * the palette will be returned.
  1079. *
  1080. * If the surface pixel format has an alpha component it will be returned as
  1081. * all 1 bits (fully opaque).
  1082. *
  1083. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1084. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1085. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1086. * for an 8-bpp format).
  1087. *
  1088. * \param surface the surface to use for the pixel format and palette.
  1089. * \param r the red component of the pixel in the range 0-255.
  1090. * \param g the green component of the pixel in the range 0-255.
  1091. * \param b the blue component of the pixel in the range 0-255.
  1092. * \returns a pixel value.
  1093. *
  1094. * \since This function is available since SDL 3.0.0.
  1095. *
  1096. * \sa SDL_MapSurfaceRGBA
  1097. */
  1098. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  1099. /**
  1100. * Map an RGBA quadruple to a pixel value for a surface.
  1101. *
  1102. * This function maps the RGBA color value to the specified pixel format and
  1103. * returns the pixel value best approximating the given RGBA color value for
  1104. * the given pixel format.
  1105. *
  1106. * If the surface pixel format has no alpha component the alpha value will be
  1107. * ignored (as it will be in formats with a palette).
  1108. *
  1109. * If the surface has a palette, the index of the closest matching color in
  1110. * the palette will be returned.
  1111. *
  1112. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1113. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1114. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1115. * for an 8-bpp format).
  1116. *
  1117. * \param surface the surface to use for the pixel format and palette.
  1118. * \param r the red component of the pixel in the range 0-255.
  1119. * \param g the green component of the pixel in the range 0-255.
  1120. * \param b the blue component of the pixel in the range 0-255.
  1121. * \param a the alpha component of the pixel in the range 0-255.
  1122. * \returns a pixel value.
  1123. *
  1124. * \since This function is available since SDL 3.0.0.
  1125. *
  1126. * \sa SDL_MapSurfaceRGB
  1127. */
  1128. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1129. /**
  1130. * Retrieves a single pixel from a surface.
  1131. *
  1132. * This function prioritizes correctness over speed: it is suitable for unit
  1133. * tests, but is not intended for use in a game engine.
  1134. *
  1135. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1136. * components from pixel formats with less than 8 bits per RGB component.
  1137. *
  1138. * \param surface the surface to read.
  1139. * \param x the horizontal coordinate, 0 <= x < width.
  1140. * \param y the vertical coordinate, 0 <= y < height.
  1141. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1142. * this channel.
  1143. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1144. * ignore this channel.
  1145. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1146. * ignore this channel.
  1147. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1148. * ignore this channel.
  1149. * \returns 0 on success or a negative error code on failure; call
  1150. * SDL_GetError() for more information.
  1151. *
  1152. * \since This function is available since SDL 3.0.0.
  1153. */
  1154. extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1155. /**
  1156. * Retrieves a single pixel from a surface.
  1157. *
  1158. * This function prioritizes correctness over speed: it is suitable for unit
  1159. * tests, but is not intended for use in a game engine.
  1160. *
  1161. * \param surface the surface to read.
  1162. * \param x the horizontal coordinate, 0 <= x < width.
  1163. * \param y the vertical coordinate, 0 <= y < height.
  1164. * \param r a pointer filled in with the red channel, normally in the range
  1165. * 0-1, or NULL to ignore this channel.
  1166. * \param g a pointer filled in with the green channel, normally in the range
  1167. * 0-1, or NULL to ignore this channel.
  1168. * \param b a pointer filled in with the blue channel, normally in the range
  1169. * 0-1, or NULL to ignore this channel.
  1170. * \param a a pointer filled in with the alpha channel, normally in the range
  1171. * 0-1, or NULL to ignore this channel.
  1172. * \returns 0 on success or a negative error code on failure; call
  1173. * SDL_GetError() for more information.
  1174. *
  1175. * \since This function is available since SDL 3.0.0.
  1176. */
  1177. extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a);
  1178. /**
  1179. * Writes a single pixel to a surface.
  1180. *
  1181. * This function prioritizes correctness over speed: it is suitable for unit
  1182. * tests, but is not intended for use in a game engine.
  1183. *
  1184. * Like SDL_MapRGBA, this uses the entire 0..255 range when converting color
  1185. * components from pixel formats with less than 8 bits per RGB component.
  1186. *
  1187. * \param surface the surface to write.
  1188. * \param x the horizontal coordinate, 0 <= x < width.
  1189. * \param y the vertical coordinate, 0 <= y < height.
  1190. * \param r the red channel value, 0-255.
  1191. * \param g the green channel value, 0-255.
  1192. * \param b the blue channel value, 0-255.
  1193. * \param a the alpha channel value, 0-255.
  1194. * \returns 0 on success or a negative error code on failure; call
  1195. * SDL_GetError() for more information.
  1196. *
  1197. * \since This function is available since SDL 3.0.0.
  1198. */
  1199. extern SDL_DECLSPEC int SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1200. /**
  1201. * Writes a single pixel to a surface.
  1202. *
  1203. * This function prioritizes correctness over speed: it is suitable for unit
  1204. * tests, but is not intended for use in a game engine.
  1205. *
  1206. * \param surface the surface to write.
  1207. * \param x the horizontal coordinate, 0 <= x < width.
  1208. * \param y the vertical coordinate, 0 <= y < height.
  1209. * \param r the red channel value, normally in the range 0-1.
  1210. * \param g the green channel value, normally in the range 0-1.
  1211. * \param b the blue channel value, normally in the range 0-1.
  1212. * \param a the alpha channel value, normally in the range 0-1.
  1213. * \returns 0 on success or a negative error code on failure; call
  1214. * SDL_GetError() for more information.
  1215. *
  1216. * \since This function is available since SDL 3.0.0.
  1217. */
  1218. extern SDL_DECLSPEC int SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a);
  1219. /* Ends C function definitions when using C++ */
  1220. #ifdef __cplusplus
  1221. }
  1222. #endif
  1223. #include <SDL3/SDL_close_code.h>
  1224. #endif /* SDL_surface_h_ */