SDL_surface.h 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
  168. * the surface colorspace, defaults to SDL_COLORSPACE_SRGB_LINEAR for
  169. * floating point formats, SDL_COLORSPACE_HDR10 for 10-bit formats,
  170. * SDL_COLORSPACE_SRGB for other RGB surfaces and SDL_COLORSPACE_BT709_FULL
  171. * for YUV surfaces.
  172. * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  173. * surfaces, this defines the value of 100% diffuse white, with higher
  174. * values being displayed in the High Dynamic Range headroom. This defaults
  175. * to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
  176. * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
  177. * surfaces, this defines the maximum dynamic range used by the content, in
  178. * terms of the SDR white point. This defaults to 0.0, which disables tone
  179. * mapping.
  180. * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
  181. * used when compressing from a surface with high dynamic range to another
  182. * with lower dynamic range. Currently this supports "chrome", which uses
  183. * the same tone mapping that Chrome uses for HDR content, the form "*=N",
  184. * where N is a floating point scale factor applied in linear space, and
  185. * "none", which disables tone mapping. This defaults to "chrome".
  186. *
  187. * \param surface the SDL_Surface structure to query.
  188. * \returns a valid property ID on success or 0 on failure; call
  189. * SDL_GetError() for more information.
  190. *
  191. * \since This function is available since SDL 3.0.0.
  192. */
  193. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
  194. #define SDL_PROP_SURFACE_COLORSPACE_NUMBER "SDL.surface.colorspace"
  195. #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
  196. #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
  197. #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
  198. /**
  199. * Set the colorspace used by a surface.
  200. *
  201. * Setting the colorspace doesn't change the pixels, only how they are
  202. * interpreted in color operations.
  203. *
  204. * \param surface the SDL_Surface structure to update.
  205. * \param colorspace an SDL_ColorSpace value describing the surface
  206. * colorspace.
  207. * \returns 0 on success or a negative error code on failure; call
  208. * SDL_GetError() for more information.
  209. *
  210. * \since This function is available since SDL 3.0.0.
  211. *
  212. * \sa SDL_GetSurfaceColorspace
  213. */
  214. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
  215. /**
  216. * Get the colorspace used by a surface.
  217. *
  218. * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
  219. * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
  220. * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
  221. *
  222. * \param surface the SDL_Surface structure to query.
  223. * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
  224. * the surface is NULL.
  225. *
  226. * \since This function is available since SDL 3.0.0.
  227. *
  228. * \sa SDL_SetSurfaceColorspace
  229. */
  230. extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
  231. /**
  232. * Create a palette and associate it with a surface.
  233. *
  234. * This function creates a palette compatible with the provided surface. The
  235. * palette is then returned for you to modify, and the surface will
  236. * automatically use the new palette in future operations. You do not need to
  237. * destroy the returned palette, it will be freed when the reference count
  238. * reaches 0, usually when the surface is destroyed.
  239. *
  240. * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
  241. * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
  242. * white and 1 as black. Other surfaces will get a palette initialized with
  243. * white in every entry.
  244. *
  245. * If this function is called for a surface that already has a palette, a new
  246. * palette will be created to replace it.
  247. *
  248. * \param surface the SDL_Surface structure to update.
  249. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  250. * the surface didn't have an index format); call SDL_GetError() for
  251. * more information.
  252. *
  253. * \since This function is available since SDL 3.0.0.
  254. *
  255. * \sa SDL_SetPaletteColors
  256. */
  257. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
  258. /**
  259. * Set the palette used by a surface.
  260. *
  261. * A single palette can be shared with many surfaces.
  262. *
  263. * \param surface the SDL_Surface structure to update.
  264. * \param palette the SDL_Palette structure to use.
  265. * \returns 0 on success or a negative error code on failure; call
  266. * SDL_GetError() for more information.
  267. *
  268. * \since This function is available since SDL 3.0.0.
  269. *
  270. * \sa SDL_CreatePalette
  271. * \sa SDL_GetSurfacePalette
  272. */
  273. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  274. /**
  275. * Get the palette used by a surface.
  276. *
  277. * \param surface the SDL_Surface structure to query.
  278. * \returns a pointer to the palette used by the surface, or NULL if there is
  279. * no palette used.
  280. *
  281. * \since This function is available since SDL 3.0.0.
  282. *
  283. * \sa SDL_SetSurfacePalette
  284. */
  285. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
  286. /**
  287. * Set up a surface for directly accessing the pixels.
  288. *
  289. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  290. * and read from `surface->pixels`, using the pixel format stored in
  291. * `surface->format`. Once you are done accessing the surface, you should use
  292. * SDL_UnlockSurface() to release it.
  293. *
  294. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  295. * 0, then you can read and write to the surface at any time, and the pixel
  296. * format of the surface will not change.
  297. *
  298. * \param surface the SDL_Surface structure to be locked.
  299. * \returns 0 on success or a negative error code on failure; call
  300. * SDL_GetError() for more information.
  301. *
  302. * \since This function is available since SDL 3.0.0.
  303. *
  304. * \sa SDL_MUSTLOCK
  305. * \sa SDL_UnlockSurface
  306. */
  307. extern SDL_DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
  308. /**
  309. * Release a surface after directly accessing the pixels.
  310. *
  311. * \param surface the SDL_Surface structure to be unlocked.
  312. *
  313. * \since This function is available since SDL 3.0.0.
  314. *
  315. * \sa SDL_LockSurface
  316. */
  317. extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  318. /**
  319. * Load a BMP image from a seekable SDL data stream.
  320. *
  321. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  322. * will result in a memory leak.
  323. *
  324. * \param src the data stream for the surface.
  325. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  326. * even in the case of an error.
  327. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  328. * SDL_GetError() for more information.
  329. *
  330. * \since This function is available since SDL 3.0.0.
  331. *
  332. * \sa SDL_DestroySurface
  333. * \sa SDL_LoadBMP
  334. * \sa SDL_SaveBMP_IO
  335. */
  336. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio);
  337. /**
  338. * Load a BMP image from a file.
  339. *
  340. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  341. * will result in a memory leak.
  342. *
  343. * \param file the BMP file to load.
  344. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  345. * SDL_GetError() for more information.
  346. *
  347. * \since This function is available since SDL 3.0.0.
  348. *
  349. * \sa SDL_DestroySurface
  350. * \sa SDL_LoadBMP_IO
  351. * \sa SDL_SaveBMP
  352. */
  353. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
  354. /**
  355. * Save a surface to a seekable SDL data stream in BMP format.
  356. *
  357. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  358. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  359. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  360. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  361. * not supported.
  362. *
  363. * \param surface the SDL_Surface structure containing the image to be saved.
  364. * \param dst a data stream to save to.
  365. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `dst` before returning,
  366. * even in the case of an error.
  367. * \returns 0 on success or a negative error code on failure; call
  368. * SDL_GetError() for more information.
  369. *
  370. * \since This function is available since SDL 3.0.0.
  371. *
  372. * \sa SDL_LoadBMP_IO
  373. * \sa SDL_SaveBMP
  374. */
  375. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio);
  376. /**
  377. * Save a surface to a file.
  378. *
  379. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  380. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  381. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  382. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  383. * not supported.
  384. *
  385. * \param surface the SDL_Surface structure containing the image to be saved.
  386. * \param file a file to save to.
  387. * \returns 0 on success or a negative error code on failure; call
  388. * SDL_GetError() for more information.
  389. *
  390. * \since This function is available since SDL 3.0.0.
  391. *
  392. * \sa SDL_LoadBMP
  393. * \sa SDL_SaveBMP_IO
  394. */
  395. extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  396. /**
  397. * Set the RLE acceleration hint for a surface.
  398. *
  399. * If RLE is enabled, color key and alpha blending blits are much faster, but
  400. * the surface must be locked before directly accessing the pixels.
  401. *
  402. * \param surface the SDL_Surface structure to optimize.
  403. * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable
  404. * it.
  405. * \returns 0 on success or a negative error code on failure; call
  406. * SDL_GetError() for more information.
  407. *
  408. * \since This function is available since SDL 3.0.0.
  409. *
  410. * \sa SDL_BlitSurface
  411. * \sa SDL_LockSurface
  412. * \sa SDL_UnlockSurface
  413. */
  414. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled);
  415. /**
  416. * Returns whether the surface is RLE enabled.
  417. *
  418. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  419. *
  420. * \param surface the SDL_Surface structure to query.
  421. * \returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise.
  422. *
  423. * \since This function is available since SDL 3.0.0.
  424. *
  425. * \sa SDL_SetSurfaceRLE
  426. */
  427. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  428. /**
  429. * Set the color key (transparent pixel) in a surface.
  430. *
  431. * The color key defines a pixel value that will be treated as transparent in
  432. * a blit. For example, one can use this to specify that cyan pixels should be
  433. * considered transparent, and therefore not rendered.
  434. *
  435. * It is a pixel of the format used by the surface, as generated by
  436. * SDL_MapRGB().
  437. *
  438. * \param surface the SDL_Surface structure to update.
  439. * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color
  440. * key.
  441. * \param key the transparent pixel.
  442. * \returns 0 on success or a negative error code on failure; call
  443. * SDL_GetError() for more information.
  444. *
  445. * \since This function is available since SDL 3.0.0.
  446. *
  447. * \sa SDL_GetSurfaceColorKey
  448. * \sa SDL_SetSurfaceRLE
  449. * \sa SDL_SurfaceHasColorKey
  450. */
  451. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key);
  452. /**
  453. * Returns whether the surface has a color key.
  454. *
  455. * It is safe to pass a NULL `surface` here; it will return SDL_FALSE.
  456. *
  457. * \param surface the SDL_Surface structure to query.
  458. * \returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise.
  459. *
  460. * \since This function is available since SDL 3.0.0.
  461. *
  462. * \sa SDL_SetSurfaceColorKey
  463. * \sa SDL_GetSurfaceColorKey
  464. */
  465. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  466. /**
  467. * Get the color key (transparent pixel) for a surface.
  468. *
  469. * The color key is a pixel of the format used by the surface, as generated by
  470. * SDL_MapRGB().
  471. *
  472. * If the surface doesn't have color key enabled this function returns -1.
  473. *
  474. * \param surface the SDL_Surface structure to query.
  475. * \param key a pointer filled in with the transparent pixel.
  476. * \returns 0 on success or a negative error code on failure; call
  477. * SDL_GetError() for more information.
  478. *
  479. * \since This function is available since SDL 3.0.0.
  480. *
  481. * \sa SDL_SetSurfaceColorKey
  482. * \sa SDL_SurfaceHasColorKey
  483. */
  484. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  485. /**
  486. * Set an additional color value multiplied into blit operations.
  487. *
  488. * When this surface is blitted, during the blit operation each source color
  489. * channel is modulated by the appropriate color value according to the
  490. * following formula:
  491. *
  492. * `srcC = srcC * (color / 255)`
  493. *
  494. * \param surface the SDL_Surface structure to update.
  495. * \param r the red color value multiplied into blit operations.
  496. * \param g the green color value multiplied into blit operations.
  497. * \param b the blue color value multiplied into blit operations.
  498. * \returns 0 on success or a negative error code on failure; call
  499. * SDL_GetError() for more information.
  500. *
  501. * \since This function is available since SDL 3.0.0.
  502. *
  503. * \sa SDL_GetSurfaceColorMod
  504. * \sa SDL_SetSurfaceAlphaMod
  505. */
  506. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  507. /**
  508. * Get the additional color value multiplied into blit operations.
  509. *
  510. * \param surface the SDL_Surface structure to query.
  511. * \param r a pointer filled in with the current red color value.
  512. * \param g a pointer filled in with the current green color value.
  513. * \param b a pointer filled in with the current blue color value.
  514. * \returns 0 on success or a negative error code on failure; call
  515. * SDL_GetError() for more information.
  516. *
  517. * \since This function is available since SDL 3.0.0.
  518. *
  519. * \sa SDL_GetSurfaceAlphaMod
  520. * \sa SDL_SetSurfaceColorMod
  521. */
  522. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  523. /**
  524. * Set an additional alpha value used in blit operations.
  525. *
  526. * When this surface is blitted, during the blit operation the source alpha
  527. * value is modulated by this alpha value according to the following formula:
  528. *
  529. * `srcA = srcA * (alpha / 255)`
  530. *
  531. * \param surface the SDL_Surface structure to update.
  532. * \param alpha the alpha value multiplied into blit operations.
  533. * \returns 0 on success or a negative error code on failure; call
  534. * SDL_GetError() for more information.
  535. *
  536. * \since This function is available since SDL 3.0.0.
  537. *
  538. * \sa SDL_GetSurfaceAlphaMod
  539. * \sa SDL_SetSurfaceColorMod
  540. */
  541. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  542. /**
  543. * Get the additional alpha value used in blit operations.
  544. *
  545. * \param surface the SDL_Surface structure to query.
  546. * \param alpha a pointer filled in with the current alpha value.
  547. * \returns 0 on success or a negative error code on failure; call
  548. * SDL_GetError() for more information.
  549. *
  550. * \since This function is available since SDL 3.0.0.
  551. *
  552. * \sa SDL_GetSurfaceColorMod
  553. * \sa SDL_SetSurfaceAlphaMod
  554. */
  555. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  556. /**
  557. * Set the blend mode used for blit operations.
  558. *
  559. * To copy a surface to another surface (or texture) without blending with the
  560. * existing data, the blendmode of the SOURCE surface should be set to
  561. * `SDL_BLENDMODE_NONE`.
  562. *
  563. * \param surface the SDL_Surface structure to update.
  564. * \param blendMode the SDL_BlendMode to use for blit blending.
  565. * \returns 0 on success or a negative error code on failure; call
  566. * SDL_GetError() for more information.
  567. *
  568. * \since This function is available since SDL 3.0.0.
  569. *
  570. * \sa SDL_GetSurfaceBlendMode
  571. */
  572. extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  573. /**
  574. * Get the blend mode used for blit operations.
  575. *
  576. * \param surface the SDL_Surface structure to query.
  577. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  578. * \returns 0 on success or a negative error code on failure; call
  579. * SDL_GetError() for more information.
  580. *
  581. * \since This function is available since SDL 3.0.0.
  582. *
  583. * \sa SDL_SetSurfaceBlendMode
  584. */
  585. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  586. /**
  587. * Set the clipping rectangle for a surface.
  588. *
  589. * When `surface` is the destination of a blit, only the area within the clip
  590. * rectangle is drawn into.
  591. *
  592. * Note that blits are automatically clipped to the edges of the source and
  593. * destination surfaces.
  594. *
  595. * \param surface the SDL_Surface structure to be clipped.
  596. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  597. * NULL to disable clipping.
  598. * \returns SDL_TRUE if the rectangle intersects the surface, otherwise
  599. * SDL_FALSE and blits will be completely clipped.
  600. *
  601. * \since This function is available since SDL 3.0.0.
  602. *
  603. * \sa SDL_GetSurfaceClipRect
  604. */
  605. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  606. /**
  607. * Get the clipping rectangle for a surface.
  608. *
  609. * When `surface` is the destination of a blit, only the area within the clip
  610. * rectangle is drawn into.
  611. *
  612. * \param surface the SDL_Surface structure representing the surface to be
  613. * clipped.
  614. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  615. * the surface.
  616. * \returns 0 on success or a negative error code on failure; call
  617. * SDL_GetError() for more information.
  618. *
  619. * \since This function is available since SDL 3.0.0.
  620. *
  621. * \sa SDL_SetSurfaceClipRect
  622. */
  623. extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  624. /**
  625. * Flip a surface vertically or horizontally.
  626. *
  627. * \param surface the surface to flip.
  628. * \param flip the direction to flip.
  629. * \returns 0 on success or a negative error code on failure; call
  630. * SDL_GetError() for more information.
  631. *
  632. * \since This function is available since SDL 3.0.0.
  633. */
  634. extern SDL_DECLSPEC int SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  635. /**
  636. * Creates a new surface identical to the existing surface.
  637. *
  638. * The returned surface should be freed with SDL_DestroySurface().
  639. *
  640. * \param surface the surface to duplicate.
  641. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  642. * more information.
  643. *
  644. * \since This function is available since SDL 3.0.0.
  645. *
  646. * \sa SDL_DestroySurface
  647. */
  648. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  649. /**
  650. * Copy an existing surface to a new surface of the specified format.
  651. *
  652. * This function is used to optimize images for faster *repeat* blitting. This
  653. * is accomplished by converting the original and storing the result as a new
  654. * surface. The new, optimized surface can then be used as the source for
  655. * future blits, making them faster.
  656. *
  657. * If you are converting to an indexed surface and want to map colors to a
  658. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  659. *
  660. * \param surface the existing SDL_Surface structure to convert.
  661. * \param format the new pixel format.
  662. * \returns the new SDL_Surface structure that is created or NULL on failure;
  663. * call SDL_GetError() for more information.
  664. *
  665. * \since This function is available since SDL 3.0.0.
  666. *
  667. * \sa SDL_ConvertSurfaceAndColorspace
  668. * \sa SDL_DestroySurface
  669. */
  670. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  671. /**
  672. * Copy an existing surface to a new surface of the specified format and
  673. * colorspace.
  674. *
  675. * This function converts an existing surface to a new format and colorspace
  676. * and returns the new surface. This will perform any pixel format and
  677. * colorspace conversion needed.
  678. *
  679. * \param surface the existing SDL_Surface structure to convert.
  680. * \param format the new pixel format.
  681. * \param palette an optional palette to use for indexed formats, may be NULL.
  682. * \param colorspace the new colorspace.
  683. * \param props an SDL_PropertiesID with additional color properties, or 0.
  684. * \returns the new SDL_Surface structure that is created or NULL on failure;
  685. * call SDL_GetError() for more information.
  686. *
  687. * \since This function is available since SDL 3.0.0.
  688. *
  689. * \sa SDL_ConvertSurface
  690. * \sa SDL_ConvertSurface
  691. * \sa SDL_DestroySurface
  692. */
  693. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  694. /**
  695. * Copy a block of pixels of one format to another format.
  696. *
  697. * \param width the width of the block to copy, in pixels.
  698. * \param height the height of the block to copy, in pixels.
  699. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  700. * \param src a pointer to the source pixels.
  701. * \param src_pitch the pitch of the source pixels, in bytes.
  702. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  703. * \param dst a pointer to be filled in with new pixel data.
  704. * \param dst_pitch the pitch of the destination pixels, in bytes.
  705. * \returns 0 on success or a negative error code on failure; call
  706. * SDL_GetError() for more information.
  707. *
  708. * \since This function is available since SDL 3.0.0.
  709. *
  710. * \sa SDL_ConvertPixelsAndColorspace
  711. */
  712. 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);
  713. /**
  714. * Copy a block of pixels of one format and colorspace to another format and
  715. * colorspace.
  716. *
  717. * \param width the width of the block to copy, in pixels.
  718. * \param height the height of the block to copy, in pixels.
  719. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  720. * \param src_colorspace an SDL_ColorSpace value describing the colorspace of
  721. * the `src` pixels.
  722. * \param src_properties an SDL_PropertiesID with additional source color
  723. * properties, or 0.
  724. * \param src a pointer to the source pixels.
  725. * \param src_pitch the pitch of the source pixels, in bytes.
  726. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  727. * \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
  728. * the `dst` pixels.
  729. * \param dst_properties an SDL_PropertiesID with additional destination color
  730. * properties, or 0.
  731. * \param dst a pointer to be filled in with new pixel data.
  732. * \param dst_pitch the pitch of the destination pixels, in bytes.
  733. * \returns 0 on success or a negative error code on failure; call
  734. * SDL_GetError() for more information.
  735. *
  736. * \since This function is available since SDL 3.0.0.
  737. *
  738. * \sa SDL_ConvertPixels
  739. */
  740. 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);
  741. /**
  742. * Premultiply the alpha on a block of pixels.
  743. *
  744. * This is safe to use with src == dst, but not for other overlapping areas.
  745. *
  746. * \param width the width of the block to convert, in pixels.
  747. * \param height the height of the block to convert, in pixels.
  748. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  749. * \param src a pointer to the source pixels.
  750. * \param src_pitch the pitch of the source pixels, in bytes.
  751. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  752. * \param dst a pointer to be filled in with premultiplied pixel data.
  753. * \param dst_pitch the pitch of the destination pixels, in bytes.
  754. * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha
  755. * multiplication, SDL_FALSE to do multiplication in sRGB space.
  756. * \returns 0 on success or a negative error code on failure; call
  757. * SDL_GetError() for more information.
  758. *
  759. * \since This function is available since SDL 3.0.0.
  760. */
  761. 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);
  762. /**
  763. * Premultiply the alpha in a surface.
  764. *
  765. * This is safe to use with src == dst, but not for other overlapping areas.
  766. *
  767. * \param surface the surface to modify.
  768. * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha
  769. * multiplication, SDL_FALSE to do multiplication in sRGB space.
  770. * \returns 0 on success or a negative error code on failure; call
  771. * SDL_GetError() for more information.
  772. *
  773. * \since This function is available since SDL 3.0.0.
  774. */
  775. extern SDL_DECLSPEC int SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear);
  776. /**
  777. * Clear a surface with a specific color, with floating point precision.
  778. *
  779. * This function handles all surface formats, and ignores any clip rectangle.
  780. *
  781. * If the surface is YUV, the color is assumed to be in the sRGB colorspace,
  782. * otherwise the color is assumed to be in the colorspace of the suface.
  783. *
  784. * \param surface the SDL_Surface to clear.
  785. * \param r the red component of the pixel, normally in the range 0-1.
  786. * \param g the green component of the pixel, normally in the range 0-1.
  787. * \param b the blue component of the pixel, normally in the range 0-1.
  788. * \param a the alpha component of the pixel, normally in the range 0-1.
  789. * \returns 0 on success or a negative error code on failure; call
  790. * SDL_GetError() for more information.
  791. *
  792. * \since This function is available since SDL 3.0.0.
  793. */
  794. extern SDL_DECLSPEC int SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a);
  795. /**
  796. * Perform a fast fill of a rectangle with a specific color.
  797. *
  798. * `color` should be a pixel of the format used by the surface, and can be
  799. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  800. * alpha component then the destination is simply filled with that alpha
  801. * information, no blending takes place.
  802. *
  803. * If there is a clip rectangle set on the destination (set via
  804. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  805. * intersection of the clip rectangle and `rect`.
  806. *
  807. * \param dst the SDL_Surface structure that is the drawing target.
  808. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  809. * NULL to fill the entire surface.
  810. * \param color the color to fill with.
  811. * \returns 0 on success or a negative error code on failure; call
  812. * SDL_GetError() for more information.
  813. *
  814. * \since This function is available since SDL 3.0.0.
  815. *
  816. * \sa SDL_FillSurfaceRects
  817. */
  818. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  819. /**
  820. * Perform a fast fill of a set of rectangles with a specific color.
  821. *
  822. * `color` should be a pixel of the format used by the surface, and can be
  823. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  824. * alpha component then the destination is simply filled with that alpha
  825. * information, no blending takes place.
  826. *
  827. * If there is a clip rectangle set on the destination (set via
  828. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  829. * intersection of the clip rectangle and `rect`.
  830. *
  831. * \param dst the SDL_Surface structure that is the drawing target.
  832. * \param rects an array of SDL_Rects representing the rectangles to fill.
  833. * \param count the number of rectangles in the array.
  834. * \param color the color to fill with.
  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_FillSurfaceRect
  841. */
  842. extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  843. /**
  844. * Performs a fast blit from the source surface to the destination surface.
  845. *
  846. * This assumes that the source and destination rectangles are the same size.
  847. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  848. * `dst`) is copied. The final blit rectangles are saved in `srcrect` and
  849. * `dstrect` after all clipping is performed.
  850. *
  851. * The blit function should not be called on a locked surface.
  852. *
  853. * The blit semantics for surfaces with and without blending and colorkey are
  854. * defined as follows:
  855. *
  856. * ```
  857. * RGBA->RGB:
  858. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  859. * alpha-blend (using the source alpha-channel and per-surface alpha)
  860. * SDL_SRCCOLORKEY ignored.
  861. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  862. * copy RGB.
  863. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  864. * RGB values of the source color key, ignoring alpha in the
  865. * comparison.
  866. *
  867. * RGB->RGBA:
  868. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  869. * alpha-blend (using the source per-surface alpha)
  870. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  871. * copy RGB, set destination alpha to source per-surface alpha value.
  872. * both:
  873. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  874. * source color key.
  875. *
  876. * RGBA->RGBA:
  877. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  878. * alpha-blend (using the source alpha-channel and per-surface alpha)
  879. * SDL_SRCCOLORKEY ignored.
  880. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  881. * copy all of RGBA to the destination.
  882. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  883. * RGB values of the source color key, ignoring alpha in the
  884. * comparison.
  885. *
  886. * RGB->RGB:
  887. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  888. * alpha-blend (using the source per-surface alpha)
  889. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  890. * copy RGB.
  891. * both:
  892. * if SDL_SRCCOLORKEY set, only copy the pixels matching the
  893. * source color key.
  894. * ```
  895. *
  896. * \param src the SDL_Surface structure to be copied from.
  897. * \param srcrect the SDL_Rect structure representing the rectangle to be
  898. * copied, or NULL to copy the entire surface.
  899. * \param dst the SDL_Surface structure that is the blit target.
  900. * \param dstrect the SDL_Rect structure representing the x and y position in
  901. * the destination surface. On input the width and height are
  902. * ignored (taken from srcrect), and on output this is filled
  903. * in with the actual rectangle used after clipping.
  904. * \returns 0 on success or a negative error code on failure; call
  905. * SDL_GetError() for more information.
  906. *
  907. * \threadsafety The same destination surface should not be used from two
  908. * threads at once. It is safe to use the same source surface
  909. * from multiple threads.
  910. *
  911. * \since This function is available since SDL 3.0.0.
  912. *
  913. * \sa SDL_BlitSurfaceScaled
  914. */
  915. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
  916. /**
  917. * Perform low-level surface blitting only.
  918. *
  919. * This is a semi-private blit function and it performs low-level surface
  920. * blitting, assuming the input rectangles have already been clipped.
  921. *
  922. * \param src the SDL_Surface structure to be copied from.
  923. * \param srcrect the SDL_Rect structure representing the rectangle to be
  924. * copied, or NULL to copy the entire surface.
  925. * \param dst the SDL_Surface structure that is the blit target.
  926. * \param dstrect the SDL_Rect structure representing the target rectangle in
  927. * the destination surface.
  928. * \returns 0 on success or a negative error code on failure; call
  929. * SDL_GetError() for more information.
  930. *
  931. * \threadsafety The same destination surface should not be used from two
  932. * threads at once. It is safe to use the same source surface
  933. * from multiple threads.
  934. *
  935. * \since This function is available since SDL 3.0.0.
  936. *
  937. * \sa SDL_BlitSurface
  938. */
  939. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  940. /**
  941. * Perform stretch blit between two surfaces of the same format.
  942. *
  943. * Using SDL_SCALEMODE_NEAREST: fast, low quality. Using SDL_SCALEMODE_LINEAR:
  944. * bilinear scaling, slower, better quality, only 32BPP.
  945. *
  946. * \param src the SDL_Surface structure to be copied from.
  947. * \param srcrect the SDL_Rect structure representing the rectangle to be
  948. * copied.
  949. * \param dst the SDL_Surface structure that is the blit target.
  950. * \param dstrect the SDL_Rect structure representing the target rectangle in
  951. * the destination surface.
  952. * \param scaleMode scale algorithm to be used.
  953. * \returns 0 on success or a negative error code on failure; call
  954. * SDL_GetError() for more information.
  955. *
  956. * \since This function is available since SDL 3.0.0.
  957. *
  958. * \sa SDL_BlitSurfaceScaled
  959. */
  960. extern SDL_DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  961. /**
  962. * Perform a scaled blit to a destination surface, which may be of a different
  963. * format.
  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.
  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, filled with the actual rectangle
  971. * used after clipping.
  972. * \param scaleMode the SDL_ScaleMode to be used.
  973. * \returns 0 on success or a negative error code on failure; call
  974. * SDL_GetError() for more information.
  975. *
  976. * \threadsafety The same destination surface should not be used from two
  977. * threads at once. It is safe to use the same source surface
  978. * from multiple threads.
  979. *
  980. * \since This function is available since SDL 3.0.0.
  981. *
  982. * \sa SDL_BlitSurface
  983. */
  984. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  985. /**
  986. * Perform low-level surface scaled blitting only.
  987. *
  988. * This is a semi-private function and it performs low-level surface blitting,
  989. * assuming the input rectangles have already been clipped.
  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.
  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.
  997. * \param scaleMode scale algorithm to be used.
  998. * \returns 0 on success or a negative error code on failure; call
  999. * SDL_GetError() for more information.
  1000. *
  1001. * \threadsafety The same destination surface should not be used from two
  1002. * threads at once. It is safe to use the same source surface
  1003. * from multiple threads.
  1004. *
  1005. * \since This function is available since SDL 3.0.0.
  1006. *
  1007. * \sa SDL_BlitSurfaceScaled
  1008. */
  1009. extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1010. /**
  1011. * Map an RGB triple to an opaque pixel value for a surface.
  1012. *
  1013. * This function maps the RGB color value to the specified pixel format and
  1014. * returns the pixel value best approximating the given RGB color value for
  1015. * the given pixel format.
  1016. *
  1017. * If the surface has a palette, the index of the closest matching color in
  1018. * the palette will be returned.
  1019. *
  1020. * If the surface pixel format has an alpha component it will be returned as
  1021. * all 1 bits (fully opaque).
  1022. *
  1023. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1024. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1025. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1026. * for an 8-bpp format).
  1027. *
  1028. * \param surface the surface to use for the pixel format and palette.
  1029. * \param r the red component of the pixel in the range 0-255.
  1030. * \param g the green component of the pixel in the range 0-255.
  1031. * \param b the blue component of the pixel in the range 0-255.
  1032. * \returns a pixel value.
  1033. *
  1034. * \since This function is available since SDL 3.0.0.
  1035. *
  1036. * \sa SDL_MapSurfaceRGBA
  1037. */
  1038. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  1039. /**
  1040. * Map an RGBA quadruple to a pixel value for a surface.
  1041. *
  1042. * This function maps the RGBA color value to the specified pixel format and
  1043. * returns the pixel value best approximating the given RGBA color value for
  1044. * the given pixel format.
  1045. *
  1046. * If the surface pixel format has no alpha component the alpha value will be
  1047. * ignored (as it will be in formats with a palette).
  1048. *
  1049. * If the surface has a palette, the index of the closest matching color in
  1050. * the palette will be returned.
  1051. *
  1052. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1053. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1054. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1055. * for an 8-bpp format).
  1056. *
  1057. * \param surface the surface to use for the pixel format and palette.
  1058. * \param r the red component of the pixel in the range 0-255.
  1059. * \param g the green component of the pixel in the range 0-255.
  1060. * \param b the blue component of the pixel in the range 0-255.
  1061. * \param a the alpha component of the pixel in the range 0-255.
  1062. * \returns a pixel value.
  1063. *
  1064. * \since This function is available since SDL 3.0.0.
  1065. *
  1066. * \sa SDL_MapSurfaceRGB
  1067. */
  1068. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1069. /**
  1070. * Retrieves a single pixel from a surface.
  1071. *
  1072. * This function prioritizes correctness over speed: it is suitable for unit
  1073. * tests, but is not intended for use in a game engine.
  1074. *
  1075. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1076. * components from pixel formats with less than 8 bits per RGB component.
  1077. *
  1078. * \param surface the surface to read.
  1079. * \param x the horizontal coordinate, 0 <= x < width.
  1080. * \param y the vertical coordinate, 0 <= y < height.
  1081. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1082. * this channel.
  1083. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1084. * ignore this channel.
  1085. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1086. * ignore this channel.
  1087. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1088. * ignore this channel.
  1089. * \returns 0 on success or a negative error code on failure; call
  1090. * SDL_GetError() for more information.
  1091. *
  1092. * \since This function is available since SDL 3.0.0.
  1093. */
  1094. extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1095. /**
  1096. * Retrieves a single pixel from a surface.
  1097. *
  1098. * This function prioritizes correctness over speed: it is suitable for unit
  1099. * tests, but is not intended for use in a game engine.
  1100. *
  1101. * \param surface the surface to read.
  1102. * \param x the horizontal coordinate, 0 <= x < width.
  1103. * \param y the vertical coordinate, 0 <= y < height.
  1104. * \param r a pointer filled in with the red channel, normally in the range
  1105. * 0-1, or NULL to ignore this channel.
  1106. * \param g a pointer filled in with the green channel, normally in the range
  1107. * 0-1, or NULL to ignore this channel.
  1108. * \param b a pointer filled in with the blue channel, normally in the range
  1109. * 0-1, or NULL to ignore this channel.
  1110. * \param a a pointer filled in with the alpha channel, normally in the range
  1111. * 0-1, or NULL to ignore this channel.
  1112. * \returns 0 on success or a negative error code on failure; call
  1113. * SDL_GetError() for more information.
  1114. *
  1115. * \since This function is available since SDL 3.0.0.
  1116. */
  1117. extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a);
  1118. /* Ends C function definitions when using C++ */
  1119. #ifdef __cplusplus
  1120. }
  1121. #endif
  1122. #include <SDL3/SDL_close_code.h>
  1123. #endif /* SDL_surface_h_ */