SDL_pixels.h 45 KB

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