1
0

SDL_surface.h 55 KB

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