2
0

SDL_pixels.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryPixels
  20. *
  21. * Pixel management.
  22. */
  23. #ifndef SDL_pixels_h_
  24. #define SDL_pixels_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_endian.h>
  28. #include <SDL3/SDL_begin_code.h>
  29. /* Set up for C function definitions, even when using C++ */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /**
  34. * \name Transparency definitions
  35. *
  36. * These define alpha as the opacity of a surface.
  37. */
  38. /* @{ */
  39. #define SDL_ALPHA_OPAQUE 255
  40. #define SDL_ALPHA_TRANSPARENT 0
  41. /* @} */
  42. /** Pixel type. */
  43. typedef enum SDL_PixelType
  44. {
  45. SDL_PIXELTYPE_UNKNOWN,
  46. SDL_PIXELTYPE_INDEX1,
  47. SDL_PIXELTYPE_INDEX4,
  48. SDL_PIXELTYPE_INDEX8,
  49. SDL_PIXELTYPE_PACKED8,
  50. SDL_PIXELTYPE_PACKED16,
  51. SDL_PIXELTYPE_PACKED32,
  52. SDL_PIXELTYPE_ARRAYU8,
  53. SDL_PIXELTYPE_ARRAYU16,
  54. SDL_PIXELTYPE_ARRAYU32,
  55. SDL_PIXELTYPE_ARRAYF16,
  56. SDL_PIXELTYPE_ARRAYF32,
  57. /* appended at the end for compatibility with sdl2-compat: */
  58. SDL_PIXELTYPE_INDEX2
  59. } SDL_PixelType;
  60. /** Bitmap pixel order, high bit -> low bit. */
  61. typedef enum SDL_BitmapOrder
  62. {
  63. SDL_BITMAPORDER_NONE,
  64. SDL_BITMAPORDER_4321,
  65. SDL_BITMAPORDER_1234
  66. } SDL_BitmapOrder;
  67. /** Packed component order, high bit -> low bit. */
  68. typedef enum SDL_PackedOrder
  69. {
  70. SDL_PACKEDORDER_NONE,
  71. SDL_PACKEDORDER_XRGB,
  72. SDL_PACKEDORDER_RGBX,
  73. SDL_PACKEDORDER_ARGB,
  74. SDL_PACKEDORDER_RGBA,
  75. SDL_PACKEDORDER_XBGR,
  76. SDL_PACKEDORDER_BGRX,
  77. SDL_PACKEDORDER_ABGR,
  78. SDL_PACKEDORDER_BGRA
  79. } SDL_PackedOrder;
  80. /** Array component order, low byte -> high byte. */
  81. typedef enum SDL_ArrayOrder
  82. {
  83. SDL_ARRAYORDER_NONE,
  84. SDL_ARRAYORDER_RGB,
  85. SDL_ARRAYORDER_RGBA,
  86. SDL_ARRAYORDER_ARGB,
  87. SDL_ARRAYORDER_BGR,
  88. SDL_ARRAYORDER_BGRA,
  89. SDL_ARRAYORDER_ABGR
  90. } SDL_ArrayOrder;
  91. /** Packed component layout. */
  92. typedef enum SDL_PackedLayout
  93. {
  94. SDL_PACKEDLAYOUT_NONE,
  95. SDL_PACKEDLAYOUT_332,
  96. SDL_PACKEDLAYOUT_4444,
  97. SDL_PACKEDLAYOUT_1555,
  98. SDL_PACKEDLAYOUT_5551,
  99. SDL_PACKEDLAYOUT_565,
  100. SDL_PACKEDLAYOUT_8888,
  101. SDL_PACKEDLAYOUT_2101010,
  102. SDL_PACKEDLAYOUT_1010102
  103. } SDL_PackedLayout;
  104. #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
  105. #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
  106. ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
  107. ((bits) << 8) | ((bytes) << 0))
  108. #define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
  109. #define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
  110. #define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
  111. #define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
  112. #define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
  113. #define SDL_BYTESPERPIXEL(X) \
  114. (SDL_ISPIXELFORMAT_FOURCC(X) ? \
  115. ((((X) == SDL_PIXELFORMAT_YUY2) || \
  116. ((X) == SDL_PIXELFORMAT_UYVY) || \
  117. ((X) == SDL_PIXELFORMAT_YVYU) || \
  118. ((X) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((X) >> 0) & 0xFF))
  119. #define SDL_ISPIXELFORMAT_INDEXED(format) \
  120. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  121. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
  122. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX2) || \
  123. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
  124. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
  125. #define SDL_ISPIXELFORMAT_PACKED(format) \
  126. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  127. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
  128. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
  129. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
  130. #define SDL_ISPIXELFORMAT_ARRAY(format) \
  131. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  132. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
  133. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
  134. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
  135. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
  136. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
  137. #define SDL_ISPIXELFORMAT_ALPHA(format) \
  138. ((SDL_ISPIXELFORMAT_PACKED(format) && \
  139. ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
  140. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
  141. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
  142. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))))
  143. #define SDL_ISPIXELFORMAT_10BIT(format) \
  144. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  145. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
  146. (SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010)))
  147. #define SDL_ISPIXELFORMAT_FLOAT(format) \
  148. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  149. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
  150. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
  151. /* The flag is set to 1 because 0x1? is not in the printable ASCII range */
  152. #define SDL_ISPIXELFORMAT_FOURCC(format) \
  153. ((format) && (SDL_PIXELFLAG(format) != 1))
  154. /* Note: If you modify this enum, update SDL_GetPixelFormatName() */
  155. /**
  156. * All pixel formats known to SDL.
  157. *
  158. * SDL's pixel formats have the following naming convention:
  159. *
  160. * - Names with a list of components and a single bit count, such as RGB24 and
  161. * ABGR32, define a platform-independent encoding into bytes in the order
  162. * specified. For example, in RGB24 data, each pixel is encoded in 3 bytes
  163. * (red, green, blue) in that order, and in ABGR32 data, each pixel is
  164. * encoded in 4 bytes alpha, blue, green, red) in that order. Use these
  165. * names if the property of a format that is important to you is the order
  166. * of the bytes in memory or on disk.
  167. * - Names with a bit count per component, such as ARGB8888 and XRGB1555, are
  168. * "packed" into an appropriately-sized integer in the platform's native
  169. * endianness. For example, ARGB8888 is a sequence of 32-bit integers; in
  170. * each integer, the most significant bits are alpha, and the least
  171. * significant bits are blue. On a little-endian CPU such as x86, the least
  172. * significant bits of each integer are arranged first in memory, but on a
  173. * big-endian CPU such as s390x, the most significant bits are arranged
  174. * first. Use these names if the property of a format that is important to
  175. * you is the meaning of each bit position within a native-endianness
  176. * integer.
  177. * - In indexed formats such as INDEX4LSB, each pixel is represented by
  178. * encoding an index into the palette into the indicated number of bits,
  179. * with multiple pixels packed into each byte if appropriate. In LSB
  180. * formats, the first (leftmost) pixel is stored in the least-significant
  181. * bits of the byte; in MSB formats, it's stored in the most-significant
  182. * bits. INDEX8 does not need LSB/MSB variants, because each pixel exactly
  183. * fills one byte.
  184. *
  185. * The 32-bit byte-array encodings such as RGBA32 are aliases for the
  186. * appropriate 8888 encoding for the current platform. For example, RGBA32 is
  187. * an alias for ABGR8888 on little-endian CPUs like x86, or an alias for
  188. * RGBA8888 on big-endian CPUs.
  189. *
  190. * \since This enum is available since SDL 3.0.0.
  191. */
  192. typedef enum SDL_PixelFormatEnum
  193. {
  194. SDL_PIXELFORMAT_UNKNOWN,
  195. SDL_PIXELFORMAT_INDEX1LSB =
  196. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
  197. 1, 0),
  198. SDL_PIXELFORMAT_INDEX1MSB =
  199. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
  200. 1, 0),
  201. SDL_PIXELFORMAT_INDEX2LSB =
  202. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_4321, 0,
  203. 2, 0),
  204. SDL_PIXELFORMAT_INDEX2MSB =
  205. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_1234, 0,
  206. 2, 0),
  207. SDL_PIXELFORMAT_INDEX4LSB =
  208. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
  209. 4, 0),
  210. SDL_PIXELFORMAT_INDEX4MSB =
  211. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
  212. 4, 0),
  213. SDL_PIXELFORMAT_INDEX8 =
  214. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
  215. SDL_PIXELFORMAT_RGB332 =
  216. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
  217. SDL_PACKEDLAYOUT_332, 8, 1),
  218. SDL_PIXELFORMAT_XRGB4444 =
  219. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  220. SDL_PACKEDLAYOUT_4444, 12, 2),
  221. SDL_PIXELFORMAT_XBGR4444 =
  222. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  223. SDL_PACKEDLAYOUT_4444, 12, 2),
  224. SDL_PIXELFORMAT_XRGB1555 =
  225. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  226. SDL_PACKEDLAYOUT_1555, 15, 2),
  227. SDL_PIXELFORMAT_XBGR1555 =
  228. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  229. SDL_PACKEDLAYOUT_1555, 15, 2),
  230. SDL_PIXELFORMAT_ARGB4444 =
  231. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
  232. SDL_PACKEDLAYOUT_4444, 16, 2),
  233. SDL_PIXELFORMAT_RGBA4444 =
  234. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
  235. SDL_PACKEDLAYOUT_4444, 16, 2),
  236. SDL_PIXELFORMAT_ABGR4444 =
  237. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
  238. SDL_PACKEDLAYOUT_4444, 16, 2),
  239. SDL_PIXELFORMAT_BGRA4444 =
  240. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
  241. SDL_PACKEDLAYOUT_4444, 16, 2),
  242. SDL_PIXELFORMAT_ARGB1555 =
  243. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
  244. SDL_PACKEDLAYOUT_1555, 16, 2),
  245. SDL_PIXELFORMAT_RGBA5551 =
  246. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
  247. SDL_PACKEDLAYOUT_5551, 16, 2),
  248. SDL_PIXELFORMAT_ABGR1555 =
  249. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
  250. SDL_PACKEDLAYOUT_1555, 16, 2),
  251. SDL_PIXELFORMAT_BGRA5551 =
  252. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
  253. SDL_PACKEDLAYOUT_5551, 16, 2),
  254. SDL_PIXELFORMAT_RGB565 =
  255. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  256. SDL_PACKEDLAYOUT_565, 16, 2),
  257. SDL_PIXELFORMAT_BGR565 =
  258. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  259. SDL_PACKEDLAYOUT_565, 16, 2),
  260. SDL_PIXELFORMAT_RGB24 =
  261. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
  262. 24, 3),
  263. SDL_PIXELFORMAT_BGR24 =
  264. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
  265. 24, 3),
  266. SDL_PIXELFORMAT_XRGB8888 =
  267. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
  268. SDL_PACKEDLAYOUT_8888, 24, 4),
  269. SDL_PIXELFORMAT_RGBX8888 =
  270. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
  271. SDL_PACKEDLAYOUT_8888, 24, 4),
  272. SDL_PIXELFORMAT_XBGR8888 =
  273. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
  274. SDL_PACKEDLAYOUT_8888, 24, 4),
  275. SDL_PIXELFORMAT_BGRX8888 =
  276. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX,
  277. SDL_PACKEDLAYOUT_8888, 24, 4),
  278. SDL_PIXELFORMAT_ARGB8888 =
  279. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
  280. SDL_PACKEDLAYOUT_8888, 32, 4),
  281. SDL_PIXELFORMAT_RGBA8888 =
  282. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
  283. SDL_PACKEDLAYOUT_8888, 32, 4),
  284. SDL_PIXELFORMAT_ABGR8888 =
  285. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
  286. SDL_PACKEDLAYOUT_8888, 32, 4),
  287. SDL_PIXELFORMAT_BGRA8888 =
  288. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
  289. SDL_PACKEDLAYOUT_8888, 32, 4),
  290. SDL_PIXELFORMAT_XRGB2101010 =
  291. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
  292. SDL_PACKEDLAYOUT_2101010, 32, 4),
  293. SDL_PIXELFORMAT_XBGR2101010 =
  294. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
  295. SDL_PACKEDLAYOUT_2101010, 32, 4),
  296. SDL_PIXELFORMAT_ARGB2101010 =
  297. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
  298. SDL_PACKEDLAYOUT_2101010, 32, 4),
  299. SDL_PIXELFORMAT_ABGR2101010 =
  300. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
  301. SDL_PACKEDLAYOUT_2101010, 32, 4),
  302. SDL_PIXELFORMAT_RGB48 =
  303. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGB, 0,
  304. 48, 6),
  305. SDL_PIXELFORMAT_BGR48 =
  306. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGR, 0,
  307. 48, 6),
  308. SDL_PIXELFORMAT_RGBA64 =
  309. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGBA, 0,
  310. 64, 8),
  311. SDL_PIXELFORMAT_ARGB64 =
  312. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ARGB, 0,
  313. 64, 8),
  314. SDL_PIXELFORMAT_BGRA64 =
  315. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGRA, 0,
  316. 64, 8),
  317. SDL_PIXELFORMAT_ABGR64 =
  318. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ABGR, 0,
  319. 64, 8),
  320. SDL_PIXELFORMAT_RGB48_FLOAT =
  321. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGB, 0,
  322. 48, 6),
  323. SDL_PIXELFORMAT_BGR48_FLOAT =
  324. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGR, 0,
  325. 48, 6),
  326. SDL_PIXELFORMAT_RGBA64_FLOAT =
  327. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGBA, 0,
  328. 64, 8),
  329. SDL_PIXELFORMAT_ARGB64_FLOAT =
  330. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ARGB, 0,
  331. 64, 8),
  332. SDL_PIXELFORMAT_BGRA64_FLOAT =
  333. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGRA, 0,
  334. 64, 8),
  335. SDL_PIXELFORMAT_ABGR64_FLOAT =
  336. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ABGR, 0,
  337. 64, 8),
  338. SDL_PIXELFORMAT_RGB96_FLOAT =
  339. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGB, 0,
  340. 96, 12),
  341. SDL_PIXELFORMAT_BGR96_FLOAT =
  342. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGR, 0,
  343. 96, 12),
  344. SDL_PIXELFORMAT_RGBA128_FLOAT =
  345. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGBA, 0,
  346. 128, 16),
  347. SDL_PIXELFORMAT_ARGB128_FLOAT =
  348. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ARGB, 0,
  349. 128, 16),
  350. SDL_PIXELFORMAT_BGRA128_FLOAT =
  351. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGRA, 0,
  352. 128, 16),
  353. SDL_PIXELFORMAT_ABGR128_FLOAT =
  354. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ABGR, 0,
  355. 128, 16),
  356. /* Aliases for RGBA byte arrays of color data, for the current platform */
  357. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  358. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
  359. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
  360. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
  361. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
  362. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_RGBX8888,
  363. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_XRGB8888,
  364. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_BGRX8888,
  365. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_XBGR8888,
  366. #else
  367. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
  368. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
  369. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
  370. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
  371. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_XBGR8888,
  372. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_BGRX8888,
  373. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_XRGB8888,
  374. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_RGBX8888,
  375. #endif
  376. SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
  377. SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
  378. SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
  379. SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
  380. SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
  381. SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
  382. SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
  383. SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
  384. SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
  385. SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
  386. SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
  387. SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
  388. SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
  389. SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
  390. SDL_PIXELFORMAT_P010 = /**< Planar mode: Y + U/V interleaved (2 planes) */
  391. SDL_DEFINE_PIXELFOURCC('P', '0', '1', '0'),
  392. SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
  393. SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
  394. } SDL_PixelFormatEnum;
  395. /**
  396. * Pixels are a representation of a color in a particular color space.
  397. *
  398. * The first characteristic of a color space is the color type. SDL understands two different color types, RGB and YCbCr, or in SDL also referred to as YUV.
  399. *
  400. * RGB colors consist of red, green, and blue channels of color that are added together to represent the colors we see on the screen.
  401. * https://en.wikipedia.org/wiki/RGB_color_model
  402. *
  403. * YCbCr colors represent colors as a Y luma brightness component and red and blue chroma color offsets. This color representation takes advantage of the fact that the human eye is more sensitive to brightness than the color in an image. The Cb and Cr components are often compressed and have lower resolution than the luma component.
  404. * https://en.wikipedia.org/wiki/YCbCr
  405. *
  406. * When the color information in YCbCr is compressed, the Y pixels are left at full resolution and each Cr and Cb pixel represents an average of the color information in a block of Y pixels. The chroma location determines where in that block of pixels the color information is coming from.
  407. *
  408. * The color range defines how much of the pixel to use when converting a pixel into a color on the display. When the full color range is used, the entire numeric range of the pixel bits is significant. When narrow color range is used, for historical reasons, the pixel uses only a portion of the numeric range to represent colors.
  409. *
  410. * The color primaries and white point are a definition of the colors in the color space relative to the standard XYZ color space.
  411. * https://en.wikipedia.org/wiki/CIE_1931_color_space
  412. *
  413. * The transfer characteristic, or opto-electrical transfer function (OETF), is the way a color is converted from mathematically linear space into a non-linear output signals.
  414. * https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
  415. *
  416. * The matrix coefficients are used to convert between YCbCr and RGB colors.
  417. */
  418. /**
  419. * The color type
  420. *
  421. * \since This enum is available since SDL 3.0.0.
  422. */
  423. typedef enum SDL_ColorType
  424. {
  425. SDL_COLOR_TYPE_UNKNOWN = 0,
  426. SDL_COLOR_TYPE_RGB = 1,
  427. SDL_COLOR_TYPE_YCBCR = 2
  428. } SDL_ColorType;
  429. /**
  430. * The color range, as described by
  431. * https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en
  432. *
  433. * \since This enum is available since SDL 3.0.0.
  434. */
  435. typedef enum SDL_ColorRange
  436. {
  437. SDL_COLOR_RANGE_UNKNOWN = 0,
  438. SDL_COLOR_RANGE_LIMITED = 1, /**< Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma */
  439. SDL_COLOR_RANGE_FULL = 2 /**< Full range, e.g. 0-255 for 8-bit RGB and luma, and 1-255 for 8-bit chroma */
  440. } SDL_ColorRange;
  441. /**
  442. * The color primaries, as described by
  443. * https://www.itu.int/rec/T-REC-H.273-201612-S/en
  444. *
  445. * \since This enum is available since SDL 3.0.0.
  446. */
  447. typedef enum SDL_ColorPrimaries
  448. {
  449. SDL_COLOR_PRIMARIES_UNKNOWN = 0,
  450. SDL_COLOR_PRIMARIES_BT709 = 1, /**< ITU-R BT.709-6 */
  451. SDL_COLOR_PRIMARIES_UNSPECIFIED = 2,
  452. SDL_COLOR_PRIMARIES_BT470M = 4, /**< ITU-R BT.470-6 System M */
  453. SDL_COLOR_PRIMARIES_BT470BG = 5, /**< ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625 */
  454. SDL_COLOR_PRIMARIES_BT601 = 6, /**< ITU-R BT.601-7 525 */
  455. SDL_COLOR_PRIMARIES_SMPTE240 = 7, /**< SMPTE 240M, functionally the same as SDL_COLOR_PRIMARIES_BT601 */
  456. SDL_COLOR_PRIMARIES_GENERIC_FILM = 8, /**< Generic film (color filters using Illuminant C) */
  457. SDL_COLOR_PRIMARIES_BT2020 = 9, /**< ITU-R BT.2020-2 / ITU-R BT.2100-0 */
  458. SDL_COLOR_PRIMARIES_XYZ = 10, /**< SMPTE ST 428-1 */
  459. SDL_COLOR_PRIMARIES_SMPTE431 = 11, /**< SMPTE RP 431-2 */
  460. SDL_COLOR_PRIMARIES_SMPTE432 = 12, /**< SMPTE EG 432-1 / DCI P3 */
  461. SDL_COLOR_PRIMARIES_EBU3213 = 22, /**< EBU Tech. 3213-E */
  462. SDL_COLOR_PRIMARIES_CUSTOM = 31
  463. } SDL_ColorPrimaries;
  464. /**
  465. * The color transfer characteristics.
  466. *
  467. * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
  468. *
  469. * \since This enum is available since SDL 3.0.0.
  470. */
  471. typedef enum SDL_TransferCharacteristics
  472. {
  473. SDL_TRANSFER_CHARACTERISTICS_UNKNOWN = 0,
  474. SDL_TRANSFER_CHARACTERISTICS_BT709 = 1, /**< Rec. ITU-R BT.709-6 / ITU-R BT1361 */
  475. SDL_TRANSFER_CHARACTERISTICS_UNSPECIFIED = 2,
  476. SDL_TRANSFER_CHARACTERISTICS_GAMMA22 = 4, /**< ITU-R BT.470-6 System M / ITU-R BT1700 625 PAL & SECAM */
  477. SDL_TRANSFER_CHARACTERISTICS_GAMMA28 = 5, /**< ITU-R BT.470-6 System B, G */
  478. SDL_TRANSFER_CHARACTERISTICS_BT601 = 6, /**< SMPTE ST 170M / ITU-R BT.601-7 525 or 625 */
  479. SDL_TRANSFER_CHARACTERISTICS_SMPTE240 = 7, /**< SMPTE ST 240M */
  480. SDL_TRANSFER_CHARACTERISTICS_LINEAR = 8,
  481. SDL_TRANSFER_CHARACTERISTICS_LOG100 = 9,
  482. SDL_TRANSFER_CHARACTERISTICS_LOG100_SQRT10 = 10,
  483. SDL_TRANSFER_CHARACTERISTICS_IEC61966 = 11, /**< IEC 61966-2-4 */
  484. SDL_TRANSFER_CHARACTERISTICS_BT1361 = 12, /**< ITU-R BT1361 Extended Colour Gamut */
  485. SDL_TRANSFER_CHARACTERISTICS_SRGB = 13, /**< IEC 61966-2-1 (sRGB or sYCC) */
  486. SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT = 14, /**< ITU-R BT2020 for 10-bit system */
  487. SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT = 15, /**< ITU-R BT2020 for 12-bit system */
  488. SDL_TRANSFER_CHARACTERISTICS_PQ = 16, /**< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems */
  489. SDL_TRANSFER_CHARACTERISTICS_SMPTE428 = 17, /**< SMPTE ST 428-1 */
  490. SDL_TRANSFER_CHARACTERISTICS_HLG = 18, /**< ARIB STD-B67, known as "hybrid log-gamma" (HLG) */
  491. SDL_TRANSFER_CHARACTERISTICS_CUSTOM = 31
  492. } SDL_TransferCharacteristics;
  493. /**
  494. * The matrix coefficients.
  495. *
  496. * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
  497. *
  498. * \since This enum is available since SDL 3.0.0.
  499. */
  500. typedef enum SDL_MatrixCoefficients
  501. {
  502. SDL_MATRIX_COEFFICIENTS_IDENTITY = 0,
  503. SDL_MATRIX_COEFFICIENTS_BT709 = 1, /**< ITU-R BT.709-6 */
  504. SDL_MATRIX_COEFFICIENTS_UNSPECIFIED = 2,
  505. SDL_MATRIX_COEFFICIENTS_FCC = 4, /**< US FCC */
  506. 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 */
  507. SDL_MATRIX_COEFFICIENTS_BT601 = 6, /**< ITU-R BT.601-7 525 */
  508. SDL_MATRIX_COEFFICIENTS_SMPTE240 = 7, /**< SMPTE 240M */
  509. SDL_MATRIX_COEFFICIENTS_YCGCO = 8,
  510. SDL_MATRIX_COEFFICIENTS_BT2020_NCL = 9, /**< ITU-R BT.2020-2 non-constant luminance */
  511. SDL_MATRIX_COEFFICIENTS_BT2020_CL = 10, /**< ITU-R BT.2020-2 constant luminance */
  512. SDL_MATRIX_COEFFICIENTS_SMPTE2085 = 11, /**< SMPTE ST 2085 */
  513. SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL = 12,
  514. SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL = 13,
  515. SDL_MATRIX_COEFFICIENTS_ICTCP = 14, /**< ITU-R BT.2100-0 ICTCP */
  516. SDL_MATRIX_COEFFICIENTS_CUSTOM = 31
  517. } SDL_MatrixCoefficients;
  518. /**
  519. * The chroma sample location.
  520. *
  521. * \since This enum is available since SDL 3.0.0.
  522. */
  523. typedef enum SDL_ChromaLocation
  524. {
  525. SDL_CHROMA_LOCATION_NONE = 0, /**< RGB, no chroma sampling */
  526. 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. */
  527. 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. */
  528. 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"). */
  529. } SDL_ChromaLocation;
  530. /* Colorspace definition */
  531. #define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
  532. (((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
  533. ((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))
  534. #define SDL_COLORSPACETYPE(X) (SDL_ColorType)(((X) >> 28) & 0x0F)
  535. #define SDL_COLORSPACERANGE(X) (SDL_ColorRange)(((X) >> 24) & 0x0F)
  536. #define SDL_COLORSPACECHROMA(X) (SDL_ChromaLocation)(((X) >> 20) & 0x0F)
  537. #define SDL_COLORSPACEPRIMARIES(X) (SDL_ColorPrimaries)(((X) >> 10) & 0x1F)
  538. #define SDL_COLORSPACETRANSFER(X) (SDL_TransferCharacteristics)(((X) >> 5) & 0x1F)
  539. #define SDL_COLORSPACEMATRIX(X) (SDL_MatrixCoefficients)((X) & 0x1F)
  540. #define SDL_ISCOLORSPACE_MATRIX_BT601(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT470BG)
  541. #define SDL_ISCOLORSPACE_MATRIX_BT709(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT709)
  542. #define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
  543. #define SDL_ISCOLORSPACE_LIMITED_RANGE(X) (SDL_COLORSPACERANGE(X) != SDL_COLOR_RANGE_FULL)
  544. #define SDL_ISCOLORSPACE_FULL_RANGE(X) (SDL_COLORSPACERANGE(X) == SDL_COLOR_RANGE_FULL)
  545. typedef enum SDL_Colorspace
  546. {
  547. SDL_COLORSPACE_UNKNOWN,
  548. /* sRGB is a gamma corrected colorspace, and the default colorspace for SDL rendering and 8-bit RGB surfaces */
  549. SDL_COLORSPACE_SRGB = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 */
  550. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  551. SDL_COLOR_RANGE_FULL,
  552. SDL_COLOR_PRIMARIES_BT709,
  553. SDL_TRANSFER_CHARACTERISTICS_SRGB,
  554. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  555. SDL_CHROMA_LOCATION_NONE),
  556. /* 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 */
  557. SDL_COLORSPACE_SRGB_LINEAR = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 */
  558. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  559. SDL_COLOR_RANGE_FULL,
  560. SDL_COLOR_PRIMARIES_BT709,
  561. SDL_TRANSFER_CHARACTERISTICS_LINEAR,
  562. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  563. SDL_CHROMA_LOCATION_NONE),
  564. /* HDR10 is a non-linear HDR colorspace and the default colorspace for 10-bit surfaces */
  565. SDL_COLORSPACE_HDR10 = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 */
  566. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  567. SDL_COLOR_RANGE_FULL,
  568. SDL_COLOR_PRIMARIES_BT2020,
  569. SDL_TRANSFER_CHARACTERISTICS_PQ,
  570. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  571. SDL_CHROMA_LOCATION_NONE),
  572. SDL_COLORSPACE_JPEG = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 */
  573. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  574. SDL_COLOR_RANGE_FULL,
  575. SDL_COLOR_PRIMARIES_BT709,
  576. SDL_TRANSFER_CHARACTERISTICS_BT601,
  577. SDL_MATRIX_COEFFICIENTS_BT601,
  578. SDL_CHROMA_LOCATION_NONE),
  579. SDL_COLORSPACE_BT601_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
  580. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  581. SDL_COLOR_RANGE_LIMITED,
  582. SDL_COLOR_PRIMARIES_BT601,
  583. SDL_TRANSFER_CHARACTERISTICS_BT601,
  584. SDL_MATRIX_COEFFICIENTS_BT601,
  585. SDL_CHROMA_LOCATION_LEFT),
  586. SDL_COLORSPACE_BT601_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
  587. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  588. SDL_COLOR_RANGE_FULL,
  589. SDL_COLOR_PRIMARIES_BT601,
  590. SDL_TRANSFER_CHARACTERISTICS_BT601,
  591. SDL_MATRIX_COEFFICIENTS_BT601,
  592. SDL_CHROMA_LOCATION_LEFT),
  593. SDL_COLORSPACE_BT709_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
  594. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  595. SDL_COLOR_RANGE_LIMITED,
  596. SDL_COLOR_PRIMARIES_BT709,
  597. SDL_TRANSFER_CHARACTERISTICS_BT709,
  598. SDL_MATRIX_COEFFICIENTS_BT709,
  599. SDL_CHROMA_LOCATION_LEFT),
  600. SDL_COLORSPACE_BT709_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
  601. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  602. SDL_COLOR_RANGE_FULL,
  603. SDL_COLOR_PRIMARIES_BT709,
  604. SDL_TRANSFER_CHARACTERISTICS_BT709,
  605. SDL_MATRIX_COEFFICIENTS_BT709,
  606. SDL_CHROMA_LOCATION_LEFT),
  607. SDL_COLORSPACE_BT2020_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 */
  608. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  609. SDL_COLOR_RANGE_LIMITED,
  610. SDL_COLOR_PRIMARIES_BT2020,
  611. SDL_TRANSFER_CHARACTERISTICS_PQ,
  612. SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
  613. SDL_CHROMA_LOCATION_LEFT),
  614. SDL_COLORSPACE_BT2020_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 */
  615. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  616. SDL_COLOR_RANGE_FULL,
  617. SDL_COLOR_PRIMARIES_BT2020,
  618. SDL_TRANSFER_CHARACTERISTICS_PQ,
  619. SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
  620. SDL_CHROMA_LOCATION_LEFT),
  621. /* The default colorspace for RGB surfaces if no colorspace is specified */
  622. SDL_COLORSPACE_RGB_DEFAULT = SDL_COLORSPACE_SRGB,
  623. /* The default colorspace for YUV surfaces if no colorspace is specified */
  624. SDL_COLORSPACE_YUV_DEFAULT = SDL_COLORSPACE_JPEG
  625. } SDL_Colorspace;
  626. /**
  627. * A structure that represents a color as RGBA components.
  628. *
  629. * The bits of this structure can be directly reinterpreted as an
  630. * integer-packed color which uses the SDL_PIXELFORMAT_RGBA32 format
  631. * (SDL_PIXELFORMAT_ABGR8888 on little-endian systems and
  632. * SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
  633. *
  634. * \since This struct is available since SDL 3.0.0.
  635. */
  636. typedef struct SDL_Color
  637. {
  638. Uint8 r;
  639. Uint8 g;
  640. Uint8 b;
  641. Uint8 a;
  642. } SDL_Color;
  643. /**
  644. * The bits of this structure can be directly reinterpreted as a float-packed
  645. * color which uses the SDL_PIXELFORMAT_RGBA128_FLOAT format
  646. *
  647. * \since This struct is available since SDL 3.0.0.
  648. */
  649. typedef struct SDL_FColor
  650. {
  651. float r;
  652. float g;
  653. float b;
  654. float a;
  655. } SDL_FColor;
  656. /**
  657. * A set of indexed colors representing a palette.
  658. *
  659. * \since This struct is available since SDL 3.0.0.
  660. *
  661. * \sa SDL_PixelFormat
  662. * \sa SDL_SetPaletteColors
  663. */
  664. typedef struct SDL_Palette
  665. {
  666. int ncolors; /**< number of elements in `colors`. */
  667. SDL_Color *colors; /**< an array of colors, `ncolors` long. */
  668. Uint32 version; /**< internal use only, do not touch. */
  669. int refcount; /**< internal use only, do not touch. */
  670. } SDL_Palette;
  671. /**
  672. * Details about the format of a pixel.
  673. *
  674. * Generally this is used with SDL_Surface, and covers many possible
  675. * configurations, including paletted data and various bit patterns.
  676. *
  677. * \since This struct is available since SDL 3.0.0.
  678. */
  679. typedef struct SDL_PixelFormat
  680. {
  681. SDL_PixelFormatEnum format;
  682. SDL_Palette *palette;
  683. Uint8 bits_per_pixel;
  684. Uint8 bytes_per_pixel;
  685. Uint8 padding[2];
  686. Uint32 Rmask;
  687. Uint32 Gmask;
  688. Uint32 Bmask;
  689. Uint32 Amask;
  690. Uint8 Rloss;
  691. Uint8 Gloss;
  692. Uint8 Bloss;
  693. Uint8 Aloss;
  694. Uint8 Rshift;
  695. Uint8 Gshift;
  696. Uint8 Bshift;
  697. Uint8 Ashift;
  698. int refcount;
  699. struct SDL_PixelFormat *next;
  700. } SDL_PixelFormat;
  701. /**
  702. * Get the human readable name of a pixel format.
  703. *
  704. * The returned string follows the SDL_GetStringRule.
  705. *
  706. * \param format the pixel format to query
  707. * \returns the human readable name of the specified pixel format or
  708. * `SDL_PIXELFORMAT_UNKNOWN` if the format isn't recognized.
  709. *
  710. * \since This function is available since SDL 3.0.0.
  711. */
  712. extern SDL_DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(SDL_PixelFormatEnum format);
  713. /**
  714. * Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
  715. *
  716. * \param format one of the SDL_PixelFormatEnum values
  717. * \param bpp a bits per pixel value; usually 15, 16, or 32
  718. * \param Rmask a pointer filled in with the red mask for the format
  719. * \param Gmask a pointer filled in with the green mask for the format
  720. * \param Bmask a pointer filled in with the blue mask for the format
  721. * \param Amask a pointer filled in with the alpha mask for the format
  722. * \returns SDL_TRUE on success or SDL_FALSE if the conversion wasn't
  723. * possible; call SDL_GetError() for more information.
  724. *
  725. * \since This function is available since SDL 3.0.0.
  726. *
  727. * \sa SDL_GetPixelFormatEnumForMasks
  728. */
  729. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format,
  730. int *bpp,
  731. Uint32 * Rmask,
  732. Uint32 * Gmask,
  733. Uint32 * Bmask,
  734. Uint32 * Amask);
  735. /**
  736. * Convert a bpp value and RGBA masks to an enumerated pixel format.
  737. *
  738. * This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't
  739. * possible.
  740. *
  741. * \param bpp a bits per pixel value; usually 15, 16, or 32
  742. * \param Rmask the red mask for the format
  743. * \param Gmask the green mask for the format
  744. * \param Bmask the blue mask for the format
  745. * \param Amask the alpha mask for the format
  746. * \returns the SDL_PixelFormatEnum value corresponding to the format masks,
  747. * or SDL_PIXELFORMAT_UNKNOWN if there isn't a match.
  748. *
  749. * \since This function is available since SDL 3.0.0.
  750. *
  751. * \sa SDL_GetMasksForPixelFormatEnum
  752. */
  753. extern SDL_DECLSPEC SDL_PixelFormatEnum SDLCALL SDL_GetPixelFormatEnumForMasks(int bpp,
  754. Uint32 Rmask,
  755. Uint32 Gmask,
  756. Uint32 Bmask,
  757. Uint32 Amask);
  758. /**
  759. * Create an SDL_PixelFormat structure corresponding to a pixel format.
  760. *
  761. * Returned structure may come from a shared global cache (i.e. not newly
  762. * allocated), and hence should not be modified, especially the palette. Weird
  763. * errors such as `Blit combination not supported` may occur.
  764. *
  765. * \param pixel_format one of the SDL_PixelFormatEnum values
  766. * \returns the new SDL_PixelFormat structure or NULL on failure; call
  767. * SDL_GetError() for more information.
  768. *
  769. * \since This function is available since SDL 3.0.0.
  770. *
  771. * \sa SDL_DestroyPixelFormat
  772. * \sa SDL_SetPixelFormatPalette
  773. */
  774. extern SDL_DECLSPEC SDL_PixelFormat * SDLCALL SDL_CreatePixelFormat(SDL_PixelFormatEnum pixel_format);
  775. /**
  776. * Free an SDL_PixelFormat structure allocated by SDL_CreatePixelFormat().
  777. *
  778. * \param format the SDL_PixelFormat structure to free
  779. *
  780. * \since This function is available since SDL 3.0.0.
  781. *
  782. * \sa SDL_CreatePixelFormat
  783. */
  784. extern SDL_DECLSPEC void SDLCALL SDL_DestroyPixelFormat(SDL_PixelFormat *format);
  785. /**
  786. * Create a palette structure with the specified number of color entries.
  787. *
  788. * The palette entries are initialized to white.
  789. *
  790. * \param ncolors represents the number of color entries in the color palette
  791. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  792. * there wasn't enough memory); call SDL_GetError() for more
  793. * information.
  794. *
  795. * \since This function is available since SDL 3.0.0.
  796. *
  797. * \sa SDL_DestroyPalette
  798. * \sa SDL_SetPaletteColors
  799. * \sa SDL_SetPixelFormatPalette
  800. */
  801. extern SDL_DECLSPEC SDL_Palette *SDLCALL SDL_CreatePalette(int ncolors);
  802. /**
  803. * Set the palette for a pixel format structure.
  804. *
  805. * \param format the SDL_PixelFormat structure that will use the palette
  806. * \param palette the SDL_Palette structure that will be used
  807. * \returns 0 on success or a negative error code on failure; call
  808. * SDL_GetError() for more information.
  809. *
  810. * \since This function is available since SDL 3.0.0.
  811. */
  812. extern SDL_DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
  813. SDL_Palette *palette);
  814. /**
  815. * Set a range of colors in a palette.
  816. *
  817. * \param palette the SDL_Palette structure to modify
  818. * \param colors an array of SDL_Color structures to copy into the palette
  819. * \param firstcolor the index of the first palette entry to modify
  820. * \param ncolors the number of entries to modify
  821. * \returns 0 on success or a negative error code on failure; call
  822. * SDL_GetError() for more information.
  823. *
  824. * \since This function is available since SDL 3.0.0.
  825. */
  826. extern SDL_DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
  827. const SDL_Color * colors,
  828. int firstcolor, int ncolors);
  829. /**
  830. * Free a palette created with SDL_CreatePalette().
  831. *
  832. * \param palette the SDL_Palette structure to be freed
  833. *
  834. * \since This function is available since SDL 3.0.0.
  835. *
  836. * \sa SDL_CreatePalette
  837. */
  838. extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette * palette);
  839. /**
  840. * Map an RGB triple to an opaque pixel value for a given pixel format.
  841. *
  842. * This function maps the RGB color value to the specified pixel format and
  843. * returns the pixel value best approximating the given RGB color value for
  844. * the given pixel format.
  845. *
  846. * If the format has a palette (8-bit) the index of the closest matching color
  847. * in the palette will be returned.
  848. *
  849. * If the specified pixel format has an alpha component it will be returned as
  850. * all 1 bits (fully opaque).
  851. *
  852. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  853. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  854. * format the return value can be assigned to a Uint16, and similarly a Uint8
  855. * for an 8-bpp format).
  856. *
  857. * \param format an SDL_PixelFormat structure describing the pixel format
  858. * \param r the red component of the pixel in the range 0-255
  859. * \param g the green component of the pixel in the range 0-255
  860. * \param b the blue component of the pixel in the range 0-255
  861. * \returns a pixel value
  862. *
  863. * \since This function is available since SDL 3.0.0.
  864. *
  865. * \sa SDL_GetRGB
  866. * \sa SDL_GetRGBA
  867. * \sa SDL_MapRGBA
  868. */
  869. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
  870. Uint8 r, Uint8 g, Uint8 b);
  871. /**
  872. * Map an RGBA quadruple to a pixel value for a given pixel format.
  873. *
  874. * This function maps the RGBA color value to the specified pixel format and
  875. * returns the pixel value best approximating the given RGBA color value for
  876. * the given pixel format.
  877. *
  878. * If the specified pixel format has no alpha component the alpha value will
  879. * be ignored (as it will be in formats with a palette).
  880. *
  881. * If the format has a palette (8-bit) the index of the closest matching color
  882. * in the palette will be returned.
  883. *
  884. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  885. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  886. * format the return value can be assigned to a Uint16, and similarly a Uint8
  887. * for an 8-bpp format).
  888. *
  889. * \param format an SDL_PixelFormat structure describing the format of the
  890. * pixel
  891. * \param r the red component of the pixel in the range 0-255
  892. * \param g the green component of the pixel in the range 0-255
  893. * \param b the blue component of the pixel in the range 0-255
  894. * \param a the alpha component of the pixel in the range 0-255
  895. * \returns a pixel value
  896. *
  897. * \since This function is available since SDL 3.0.0.
  898. *
  899. * \sa SDL_GetRGB
  900. * \sa SDL_GetRGBA
  901. * \sa SDL_MapRGB
  902. */
  903. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
  904. Uint8 r, Uint8 g, Uint8 b,
  905. Uint8 a);
  906. /**
  907. * Get RGB values from a pixel in the specified format.
  908. *
  909. * This function uses the entire 8-bit [0..255] range when converting color
  910. * components from pixel formats with less than 8-bits per RGB component
  911. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  912. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  913. *
  914. * \param pixel a pixel value
  915. * \param format an SDL_PixelFormat structure describing the format of the
  916. * pixel
  917. * \param r a pointer filled in with the red component
  918. * \param g a pointer filled in with the green component
  919. * \param b a pointer filled in with the blue component
  920. *
  921. * \since This function is available since SDL 3.0.0.
  922. *
  923. * \sa SDL_GetRGBA
  924. * \sa SDL_MapRGB
  925. * \sa SDL_MapRGBA
  926. */
  927. extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
  928. const SDL_PixelFormat * format,
  929. Uint8 * r, Uint8 * g, Uint8 * b);
  930. /**
  931. * Get RGBA values from a pixel in the specified format.
  932. *
  933. * This function uses the entire 8-bit [0..255] range when converting color
  934. * components from pixel formats with less than 8-bits per RGB component
  935. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  936. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  937. *
  938. * If the surface has no alpha component, the alpha will be returned as 0xff
  939. * (100% opaque).
  940. *
  941. * \param pixel a pixel value
  942. * \param format an SDL_PixelFormat structure describing the format of the
  943. * pixel
  944. * \param r a pointer filled in with the red component
  945. * \param g a pointer filled in with the green component
  946. * \param b a pointer filled in with the blue component
  947. * \param a a pointer filled in with the alpha component
  948. *
  949. * \since This function is available since SDL 3.0.0.
  950. *
  951. * \sa SDL_GetRGB
  952. * \sa SDL_MapRGB
  953. * \sa SDL_MapRGBA
  954. */
  955. extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
  956. const SDL_PixelFormat * format,
  957. Uint8 * r, Uint8 * g, Uint8 * b,
  958. Uint8 * a);
  959. /* Ends C function definitions when using C++ */
  960. #ifdef __cplusplus
  961. }
  962. #endif
  963. #include <SDL3/SDL_close_code.h>
  964. #endif /* SDL_pixels_h_ */