SDL_pixels.h 45 KB

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