SDL_surface.h 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategorySurface
  20. *
  21. * SDL surfaces are buffers of pixels in system RAM. These are useful for
  22. * passing around and manipulating images that are not stored in GPU memory.
  23. *
  24. * SDL_Surface makes serious efforts to manage images in various formats, and
  25. * provides a reasonable toolbox for transforming the data, including copying
  26. * between surfaces, filling rectangles in the image data, etc.
  27. *
  28. * There is also a simple .bmp loader, SDL_LoadBMP(), and a simple .png
  29. * loader, SDL_LoadPNG(). SDL itself does not provide loaders for other file
  30. * formats, but there are several excellent external libraries that do,
  31. * including its own satellite library,
  32. * [SDL_image](https://wiki.libsdl.org/SDL3_image)
  33. * .
  34. *
  35. * In general these functions are thread-safe in that they can be called on
  36. * different threads with different surfaces. You should not try to modify any
  37. * surface from two threads simultaneously.
  38. */
  39. #ifndef SDL_surface_h_
  40. #define SDL_surface_h_
  41. #include <SDL3/SDL_stdinc.h>
  42. #include <SDL3/SDL_error.h>
  43. #include <SDL3/SDL_blendmode.h>
  44. #include <SDL3/SDL_pixels.h>
  45. #include <SDL3/SDL_properties.h>
  46. #include <SDL3/SDL_rect.h>
  47. #include <SDL3/SDL_iostream.h>
  48. #include <SDL3/SDL_begin_code.h>
  49. /* Set up for C function definitions, even when using C++ */
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53. /**
  54. * The flags on an SDL_Surface.
  55. *
  56. * These are generally considered read-only.
  57. *
  58. * \since This datatype is available since SDL 3.2.0.
  59. */
  60. typedef Uint32 SDL_SurfaceFlags;
  61. #define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */
  62. #define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */
  63. #define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */
  64. #define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */
  65. /**
  66. * Evaluates to true if the surface needs to be locked before access.
  67. *
  68. * \since This macro is available since SDL 3.2.0.
  69. */
  70. #define SDL_MUSTLOCK(S) (((S)->flags & SDL_SURFACE_LOCK_NEEDED) == SDL_SURFACE_LOCK_NEEDED)
  71. /**
  72. * The scaling mode.
  73. *
  74. * \since This enum is available since SDL 3.2.0.
  75. */
  76. typedef enum SDL_ScaleMode
  77. {
  78. SDL_SCALEMODE_INVALID = -1,
  79. SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
  80. SDL_SCALEMODE_LINEAR, /**< linear filtering */
  81. SDL_SCALEMODE_PIXELART /**< nearest pixel sampling with improved scaling for pixel art, available since SDL 3.4.0 */
  82. } SDL_ScaleMode;
  83. /**
  84. * The flip mode.
  85. *
  86. * \since This enum is available since SDL 3.2.0.
  87. */
  88. typedef enum SDL_FlipMode
  89. {
  90. SDL_FLIP_NONE, /**< Do not flip */
  91. SDL_FLIP_HORIZONTAL, /**< flip horizontally */
  92. SDL_FLIP_VERTICAL, /**< flip vertically */
  93. SDL_FLIP_HORIZONTAL_AND_VERTICAL = (SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL) /**< flip horizontally and vertically (not a diagonal flip) */
  94. } SDL_FlipMode;
  95. #ifndef SDL_INTERNAL
  96. /**
  97. * A collection of pixels used in software blitting.
  98. *
  99. * Pixels are arranged in memory in rows, with the top row first. Each row
  100. * occupies an amount of memory given by the pitch (sometimes known as the row
  101. * stride in non-SDL APIs).
  102. *
  103. * Within each row, pixels are arranged from left to right until the width is
  104. * reached. Each pixel occupies a number of bits appropriate for its format,
  105. * with most formats representing each pixel as one or more whole bytes (in
  106. * some indexed formats, instead multiple pixels are packed into each byte),
  107. * and a byte order given by the format. After encoding all pixels, any
  108. * remaining bytes to reach the pitch are used as padding to reach a desired
  109. * alignment, and have undefined contents.
  110. *
  111. * When a surface holds YUV format data, the planes are assumed to be
  112. * contiguous without padding between them, e.g. a 32x32 surface in NV12
  113. * format with a pitch of 32 would consist of 32x32 bytes of Y plane followed
  114. * by 32x16 bytes of UV plane.
  115. *
  116. * When a surface holds MJPG format data, pixels points at the compressed JPEG
  117. * image and pitch is the length of that data.
  118. *
  119. * \since This struct is available since SDL 3.2.0.
  120. *
  121. * \sa SDL_CreateSurface
  122. * \sa SDL_DestroySurface
  123. */
  124. struct SDL_Surface
  125. {
  126. SDL_SurfaceFlags flags; /**< The flags of the surface, read-only */
  127. SDL_PixelFormat format; /**< The format of the surface, read-only */
  128. int w; /**< The width of the surface, read-only. */
  129. int h; /**< The height of the surface, read-only. */
  130. int pitch; /**< The distance in bytes between rows of pixels, read-only */
  131. void *pixels; /**< A pointer to the pixels of the surface, the pixels are writeable if non-NULL */
  132. int refcount; /**< Application reference count, used when freeing surface */
  133. void *reserved; /**< Reserved for internal use */
  134. };
  135. #endif /* !SDL_INTERNAL */
  136. typedef struct SDL_Surface SDL_Surface;
  137. /**
  138. * Allocate a new surface with a specific pixel format.
  139. *
  140. * The pixels of the new surface are initialized to zero.
  141. *
  142. * \param width the width of the surface.
  143. * \param height the height of the surface.
  144. * \param format the SDL_PixelFormat for the new surface's pixel format.
  145. * \returns the new SDL_Surface structure that is created or NULL on failure;
  146. * call SDL_GetError() for more information.
  147. *
  148. * \threadsafety It is safe to call this function from any thread.
  149. *
  150. * \since This function is available since SDL 3.2.0.
  151. *
  152. * \sa SDL_CreateSurfaceFrom
  153. * \sa SDL_DestroySurface
  154. */
  155. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
  156. /**
  157. * Allocate a new surface with a specific pixel format and existing pixel
  158. * data.
  159. *
  160. * No copy is made of the pixel data. Pixel data is not managed automatically;
  161. * you must free the surface before you free the pixel data.
  162. *
  163. * Pitch is the offset in bytes from one row of pixels to the next, e.g.
  164. * `width*4` for `SDL_PIXELFORMAT_RGBA8888`.
  165. *
  166. * You may pass NULL for pixels and 0 for pitch to create a surface that you
  167. * will fill in with valid values later.
  168. *
  169. * \param width the width of the surface.
  170. * \param height the height of the surface.
  171. * \param format the SDL_PixelFormat for the new surface's pixel format.
  172. * \param pixels a pointer to existing pixel data.
  173. * \param pitch the number of bytes between each row, including padding.
  174. * \returns the new SDL_Surface structure that is created or NULL on failure;
  175. * call SDL_GetError() for more information.
  176. *
  177. * \threadsafety It is safe to call this function from any thread.
  178. *
  179. * \since This function is available since SDL 3.2.0.
  180. *
  181. * \sa SDL_CreateSurface
  182. * \sa SDL_DestroySurface
  183. */
  184. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
  185. /**
  186. * Free a surface.
  187. *
  188. * It is safe to pass NULL to this function.
  189. *
  190. * \param surface the SDL_Surface to free.
  191. *
  192. * \threadsafety No other thread should be using the surface when it is freed.
  193. *
  194. * \since This function is available since SDL 3.2.0.
  195. *
  196. * \sa SDL_CreateSurface
  197. * \sa SDL_CreateSurfaceFrom
  198. */
  199. extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
  200. /**
  201. * Get the properties associated with a surface.
  202. *
  203. * The following properties are understood by SDL:
  204. *
  205. * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  206. * surfaces, this defines the value of 100% diffuse white, with higher
  207. * values being displayed in the High Dynamic Range headroom. This defaults
  208. * to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
  209. * - `SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
  210. * surfaces, this defines the maximum dynamic range used by the content, in
  211. * terms of the SDR white point. This defaults to 0.0, which disables tone
  212. * mapping.
  213. * - `SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`: the tone mapping operator
  214. * used when compressing from a surface with high dynamic range to another
  215. * with lower dynamic range. Currently this supports "chrome", which uses
  216. * the same tone mapping that Chrome uses for HDR content, the form "*=N",
  217. * where N is a floating point scale factor applied in linear space, and
  218. * "none", which disables tone mapping. This defaults to "chrome".
  219. * - `SDL_PROP_SURFACE_HOTSPOT_X_NUMBER`: the hotspot pixel offset from the
  220. * left edge of the image, if this surface is being used as a cursor.
  221. * - `SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`: the hotspot pixel offset from the
  222. * top edge of the image, if this surface is being used as a cursor.
  223. * - `SDL_PROP_SURFACE_ROTATION_FLOAT`: the number of degrees a surface's
  224. * data is meant to be rotated clockwise to make the image right-side up.
  225. * Default 0. This is used by the camera API, if a mobile device is oriented
  226. * differently than what its camera provides (i.e. - the camera always
  227. * provides portrait images but the phone is being held in landscape
  228. * orientation). Since SDL 3.4.0.
  229. *
  230. * \param surface the SDL_Surface structure to query.
  231. * \returns a valid property ID on success or 0 on failure; call
  232. * SDL_GetError() for more information.
  233. *
  234. * \threadsafety It is safe to call this function from any thread.
  235. *
  236. * \since This function is available since SDL 3.2.0.
  237. */
  238. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
  239. #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
  240. #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
  241. #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
  242. #define SDL_PROP_SURFACE_HOTSPOT_X_NUMBER "SDL.surface.hotspot.x"
  243. #define SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER "SDL.surface.hotspot.y"
  244. #define SDL_PROP_SURFACE_ROTATION_FLOAT "SDL.surface.rotation"
  245. /**
  246. * Set the colorspace used by a surface.
  247. *
  248. * Setting the colorspace doesn't change the pixels, only how they are
  249. * interpreted in color operations.
  250. *
  251. * \param surface the SDL_Surface structure to update.
  252. * \param colorspace an SDL_Colorspace value describing the surface
  253. * colorspace.
  254. * \returns true on success or false on failure; call SDL_GetError() for more
  255. * information.
  256. *
  257. * \threadsafety This function can be called on different threads with
  258. * different surfaces.
  259. *
  260. * \since This function is available since SDL 3.2.0.
  261. *
  262. * \sa SDL_GetSurfaceColorspace
  263. */
  264. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
  265. /**
  266. * Get the colorspace used by a surface.
  267. *
  268. * The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point
  269. * formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for
  270. * other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
  271. *
  272. * \param surface the SDL_Surface structure to query.
  273. * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
  274. * the surface is NULL.
  275. *
  276. * \threadsafety This function can be called on different threads with
  277. * different surfaces.
  278. *
  279. * \since This function is available since SDL 3.2.0.
  280. *
  281. * \sa SDL_SetSurfaceColorspace
  282. */
  283. extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
  284. /**
  285. * Create a palette and associate it with a surface.
  286. *
  287. * This function creates a palette compatible with the provided surface. The
  288. * palette is then returned for you to modify, and the surface will
  289. * automatically use the new palette in future operations. You do not need to
  290. * destroy the returned palette, it will be freed when the reference count
  291. * reaches 0, usually when the surface is destroyed.
  292. *
  293. * Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or
  294. * SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as
  295. * white and 1 as black. Other surfaces will get a palette initialized with
  296. * white in every entry.
  297. *
  298. * If this function is called for a surface that already has a palette, a new
  299. * palette will be created to replace it.
  300. *
  301. * \param surface the SDL_Surface structure to update.
  302. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  303. * the surface didn't have an index format); call SDL_GetError() for
  304. * more information.
  305. *
  306. * \threadsafety This function can be called on different threads with
  307. * different surfaces.
  308. *
  309. * \since This function is available since SDL 3.2.0.
  310. *
  311. * \sa SDL_SetPaletteColors
  312. */
  313. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *surface);
  314. /**
  315. * Set the palette used by a surface.
  316. *
  317. * Setting the palette keeps an internal reference to the palette, which can
  318. * be safely destroyed afterwards.
  319. *
  320. * A single palette can be shared with many surfaces.
  321. *
  322. * \param surface the SDL_Surface structure to update.
  323. * \param palette the SDL_Palette structure to use.
  324. * \returns true on success or false on failure; call SDL_GetError() for more
  325. * information.
  326. *
  327. * \threadsafety This function can be called on different threads with
  328. * different surfaces.
  329. *
  330. * \since This function is available since SDL 3.2.0.
  331. *
  332. * \sa SDL_CreatePalette
  333. * \sa SDL_GetSurfacePalette
  334. */
  335. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
  336. /**
  337. * Get the palette used by a surface.
  338. *
  339. * \param surface the SDL_Surface structure to query.
  340. * \returns a pointer to the palette used by the surface, or NULL if there is
  341. * no palette used.
  342. *
  343. * \threadsafety It is safe to call this function from any thread.
  344. *
  345. * \since This function is available since SDL 3.2.0.
  346. *
  347. * \sa SDL_SetSurfacePalette
  348. */
  349. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
  350. /**
  351. * Add an alternate version of a surface.
  352. *
  353. * This function adds an alternate version of this surface, usually used for
  354. * content with high DPI representations like cursors or icons. The size,
  355. * format, and content do not need to match the original surface, and these
  356. * alternate versions will not be updated when the original surface changes.
  357. *
  358. * This function adds a reference to the alternate version, so you should call
  359. * SDL_DestroySurface() on the image after this call.
  360. *
  361. * \param surface the SDL_Surface structure to update.
  362. * \param image a pointer to an alternate SDL_Surface to associate with this
  363. * surface.
  364. * \returns true on success or false on failure; call SDL_GetError() for more
  365. * information.
  366. *
  367. * \threadsafety This function can be called on different threads with
  368. * different surfaces.
  369. *
  370. * \since This function is available since SDL 3.2.0.
  371. *
  372. * \sa SDL_RemoveSurfaceAlternateImages
  373. * \sa SDL_GetSurfaceImages
  374. * \sa SDL_SurfaceHasAlternateImages
  375. */
  376. extern SDL_DECLSPEC bool SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image);
  377. /**
  378. * Return whether a surface has alternate versions available.
  379. *
  380. * \param surface the SDL_Surface structure to query.
  381. * \returns true if alternate versions are available or false otherwise.
  382. *
  383. * \threadsafety It is safe to call this function from any thread.
  384. *
  385. * \since This function is available since SDL 3.2.0.
  386. *
  387. * \sa SDL_AddSurfaceAlternateImage
  388. * \sa SDL_RemoveSurfaceAlternateImages
  389. * \sa SDL_GetSurfaceImages
  390. */
  391. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasAlternateImages(SDL_Surface *surface);
  392. /**
  393. * Get an array including all versions of a surface.
  394. *
  395. * This returns all versions of a surface, with the surface being queried as
  396. * the first element in the returned array.
  397. *
  398. * Freeing the array of surfaces does not affect the surfaces in the array.
  399. * They are still referenced by the surface being queried and will be cleaned
  400. * up normally.
  401. *
  402. * \param surface the SDL_Surface structure to query.
  403. * \param count a pointer filled in with the number of surface pointers
  404. * returned, may be NULL.
  405. * \returns a NULL terminated array of SDL_Surface pointers or NULL on
  406. * failure; call SDL_GetError() for more information. This should be
  407. * freed with SDL_free() when it is no longer needed.
  408. *
  409. * \threadsafety This function can be called on different threads with
  410. * different surfaces.
  411. *
  412. * \since This function is available since SDL 3.2.0.
  413. *
  414. * \sa SDL_AddSurfaceAlternateImage
  415. * \sa SDL_RemoveSurfaceAlternateImages
  416. * \sa SDL_SurfaceHasAlternateImages
  417. */
  418. extern SDL_DECLSPEC SDL_Surface ** SDLCALL SDL_GetSurfaceImages(SDL_Surface *surface, int *count);
  419. /**
  420. * Remove all alternate versions of a surface.
  421. *
  422. * This function removes a reference from all the alternative versions,
  423. * destroying them if this is the last reference to them.
  424. *
  425. * \param surface the SDL_Surface structure to update.
  426. *
  427. * \threadsafety This function can be called on different threads with
  428. * different surfaces.
  429. *
  430. * \since This function is available since SDL 3.2.0.
  431. *
  432. * \sa SDL_AddSurfaceAlternateImage
  433. * \sa SDL_GetSurfaceImages
  434. * \sa SDL_SurfaceHasAlternateImages
  435. */
  436. extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface);
  437. /**
  438. * Set up a surface for directly accessing the pixels.
  439. *
  440. * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to
  441. * and read from `surface->pixels`, using the pixel format stored in
  442. * `surface->format`. Once you are done accessing the surface, you should use
  443. * SDL_UnlockSurface() to release it.
  444. *
  445. * Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
  446. * 0, then you can read and write to the surface at any time, and the pixel
  447. * format of the surface will not change.
  448. *
  449. * \param surface the SDL_Surface structure to be locked.
  450. * \returns true on success or false on failure; call SDL_GetError() for more
  451. * information.
  452. *
  453. * \threadsafety This function can be called on different threads with
  454. * different surfaces. The locking referred to by this function
  455. * is making the pixels available for direct access, not
  456. * thread-safe locking.
  457. *
  458. * \since This function is available since SDL 3.2.0.
  459. *
  460. * \sa SDL_MUSTLOCK
  461. * \sa SDL_UnlockSurface
  462. */
  463. extern SDL_DECLSPEC bool SDLCALL SDL_LockSurface(SDL_Surface *surface);
  464. /**
  465. * Release a surface after directly accessing the pixels.
  466. *
  467. * \param surface the SDL_Surface structure to be unlocked.
  468. *
  469. * \threadsafety This function is not thread safe. The locking referred to by
  470. * this function is making the pixels available for direct
  471. * access, not thread-safe locking.
  472. *
  473. * \since This function is available since SDL 3.2.0.
  474. *
  475. * \sa SDL_LockSurface
  476. */
  477. extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
  478. /**
  479. * Load a BMP or PNG image from a seekable SDL data stream.
  480. *
  481. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  482. * will result in a memory leak.
  483. *
  484. * \param src the data stream for the surface.
  485. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  486. * in the case of an error.
  487. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  488. * SDL_GetError() for more information.
  489. *
  490. * \threadsafety It is safe to call this function from any thread.
  491. *
  492. * \since This function is available since SDL 3.4.0.
  493. *
  494. * \sa SDL_DestroySurface
  495. * \sa SDL_LoadSurface
  496. */
  497. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadSurface_IO(SDL_IOStream *src, bool closeio);
  498. /**
  499. * Load a BMP or PNG image from a file.
  500. *
  501. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  502. * will result in a memory leak.
  503. *
  504. * \param file the file to load.
  505. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  506. * SDL_GetError() for more information.
  507. *
  508. * \threadsafety It is safe to call this function from any thread.
  509. *
  510. * \since This function is available since SDL 3.4.0.
  511. *
  512. * \sa SDL_DestroySurface
  513. * \sa SDL_LoadSurface_IO
  514. */
  515. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadSurface(const char *file);
  516. /**
  517. * Load a BMP image from a seekable SDL data stream.
  518. *
  519. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  520. * will result in a memory leak.
  521. *
  522. * \param src the data stream for the surface.
  523. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  524. * in the case of an error.
  525. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  526. * SDL_GetError() for more information.
  527. *
  528. * \threadsafety It is safe to call this function from any thread.
  529. *
  530. * \since This function is available since SDL 3.2.0.
  531. *
  532. * \sa SDL_DestroySurface
  533. * \sa SDL_LoadBMP
  534. * \sa SDL_SaveBMP_IO
  535. */
  536. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio);
  537. /**
  538. * Load a BMP image from a file.
  539. *
  540. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  541. * will result in a memory leak.
  542. *
  543. * \param file the BMP file to load.
  544. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  545. * SDL_GetError() for more information.
  546. *
  547. * \threadsafety It is safe to call this function from any thread.
  548. *
  549. * \since This function is available since SDL 3.2.0.
  550. *
  551. * \sa SDL_DestroySurface
  552. * \sa SDL_LoadBMP_IO
  553. * \sa SDL_SaveBMP
  554. */
  555. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
  556. /**
  557. * Save a surface to a seekable SDL data stream in BMP format.
  558. *
  559. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  560. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  561. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  562. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  563. * not supported.
  564. *
  565. * \param surface the SDL_Surface structure containing the image to be saved.
  566. * \param dst a data stream to save to.
  567. * \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even
  568. * in the case of an error.
  569. * \returns true on success or false on failure; call SDL_GetError() for more
  570. * information.
  571. *
  572. * \threadsafety This function can be called on different threads with
  573. * different surfaces.
  574. *
  575. * \since This function is available since SDL 3.2.0.
  576. *
  577. * \sa SDL_LoadBMP_IO
  578. * \sa SDL_SaveBMP
  579. */
  580. extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
  581. /**
  582. * Save a surface to a file in BMP format.
  583. *
  584. * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
  585. * BMP directly. Other RGB formats with 8-bit or higher get converted to a
  586. * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
  587. * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
  588. * not supported.
  589. *
  590. * \param surface the SDL_Surface structure containing the image to be saved.
  591. * \param file a file to save to.
  592. * \returns true on success or false on failure; call SDL_GetError() for more
  593. * information.
  594. *
  595. * \threadsafety This function can be called on different threads with
  596. * different surfaces.
  597. *
  598. * \since This function is available since SDL 3.2.0.
  599. *
  600. * \sa SDL_LoadBMP
  601. * \sa SDL_SaveBMP_IO
  602. */
  603. extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
  604. /**
  605. * Load a PNG image from a seekable SDL data stream.
  606. *
  607. * This is intended as a convenience function for loading images from trusted
  608. * sources. If you want to load arbitrary images you should use libpng or
  609. * another image loading library designed with security in mind.
  610. *
  611. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  612. * will result in a memory leak.
  613. *
  614. * \param src the data stream for the surface.
  615. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  616. * in the case of an error.
  617. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  618. * SDL_GetError() for more information.
  619. *
  620. * \threadsafety It is safe to call this function from any thread.
  621. *
  622. * \since This function is available since SDL 3.4.0.
  623. *
  624. * \sa SDL_DestroySurface
  625. * \sa SDL_LoadPNG
  626. * \sa SDL_SavePNG_IO
  627. */
  628. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio);
  629. /**
  630. * Load a PNG image from a file.
  631. *
  632. * This is intended as a convenience function for loading images from trusted
  633. * sources. If you want to load arbitrary images you should use libpng or
  634. * another image loading library designed with security in mind.
  635. *
  636. * The new surface should be freed with SDL_DestroySurface(). Not doing so
  637. * will result in a memory leak.
  638. *
  639. * \param file the PNG file to load.
  640. * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
  641. * SDL_GetError() for more information.
  642. *
  643. * \threadsafety It is safe to call this function from any thread.
  644. *
  645. * \since This function is available since SDL 3.4.0.
  646. *
  647. * \sa SDL_DestroySurface
  648. * \sa SDL_LoadPNG_IO
  649. * \sa SDL_SavePNG
  650. */
  651. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadPNG(const char *file);
  652. /**
  653. * Save a surface to a seekable SDL data stream in PNG format.
  654. *
  655. * \param surface the SDL_Surface structure containing the image to be saved.
  656. * \param dst a data stream to save to.
  657. * \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even
  658. * in the case of an error.
  659. * \returns true on success or false on failure; call SDL_GetError() for more
  660. * information.
  661. *
  662. * \threadsafety This function can be called on different threads with
  663. * different surfaces.
  664. *
  665. * \since This function is available since SDL 3.4.0.
  666. *
  667. * \sa SDL_LoadPNG_IO
  668. * \sa SDL_SavePNG
  669. */
  670. extern SDL_DECLSPEC bool SDLCALL SDL_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
  671. /**
  672. * Save a surface to a file in PNG format.
  673. *
  674. * \param surface the SDL_Surface structure containing the image to be saved.
  675. * \param file a file to save to.
  676. * \returns true on success or false on failure; call SDL_GetError() for more
  677. * information.
  678. *
  679. * \threadsafety This function can be called on different threads with
  680. * different surfaces.
  681. *
  682. * \since This function is available since SDL 3.4.0.
  683. *
  684. * \sa SDL_LoadPNG
  685. * \sa SDL_SavePNG_IO
  686. */
  687. extern SDL_DECLSPEC bool SDLCALL SDL_SavePNG(SDL_Surface *surface, const char *file);
  688. /**
  689. * Set the RLE acceleration hint for a surface.
  690. *
  691. * If RLE is enabled, color key and alpha blending blits are much faster, but
  692. * the surface must be locked before directly accessing the pixels.
  693. *
  694. * \param surface the SDL_Surface structure to optimize.
  695. * \param enabled true to enable RLE acceleration, false to disable it.
  696. * \returns true on success or false on failure; call SDL_GetError() for more
  697. * information.
  698. *
  699. * \threadsafety This function can be called on different threads with
  700. * different surfaces.
  701. *
  702. * \since This function is available since SDL 3.2.0.
  703. *
  704. * \sa SDL_BlitSurface
  705. * \sa SDL_LockSurface
  706. * \sa SDL_UnlockSurface
  707. */
  708. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled);
  709. /**
  710. * Returns whether the surface is RLE enabled.
  711. *
  712. * It is safe to pass a NULL `surface` here; it will return false.
  713. *
  714. * \param surface the SDL_Surface structure to query.
  715. * \returns true if the surface is RLE enabled, false otherwise.
  716. *
  717. * \threadsafety It is safe to call this function from any thread.
  718. *
  719. * \since This function is available since SDL 3.2.0.
  720. *
  721. * \sa SDL_SetSurfaceRLE
  722. */
  723. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
  724. /**
  725. * Set the color key (transparent pixel) in a surface.
  726. *
  727. * The color key defines a pixel value that will be treated as transparent in
  728. * a blit. For example, one can use this to specify that cyan pixels should be
  729. * considered transparent, and therefore not rendered.
  730. *
  731. * It is a pixel of the format used by the surface, as generated by
  732. * SDL_MapRGB().
  733. *
  734. * \param surface the SDL_Surface structure to update.
  735. * \param enabled true to enable color key, false to disable color key.
  736. * \param key the transparent pixel.
  737. * \returns true on success or false on failure; call SDL_GetError() for more
  738. * information.
  739. *
  740. * \threadsafety This function can be called on different threads with
  741. * different surfaces.
  742. *
  743. * \since This function is available since SDL 3.2.0.
  744. *
  745. * \sa SDL_GetSurfaceColorKey
  746. * \sa SDL_SetSurfaceRLE
  747. * \sa SDL_SurfaceHasColorKey
  748. */
  749. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key);
  750. /**
  751. * Returns whether the surface has a color key.
  752. *
  753. * It is safe to pass a NULL `surface` here; it will return false.
  754. *
  755. * \param surface the SDL_Surface structure to query.
  756. * \returns true if the surface has a color key, false otherwise.
  757. *
  758. * \threadsafety It is safe to call this function from any thread.
  759. *
  760. * \since This function is available since SDL 3.2.0.
  761. *
  762. * \sa SDL_SetSurfaceColorKey
  763. * \sa SDL_GetSurfaceColorKey
  764. */
  765. extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface);
  766. /**
  767. * Get the color key (transparent pixel) for a surface.
  768. *
  769. * The color key is a pixel of the format used by the surface, as generated by
  770. * SDL_MapRGB().
  771. *
  772. * If the surface doesn't have color key enabled this function returns false.
  773. *
  774. * \param surface the SDL_Surface structure to query.
  775. * \param key a pointer filled in with the transparent pixel.
  776. * \returns true on success or false on failure; call SDL_GetError() for more
  777. * information.
  778. *
  779. * \threadsafety It is safe to call this function from any thread.
  780. *
  781. * \since This function is available since SDL 3.2.0.
  782. *
  783. * \sa SDL_SetSurfaceColorKey
  784. * \sa SDL_SurfaceHasColorKey
  785. */
  786. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);
  787. /**
  788. * Set an additional color value multiplied into blit operations.
  789. *
  790. * When this surface is blitted, during the blit operation each source color
  791. * channel is modulated by the appropriate color value according to the
  792. * following formula:
  793. *
  794. * `srcC = srcC * (color / 255)`
  795. *
  796. * \param surface the SDL_Surface structure to update.
  797. * \param r the red color value multiplied into blit operations.
  798. * \param g the green color value multiplied into blit operations.
  799. * \param b the blue color value multiplied into blit operations.
  800. * \returns true on success or false on failure; call SDL_GetError() for more
  801. * information.
  802. *
  803. * \threadsafety This function can be called on different threads with
  804. * different surfaces.
  805. *
  806. * \since This function is available since SDL 3.2.0.
  807. *
  808. * \sa SDL_GetSurfaceColorMod
  809. * \sa SDL_SetSurfaceAlphaMod
  810. */
  811. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  812. /**
  813. * Get the additional color value multiplied into blit operations.
  814. *
  815. * \param surface the SDL_Surface structure to query.
  816. * \param r a pointer filled in with the current red color value.
  817. * \param g a pointer filled in with the current green color value.
  818. * \param b a pointer filled in with the current blue color value.
  819. * \returns true on success or false on failure; call SDL_GetError() for more
  820. * information.
  821. *
  822. * \threadsafety This function can be called on different threads with
  823. * different surfaces.
  824. *
  825. * \since This function is available since SDL 3.2.0.
  826. *
  827. * \sa SDL_GetSurfaceAlphaMod
  828. * \sa SDL_SetSurfaceColorMod
  829. */
  830. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b);
  831. /**
  832. * Set an additional alpha value used in blit operations.
  833. *
  834. * When this surface is blitted, during the blit operation the source alpha
  835. * value is modulated by this alpha value according to the following formula:
  836. *
  837. * `srcA = srcA * (alpha / 255)`
  838. *
  839. * \param surface the SDL_Surface structure to update.
  840. * \param alpha the alpha value multiplied into blit operations.
  841. * \returns true on success or false on failure; call SDL_GetError() for more
  842. * information.
  843. *
  844. * \threadsafety This function can be called on different threads with
  845. * different surfaces.
  846. *
  847. * \since This function is available since SDL 3.2.0.
  848. *
  849. * \sa SDL_GetSurfaceAlphaMod
  850. * \sa SDL_SetSurfaceColorMod
  851. */
  852. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha);
  853. /**
  854. * Get the additional alpha value used in blit operations.
  855. *
  856. * \param surface the SDL_Surface structure to query.
  857. * \param alpha a pointer filled in with the current alpha value.
  858. * \returns true on success or false on failure; call SDL_GetError() for more
  859. * information.
  860. *
  861. * \threadsafety It is safe to call this function from any thread.
  862. *
  863. * \since This function is available since SDL 3.2.0.
  864. *
  865. * \sa SDL_GetSurfaceColorMod
  866. * \sa SDL_SetSurfaceAlphaMod
  867. */
  868. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha);
  869. /**
  870. * Set the blend mode used for blit operations.
  871. *
  872. * To copy a surface to another surface (or texture) without blending with the
  873. * existing data, the blendmode of the SOURCE surface should be set to
  874. * `SDL_BLENDMODE_NONE`.
  875. *
  876. * \param surface the SDL_Surface structure to update.
  877. * \param blendMode the SDL_BlendMode to use for blit blending.
  878. * \returns true on success or false on failure; call SDL_GetError() for more
  879. * information.
  880. *
  881. * \threadsafety This function can be called on different threads with
  882. * different surfaces.
  883. *
  884. * \since This function is available since SDL 3.2.0.
  885. *
  886. * \sa SDL_GetSurfaceBlendMode
  887. */
  888. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode);
  889. /**
  890. * Get the blend mode used for blit operations.
  891. *
  892. * \param surface the SDL_Surface structure to query.
  893. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  894. * \returns true on success or false on failure; call SDL_GetError() for more
  895. * information.
  896. *
  897. * \threadsafety It is safe to call this function from any thread.
  898. *
  899. * \since This function is available since SDL 3.2.0.
  900. *
  901. * \sa SDL_SetSurfaceBlendMode
  902. */
  903. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);
  904. /**
  905. * Set the clipping rectangle for a surface.
  906. *
  907. * When `surface` is the destination of a blit, only the area within the clip
  908. * rectangle is drawn into.
  909. *
  910. * Note that blits are automatically clipped to the edges of the source and
  911. * destination surfaces.
  912. *
  913. * \param surface the SDL_Surface structure to be clipped.
  914. * \param rect the SDL_Rect structure representing the clipping rectangle, or
  915. * NULL to disable clipping.
  916. * \returns true if the rectangle intersects the surface, otherwise false and
  917. * blits will be completely clipped.
  918. *
  919. * \threadsafety This function can be called on different threads with
  920. * different surfaces.
  921. *
  922. * \since This function is available since SDL 3.2.0.
  923. *
  924. * \sa SDL_GetSurfaceClipRect
  925. */
  926. extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect);
  927. /**
  928. * Get the clipping rectangle for a surface.
  929. *
  930. * When `surface` is the destination of a blit, only the area within the clip
  931. * rectangle is drawn into.
  932. *
  933. * \param surface the SDL_Surface structure representing the surface to be
  934. * clipped.
  935. * \param rect an SDL_Rect structure filled in with the clipping rectangle for
  936. * the surface.
  937. * \returns true on success or false on failure; call SDL_GetError() for more
  938. * information.
  939. *
  940. * \threadsafety This function can be called on different threads with
  941. * different surfaces.
  942. *
  943. * \since This function is available since SDL 3.2.0.
  944. *
  945. * \sa SDL_SetSurfaceClipRect
  946. */
  947. extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect);
  948. /**
  949. * Flip a surface vertically or horizontally.
  950. *
  951. * \param surface the surface to flip.
  952. * \param flip the direction to flip.
  953. * \returns true on success or false on failure; call SDL_GetError() for more
  954. * information.
  955. *
  956. * \threadsafety This function can be called on different threads with
  957. * different surfaces.
  958. *
  959. * \since This function is available since SDL 3.2.0.
  960. */
  961. extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
  962. /**
  963. * Return a copy of a surface rotated clockwise a number of degrees.
  964. *
  965. * The angle of rotation can be negative for counter-clockwise rotation.
  966. *
  967. * When the rotation isn't a multiple of 90 degrees, the resulting surface is
  968. * larger than the original, with the background filled in with the colorkey,
  969. * if available, or RGBA 255/255/255/0 if not.
  970. *
  971. * \param surface the surface to rotate.
  972. * \param angle the rotation angle, in degrees.
  973. * \returns a rotated copy of the surface or NULL on failure; call
  974. * SDL_GetError() for more information.
  975. *
  976. * \threadsafety This function can be called on different threads with
  977. * different surfaces.
  978. *
  979. * \since This function is available since SDL 3.4.0.
  980. */
  981. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RotateSurface(SDL_Surface *surface, float angle);
  982. /**
  983. * Creates a new surface identical to the existing surface.
  984. *
  985. * If the original surface has alternate images, the new surface will have a
  986. * reference to them as well.
  987. *
  988. * The returned surface should be freed with SDL_DestroySurface().
  989. *
  990. * \param surface the surface to duplicate.
  991. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  992. * more information.
  993. *
  994. * \threadsafety This function can be called on different threads with
  995. * different surfaces.
  996. *
  997. * \since This function is available since SDL 3.2.0.
  998. *
  999. * \sa SDL_DestroySurface
  1000. */
  1001. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surface);
  1002. /**
  1003. * Creates a new surface identical to the existing surface, scaled to the
  1004. * desired size.
  1005. *
  1006. * The returned surface should be freed with SDL_DestroySurface().
  1007. *
  1008. * \param surface the surface to duplicate and scale.
  1009. * \param width the width of the new surface.
  1010. * \param height the height of the new surface.
  1011. * \param scaleMode the SDL_ScaleMode to be used.
  1012. * \returns a copy of the surface or NULL on failure; call SDL_GetError() for
  1013. * more information.
  1014. *
  1015. * \threadsafety This function can be called on different threads with
  1016. * different surfaces.
  1017. *
  1018. * \since This function is available since SDL 3.2.0.
  1019. *
  1020. * \sa SDL_DestroySurface
  1021. */
  1022. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode);
  1023. /**
  1024. * Copy an existing surface to a new surface of the specified format.
  1025. *
  1026. * This function is used to optimize images for faster *repeat* blitting. This
  1027. * is accomplished by converting the original and storing the result as a new
  1028. * surface. The new, optimized surface can then be used as the source for
  1029. * future blits, making them faster.
  1030. *
  1031. * If you are converting to an indexed surface and want to map colors to a
  1032. * palette, you can use SDL_ConvertSurfaceAndColorspace() instead.
  1033. *
  1034. * If the original surface has alternate images, the new surface will have a
  1035. * reference to them as well.
  1036. *
  1037. * \param surface the existing SDL_Surface structure to convert.
  1038. * \param format the new pixel format.
  1039. * \returns the new SDL_Surface structure that is created or NULL on failure;
  1040. * call SDL_GetError() for more information.
  1041. *
  1042. * \threadsafety This function can be called on different threads with
  1043. * different surfaces.
  1044. *
  1045. * \since This function is available since SDL 3.2.0.
  1046. *
  1047. * \sa SDL_ConvertSurfaceAndColorspace
  1048. * \sa SDL_DestroySurface
  1049. */
  1050. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
  1051. /**
  1052. * Copy an existing surface to a new surface of the specified format and
  1053. * colorspace.
  1054. *
  1055. * This function converts an existing surface to a new format and colorspace
  1056. * and returns the new surface. This will perform any pixel format and
  1057. * colorspace conversion needed.
  1058. *
  1059. * If the original surface has alternate images, the new surface will have a
  1060. * reference to them as well.
  1061. *
  1062. * \param surface the existing SDL_Surface structure to convert.
  1063. * \param format the new pixel format.
  1064. * \param palette an optional palette to use for indexed formats, may be NULL.
  1065. * \param colorspace the new colorspace.
  1066. * \param props an SDL_PropertiesID with additional color properties, or 0.
  1067. * \returns the new SDL_Surface structure that is created or NULL on failure;
  1068. * call SDL_GetError() for more information.
  1069. *
  1070. * \threadsafety This function can be called on different threads with
  1071. * different surfaces.
  1072. *
  1073. * \since This function is available since SDL 3.2.0.
  1074. *
  1075. * \sa SDL_ConvertSurface
  1076. * \sa SDL_DestroySurface
  1077. */
  1078. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props);
  1079. /**
  1080. * Copy a block of pixels of one format to another format.
  1081. *
  1082. * \param width the width of the block to copy, in pixels.
  1083. * \param height the height of the block to copy, in pixels.
  1084. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  1085. * \param src a pointer to the source pixels.
  1086. * \param src_pitch the pitch of the source pixels, in bytes.
  1087. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  1088. * \param dst a pointer to be filled in with new pixel data.
  1089. * \param dst_pitch the pitch of the destination pixels, in bytes.
  1090. * \returns true on success or false on failure; call SDL_GetError() for more
  1091. * information.
  1092. *
  1093. * \threadsafety The same destination pixels should not be used from two
  1094. * threads at once. It is safe to use the same source pixels
  1095. * from multiple threads.
  1096. *
  1097. * \since This function is available since SDL 3.2.0.
  1098. *
  1099. * \sa SDL_ConvertPixelsAndColorspace
  1100. */
  1101. 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);
  1102. /**
  1103. * Copy a block of pixels of one format and colorspace to another format and
  1104. * colorspace.
  1105. *
  1106. * \param width the width of the block to copy, in pixels.
  1107. * \param height the height of the block to copy, in pixels.
  1108. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  1109. * \param src_colorspace an SDL_Colorspace value describing the colorspace of
  1110. * the `src` pixels.
  1111. * \param src_properties an SDL_PropertiesID with additional source color
  1112. * properties, or 0.
  1113. * \param src a pointer to the source pixels.
  1114. * \param src_pitch the pitch of the source pixels, in bytes.
  1115. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  1116. * \param dst_colorspace an SDL_Colorspace value describing the colorspace of
  1117. * the `dst` pixels.
  1118. * \param dst_properties an SDL_PropertiesID with additional destination color
  1119. * properties, or 0.
  1120. * \param dst a pointer to be filled in with new pixel data.
  1121. * \param dst_pitch the pitch of the destination pixels, in bytes.
  1122. * \returns true on success or false on failure; call SDL_GetError() for more
  1123. * information.
  1124. *
  1125. * \threadsafety The same destination pixels should not be used from two
  1126. * threads at once. It is safe to use the same source pixels
  1127. * from multiple threads.
  1128. *
  1129. * \since This function is available since SDL 3.2.0.
  1130. *
  1131. * \sa SDL_ConvertPixels
  1132. */
  1133. 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);
  1134. /**
  1135. * Premultiply the alpha on a block of pixels.
  1136. *
  1137. * This is safe to use with src == dst, but not for other overlapping areas.
  1138. *
  1139. * \param width the width of the block to convert, in pixels.
  1140. * \param height the height of the block to convert, in pixels.
  1141. * \param src_format an SDL_PixelFormat value of the `src` pixels format.
  1142. * \param src a pointer to the source pixels.
  1143. * \param src_pitch the pitch of the source pixels, in bytes.
  1144. * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
  1145. * \param dst a pointer to be filled in with premultiplied pixel data.
  1146. * \param dst_pitch the pitch of the destination pixels, in bytes.
  1147. * \param linear true to convert from sRGB to linear space for the alpha
  1148. * multiplication, false to do multiplication in sRGB space.
  1149. * \returns true on success or false on failure; call SDL_GetError() for more
  1150. * information.
  1151. *
  1152. * \threadsafety The same destination pixels should not be used from two
  1153. * threads at once. It is safe to use the same source pixels
  1154. * from multiple threads.
  1155. *
  1156. * \since This function is available since SDL 3.2.0.
  1157. */
  1158. 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);
  1159. /**
  1160. * Premultiply the alpha in a surface.
  1161. *
  1162. * This is safe to use with src == dst, but not for other overlapping areas.
  1163. *
  1164. * \param surface the surface to modify.
  1165. * \param linear true to convert from sRGB to linear space for the alpha
  1166. * multiplication, false to do multiplication in sRGB space.
  1167. * \returns true on success or false on failure; call SDL_GetError() for more
  1168. * information.
  1169. *
  1170. * \threadsafety This function can be called on different threads with
  1171. * different surfaces.
  1172. *
  1173. * \since This function is available since SDL 3.2.0.
  1174. */
  1175. extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, bool linear);
  1176. /**
  1177. * Clear a surface with a specific color, with floating point precision.
  1178. *
  1179. * This function handles all surface formats, and ignores any clip rectangle.
  1180. *
  1181. * If the surface is YUV, the color is assumed to be in the sRGB colorspace,
  1182. * otherwise the color is assumed to be in the colorspace of the suface.
  1183. *
  1184. * \param surface the SDL_Surface to clear.
  1185. * \param r the red component of the pixel, normally in the range 0-1.
  1186. * \param g the green component of the pixel, normally in the range 0-1.
  1187. * \param b the blue component of the pixel, normally in the range 0-1.
  1188. * \param a the alpha component of the pixel, normally in the range 0-1.
  1189. * \returns true on success or false on failure; call SDL_GetError() for more
  1190. * information.
  1191. *
  1192. * \threadsafety This function can be called on different threads with
  1193. * different surfaces.
  1194. *
  1195. * \since This function is available since SDL 3.2.0.
  1196. */
  1197. extern SDL_DECLSPEC bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a);
  1198. /**
  1199. * Perform a fast fill of a rectangle with a specific color.
  1200. *
  1201. * `color` should be a pixel of the format used by the surface, and can be
  1202. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  1203. * alpha component then the destination is simply filled with that alpha
  1204. * information, no blending takes place.
  1205. *
  1206. * If there is a clip rectangle set on the destination (set via
  1207. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  1208. * intersection of the clip rectangle and `rect`.
  1209. *
  1210. * \param dst the SDL_Surface structure that is the drawing target.
  1211. * \param rect the SDL_Rect structure representing the rectangle to fill, or
  1212. * NULL to fill the entire surface.
  1213. * \param color the color to fill with.
  1214. * \returns true on success or false on failure; call SDL_GetError() for more
  1215. * information.
  1216. *
  1217. * \threadsafety This function can be called on different threads with
  1218. * different surfaces.
  1219. *
  1220. * \since This function is available since SDL 3.2.0.
  1221. *
  1222. * \sa SDL_FillSurfaceRects
  1223. */
  1224. extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color);
  1225. /**
  1226. * Perform a fast fill of a set of rectangles with a specific color.
  1227. *
  1228. * `color` should be a pixel of the format used by the surface, and can be
  1229. * generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an
  1230. * alpha component then the destination is simply filled with that alpha
  1231. * information, no blending takes place.
  1232. *
  1233. * If there is a clip rectangle set on the destination (set via
  1234. * SDL_SetSurfaceClipRect()), then this function will fill based on the
  1235. * intersection of the clip rectangle and `rect`.
  1236. *
  1237. * \param dst the SDL_Surface structure that is the drawing target.
  1238. * \param rects an array of SDL_Rects representing the rectangles to fill.
  1239. * \param count the number of rectangles in the array.
  1240. * \param color the color to fill with.
  1241. * \returns true on success or false on failure; call SDL_GetError() for more
  1242. * information.
  1243. *
  1244. * \threadsafety This function can be called on different threads with
  1245. * different surfaces.
  1246. *
  1247. * \since This function is available since SDL 3.2.0.
  1248. *
  1249. * \sa SDL_FillSurfaceRect
  1250. */
  1251. extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color);
  1252. /**
  1253. * Performs a fast blit from the source surface to the destination surface
  1254. * with clipping.
  1255. *
  1256. * If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
  1257. * `dst`) is copied while ensuring clipping to `dst->clip_rect`.
  1258. *
  1259. * The blit function should not be called on a locked surface.
  1260. *
  1261. * The blit semantics for surfaces with and without blending and colorkey are
  1262. * defined as follows:
  1263. *
  1264. * ```
  1265. * RGBA->RGB:
  1266. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1267. * alpha-blend (using the source alpha-channel and per-surface alpha)
  1268. * SDL_SRCCOLORKEY ignored.
  1269. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1270. * copy RGB.
  1271. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1272. * RGB values of the source color key, ignoring alpha in the
  1273. * comparison.
  1274. *
  1275. * RGB->RGBA:
  1276. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1277. * alpha-blend (using the source per-surface alpha)
  1278. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1279. * copy RGB, set destination alpha to source per-surface alpha value.
  1280. * both:
  1281. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1282. * source color key.
  1283. *
  1284. * RGBA->RGBA:
  1285. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1286. * alpha-blend (using the source alpha-channel and per-surface alpha)
  1287. * SDL_SRCCOLORKEY ignored.
  1288. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1289. * copy all of RGBA to the destination.
  1290. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1291. * RGB values of the source color key, ignoring alpha in the
  1292. * comparison.
  1293. *
  1294. * RGB->RGB:
  1295. * Source surface blend mode set to SDL_BLENDMODE_BLEND:
  1296. * alpha-blend (using the source per-surface alpha)
  1297. * Source surface blend mode set to SDL_BLENDMODE_NONE:
  1298. * copy RGB.
  1299. * both:
  1300. * if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
  1301. * source color key.
  1302. * ```
  1303. *
  1304. * \param src the SDL_Surface structure to be copied from.
  1305. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1306. * copied, or NULL to copy the entire surface.
  1307. * \param dst the SDL_Surface structure that is the blit target.
  1308. * \param dstrect the SDL_Rect structure representing the x and y position in
  1309. * the destination surface, or NULL for (0,0). The width and
  1310. * height are ignored, and are copied from `srcrect`. If you
  1311. * want a specific width and height, you should use
  1312. * SDL_BlitSurfaceScaled().
  1313. * \returns true on success or false on failure; call SDL_GetError() for more
  1314. * information.
  1315. *
  1316. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1317. * at any given time.
  1318. *
  1319. * \since This function is available since SDL 3.2.0.
  1320. *
  1321. * \sa SDL_BlitSurfaceScaled
  1322. */
  1323. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1324. /**
  1325. * Perform low-level surface blitting only.
  1326. *
  1327. * This is a semi-private blit function and it performs low-level surface
  1328. * blitting, assuming the input rectangles have already been clipped.
  1329. *
  1330. * \param src the SDL_Surface structure to be copied from.
  1331. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1332. * copied, may not be NULL.
  1333. * \param dst the SDL_Surface structure that is the blit target.
  1334. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1335. * the destination surface, may not be NULL.
  1336. * \returns true on success or false on failure; call SDL_GetError() for more
  1337. * information.
  1338. *
  1339. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1340. * at any given time.
  1341. *
  1342. * \since This function is available since SDL 3.2.0.
  1343. *
  1344. * \sa SDL_BlitSurface
  1345. */
  1346. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1347. /**
  1348. * Perform a scaled blit to a destination surface, which may be of a different
  1349. * format.
  1350. *
  1351. * \param src the SDL_Surface structure to be copied from.
  1352. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1353. * copied, or NULL to copy the entire surface.
  1354. * \param dst the SDL_Surface structure that is the blit target.
  1355. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1356. * the destination surface, or NULL to fill the entire
  1357. * destination surface.
  1358. * \param scaleMode the SDL_ScaleMode to be used.
  1359. * \returns true on success or false on failure; call SDL_GetError() for more
  1360. * information.
  1361. *
  1362. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1363. * at any given time.
  1364. *
  1365. * \since This function is available since SDL 3.2.0.
  1366. *
  1367. * \sa SDL_BlitSurface
  1368. */
  1369. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1370. /**
  1371. * Perform low-level surface scaled blitting only.
  1372. *
  1373. * This is a semi-private function and it performs low-level surface blitting,
  1374. * assuming the input rectangles have already been clipped.
  1375. *
  1376. * \param src the SDL_Surface structure to be copied from.
  1377. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1378. * copied, may not be NULL.
  1379. * \param dst the SDL_Surface structure that is the blit target.
  1380. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1381. * the destination surface, may not be NULL.
  1382. * \param scaleMode the SDL_ScaleMode to be used.
  1383. * \returns true on success or false on failure; call SDL_GetError() for more
  1384. * information.
  1385. *
  1386. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1387. * at any given time.
  1388. *
  1389. * \since This function is available since SDL 3.2.0.
  1390. *
  1391. * \sa SDL_BlitSurfaceScaled
  1392. */
  1393. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1394. /**
  1395. * Perform a stretched pixel copy from one surface to another.
  1396. *
  1397. * \param src the SDL_Surface structure to be copied from.
  1398. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1399. * copied, or NULL to copy the entire surface.
  1400. * \param dst the SDL_Surface structure that is the blit target.
  1401. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1402. * the destination surface, or NULL to fill the entire
  1403. * destination surface.
  1404. * \param scaleMode the SDL_ScaleMode to be used.
  1405. * \returns true on success or false on failure; call SDL_GetError() for more
  1406. * information.
  1407. *
  1408. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1409. * at any given time.
  1410. *
  1411. * \since This function is available since SDL 3.4.0.
  1412. *
  1413. * \sa SDL_BlitSurfaceScaled
  1414. */
  1415. extern SDL_DECLSPEC bool SDLCALL SDL_StretchSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
  1416. /**
  1417. * Perform a tiled blit to a destination surface, which may be of a different
  1418. * format.
  1419. *
  1420. * The pixels in `srcrect` will be repeated as many times as needed to
  1421. * completely fill `dstrect`.
  1422. *
  1423. * \param src the SDL_Surface structure to be copied from.
  1424. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1425. * copied, or NULL to copy the entire surface.
  1426. * \param dst the SDL_Surface structure that is the blit target.
  1427. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1428. * the destination surface, or NULL to fill the entire surface.
  1429. * \returns true on success or false on failure; call SDL_GetError() for more
  1430. * information.
  1431. *
  1432. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1433. * at any given time.
  1434. *
  1435. * \since This function is available since SDL 3.2.0.
  1436. *
  1437. * \sa SDL_BlitSurface
  1438. */
  1439. extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  1440. /**
  1441. * Perform a scaled and tiled blit to a destination surface, which may be of a
  1442. * different format.
  1443. *
  1444. * The pixels in `srcrect` will be scaled and repeated as many times as needed
  1445. * to completely fill `dstrect`.
  1446. *
  1447. * \param src the SDL_Surface structure to be copied from.
  1448. * \param srcrect the SDL_Rect structure representing the rectangle to be
  1449. * copied, or NULL to copy the entire surface.
  1450. * \param scale the scale used to transform srcrect into the destination
  1451. * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
  1452. * 64x64 tiles.
  1453. * \param scaleMode scale algorithm to be used.
  1454. * \param dst the SDL_Surface structure that is the blit target.
  1455. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1456. * the destination surface, or NULL to fill the entire surface.
  1457. * \returns true on success or false on failure; call SDL_GetError() for more
  1458. * information.
  1459. *
  1460. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1461. * at any given time.
  1462. *
  1463. * \since This function is available since SDL 3.2.0.
  1464. *
  1465. * \sa SDL_BlitSurface
  1466. */
  1467. 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);
  1468. /**
  1469. * Perform a scaled blit using the 9-grid algorithm to a destination surface,
  1470. * which may be of a different format.
  1471. *
  1472. * The pixels in the source surface are split into a 3x3 grid, using the
  1473. * different corner sizes for each corner, and the sides and center making up
  1474. * the remaining pixels. The corners are then scaled using `scale` and fit
  1475. * into the corners of the destination rectangle. The sides and center are
  1476. * then stretched into place to cover the remaining destination rectangle.
  1477. *
  1478. * \param src the SDL_Surface structure to be copied from.
  1479. * \param srcrect the SDL_Rect structure representing the rectangle to be used
  1480. * for the 9-grid, or NULL to use the entire surface.
  1481. * \param left_width the width, in pixels, of the left corners in `srcrect`.
  1482. * \param right_width the width, in pixels, of the right corners in `srcrect`.
  1483. * \param top_height the height, in pixels, of the top corners in `srcrect`.
  1484. * \param bottom_height the height, in pixels, of the bottom corners in
  1485. * `srcrect`.
  1486. * \param scale the scale used to transform the corner of `srcrect` into the
  1487. * corner of `dstrect`, or 0.0f for an unscaled blit.
  1488. * \param scaleMode scale algorithm to be used.
  1489. * \param dst the SDL_Surface structure that is the blit target.
  1490. * \param dstrect the SDL_Rect structure representing the target rectangle in
  1491. * the destination surface, or NULL to fill the entire surface.
  1492. * \returns true on success or false on failure; call SDL_GetError() for more
  1493. * information.
  1494. *
  1495. * \threadsafety Only one thread should be using the `src` and `dst` surfaces
  1496. * at any given time.
  1497. *
  1498. * \since This function is available since SDL 3.2.0.
  1499. *
  1500. * \sa SDL_BlitSurface
  1501. */
  1502. 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);
  1503. /**
  1504. * Map an RGB triple to an opaque pixel value for a surface.
  1505. *
  1506. * This function maps the RGB color value to the specified pixel format and
  1507. * returns the pixel value best approximating the given RGB color value for
  1508. * the given pixel format.
  1509. *
  1510. * If the surface has a palette, the index of the closest matching color in
  1511. * the palette will be returned.
  1512. *
  1513. * If the surface pixel format has an alpha component it will be returned as
  1514. * all 1 bits (fully opaque).
  1515. *
  1516. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1517. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1518. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1519. * for an 8-bpp format).
  1520. *
  1521. * \param surface the surface to use for the pixel format and palette.
  1522. * \param r the red component of the pixel in the range 0-255.
  1523. * \param g the green component of the pixel in the range 0-255.
  1524. * \param b the blue component of the pixel in the range 0-255.
  1525. * \returns a pixel value.
  1526. *
  1527. * \threadsafety This function can be called on different threads with
  1528. * different surfaces.
  1529. *
  1530. * \since This function is available since SDL 3.2.0.
  1531. *
  1532. * \sa SDL_MapSurfaceRGBA
  1533. */
  1534. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
  1535. /**
  1536. * Map an RGBA quadruple to a pixel value for a surface.
  1537. *
  1538. * This function maps the RGBA color value to the specified pixel format and
  1539. * returns the pixel value best approximating the given RGBA color value for
  1540. * the given pixel format.
  1541. *
  1542. * If the surface pixel format has no alpha component the alpha value will be
  1543. * ignored (as it will be in formats with a palette).
  1544. *
  1545. * If the surface has a palette, the index of the closest matching color in
  1546. * the palette will be returned.
  1547. *
  1548. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1549. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1550. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1551. * for an 8-bpp format).
  1552. *
  1553. * \param surface the surface to use for the pixel format and palette.
  1554. * \param r the red component of the pixel in the range 0-255.
  1555. * \param g the green component of the pixel in the range 0-255.
  1556. * \param b the blue component of the pixel in the range 0-255.
  1557. * \param a the alpha component of the pixel in the range 0-255.
  1558. * \returns a pixel value.
  1559. *
  1560. * \threadsafety This function can be called on different threads with
  1561. * different surfaces.
  1562. *
  1563. * \since This function is available since SDL 3.2.0.
  1564. *
  1565. * \sa SDL_MapSurfaceRGB
  1566. */
  1567. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1568. /**
  1569. * Retrieves a single pixel from a surface.
  1570. *
  1571. * This function prioritizes correctness over speed: it is suitable for unit
  1572. * tests, but is not intended for use in a game engine.
  1573. *
  1574. * Like SDL_GetRGBA, this uses the entire 0..255 range when converting color
  1575. * components from pixel formats with less than 8 bits per RGB component.
  1576. *
  1577. * \param surface the surface to read.
  1578. * \param x the horizontal coordinate, 0 <= x < width.
  1579. * \param y the vertical coordinate, 0 <= y < height.
  1580. * \param r a pointer filled in with the red channel, 0-255, or NULL to ignore
  1581. * this channel.
  1582. * \param g a pointer filled in with the green channel, 0-255, or NULL to
  1583. * ignore this channel.
  1584. * \param b a pointer filled in with the blue channel, 0-255, or NULL to
  1585. * ignore this channel.
  1586. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to
  1587. * ignore this channel.
  1588. * \returns true on success or false on failure; call SDL_GetError() for more
  1589. * information.
  1590. *
  1591. * \threadsafety This function can be called on different threads with
  1592. * different surfaces.
  1593. *
  1594. * \since This function is available since SDL 3.2.0.
  1595. */
  1596. extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1597. /**
  1598. * Retrieves a single pixel from a surface.
  1599. *
  1600. * This function prioritizes correctness over speed: it is suitable for unit
  1601. * tests, but is not intended for use in a game engine.
  1602. *
  1603. * \param surface the surface to read.
  1604. * \param x the horizontal coordinate, 0 <= x < width.
  1605. * \param y the vertical coordinate, 0 <= y < height.
  1606. * \param r a pointer filled in with the red channel, normally in the range
  1607. * 0-1, or NULL to ignore this channel.
  1608. * \param g a pointer filled in with the green channel, normally in the range
  1609. * 0-1, or NULL to ignore this channel.
  1610. * \param b a pointer filled in with the blue channel, normally in the range
  1611. * 0-1, or NULL to ignore this channel.
  1612. * \param a a pointer filled in with the alpha channel, normally in the range
  1613. * 0-1, or NULL to ignore this channel.
  1614. * \returns true on success or false on failure; call SDL_GetError() for more
  1615. * information.
  1616. *
  1617. * \threadsafety This function can be called on different threads with
  1618. * different surfaces.
  1619. *
  1620. * \since This function is available since SDL 3.2.0.
  1621. */
  1622. extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a);
  1623. /**
  1624. * Writes a single pixel to a surface.
  1625. *
  1626. * This function prioritizes correctness over speed: it is suitable for unit
  1627. * tests, but is not intended for use in a game engine.
  1628. *
  1629. * Like SDL_MapRGBA, this uses the entire 0..255 range when converting color
  1630. * components from pixel formats with less than 8 bits per RGB component.
  1631. *
  1632. * \param surface the surface to write.
  1633. * \param x the horizontal coordinate, 0 <= x < width.
  1634. * \param y the vertical coordinate, 0 <= y < height.
  1635. * \param r the red channel value, 0-255.
  1636. * \param g the green channel value, 0-255.
  1637. * \param b the blue channel value, 0-255.
  1638. * \param a the alpha channel value, 0-255.
  1639. * \returns true on success or false on failure; call SDL_GetError() for more
  1640. * information.
  1641. *
  1642. * \threadsafety This function can be called on different threads with
  1643. * different surfaces.
  1644. *
  1645. * \since This function is available since SDL 3.2.0.
  1646. */
  1647. extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1648. /**
  1649. * Writes a single pixel to a surface.
  1650. *
  1651. * This function prioritizes correctness over speed: it is suitable for unit
  1652. * tests, but is not intended for use in a game engine.
  1653. *
  1654. * \param surface the surface to write.
  1655. * \param x the horizontal coordinate, 0 <= x < width.
  1656. * \param y the vertical coordinate, 0 <= y < height.
  1657. * \param r the red channel value, normally in the range 0-1.
  1658. * \param g the green channel value, normally in the range 0-1.
  1659. * \param b the blue channel value, normally in the range 0-1.
  1660. * \param a the alpha channel value, normally in the range 0-1.
  1661. * \returns true on success or false on failure; call SDL_GetError() for more
  1662. * information.
  1663. *
  1664. * \threadsafety This function can be called on different threads with
  1665. * different surfaces.
  1666. *
  1667. * \since This function is available since SDL 3.2.0.
  1668. */
  1669. extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a);
  1670. /* Ends C function definitions when using C++ */
  1671. #ifdef __cplusplus
  1672. }
  1673. #endif
  1674. #include <SDL3/SDL_close_code.h>
  1675. #endif /* SDL_surface_h_ */