SDL_surface.h 55 KB

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