SDL_pixels.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. * # CategoryPixels
  20. *
  21. * SDL offers facilities for pixel management.
  22. *
  23. * Largely these facilities deal with pixel _format_: what does this set of
  24. * bits represent?
  25. *
  26. * If you mostly want to think of a pixel as some combination of red, green,
  27. * blue, and maybe alpha intensities, this is all pretty straightforward, and
  28. * in many cases, is enough information to build a perfectly fine game.
  29. *
  30. * However, the actual definition of a pixel is more complex than that:
  31. *
  32. * Pixels are a representation of a color in a particular color space.
  33. *
  34. * The first characteristic of a color space is the color type. SDL
  35. * understands two different color types, RGB and YCbCr, or in SDL also
  36. * referred to as YUV.
  37. *
  38. * RGB colors consist of red, green, and blue channels of color that are added
  39. * together to represent the colors we see on the screen.
  40. *
  41. * https://en.wikipedia.org/wiki/RGB_color_model
  42. *
  43. * YCbCr colors represent colors as a Y luma brightness component and red and
  44. * blue chroma color offsets. This color representation takes advantage of the
  45. * fact that the human eye is more sensitive to brightness than the color in
  46. * an image. The Cb and Cr components are often compressed and have lower
  47. * resolution than the luma component.
  48. *
  49. * https://en.wikipedia.org/wiki/YCbCr
  50. *
  51. * When the color information in YCbCr is compressed, the Y pixels are left at
  52. * full resolution and each Cr and Cb pixel represents an average of the color
  53. * information in a block of Y pixels. The chroma location determines where in
  54. * that block of pixels the color information is coming from.
  55. *
  56. * The color range defines how much of the pixel to use when converting a
  57. * pixel into a color on the display. When the full color range is used, the
  58. * entire numeric range of the pixel bits is significant. When narrow color
  59. * range is used, for historical reasons, the pixel uses only a portion of the
  60. * numeric range to represent colors.
  61. *
  62. * The color primaries and white point are a definition of the colors in the
  63. * color space relative to the standard XYZ color space.
  64. *
  65. * https://en.wikipedia.org/wiki/CIE_1931_color_space
  66. *
  67. * The transfer characteristic, or opto-electrical transfer function (OETF),
  68. * is the way a color is converted from mathematically linear space into a
  69. * non-linear output signals.
  70. *
  71. * https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
  72. *
  73. * The matrix coefficients are used to convert between YCbCr and RGB colors.
  74. */
  75. #ifndef SDL_pixels_h_
  76. #define SDL_pixels_h_
  77. #include <SDL3/SDL_stdinc.h>
  78. #include <SDL3/SDL_error.h>
  79. #include <SDL3/SDL_endian.h>
  80. #include <SDL3/SDL_begin_code.h>
  81. /* Set up for C function definitions, even when using C++ */
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. /**
  86. * A fully opaque 8-bit alpha value.
  87. *
  88. * \since This macro is available since SDL 3.2.0.
  89. *
  90. * \sa SDL_ALPHA_TRANSPARENT
  91. */
  92. #define SDL_ALPHA_OPAQUE 255
  93. /**
  94. * A fully opaque floating point alpha value.
  95. *
  96. * \since This macro is available since SDL 3.2.0.
  97. *
  98. * \sa SDL_ALPHA_TRANSPARENT_FLOAT
  99. */
  100. #define SDL_ALPHA_OPAQUE_FLOAT 1.0f
  101. /**
  102. * A fully transparent 8-bit alpha value.
  103. *
  104. * \since This macro is available since SDL 3.2.0.
  105. *
  106. * \sa SDL_ALPHA_OPAQUE
  107. */
  108. #define SDL_ALPHA_TRANSPARENT 0
  109. /**
  110. * A fully transparent floating point alpha value.
  111. *
  112. * \since This macro is available since SDL 3.2.0.
  113. *
  114. * \sa SDL_ALPHA_OPAQUE_FLOAT
  115. */
  116. #define SDL_ALPHA_TRANSPARENT_FLOAT 0.0f
  117. /**
  118. * Pixel type.
  119. *
  120. * \since This enum is available since SDL 3.2.0.
  121. */
  122. typedef enum SDL_PixelType
  123. {
  124. SDL_PIXELTYPE_UNKNOWN,
  125. SDL_PIXELTYPE_INDEX1,
  126. SDL_PIXELTYPE_INDEX4,
  127. SDL_PIXELTYPE_INDEX8,
  128. SDL_PIXELTYPE_PACKED8,
  129. SDL_PIXELTYPE_PACKED16,
  130. SDL_PIXELTYPE_PACKED32,
  131. SDL_PIXELTYPE_ARRAYU8,
  132. SDL_PIXELTYPE_ARRAYU16,
  133. SDL_PIXELTYPE_ARRAYU32,
  134. SDL_PIXELTYPE_ARRAYF16,
  135. SDL_PIXELTYPE_ARRAYF32,
  136. /* appended at the end for compatibility with sdl2-compat: */
  137. SDL_PIXELTYPE_INDEX2
  138. } SDL_PixelType;
  139. /**
  140. * Bitmap pixel order, high bit -> low bit.
  141. *
  142. * \since This enum is available since SDL 3.2.0.
  143. */
  144. typedef enum SDL_BitmapOrder
  145. {
  146. SDL_BITMAPORDER_NONE,
  147. SDL_BITMAPORDER_4321,
  148. SDL_BITMAPORDER_1234
  149. } SDL_BitmapOrder;
  150. /**
  151. * Packed component order, high bit -> low bit.
  152. *
  153. * \since This enum is available since SDL 3.2.0.
  154. */
  155. typedef enum SDL_PackedOrder
  156. {
  157. SDL_PACKEDORDER_NONE,
  158. SDL_PACKEDORDER_XRGB,
  159. SDL_PACKEDORDER_RGBX,
  160. SDL_PACKEDORDER_ARGB,
  161. SDL_PACKEDORDER_RGBA,
  162. SDL_PACKEDORDER_XBGR,
  163. SDL_PACKEDORDER_BGRX,
  164. SDL_PACKEDORDER_ABGR,
  165. SDL_PACKEDORDER_BGRA
  166. } SDL_PackedOrder;
  167. /**
  168. * Array component order, low byte -> high byte.
  169. *
  170. * \since This enum is available since SDL 3.2.0.
  171. */
  172. typedef enum SDL_ArrayOrder
  173. {
  174. SDL_ARRAYORDER_NONE,
  175. SDL_ARRAYORDER_RGB,
  176. SDL_ARRAYORDER_RGBA,
  177. SDL_ARRAYORDER_ARGB,
  178. SDL_ARRAYORDER_BGR,
  179. SDL_ARRAYORDER_BGRA,
  180. SDL_ARRAYORDER_ABGR
  181. } SDL_ArrayOrder;
  182. /**
  183. * Packed component layout.
  184. *
  185. * \since This enum is available since SDL 3.2.0.
  186. */
  187. typedef enum SDL_PackedLayout
  188. {
  189. SDL_PACKEDLAYOUT_NONE,
  190. SDL_PACKEDLAYOUT_332,
  191. SDL_PACKEDLAYOUT_4444,
  192. SDL_PACKEDLAYOUT_1555,
  193. SDL_PACKEDLAYOUT_5551,
  194. SDL_PACKEDLAYOUT_565,
  195. SDL_PACKEDLAYOUT_8888,
  196. SDL_PACKEDLAYOUT_2101010,
  197. SDL_PACKEDLAYOUT_1010102
  198. } SDL_PackedLayout;
  199. /**
  200. * A macro for defining custom FourCC pixel formats.
  201. *
  202. * For example, defining SDL_PIXELFORMAT_YV12 looks like this:
  203. *
  204. * ```c
  205. * SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')
  206. * ```
  207. *
  208. * \param A the first character of the FourCC code.
  209. * \param B the second character of the FourCC code.
  210. * \param C the third character of the FourCC code.
  211. * \param D the fourth character of the FourCC code.
  212. * \returns a format value in the style of SDL_PixelFormat.
  213. *
  214. * \threadsafety It is safe to call this macro from any thread.
  215. *
  216. * \since This macro is available since SDL 3.2.0.
  217. */
  218. #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
  219. /**
  220. * A macro for defining custom non-FourCC pixel formats.
  221. *
  222. * For example, defining SDL_PIXELFORMAT_RGBA8888 looks like this:
  223. *
  224. * ```c
  225. * SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4)
  226. * ```
  227. *
  228. * \param type the type of the new format, probably a SDL_PixelType value.
  229. * \param order the order of the new format, probably a SDL_BitmapOrder,
  230. * SDL_PackedOrder, or SDL_ArrayOrder value.
  231. * \param layout the layout of the new format, probably an SDL_PackedLayout
  232. * value or zero.
  233. * \param bits the number of bits per pixel of the new format.
  234. * \param bytes the number of bytes per pixel of the new format.
  235. * \returns a format value in the style of SDL_PixelFormat.
  236. *
  237. * \threadsafety It is safe to call this macro from any thread.
  238. *
  239. * \since This macro is available since SDL 3.2.0.
  240. */
  241. #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
  242. ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
  243. ((bits) << 8) | ((bytes) << 0))
  244. /**
  245. * A macro to retrieve the flags of an SDL_PixelFormat.
  246. *
  247. * This macro is generally not needed directly by an app, which should use
  248. * specific tests, like SDL_ISPIXELFORMAT_FOURCC, instead.
  249. *
  250. * \param format an SDL_PixelFormat to check.
  251. * \returns the flags of `format`.
  252. *
  253. * \threadsafety It is safe to call this macro from any thread.
  254. *
  255. * \since This macro is available since SDL 3.2.0.
  256. */
  257. #define SDL_PIXELFLAG(format) (((format) >> 28) & 0x0F)
  258. /**
  259. * A macro to retrieve the type of an SDL_PixelFormat.
  260. *
  261. * This is usually a value from the SDL_PixelType enumeration.
  262. *
  263. * \param format an SDL_PixelFormat to check.
  264. * \returns the type of `format`.
  265. *
  266. * \threadsafety It is safe to call this macro from any thread.
  267. *
  268. * \since This macro is available since SDL 3.2.0.
  269. */
  270. #define SDL_PIXELTYPE(format) (((format) >> 24) & 0x0F)
  271. /**
  272. * A macro to retrieve the order of an SDL_PixelFormat.
  273. *
  274. * This is usually a value from the SDL_BitmapOrder, SDL_PackedOrder, or
  275. * SDL_ArrayOrder enumerations, depending on the format type.
  276. *
  277. * \param format an SDL_PixelFormat to check.
  278. * \returns the order of `format`.
  279. *
  280. * \threadsafety It is safe to call this macro from any thread.
  281. *
  282. * \since This macro is available since SDL 3.2.0.
  283. */
  284. #define SDL_PIXELORDER(format) (((format) >> 20) & 0x0F)
  285. /**
  286. * A macro to retrieve the layout of an SDL_PixelFormat.
  287. *
  288. * This is usually a value from the SDL_PackedLayout enumeration, or zero if a
  289. * layout doesn't make sense for the format type.
  290. *
  291. * \param format an SDL_PixelFormat to check.
  292. * \returns the layout of `format`.
  293. *
  294. * \threadsafety It is safe to call this macro from any thread.
  295. *
  296. * \since This macro is available since SDL 3.2.0.
  297. */
  298. #define SDL_PIXELLAYOUT(format) (((format) >> 16) & 0x0F)
  299. /**
  300. * A macro to determine an SDL_PixelFormat's bits per pixel.
  301. *
  302. * Note that this macro double-evaluates its parameter, so do not use
  303. * expressions with side-effects here.
  304. *
  305. * FourCC formats will report zero here, as it rarely makes sense to measure
  306. * them per-pixel.
  307. *
  308. * \param format an SDL_PixelFormat to check.
  309. * \returns the bits-per-pixel of `format`.
  310. *
  311. * \threadsafety It is safe to call this macro from any thread.
  312. *
  313. * \since This macro is available since SDL 3.2.0.
  314. *
  315. * \sa SDL_BYTESPERPIXEL
  316. */
  317. #define SDL_BITSPERPIXEL(format) \
  318. (SDL_ISPIXELFORMAT_FOURCC(format) ? 0 : (((format) >> 8) & 0xFF))
  319. /**
  320. * A macro to determine an SDL_PixelFormat's bytes per pixel.
  321. *
  322. * Note that this macro double-evaluates its parameter, so do not use
  323. * expressions with side-effects here.
  324. *
  325. * FourCC formats do their best here, but many of them don't have a meaningful
  326. * measurement of bytes per pixel.
  327. *
  328. * \param format an SDL_PixelFormat to check.
  329. * \returns the bytes-per-pixel of `format`.
  330. *
  331. * \threadsafety It is safe to call this macro from any thread.
  332. *
  333. * \since This macro is available since SDL 3.2.0.
  334. *
  335. * \sa SDL_BITSPERPIXEL
  336. */
  337. #define SDL_BYTESPERPIXEL(format) \
  338. (SDL_ISPIXELFORMAT_FOURCC(format) ? \
  339. ((((format) == SDL_PIXELFORMAT_YUY2) || \
  340. ((format) == SDL_PIXELFORMAT_UYVY) || \
  341. ((format) == SDL_PIXELFORMAT_YVYU) || \
  342. ((format) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((format) >> 0) & 0xFF))
  343. /**
  344. * A macro to determine if an SDL_PixelFormat is an indexed format.
  345. *
  346. * Note that this macro double-evaluates its parameter, so do not use
  347. * expressions with side-effects here.
  348. *
  349. * \param format an SDL_PixelFormat to check.
  350. * \returns true if the format is indexed, false otherwise.
  351. *
  352. * \threadsafety It is safe to call this macro from any thread.
  353. *
  354. * \since This macro is available since SDL 3.2.0.
  355. */
  356. #define SDL_ISPIXELFORMAT_INDEXED(format) \
  357. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  358. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
  359. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX2) || \
  360. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
  361. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
  362. /**
  363. * A macro to determine if an SDL_PixelFormat is a packed format.
  364. *
  365. * Note that this macro double-evaluates its parameter, so do not use
  366. * expressions with side-effects here.
  367. *
  368. * \param format an SDL_PixelFormat to check.
  369. * \returns true if the format is packed, false otherwise.
  370. *
  371. * \threadsafety It is safe to call this macro from any thread.
  372. *
  373. * \since This macro is available since SDL 3.2.0.
  374. */
  375. #define SDL_ISPIXELFORMAT_PACKED(format) \
  376. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  377. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
  378. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
  379. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
  380. /**
  381. * A macro to determine if an SDL_PixelFormat is an array format.
  382. *
  383. * Note that this macro double-evaluates its parameter, so do not use
  384. * expressions with side-effects here.
  385. *
  386. * \param format an SDL_PixelFormat to check.
  387. * \returns true if the format is an array, false otherwise.
  388. *
  389. * \threadsafety It is safe to call this macro from any thread.
  390. *
  391. * \since This macro is available since SDL 3.2.0.
  392. */
  393. #define SDL_ISPIXELFORMAT_ARRAY(format) \
  394. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  395. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
  396. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
  397. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
  398. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
  399. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
  400. /**
  401. * A macro to determine if an SDL_PixelFormat is a 10-bit format.
  402. *
  403. * Note that this macro double-evaluates its parameter, so do not use
  404. * expressions with side-effects here.
  405. *
  406. * \param format an SDL_PixelFormat to check.
  407. * \returns true if the format is 10-bit, false otherwise.
  408. *
  409. * \threadsafety It is safe to call this macro from any thread.
  410. *
  411. * \since This macro is available since SDL 3.2.0.
  412. */
  413. #define SDL_ISPIXELFORMAT_10BIT(format) \
  414. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  415. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
  416. (SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010)))
  417. /**
  418. * A macro to determine if an SDL_PixelFormat is a floating point format.
  419. *
  420. * Note that this macro double-evaluates its parameter, so do not use
  421. * expressions with side-effects here.
  422. *
  423. * \param format an SDL_PixelFormat to check.
  424. * \returns true if the format is 10-bit, false otherwise.
  425. *
  426. * \threadsafety It is safe to call this macro from any thread.
  427. *
  428. * \since This macro is available since SDL 3.2.0.
  429. */
  430. #define SDL_ISPIXELFORMAT_FLOAT(format) \
  431. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  432. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
  433. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
  434. /**
  435. * A macro to determine if an SDL_PixelFormat has an alpha channel.
  436. *
  437. * Note that this macro double-evaluates its parameter, so do not use
  438. * expressions with side-effects here.
  439. *
  440. * \param format an SDL_PixelFormat to check.
  441. * \returns true if the format has alpha, false otherwise.
  442. *
  443. * \threadsafety It is safe to call this macro from any thread.
  444. *
  445. * \since This macro is available since SDL 3.2.0.
  446. */
  447. #define SDL_ISPIXELFORMAT_ALPHA(format) \
  448. ((SDL_ISPIXELFORMAT_PACKED(format) && \
  449. ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
  450. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
  451. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
  452. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
  453. (SDL_ISPIXELFORMAT_ARRAY(format) && \
  454. ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
  455. (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
  456. (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
  457. (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
  458. /**
  459. * A macro to determine if an SDL_PixelFormat is a "FourCC" format.
  460. *
  461. * This covers custom and other unusual formats.
  462. *
  463. * Note that this macro double-evaluates its parameter, so do not use
  464. * expressions with side-effects here.
  465. *
  466. * \param format an SDL_PixelFormat to check.
  467. * \returns true if the format has alpha, false otherwise.
  468. *
  469. * \threadsafety It is safe to call this macro from any thread.
  470. *
  471. * \since This macro is available since SDL 3.2.0.
  472. */
  473. #define SDL_ISPIXELFORMAT_FOURCC(format) /* The flag is set to 1 because 0x1? is not in the printable ASCII range */ \
  474. ((format) && (SDL_PIXELFLAG(format) != 1))
  475. /* Note: If you modify this enum, update SDL_GetPixelFormatName() */
  476. /**
  477. * Pixel format.
  478. *
  479. * SDL's pixel formats have the following naming convention:
  480. *
  481. * - Names with a list of components and a single bit count, such as RGB24 and
  482. * ABGR32, define a platform-independent encoding into bytes in the order
  483. * specified. For example, in RGB24 data, each pixel is encoded in 3 bytes
  484. * (red, green, blue) in that order, and in ABGR32 data, each pixel is
  485. * encoded in 4 bytes alpha, blue, green, red) in that order. Use these
  486. * names if the property of a format that is important to you is the order
  487. * of the bytes in memory or on disk.
  488. * - Names with a bit count per component, such as ARGB8888 and XRGB1555, are
  489. * "packed" into an appropriately-sized integer in the platform's native
  490. * endianness. For example, ARGB8888 is a sequence of 32-bit integers; in
  491. * each integer, the most significant bits are alpha, and the least
  492. * significant bits are blue. On a little-endian CPU such as x86, the least
  493. * significant bits of each integer are arranged first in memory, but on a
  494. * big-endian CPU such as s390x, the most significant bits are arranged
  495. * first. Use these names if the property of a format that is important to
  496. * you is the meaning of each bit position within a native-endianness
  497. * integer.
  498. * - In indexed formats such as INDEX4LSB, each pixel is represented by
  499. * encoding an index into the palette into the indicated number of bits,
  500. * with multiple pixels packed into each byte if appropriate. In LSB
  501. * formats, the first (leftmost) pixel is stored in the least-significant
  502. * bits of the byte; in MSB formats, it's stored in the most-significant
  503. * bits. INDEX8 does not need LSB/MSB variants, because each pixel exactly
  504. * fills one byte.
  505. *
  506. * The 32-bit byte-array encodings such as RGBA32 are aliases for the
  507. * appropriate 8888 encoding for the current platform. For example, RGBA32 is
  508. * an alias for ABGR8888 on little-endian CPUs like x86, or an alias for
  509. * RGBA8888 on big-endian CPUs.
  510. *
  511. * \since This enum is available since SDL 3.2.0.
  512. */
  513. typedef enum SDL_PixelFormat
  514. {
  515. SDL_PIXELFORMAT_UNKNOWN = 0,
  516. SDL_PIXELFORMAT_INDEX1LSB = 0x11100100u,
  517. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0, 1, 0), */
  518. SDL_PIXELFORMAT_INDEX1MSB = 0x11200100u,
  519. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0, 1, 0), */
  520. SDL_PIXELFORMAT_INDEX2LSB = 0x1c100200u,
  521. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_4321, 0, 2, 0), */
  522. SDL_PIXELFORMAT_INDEX2MSB = 0x1c200200u,
  523. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_1234, 0, 2, 0), */
  524. SDL_PIXELFORMAT_INDEX4LSB = 0x12100400u,
  525. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0, 4, 0), */
  526. SDL_PIXELFORMAT_INDEX4MSB = 0x12200400u,
  527. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0, 4, 0), */
  528. SDL_PIXELFORMAT_INDEX8 = 0x13000801u,
  529. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1), */
  530. SDL_PIXELFORMAT_RGB332 = 0x14110801u,
  531. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_332, 8, 1), */
  532. SDL_PIXELFORMAT_XRGB4444 = 0x15120c02u,
  533. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_4444, 12, 2), */
  534. SDL_PIXELFORMAT_XBGR4444 = 0x15520c02u,
  535. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_4444, 12, 2), */
  536. SDL_PIXELFORMAT_XRGB1555 = 0x15130f02u,
  537. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_1555, 15, 2), */
  538. SDL_PIXELFORMAT_XBGR1555 = 0x15530f02u,
  539. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_1555, 15, 2), */
  540. SDL_PIXELFORMAT_ARGB4444 = 0x15321002u,
  541. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_4444, 16, 2), */
  542. SDL_PIXELFORMAT_RGBA4444 = 0x15421002u,
  543. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_4444, 16, 2), */
  544. SDL_PIXELFORMAT_ABGR4444 = 0x15721002u,
  545. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_4444, 16, 2), */
  546. SDL_PIXELFORMAT_BGRA4444 = 0x15821002u,
  547. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_4444, 16, 2), */
  548. SDL_PIXELFORMAT_ARGB1555 = 0x15331002u,
  549. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_1555, 16, 2), */
  550. SDL_PIXELFORMAT_RGBA5551 = 0x15441002u,
  551. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_5551, 16, 2), */
  552. SDL_PIXELFORMAT_ABGR1555 = 0x15731002u,
  553. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_1555, 16, 2), */
  554. SDL_PIXELFORMAT_BGRA5551 = 0x15841002u,
  555. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_5551, 16, 2), */
  556. SDL_PIXELFORMAT_RGB565 = 0x15151002u,
  557. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_565, 16, 2), */
  558. SDL_PIXELFORMAT_BGR565 = 0x15551002u,
  559. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_565, 16, 2), */
  560. SDL_PIXELFORMAT_RGB24 = 0x17101803u,
  561. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0, 24, 3), */
  562. SDL_PIXELFORMAT_BGR24 = 0x17401803u,
  563. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0, 24, 3), */
  564. SDL_PIXELFORMAT_XRGB8888 = 0x16161804u,
  565. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_8888, 24, 4), */
  566. SDL_PIXELFORMAT_RGBX8888 = 0x16261804u,
  567. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX, SDL_PACKEDLAYOUT_8888, 24, 4), */
  568. SDL_PIXELFORMAT_XBGR8888 = 0x16561804u,
  569. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_8888, 24, 4), */
  570. SDL_PIXELFORMAT_BGRX8888 = 0x16661804u,
  571. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX, SDL_PACKEDLAYOUT_8888, 24, 4), */
  572. SDL_PIXELFORMAT_ARGB8888 = 0x16362004u,
  573. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_8888, 32, 4), */
  574. SDL_PIXELFORMAT_RGBA8888 = 0x16462004u,
  575. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4), */
  576. SDL_PIXELFORMAT_ABGR8888 = 0x16762004u,
  577. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_8888, 32, 4), */
  578. SDL_PIXELFORMAT_BGRA8888 = 0x16862004u,
  579. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_8888, 32, 4), */
  580. SDL_PIXELFORMAT_XRGB2101010 = 0x16172004u,
  581. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_2101010, 32, 4), */
  582. SDL_PIXELFORMAT_XBGR2101010 = 0x16572004u,
  583. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_2101010, 32, 4), */
  584. SDL_PIXELFORMAT_ARGB2101010 = 0x16372004u,
  585. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_2101010, 32, 4), */
  586. SDL_PIXELFORMAT_ABGR2101010 = 0x16772004u,
  587. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_2101010, 32, 4), */
  588. SDL_PIXELFORMAT_RGB48 = 0x18103006u,
  589. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGB, 0, 48, 6), */
  590. SDL_PIXELFORMAT_BGR48 = 0x18403006u,
  591. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGR, 0, 48, 6), */
  592. SDL_PIXELFORMAT_RGBA64 = 0x18204008u,
  593. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGBA, 0, 64, 8), */
  594. SDL_PIXELFORMAT_ARGB64 = 0x18304008u,
  595. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ARGB, 0, 64, 8), */
  596. SDL_PIXELFORMAT_BGRA64 = 0x18504008u,
  597. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGRA, 0, 64, 8), */
  598. SDL_PIXELFORMAT_ABGR64 = 0x18604008u,
  599. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ABGR, 0, 64, 8), */
  600. SDL_PIXELFORMAT_RGB48_FLOAT = 0x1a103006u,
  601. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGB, 0, 48, 6), */
  602. SDL_PIXELFORMAT_BGR48_FLOAT = 0x1a403006u,
  603. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGR, 0, 48, 6), */
  604. SDL_PIXELFORMAT_RGBA64_FLOAT = 0x1a204008u,
  605. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGBA, 0, 64, 8), */
  606. SDL_PIXELFORMAT_ARGB64_FLOAT = 0x1a304008u,
  607. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ARGB, 0, 64, 8), */
  608. SDL_PIXELFORMAT_BGRA64_FLOAT = 0x1a504008u,
  609. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGRA, 0, 64, 8), */
  610. SDL_PIXELFORMAT_ABGR64_FLOAT = 0x1a604008u,
  611. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ABGR, 0, 64, 8), */
  612. SDL_PIXELFORMAT_RGB96_FLOAT = 0x1b10600cu,
  613. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGB, 0, 96, 12), */
  614. SDL_PIXELFORMAT_BGR96_FLOAT = 0x1b40600cu,
  615. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGR, 0, 96, 12), */
  616. SDL_PIXELFORMAT_RGBA128_FLOAT = 0x1b208010u,
  617. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGBA, 0, 128, 16), */
  618. SDL_PIXELFORMAT_ARGB128_FLOAT = 0x1b308010u,
  619. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ARGB, 0, 128, 16), */
  620. SDL_PIXELFORMAT_BGRA128_FLOAT = 0x1b508010u,
  621. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGRA, 0, 128, 16), */
  622. SDL_PIXELFORMAT_ABGR128_FLOAT = 0x1b608010u,
  623. /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ABGR, 0, 128, 16), */
  624. SDL_PIXELFORMAT_YV12 = 0x32315659u, /**< Planar mode: Y + V + U (3 planes) */
  625. /* SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'), */
  626. SDL_PIXELFORMAT_IYUV = 0x56555949u, /**< Planar mode: Y + U + V (3 planes) */
  627. /* SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'), */
  628. SDL_PIXELFORMAT_YUY2 = 0x32595559u, /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
  629. /* SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'), */
  630. SDL_PIXELFORMAT_UYVY = 0x59565955u, /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
  631. /* SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'), */
  632. SDL_PIXELFORMAT_YVYU = 0x55595659u, /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
  633. /* SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'), */
  634. SDL_PIXELFORMAT_NV12 = 0x3231564eu, /**< Planar mode: Y + U/V interleaved (2 planes) */
  635. /* SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'), */
  636. SDL_PIXELFORMAT_NV21 = 0x3132564eu, /**< Planar mode: Y + V/U interleaved (2 planes) */
  637. /* SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'), */
  638. SDL_PIXELFORMAT_P010 = 0x30313050u, /**< Planar mode: Y + U/V interleaved (2 planes) */
  639. /* SDL_DEFINE_PIXELFOURCC('P', '0', '1', '0'), */
  640. SDL_PIXELFORMAT_EXTERNAL_OES = 0x2053454fu, /**< Android video texture format */
  641. /* SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ') */
  642. SDL_PIXELFORMAT_MJPG = 0x47504a4du, /**< Motion JPEG */
  643. /* SDL_DEFINE_PIXELFOURCC('M', 'J', 'P', 'G') */
  644. /* Aliases for RGBA byte arrays of color data, for the current platform */
  645. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  646. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
  647. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
  648. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
  649. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
  650. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_RGBX8888,
  651. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_XRGB8888,
  652. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_BGRX8888,
  653. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_XBGR8888
  654. #else
  655. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
  656. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
  657. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
  658. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
  659. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_XBGR8888,
  660. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_BGRX8888,
  661. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_XRGB8888,
  662. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_RGBX8888
  663. #endif
  664. } SDL_PixelFormat;
  665. /**
  666. * Colorspace color type.
  667. *
  668. * \since This enum is available since SDL 3.2.0.
  669. */
  670. typedef enum SDL_ColorType
  671. {
  672. SDL_COLOR_TYPE_UNKNOWN = 0,
  673. SDL_COLOR_TYPE_RGB = 1,
  674. SDL_COLOR_TYPE_YCBCR = 2
  675. } SDL_ColorType;
  676. /**
  677. * Colorspace color range, as described by
  678. * https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en
  679. *
  680. * \since This enum is available since SDL 3.2.0.
  681. */
  682. typedef enum SDL_ColorRange
  683. {
  684. SDL_COLOR_RANGE_UNKNOWN = 0,
  685. SDL_COLOR_RANGE_LIMITED = 1, /**< Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma */
  686. SDL_COLOR_RANGE_FULL = 2 /**< Full range, e.g. 0-255 for 8-bit RGB and luma, and 1-255 for 8-bit chroma */
  687. } SDL_ColorRange;
  688. /**
  689. * Colorspace color primaries, as described by
  690. * https://www.itu.int/rec/T-REC-H.273-201612-S/en
  691. *
  692. * \since This enum is available since SDL 3.2.0.
  693. */
  694. typedef enum SDL_ColorPrimaries
  695. {
  696. SDL_COLOR_PRIMARIES_UNKNOWN = 0,
  697. SDL_COLOR_PRIMARIES_BT709 = 1, /**< ITU-R BT.709-6 */
  698. SDL_COLOR_PRIMARIES_UNSPECIFIED = 2,
  699. SDL_COLOR_PRIMARIES_BT470M = 4, /**< ITU-R BT.470-6 System M */
  700. SDL_COLOR_PRIMARIES_BT470BG = 5, /**< ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625 */
  701. SDL_COLOR_PRIMARIES_BT601 = 6, /**< ITU-R BT.601-7 525, SMPTE 170M */
  702. SDL_COLOR_PRIMARIES_SMPTE240 = 7, /**< SMPTE 240M, functionally the same as SDL_COLOR_PRIMARIES_BT601 */
  703. SDL_COLOR_PRIMARIES_GENERIC_FILM = 8, /**< Generic film (color filters using Illuminant C) */
  704. SDL_COLOR_PRIMARIES_BT2020 = 9, /**< ITU-R BT.2020-2 / ITU-R BT.2100-0 */
  705. SDL_COLOR_PRIMARIES_XYZ = 10, /**< SMPTE ST 428-1 */
  706. SDL_COLOR_PRIMARIES_SMPTE431 = 11, /**< SMPTE RP 431-2 */
  707. SDL_COLOR_PRIMARIES_SMPTE432 = 12, /**< SMPTE EG 432-1 / DCI P3 */
  708. SDL_COLOR_PRIMARIES_EBU3213 = 22, /**< EBU Tech. 3213-E */
  709. SDL_COLOR_PRIMARIES_CUSTOM = 31
  710. } SDL_ColorPrimaries;
  711. /**
  712. * Colorspace transfer characteristics.
  713. *
  714. * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
  715. *
  716. * \since This enum is available since SDL 3.2.0.
  717. */
  718. typedef enum SDL_TransferCharacteristics
  719. {
  720. SDL_TRANSFER_CHARACTERISTICS_UNKNOWN = 0,
  721. SDL_TRANSFER_CHARACTERISTICS_BT709 = 1, /**< Rec. ITU-R BT.709-6 / ITU-R BT1361 */
  722. SDL_TRANSFER_CHARACTERISTICS_UNSPECIFIED = 2,
  723. SDL_TRANSFER_CHARACTERISTICS_GAMMA22 = 4, /**< ITU-R BT.470-6 System M / ITU-R BT1700 625 PAL & SECAM */
  724. SDL_TRANSFER_CHARACTERISTICS_GAMMA28 = 5, /**< ITU-R BT.470-6 System B, G */
  725. SDL_TRANSFER_CHARACTERISTICS_BT601 = 6, /**< SMPTE ST 170M / ITU-R BT.601-7 525 or 625 */
  726. SDL_TRANSFER_CHARACTERISTICS_SMPTE240 = 7, /**< SMPTE ST 240M */
  727. SDL_TRANSFER_CHARACTERISTICS_LINEAR = 8,
  728. SDL_TRANSFER_CHARACTERISTICS_LOG100 = 9,
  729. SDL_TRANSFER_CHARACTERISTICS_LOG100_SQRT10 = 10,
  730. SDL_TRANSFER_CHARACTERISTICS_IEC61966 = 11, /**< IEC 61966-2-4 */
  731. SDL_TRANSFER_CHARACTERISTICS_BT1361 = 12, /**< ITU-R BT1361 Extended Colour Gamut */
  732. SDL_TRANSFER_CHARACTERISTICS_SRGB = 13, /**< IEC 61966-2-1 (sRGB or sYCC) */
  733. SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT = 14, /**< ITU-R BT2020 for 10-bit system */
  734. SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT = 15, /**< ITU-R BT2020 for 12-bit system */
  735. SDL_TRANSFER_CHARACTERISTICS_PQ = 16, /**< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems */
  736. SDL_TRANSFER_CHARACTERISTICS_SMPTE428 = 17, /**< SMPTE ST 428-1 */
  737. SDL_TRANSFER_CHARACTERISTICS_HLG = 18, /**< ARIB STD-B67, known as "hybrid log-gamma" (HLG) */
  738. SDL_TRANSFER_CHARACTERISTICS_CUSTOM = 31
  739. } SDL_TransferCharacteristics;
  740. /**
  741. * Colorspace matrix coefficients.
  742. *
  743. * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
  744. *
  745. * \since This enum is available since SDL 3.2.0.
  746. */
  747. typedef enum SDL_MatrixCoefficients
  748. {
  749. SDL_MATRIX_COEFFICIENTS_IDENTITY = 0,
  750. SDL_MATRIX_COEFFICIENTS_BT709 = 1, /**< ITU-R BT.709-6 */
  751. SDL_MATRIX_COEFFICIENTS_UNSPECIFIED = 2,
  752. SDL_MATRIX_COEFFICIENTS_FCC = 4, /**< US FCC Title 47 */
  753. SDL_MATRIX_COEFFICIENTS_BT470BG = 5, /**< ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625, functionally the same as SDL_MATRIX_COEFFICIENTS_BT601 */
  754. SDL_MATRIX_COEFFICIENTS_BT601 = 6, /**< ITU-R BT.601-7 525 */
  755. SDL_MATRIX_COEFFICIENTS_SMPTE240 = 7, /**< SMPTE 240M */
  756. SDL_MATRIX_COEFFICIENTS_YCGCO = 8,
  757. SDL_MATRIX_COEFFICIENTS_BT2020_NCL = 9, /**< ITU-R BT.2020-2 non-constant luminance */
  758. SDL_MATRIX_COEFFICIENTS_BT2020_CL = 10, /**< ITU-R BT.2020-2 constant luminance */
  759. SDL_MATRIX_COEFFICIENTS_SMPTE2085 = 11, /**< SMPTE ST 2085 */
  760. SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL = 12,
  761. SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL = 13,
  762. SDL_MATRIX_COEFFICIENTS_ICTCP = 14, /**< ITU-R BT.2100-0 ICTCP */
  763. SDL_MATRIX_COEFFICIENTS_CUSTOM = 31
  764. } SDL_MatrixCoefficients;
  765. /**
  766. * Colorspace chroma sample location.
  767. *
  768. * \since This enum is available since SDL 3.2.0.
  769. */
  770. typedef enum SDL_ChromaLocation
  771. {
  772. SDL_CHROMA_LOCATION_NONE = 0, /**< RGB, no chroma sampling */
  773. SDL_CHROMA_LOCATION_LEFT = 1, /**< In MPEG-2, MPEG-4, and AVC, Cb and Cr are taken on midpoint of the left-edge of the 2x2 square. In other words, they have the same horizontal location as the top-left pixel, but is shifted one-half pixel down vertically. */
  774. SDL_CHROMA_LOCATION_CENTER = 2, /**< In JPEG/JFIF, H.261, and MPEG-1, Cb and Cr are taken at the center of the 2x2 square. In other words, they are offset one-half pixel to the right and one-half pixel down compared to the top-left pixel. */
  775. SDL_CHROMA_LOCATION_TOPLEFT = 3 /**< In HEVC for BT.2020 and BT.2100 content (in particular on Blu-rays), Cb and Cr are sampled at the same location as the group's top-left Y pixel ("co-sited", "co-located"). */
  776. } SDL_ChromaLocation;
  777. /* Colorspace definition */
  778. /**
  779. * A macro for defining custom SDL_Colorspace formats.
  780. *
  781. * For example, defining SDL_COLORSPACE_SRGB looks like this:
  782. *
  783. * ```c
  784. * SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  785. * SDL_COLOR_RANGE_FULL,
  786. * SDL_COLOR_PRIMARIES_BT709,
  787. * SDL_TRANSFER_CHARACTERISTICS_SRGB,
  788. * SDL_MATRIX_COEFFICIENTS_IDENTITY,
  789. * SDL_CHROMA_LOCATION_NONE)
  790. * ```
  791. *
  792. * \param type the type of the new format, probably an SDL_ColorType value.
  793. * \param range the range of the new format, probably a SDL_ColorRange value.
  794. * \param primaries the primaries of the new format, probably an
  795. * SDL_ColorPrimaries value.
  796. * \param transfer the transfer characteristics of the new format, probably an
  797. * SDL_TransferCharacteristics value.
  798. * \param matrix the matrix coefficients of the new format, probably an
  799. * SDL_MatrixCoefficients value.
  800. * \param chroma the chroma sample location of the new format, probably an
  801. * SDL_ChromaLocation value.
  802. * \returns a format value in the style of SDL_Colorspace.
  803. *
  804. * \threadsafety It is safe to call this macro from any thread.
  805. *
  806. * \since This macro is available since SDL 3.2.0.
  807. */
  808. #define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
  809. (((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
  810. ((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))
  811. /**
  812. * A macro to retrieve the type of an SDL_Colorspace.
  813. *
  814. * \param cspace an SDL_Colorspace to check.
  815. * \returns the SDL_ColorType for `cspace`.
  816. *
  817. * \threadsafety It is safe to call this macro from any thread.
  818. *
  819. * \since This macro is available since SDL 3.2.0.
  820. */
  821. #define SDL_COLORSPACETYPE(cspace) (SDL_ColorType)(((cspace) >> 28) & 0x0F)
  822. /**
  823. * A macro to retrieve the range of an SDL_Colorspace.
  824. *
  825. * \param cspace an SDL_Colorspace to check.
  826. * \returns the SDL_ColorRange of `cspace`.
  827. *
  828. * \threadsafety It is safe to call this macro from any thread.
  829. *
  830. * \since This macro is available since SDL 3.2.0.
  831. */
  832. #define SDL_COLORSPACERANGE(cspace) (SDL_ColorRange)(((cspace) >> 24) & 0x0F)
  833. /**
  834. * A macro to retrieve the chroma sample location of an SDL_Colorspace.
  835. *
  836. * \param cspace an SDL_Colorspace to check.
  837. * \returns the SDL_ChromaLocation of `cspace`.
  838. *
  839. * \threadsafety It is safe to call this macro from any thread.
  840. *
  841. * \since This macro is available since SDL 3.2.0.
  842. */
  843. #define SDL_COLORSPACECHROMA(cspace) (SDL_ChromaLocation)(((cspace) >> 20) & 0x0F)
  844. /**
  845. * A macro to retrieve the primaries of an SDL_Colorspace.
  846. *
  847. * \param cspace an SDL_Colorspace to check.
  848. * \returns the SDL_ColorPrimaries of `cspace`.
  849. *
  850. * \threadsafety It is safe to call this macro from any thread.
  851. *
  852. * \since This macro is available since SDL 3.2.0.
  853. */
  854. #define SDL_COLORSPACEPRIMARIES(cspace) (SDL_ColorPrimaries)(((cspace) >> 10) & 0x1F)
  855. /**
  856. * A macro to retrieve the transfer characteristics of an SDL_Colorspace.
  857. *
  858. * \param cspace an SDL_Colorspace to check.
  859. * \returns the SDL_TransferCharacteristics of `cspace`.
  860. *
  861. * \threadsafety It is safe to call this macro from any thread.
  862. *
  863. * \since This macro is available since SDL 3.2.0.
  864. */
  865. #define SDL_COLORSPACETRANSFER(cspace) (SDL_TransferCharacteristics)(((cspace) >> 5) & 0x1F)
  866. /**
  867. * A macro to retrieve the matrix coefficients of an SDL_Colorspace.
  868. *
  869. * \param cspace an SDL_Colorspace to check.
  870. * \returns the SDL_MatrixCoefficients of `cspace`.
  871. *
  872. * \threadsafety It is safe to call this macro from any thread.
  873. *
  874. * \since This macro is available since SDL 3.2.0.
  875. */
  876. #define SDL_COLORSPACEMATRIX(cspace) (SDL_MatrixCoefficients)((cspace) & 0x1F)
  877. /**
  878. * A macro to determine if an SDL_Colorspace uses BT601 (or BT470BG) matrix
  879. * coefficients.
  880. *
  881. * Note that this macro double-evaluates its parameter, so do not use
  882. * expressions with side-effects here.
  883. *
  884. * \param cspace an SDL_Colorspace to check.
  885. * \returns true if BT601 or BT470BG, false otherwise.
  886. *
  887. * \threadsafety It is safe to call this macro from any thread.
  888. *
  889. * \since This macro is available since SDL 3.2.0.
  890. */
  891. #define SDL_ISCOLORSPACE_MATRIX_BT601(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT470BG)
  892. /**
  893. * A macro to determine if an SDL_Colorspace uses BT709 matrix coefficients.
  894. *
  895. * \param cspace an SDL_Colorspace to check.
  896. * \returns true if BT709, false otherwise.
  897. *
  898. * \threadsafety It is safe to call this macro from any thread.
  899. *
  900. * \since This macro is available since SDL 3.2.0.
  901. */
  902. #define SDL_ISCOLORSPACE_MATRIX_BT709(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT709)
  903. /**
  904. * A macro to determine if an SDL_Colorspace uses BT2020_NCL matrix
  905. * coefficients.
  906. *
  907. * \param cspace an SDL_Colorspace to check.
  908. * \returns true if BT2020_NCL, false otherwise.
  909. *
  910. * \threadsafety It is safe to call this macro from any thread.
  911. *
  912. * \since This macro is available since SDL 3.2.0.
  913. */
  914. #define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
  915. /**
  916. * A macro to determine if an SDL_Colorspace has a limited range.
  917. *
  918. * \param cspace an SDL_Colorspace to check.
  919. * \returns true if limited range, false otherwise.
  920. *
  921. * \threadsafety It is safe to call this macro from any thread.
  922. *
  923. * \since This macro is available since SDL 3.2.0.
  924. */
  925. #define SDL_ISCOLORSPACE_LIMITED_RANGE(cspace) (SDL_COLORSPACERANGE(cspace) != SDL_COLOR_RANGE_FULL)
  926. /**
  927. * A macro to determine if an SDL_Colorspace has a full range.
  928. *
  929. * \param cspace an SDL_Colorspace to check.
  930. * \returns true if full range, false otherwise.
  931. *
  932. * \threadsafety It is safe to call this macro from any thread.
  933. *
  934. * \since This macro is available since SDL 3.2.0.
  935. */
  936. #define SDL_ISCOLORSPACE_FULL_RANGE(cspace) (SDL_COLORSPACERANGE(cspace) == SDL_COLOR_RANGE_FULL)
  937. /**
  938. * Colorspace definitions.
  939. *
  940. * Since similar colorspaces may vary in their details (matrix, transfer
  941. * function, etc.), this is not an exhaustive list, but rather a
  942. * representative sample of the kinds of colorspaces supported in SDL.
  943. *
  944. * \since This enum is available since SDL 3.2.0.
  945. *
  946. * \sa SDL_ColorPrimaries
  947. * \sa SDL_ColorRange
  948. * \sa SDL_ColorType
  949. * \sa SDL_MatrixCoefficients
  950. * \sa SDL_TransferCharacteristics
  951. */
  952. typedef enum SDL_Colorspace
  953. {
  954. SDL_COLORSPACE_UNKNOWN = 0,
  955. /* sRGB is a gamma corrected colorspace, and the default colorspace for SDL rendering and 8-bit RGB surfaces */
  956. SDL_COLORSPACE_SRGB = 0x120005a0u, /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 */
  957. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  958. SDL_COLOR_RANGE_FULL,
  959. SDL_COLOR_PRIMARIES_BT709,
  960. SDL_TRANSFER_CHARACTERISTICS_SRGB,
  961. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  962. SDL_CHROMA_LOCATION_NONE), */
  963. /* This is a linear colorspace and the default colorspace for floating point surfaces. On Windows this is the scRGB colorspace, and on Apple platforms this is kCGColorSpaceExtendedLinearSRGB for EDR content */
  964. SDL_COLORSPACE_SRGB_LINEAR = 0x12000500u, /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 */
  965. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  966. SDL_COLOR_RANGE_FULL,
  967. SDL_COLOR_PRIMARIES_BT709,
  968. SDL_TRANSFER_CHARACTERISTICS_LINEAR,
  969. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  970. SDL_CHROMA_LOCATION_NONE), */
  971. /* HDR10 is a non-linear HDR colorspace and the default colorspace for 10-bit surfaces */
  972. SDL_COLORSPACE_HDR10 = 0x12002600u, /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 */
  973. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  974. SDL_COLOR_RANGE_FULL,
  975. SDL_COLOR_PRIMARIES_BT2020,
  976. SDL_TRANSFER_CHARACTERISTICS_PQ,
  977. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  978. SDL_CHROMA_LOCATION_NONE), */
  979. SDL_COLORSPACE_JPEG = 0x220004c6u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 */
  980. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  981. SDL_COLOR_RANGE_FULL,
  982. SDL_COLOR_PRIMARIES_BT709,
  983. SDL_TRANSFER_CHARACTERISTICS_BT601,
  984. SDL_MATRIX_COEFFICIENTS_BT601,
  985. SDL_CHROMA_LOCATION_NONE), */
  986. SDL_COLORSPACE_BT601_LIMITED = 0x211018c6u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
  987. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  988. SDL_COLOR_RANGE_LIMITED,
  989. SDL_COLOR_PRIMARIES_BT601,
  990. SDL_TRANSFER_CHARACTERISTICS_BT601,
  991. SDL_MATRIX_COEFFICIENTS_BT601,
  992. SDL_CHROMA_LOCATION_LEFT), */
  993. SDL_COLORSPACE_BT601_FULL = 0x221018c6u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
  994. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  995. SDL_COLOR_RANGE_FULL,
  996. SDL_COLOR_PRIMARIES_BT601,
  997. SDL_TRANSFER_CHARACTERISTICS_BT601,
  998. SDL_MATRIX_COEFFICIENTS_BT601,
  999. SDL_CHROMA_LOCATION_LEFT), */
  1000. SDL_COLORSPACE_BT709_LIMITED = 0x21100421u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
  1001. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  1002. SDL_COLOR_RANGE_LIMITED,
  1003. SDL_COLOR_PRIMARIES_BT709,
  1004. SDL_TRANSFER_CHARACTERISTICS_BT709,
  1005. SDL_MATRIX_COEFFICIENTS_BT709,
  1006. SDL_CHROMA_LOCATION_LEFT), */
  1007. SDL_COLORSPACE_BT709_FULL = 0x22100421u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
  1008. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  1009. SDL_COLOR_RANGE_FULL,
  1010. SDL_COLOR_PRIMARIES_BT709,
  1011. SDL_TRANSFER_CHARACTERISTICS_BT709,
  1012. SDL_MATRIX_COEFFICIENTS_BT709,
  1013. SDL_CHROMA_LOCATION_LEFT), */
  1014. SDL_COLORSPACE_BT2020_LIMITED = 0x21102609u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 */
  1015. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  1016. SDL_COLOR_RANGE_LIMITED,
  1017. SDL_COLOR_PRIMARIES_BT2020,
  1018. SDL_TRANSFER_CHARACTERISTICS_PQ,
  1019. SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
  1020. SDL_CHROMA_LOCATION_LEFT), */
  1021. SDL_COLORSPACE_BT2020_FULL = 0x22102609u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 */
  1022. /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  1023. SDL_COLOR_RANGE_FULL,
  1024. SDL_COLOR_PRIMARIES_BT2020,
  1025. SDL_TRANSFER_CHARACTERISTICS_PQ,
  1026. SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
  1027. SDL_CHROMA_LOCATION_LEFT), */
  1028. SDL_COLORSPACE_RGB_DEFAULT = SDL_COLORSPACE_SRGB, /**< The default colorspace for RGB surfaces if no colorspace is specified */
  1029. SDL_COLORSPACE_YUV_DEFAULT = SDL_COLORSPACE_JPEG /**< The default colorspace for YUV surfaces if no colorspace is specified */
  1030. } SDL_Colorspace;
  1031. /**
  1032. * A structure that represents a color as RGBA components.
  1033. *
  1034. * The bits of this structure can be directly reinterpreted as an
  1035. * integer-packed color which uses the SDL_PIXELFORMAT_RGBA32 format
  1036. * (SDL_PIXELFORMAT_ABGR8888 on little-endian systems and
  1037. * SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
  1038. *
  1039. * \since This struct is available since SDL 3.2.0.
  1040. */
  1041. typedef struct SDL_Color
  1042. {
  1043. Uint8 r;
  1044. Uint8 g;
  1045. Uint8 b;
  1046. Uint8 a;
  1047. } SDL_Color;
  1048. /**
  1049. * The bits of this structure can be directly reinterpreted as a float-packed
  1050. * color which uses the SDL_PIXELFORMAT_RGBA128_FLOAT format
  1051. *
  1052. * \since This struct is available since SDL 3.2.0.
  1053. */
  1054. typedef struct SDL_FColor
  1055. {
  1056. float r;
  1057. float g;
  1058. float b;
  1059. float a;
  1060. } SDL_FColor;
  1061. /**
  1062. * A set of indexed colors representing a palette.
  1063. *
  1064. * \since This struct is available since SDL 3.2.0.
  1065. *
  1066. * \sa SDL_SetPaletteColors
  1067. */
  1068. typedef struct SDL_Palette
  1069. {
  1070. int ncolors; /**< number of elements in `colors`. */
  1071. SDL_Color *colors; /**< an array of colors, `ncolors` long. */
  1072. Uint32 version; /**< internal use only, do not touch. */
  1073. int refcount; /**< internal use only, do not touch. */
  1074. } SDL_Palette;
  1075. /**
  1076. * Details about the format of a pixel.
  1077. *
  1078. * \since This struct is available since SDL 3.2.0.
  1079. */
  1080. typedef struct SDL_PixelFormatDetails
  1081. {
  1082. SDL_PixelFormat format;
  1083. Uint8 bits_per_pixel;
  1084. Uint8 bytes_per_pixel;
  1085. Uint8 padding[2];
  1086. Uint32 Rmask;
  1087. Uint32 Gmask;
  1088. Uint32 Bmask;
  1089. Uint32 Amask;
  1090. Uint8 Rbits;
  1091. Uint8 Gbits;
  1092. Uint8 Bbits;
  1093. Uint8 Abits;
  1094. Uint8 Rshift;
  1095. Uint8 Gshift;
  1096. Uint8 Bshift;
  1097. Uint8 Ashift;
  1098. } SDL_PixelFormatDetails;
  1099. /**
  1100. * Get the human readable name of a pixel format.
  1101. *
  1102. * \param format the pixel format to query.
  1103. * \returns the human readable name of the specified pixel format or
  1104. * "SDL_PIXELFORMAT_UNKNOWN" if the format isn't recognized.
  1105. *
  1106. * \threadsafety It is safe to call this function from any thread.
  1107. *
  1108. * \since This function is available since SDL 3.2.0.
  1109. */
  1110. extern SDL_DECLSPEC const char * SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat format);
  1111. /**
  1112. * Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
  1113. *
  1114. * \param format one of the SDL_PixelFormat values.
  1115. * \param bpp a bits per pixel value; usually 15, 16, or 32.
  1116. * \param Rmask a pointer filled in with the red mask for the format.
  1117. * \param Gmask a pointer filled in with the green mask for the format.
  1118. * \param Bmask a pointer filled in with the blue mask for the format.
  1119. * \param Amask a pointer filled in with the alpha mask for the format.
  1120. * \returns true on success or false on failure; call SDL_GetError() for more
  1121. * information.
  1122. *
  1123. * \threadsafety It is safe to call this function from any thread.
  1124. *
  1125. * \since This function is available since SDL 3.2.0.
  1126. *
  1127. * \sa SDL_GetPixelFormatForMasks
  1128. */
  1129. extern SDL_DECLSPEC bool SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask);
  1130. /**
  1131. * Convert a bpp value and RGBA masks to an enumerated pixel format.
  1132. *
  1133. * This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't
  1134. * possible.
  1135. *
  1136. * \param bpp a bits per pixel value; usually 15, 16, or 32.
  1137. * \param Rmask the red mask for the format.
  1138. * \param Gmask the green mask for the format.
  1139. * \param Bmask the blue mask for the format.
  1140. * \param Amask the alpha mask for the format.
  1141. * \returns the SDL_PixelFormat value corresponding to the format masks, or
  1142. * SDL_PIXELFORMAT_UNKNOWN if there isn't a match.
  1143. *
  1144. * \threadsafety It is safe to call this function from any thread.
  1145. *
  1146. * \since This function is available since SDL 3.2.0.
  1147. *
  1148. * \sa SDL_GetMasksForPixelFormat
  1149. */
  1150. extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
  1151. /**
  1152. * Create an SDL_PixelFormatDetails structure corresponding to a pixel format.
  1153. *
  1154. * Returned structure may come from a shared global cache (i.e. not newly
  1155. * allocated), and hence should not be modified, especially the palette. Weird
  1156. * errors such as `Blit combination not supported` may occur.
  1157. *
  1158. * \param format one of the SDL_PixelFormat values.
  1159. * \returns a pointer to a SDL_PixelFormatDetails structure or NULL on
  1160. * failure; call SDL_GetError() for more information.
  1161. *
  1162. * \threadsafety It is safe to call this function from any thread.
  1163. *
  1164. * \since This function is available since SDL 3.2.0.
  1165. */
  1166. extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDetails(SDL_PixelFormat format);
  1167. /**
  1168. * Create a palette structure with the specified number of color entries.
  1169. *
  1170. * The palette entries are initialized to white.
  1171. *
  1172. * \param ncolors represents the number of color entries in the color palette.
  1173. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  1174. * there wasn't enough memory); call SDL_GetError() for more
  1175. * information.
  1176. *
  1177. * \threadsafety It is safe to call this function from any thread.
  1178. *
  1179. * \since This function is available since SDL 3.2.0.
  1180. *
  1181. * \sa SDL_DestroyPalette
  1182. * \sa SDL_SetPaletteColors
  1183. * \sa SDL_SetSurfacePalette
  1184. */
  1185. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreatePalette(int ncolors);
  1186. /**
  1187. * Set a range of colors in a palette.
  1188. *
  1189. * \param palette the SDL_Palette structure to modify.
  1190. * \param colors an array of SDL_Color structures to copy into the palette.
  1191. * \param firstcolor the index of the first palette entry to modify.
  1192. * \param ncolors the number of entries to modify.
  1193. * \returns true on success or false on failure; call SDL_GetError() for more
  1194. * information.
  1195. *
  1196. * \threadsafety It is safe to call this function from any thread, as long as
  1197. * the palette is not modified or destroyed in another thread.
  1198. *
  1199. * \since This function is available since SDL 3.2.0.
  1200. */
  1201. extern SDL_DECLSPEC bool SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors);
  1202. /**
  1203. * Free a palette created with SDL_CreatePalette().
  1204. *
  1205. * \param palette the SDL_Palette structure to be freed.
  1206. *
  1207. * \threadsafety It is safe to call this function from any thread, as long as
  1208. * the palette is not modified or destroyed in another thread.
  1209. *
  1210. * \since This function is available since SDL 3.2.0.
  1211. *
  1212. * \sa SDL_CreatePalette
  1213. */
  1214. extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette *palette);
  1215. /**
  1216. * Map an RGB triple to an opaque pixel value for a given pixel format.
  1217. *
  1218. * This function maps the RGB color value to the specified pixel format and
  1219. * returns the pixel value best approximating the given RGB color value for
  1220. * the given pixel format.
  1221. *
  1222. * If the format has a palette (8-bit) the index of the closest matching color
  1223. * in the palette will be returned.
  1224. *
  1225. * If the specified pixel format has an alpha component it will be returned as
  1226. * all 1 bits (fully opaque).
  1227. *
  1228. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1229. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1230. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1231. * for an 8-bpp format).
  1232. *
  1233. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  1234. * format.
  1235. * \param palette an optional palette for indexed formats, may be NULL.
  1236. * \param r the red component of the pixel in the range 0-255.
  1237. * \param g the green component of the pixel in the range 0-255.
  1238. * \param b the blue component of the pixel in the range 0-255.
  1239. * \returns a pixel value.
  1240. *
  1241. * \threadsafety It is safe to call this function from any thread, as long as
  1242. * the palette is not modified.
  1243. *
  1244. * \since This function is available since SDL 3.2.0.
  1245. *
  1246. * \sa SDL_GetPixelFormatDetails
  1247. * \sa SDL_GetRGB
  1248. * \sa SDL_MapRGBA
  1249. * \sa SDL_MapSurfaceRGB
  1250. */
  1251. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b);
  1252. /**
  1253. * Map an RGBA quadruple to a pixel value for a given pixel format.
  1254. *
  1255. * This function maps the RGBA color value to the specified pixel format and
  1256. * returns the pixel value best approximating the given RGBA color value for
  1257. * the given pixel format.
  1258. *
  1259. * If the specified pixel format has no alpha component the alpha value will
  1260. * be ignored (as it will be in formats with a palette).
  1261. *
  1262. * If the format has a palette (8-bit) the index of the closest matching color
  1263. * in the palette will be returned.
  1264. *
  1265. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  1266. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  1267. * format the return value can be assigned to a Uint16, and similarly a Uint8
  1268. * for an 8-bpp format).
  1269. *
  1270. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  1271. * format.
  1272. * \param palette an optional palette for indexed formats, may be NULL.
  1273. * \param r the red component of the pixel in the range 0-255.
  1274. * \param g the green component of the pixel in the range 0-255.
  1275. * \param b the blue component of the pixel in the range 0-255.
  1276. * \param a the alpha component of the pixel in the range 0-255.
  1277. * \returns a pixel value.
  1278. *
  1279. * \threadsafety It is safe to call this function from any thread, as long as
  1280. * the palette is not modified.
  1281. *
  1282. * \since This function is available since SDL 3.2.0.
  1283. *
  1284. * \sa SDL_GetPixelFormatDetails
  1285. * \sa SDL_GetRGBA
  1286. * \sa SDL_MapRGB
  1287. * \sa SDL_MapSurfaceRGBA
  1288. */
  1289. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1290. /**
  1291. * Get RGB values from a pixel in the specified format.
  1292. *
  1293. * This function uses the entire 8-bit [0..255] range when converting color
  1294. * components from pixel formats with less than 8-bits per RGB component
  1295. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  1296. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  1297. *
  1298. * \param pixelvalue a pixel value.
  1299. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  1300. * format.
  1301. * \param palette an optional palette for indexed formats, may be NULL.
  1302. * \param r a pointer filled in with the red component, may be NULL.
  1303. * \param g a pointer filled in with the green component, may be NULL.
  1304. * \param b a pointer filled in with the blue component, may be NULL.
  1305. *
  1306. * \threadsafety It is safe to call this function from any thread, as long as
  1307. * the palette is not modified.
  1308. *
  1309. * \since This function is available since SDL 3.2.0.
  1310. *
  1311. * \sa SDL_GetPixelFormatDetails
  1312. * \sa SDL_GetRGBA
  1313. * \sa SDL_MapRGB
  1314. * \sa SDL_MapRGBA
  1315. */
  1316. extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
  1317. /**
  1318. * Get RGBA values from a pixel in the specified format.
  1319. *
  1320. * This function uses the entire 8-bit [0..255] range when converting color
  1321. * components from pixel formats with less than 8-bits per RGB component
  1322. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  1323. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  1324. *
  1325. * If the surface has no alpha component, the alpha will be returned as 0xff
  1326. * (100% opaque).
  1327. *
  1328. * \param pixelvalue a pixel value.
  1329. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  1330. * format.
  1331. * \param palette an optional palette for indexed formats, may be NULL.
  1332. * \param r a pointer filled in with the red component, may be NULL.
  1333. * \param g a pointer filled in with the green component, may be NULL.
  1334. * \param b a pointer filled in with the blue component, may be NULL.
  1335. * \param a a pointer filled in with the alpha component, may be NULL.
  1336. *
  1337. * \threadsafety It is safe to call this function from any thread, as long as
  1338. * the palette is not modified.
  1339. *
  1340. * \since This function is available since SDL 3.2.0.
  1341. *
  1342. * \sa SDL_GetPixelFormatDetails
  1343. * \sa SDL_GetRGB
  1344. * \sa SDL_MapRGB
  1345. * \sa SDL_MapRGBA
  1346. */
  1347. extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1348. /* Ends C function definitions when using C++ */
  1349. #ifdef __cplusplus
  1350. }
  1351. #endif
  1352. #include <SDL3/SDL_close_code.h>
  1353. #endif /* SDL_pixels_h_ */