SDL_pixels.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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. * All pixel formats known to SDL.
  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,
  203. SDL_PIXELFORMAT_INDEX1LSB =
  204. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
  205. 1, 0),
  206. SDL_PIXELFORMAT_INDEX1MSB =
  207. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
  208. 1, 0),
  209. SDL_PIXELFORMAT_INDEX2LSB =
  210. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_4321, 0,
  211. 2, 0),
  212. SDL_PIXELFORMAT_INDEX2MSB =
  213. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_1234, 0,
  214. 2, 0),
  215. SDL_PIXELFORMAT_INDEX4LSB =
  216. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
  217. 4, 0),
  218. SDL_PIXELFORMAT_INDEX4MSB =
  219. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
  220. 4, 0),
  221. SDL_PIXELFORMAT_INDEX8 =
  222. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
  223. SDL_PIXELFORMAT_RGB332 =
  224. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
  225. SDL_PACKEDLAYOUT_332, 8, 1),
  226. SDL_PIXELFORMAT_XRGB4444 =
  227. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  228. SDL_PACKEDLAYOUT_4444, 12, 2),
  229. SDL_PIXELFORMAT_XBGR4444 =
  230. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  231. SDL_PACKEDLAYOUT_4444, 12, 2),
  232. SDL_PIXELFORMAT_XRGB1555 =
  233. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  234. SDL_PACKEDLAYOUT_1555, 15, 2),
  235. SDL_PIXELFORMAT_XBGR1555 =
  236. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  237. SDL_PACKEDLAYOUT_1555, 15, 2),
  238. SDL_PIXELFORMAT_ARGB4444 =
  239. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
  240. SDL_PACKEDLAYOUT_4444, 16, 2),
  241. SDL_PIXELFORMAT_RGBA4444 =
  242. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
  243. SDL_PACKEDLAYOUT_4444, 16, 2),
  244. SDL_PIXELFORMAT_ABGR4444 =
  245. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
  246. SDL_PACKEDLAYOUT_4444, 16, 2),
  247. SDL_PIXELFORMAT_BGRA4444 =
  248. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
  249. SDL_PACKEDLAYOUT_4444, 16, 2),
  250. SDL_PIXELFORMAT_ARGB1555 =
  251. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
  252. SDL_PACKEDLAYOUT_1555, 16, 2),
  253. SDL_PIXELFORMAT_RGBA5551 =
  254. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
  255. SDL_PACKEDLAYOUT_5551, 16, 2),
  256. SDL_PIXELFORMAT_ABGR1555 =
  257. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
  258. SDL_PACKEDLAYOUT_1555, 16, 2),
  259. SDL_PIXELFORMAT_BGRA5551 =
  260. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
  261. SDL_PACKEDLAYOUT_5551, 16, 2),
  262. SDL_PIXELFORMAT_RGB565 =
  263. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  264. SDL_PACKEDLAYOUT_565, 16, 2),
  265. SDL_PIXELFORMAT_BGR565 =
  266. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  267. SDL_PACKEDLAYOUT_565, 16, 2),
  268. SDL_PIXELFORMAT_RGB24 =
  269. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
  270. 24, 3),
  271. SDL_PIXELFORMAT_BGR24 =
  272. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
  273. 24, 3),
  274. SDL_PIXELFORMAT_XRGB8888 =
  275. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
  276. SDL_PACKEDLAYOUT_8888, 24, 4),
  277. SDL_PIXELFORMAT_RGBX8888 =
  278. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
  279. SDL_PACKEDLAYOUT_8888, 24, 4),
  280. SDL_PIXELFORMAT_XBGR8888 =
  281. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
  282. SDL_PACKEDLAYOUT_8888, 24, 4),
  283. SDL_PIXELFORMAT_BGRX8888 =
  284. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX,
  285. SDL_PACKEDLAYOUT_8888, 24, 4),
  286. SDL_PIXELFORMAT_ARGB8888 =
  287. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
  288. SDL_PACKEDLAYOUT_8888, 32, 4),
  289. SDL_PIXELFORMAT_RGBA8888 =
  290. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
  291. SDL_PACKEDLAYOUT_8888, 32, 4),
  292. SDL_PIXELFORMAT_ABGR8888 =
  293. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
  294. SDL_PACKEDLAYOUT_8888, 32, 4),
  295. SDL_PIXELFORMAT_BGRA8888 =
  296. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
  297. SDL_PACKEDLAYOUT_8888, 32, 4),
  298. SDL_PIXELFORMAT_XRGB2101010 =
  299. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
  300. SDL_PACKEDLAYOUT_2101010, 32, 4),
  301. SDL_PIXELFORMAT_XBGR2101010 =
  302. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
  303. SDL_PACKEDLAYOUT_2101010, 32, 4),
  304. SDL_PIXELFORMAT_ARGB2101010 =
  305. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
  306. SDL_PACKEDLAYOUT_2101010, 32, 4),
  307. SDL_PIXELFORMAT_ABGR2101010 =
  308. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
  309. SDL_PACKEDLAYOUT_2101010, 32, 4),
  310. SDL_PIXELFORMAT_RGB48 =
  311. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGB, 0,
  312. 48, 6),
  313. SDL_PIXELFORMAT_BGR48 =
  314. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGR, 0,
  315. 48, 6),
  316. SDL_PIXELFORMAT_RGBA64 =
  317. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGBA, 0,
  318. 64, 8),
  319. SDL_PIXELFORMAT_ARGB64 =
  320. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ARGB, 0,
  321. 64, 8),
  322. SDL_PIXELFORMAT_BGRA64 =
  323. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGRA, 0,
  324. 64, 8),
  325. SDL_PIXELFORMAT_ABGR64 =
  326. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ABGR, 0,
  327. 64, 8),
  328. SDL_PIXELFORMAT_RGB48_FLOAT =
  329. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGB, 0,
  330. 48, 6),
  331. SDL_PIXELFORMAT_BGR48_FLOAT =
  332. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGR, 0,
  333. 48, 6),
  334. SDL_PIXELFORMAT_RGBA64_FLOAT =
  335. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGBA, 0,
  336. 64, 8),
  337. SDL_PIXELFORMAT_ARGB64_FLOAT =
  338. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ARGB, 0,
  339. 64, 8),
  340. SDL_PIXELFORMAT_BGRA64_FLOAT =
  341. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGRA, 0,
  342. 64, 8),
  343. SDL_PIXELFORMAT_ABGR64_FLOAT =
  344. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ABGR, 0,
  345. 64, 8),
  346. SDL_PIXELFORMAT_RGB96_FLOAT =
  347. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGB, 0,
  348. 96, 12),
  349. SDL_PIXELFORMAT_BGR96_FLOAT =
  350. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGR, 0,
  351. 96, 12),
  352. SDL_PIXELFORMAT_RGBA128_FLOAT =
  353. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGBA, 0,
  354. 128, 16),
  355. SDL_PIXELFORMAT_ARGB128_FLOAT =
  356. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ARGB, 0,
  357. 128, 16),
  358. SDL_PIXELFORMAT_BGRA128_FLOAT =
  359. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGRA, 0,
  360. 128, 16),
  361. SDL_PIXELFORMAT_ABGR128_FLOAT =
  362. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ABGR, 0,
  363. 128, 16),
  364. /* Aliases for RGBA byte arrays of color data, for the current platform */
  365. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  366. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
  367. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
  368. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
  369. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
  370. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_RGBX8888,
  371. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_XRGB8888,
  372. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_BGRX8888,
  373. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_XBGR8888,
  374. #else
  375. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
  376. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
  377. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
  378. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
  379. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_XBGR8888,
  380. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_BGRX8888,
  381. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_XRGB8888,
  382. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_RGBX8888,
  383. #endif
  384. SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
  385. SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
  386. SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
  387. SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
  388. SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
  389. SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
  390. SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
  391. SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
  392. SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
  393. SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
  394. SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
  395. SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
  396. SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
  397. SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
  398. SDL_PIXELFORMAT_P010 = /**< Planar mode: Y + U/V interleaved (2 planes) */
  399. SDL_DEFINE_PIXELFOURCC('P', '0', '1', '0'),
  400. SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
  401. SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
  402. } SDL_PixelFormat;
  403. /**
  404. * Pixels are a representation of a color in a particular color space.
  405. *
  406. * 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.
  407. *
  408. * RGB colors consist of red, green, and blue channels of color that are added together to represent the colors we see on the screen.
  409. * https://en.wikipedia.org/wiki/RGB_color_model
  410. *
  411. * 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.
  412. * https://en.wikipedia.org/wiki/YCbCr
  413. *
  414. * 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.
  415. *
  416. * 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.
  417. *
  418. * The color primaries and white point are a definition of the colors in the color space relative to the standard XYZ color space.
  419. * https://en.wikipedia.org/wiki/CIE_1931_color_space
  420. *
  421. * 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.
  422. * https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
  423. *
  424. * The matrix coefficients are used to convert between YCbCr and RGB colors.
  425. */
  426. /**
  427. * The color type
  428. *
  429. * \since This enum is available since SDL 3.0.0.
  430. */
  431. typedef enum SDL_ColorType
  432. {
  433. SDL_COLOR_TYPE_UNKNOWN = 0,
  434. SDL_COLOR_TYPE_RGB = 1,
  435. SDL_COLOR_TYPE_YCBCR = 2
  436. } SDL_ColorType;
  437. /**
  438. * The color range, as described by
  439. * https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en
  440. *
  441. * \since This enum is available since SDL 3.0.0.
  442. */
  443. typedef enum SDL_ColorRange
  444. {
  445. SDL_COLOR_RANGE_UNKNOWN = 0,
  446. SDL_COLOR_RANGE_LIMITED = 1, /**< Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma */
  447. SDL_COLOR_RANGE_FULL = 2 /**< Full range, e.g. 0-255 for 8-bit RGB and luma, and 1-255 for 8-bit chroma */
  448. } SDL_ColorRange;
  449. /**
  450. * The color primaries, as described by
  451. * 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_ColorPrimaries
  456. {
  457. SDL_COLOR_PRIMARIES_UNKNOWN = 0,
  458. SDL_COLOR_PRIMARIES_BT709 = 1, /**< ITU-R BT.709-6 */
  459. SDL_COLOR_PRIMARIES_UNSPECIFIED = 2,
  460. SDL_COLOR_PRIMARIES_BT470M = 4, /**< ITU-R BT.470-6 System M */
  461. SDL_COLOR_PRIMARIES_BT470BG = 5, /**< ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625 */
  462. SDL_COLOR_PRIMARIES_BT601 = 6, /**< ITU-R BT.601-7 525, SMPTE 170M */
  463. SDL_COLOR_PRIMARIES_SMPTE240 = 7, /**< SMPTE 240M, functionally the same as SDL_COLOR_PRIMARIES_BT601 */
  464. SDL_COLOR_PRIMARIES_GENERIC_FILM = 8, /**< Generic film (color filters using Illuminant C) */
  465. SDL_COLOR_PRIMARIES_BT2020 = 9, /**< ITU-R BT.2020-2 / ITU-R BT.2100-0 */
  466. SDL_COLOR_PRIMARIES_XYZ = 10, /**< SMPTE ST 428-1 */
  467. SDL_COLOR_PRIMARIES_SMPTE431 = 11, /**< SMPTE RP 431-2 */
  468. SDL_COLOR_PRIMARIES_SMPTE432 = 12, /**< SMPTE EG 432-1 / DCI P3 */
  469. SDL_COLOR_PRIMARIES_EBU3213 = 22, /**< EBU Tech. 3213-E */
  470. SDL_COLOR_PRIMARIES_CUSTOM = 31
  471. } SDL_ColorPrimaries;
  472. /**
  473. * The color transfer characteristics.
  474. *
  475. * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
  476. *
  477. * \since This enum is available since SDL 3.0.0.
  478. */
  479. typedef enum SDL_TransferCharacteristics
  480. {
  481. SDL_TRANSFER_CHARACTERISTICS_UNKNOWN = 0,
  482. SDL_TRANSFER_CHARACTERISTICS_BT709 = 1, /**< Rec. ITU-R BT.709-6 / ITU-R BT1361 */
  483. SDL_TRANSFER_CHARACTERISTICS_UNSPECIFIED = 2,
  484. SDL_TRANSFER_CHARACTERISTICS_GAMMA22 = 4, /**< ITU-R BT.470-6 System M / ITU-R BT1700 625 PAL & SECAM */
  485. SDL_TRANSFER_CHARACTERISTICS_GAMMA28 = 5, /**< ITU-R BT.470-6 System B, G */
  486. SDL_TRANSFER_CHARACTERISTICS_BT601 = 6, /**< SMPTE ST 170M / ITU-R BT.601-7 525 or 625 */
  487. SDL_TRANSFER_CHARACTERISTICS_SMPTE240 = 7, /**< SMPTE ST 240M */
  488. SDL_TRANSFER_CHARACTERISTICS_LINEAR = 8,
  489. SDL_TRANSFER_CHARACTERISTICS_LOG100 = 9,
  490. SDL_TRANSFER_CHARACTERISTICS_LOG100_SQRT10 = 10,
  491. SDL_TRANSFER_CHARACTERISTICS_IEC61966 = 11, /**< IEC 61966-2-4 */
  492. SDL_TRANSFER_CHARACTERISTICS_BT1361 = 12, /**< ITU-R BT1361 Extended Colour Gamut */
  493. SDL_TRANSFER_CHARACTERISTICS_SRGB = 13, /**< IEC 61966-2-1 (sRGB or sYCC) */
  494. SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT = 14, /**< ITU-R BT2020 for 10-bit system */
  495. SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT = 15, /**< ITU-R BT2020 for 12-bit system */
  496. SDL_TRANSFER_CHARACTERISTICS_PQ = 16, /**< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems */
  497. SDL_TRANSFER_CHARACTERISTICS_SMPTE428 = 17, /**< SMPTE ST 428-1 */
  498. SDL_TRANSFER_CHARACTERISTICS_HLG = 18, /**< ARIB STD-B67, known as "hybrid log-gamma" (HLG) */
  499. SDL_TRANSFER_CHARACTERISTICS_CUSTOM = 31
  500. } SDL_TransferCharacteristics;
  501. /**
  502. * The matrix coefficients.
  503. *
  504. * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
  505. *
  506. * \since This enum is available since SDL 3.0.0.
  507. */
  508. typedef enum SDL_MatrixCoefficients
  509. {
  510. SDL_MATRIX_COEFFICIENTS_IDENTITY = 0,
  511. SDL_MATRIX_COEFFICIENTS_BT709 = 1, /**< ITU-R BT.709-6 */
  512. SDL_MATRIX_COEFFICIENTS_UNSPECIFIED = 2,
  513. SDL_MATRIX_COEFFICIENTS_FCC = 4, /**< US FCC Title 47 */
  514. 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 */
  515. SDL_MATRIX_COEFFICIENTS_BT601 = 6, /**< ITU-R BT.601-7 525 */
  516. SDL_MATRIX_COEFFICIENTS_SMPTE240 = 7, /**< SMPTE 240M */
  517. SDL_MATRIX_COEFFICIENTS_YCGCO = 8,
  518. SDL_MATRIX_COEFFICIENTS_BT2020_NCL = 9, /**< ITU-R BT.2020-2 non-constant luminance */
  519. SDL_MATRIX_COEFFICIENTS_BT2020_CL = 10, /**< ITU-R BT.2020-2 constant luminance */
  520. SDL_MATRIX_COEFFICIENTS_SMPTE2085 = 11, /**< SMPTE ST 2085 */
  521. SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL = 12,
  522. SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL = 13,
  523. SDL_MATRIX_COEFFICIENTS_ICTCP = 14, /**< ITU-R BT.2100-0 ICTCP */
  524. SDL_MATRIX_COEFFICIENTS_CUSTOM = 31
  525. } SDL_MatrixCoefficients;
  526. /**
  527. * The chroma sample location.
  528. *
  529. * \since This enum is available since SDL 3.0.0.
  530. */
  531. typedef enum SDL_ChromaLocation
  532. {
  533. SDL_CHROMA_LOCATION_NONE = 0, /**< RGB, no chroma sampling */
  534. 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. */
  535. 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. */
  536. 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"). */
  537. } SDL_ChromaLocation;
  538. /* Colorspace definition */
  539. #define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
  540. (((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
  541. ((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))
  542. #define SDL_COLORSPACETYPE(X) (SDL_ColorType)(((X) >> 28) & 0x0F)
  543. #define SDL_COLORSPACERANGE(X) (SDL_ColorRange)(((X) >> 24) & 0x0F)
  544. #define SDL_COLORSPACECHROMA(X) (SDL_ChromaLocation)(((X) >> 20) & 0x0F)
  545. #define SDL_COLORSPACEPRIMARIES(X) (SDL_ColorPrimaries)(((X) >> 10) & 0x1F)
  546. #define SDL_COLORSPACETRANSFER(X) (SDL_TransferCharacteristics)(((X) >> 5) & 0x1F)
  547. #define SDL_COLORSPACEMATRIX(X) (SDL_MatrixCoefficients)((X) & 0x1F)
  548. #define SDL_ISCOLORSPACE_MATRIX_BT601(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT470BG)
  549. #define SDL_ISCOLORSPACE_MATRIX_BT709(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT709)
  550. #define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
  551. #define SDL_ISCOLORSPACE_LIMITED_RANGE(X) (SDL_COLORSPACERANGE(X) != SDL_COLOR_RANGE_FULL)
  552. #define SDL_ISCOLORSPACE_FULL_RANGE(X) (SDL_COLORSPACERANGE(X) == SDL_COLOR_RANGE_FULL)
  553. typedef enum SDL_Colorspace
  554. {
  555. SDL_COLORSPACE_UNKNOWN,
  556. /* sRGB is a gamma corrected colorspace, and the default colorspace for SDL rendering and 8-bit RGB surfaces */
  557. SDL_COLORSPACE_SRGB = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 */
  558. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  559. SDL_COLOR_RANGE_FULL,
  560. SDL_COLOR_PRIMARIES_BT709,
  561. SDL_TRANSFER_CHARACTERISTICS_SRGB,
  562. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  563. SDL_CHROMA_LOCATION_NONE),
  564. /* 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 */
  565. SDL_COLORSPACE_SRGB_LINEAR = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 */
  566. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  567. SDL_COLOR_RANGE_FULL,
  568. SDL_COLOR_PRIMARIES_BT709,
  569. SDL_TRANSFER_CHARACTERISTICS_LINEAR,
  570. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  571. SDL_CHROMA_LOCATION_NONE),
  572. /* HDR10 is a non-linear HDR colorspace and the default colorspace for 10-bit surfaces */
  573. SDL_COLORSPACE_HDR10 = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 */
  574. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
  575. SDL_COLOR_RANGE_FULL,
  576. SDL_COLOR_PRIMARIES_BT2020,
  577. SDL_TRANSFER_CHARACTERISTICS_PQ,
  578. SDL_MATRIX_COEFFICIENTS_IDENTITY,
  579. SDL_CHROMA_LOCATION_NONE),
  580. SDL_COLORSPACE_JPEG = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 */
  581. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  582. SDL_COLOR_RANGE_FULL,
  583. SDL_COLOR_PRIMARIES_BT709,
  584. SDL_TRANSFER_CHARACTERISTICS_BT601,
  585. SDL_MATRIX_COEFFICIENTS_BT601,
  586. SDL_CHROMA_LOCATION_NONE),
  587. SDL_COLORSPACE_BT601_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
  588. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  589. SDL_COLOR_RANGE_LIMITED,
  590. SDL_COLOR_PRIMARIES_BT601,
  591. SDL_TRANSFER_CHARACTERISTICS_BT601,
  592. SDL_MATRIX_COEFFICIENTS_BT601,
  593. SDL_CHROMA_LOCATION_LEFT),
  594. SDL_COLORSPACE_BT601_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
  595. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  596. SDL_COLOR_RANGE_FULL,
  597. SDL_COLOR_PRIMARIES_BT601,
  598. SDL_TRANSFER_CHARACTERISTICS_BT601,
  599. SDL_MATRIX_COEFFICIENTS_BT601,
  600. SDL_CHROMA_LOCATION_LEFT),
  601. SDL_COLORSPACE_BT709_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
  602. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  603. SDL_COLOR_RANGE_LIMITED,
  604. SDL_COLOR_PRIMARIES_BT709,
  605. SDL_TRANSFER_CHARACTERISTICS_BT709,
  606. SDL_MATRIX_COEFFICIENTS_BT709,
  607. SDL_CHROMA_LOCATION_LEFT),
  608. SDL_COLORSPACE_BT709_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
  609. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  610. SDL_COLOR_RANGE_FULL,
  611. SDL_COLOR_PRIMARIES_BT709,
  612. SDL_TRANSFER_CHARACTERISTICS_BT709,
  613. SDL_MATRIX_COEFFICIENTS_BT709,
  614. SDL_CHROMA_LOCATION_LEFT),
  615. SDL_COLORSPACE_BT2020_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 */
  616. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  617. SDL_COLOR_RANGE_LIMITED,
  618. SDL_COLOR_PRIMARIES_BT2020,
  619. SDL_TRANSFER_CHARACTERISTICS_PQ,
  620. SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
  621. SDL_CHROMA_LOCATION_LEFT),
  622. SDL_COLORSPACE_BT2020_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 */
  623. SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
  624. SDL_COLOR_RANGE_FULL,
  625. SDL_COLOR_PRIMARIES_BT2020,
  626. SDL_TRANSFER_CHARACTERISTICS_PQ,
  627. SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
  628. SDL_CHROMA_LOCATION_LEFT),
  629. /* The default colorspace for RGB surfaces if no colorspace is specified */
  630. SDL_COLORSPACE_RGB_DEFAULT = SDL_COLORSPACE_SRGB,
  631. /* The default colorspace for YUV surfaces if no colorspace is specified */
  632. SDL_COLORSPACE_YUV_DEFAULT = SDL_COLORSPACE_JPEG
  633. } SDL_Colorspace;
  634. /**
  635. * A structure that represents a color as RGBA components.
  636. *
  637. * The bits of this structure can be directly reinterpreted as an
  638. * integer-packed color which uses the SDL_PIXELFORMAT_RGBA32 format
  639. * (SDL_PIXELFORMAT_ABGR8888 on little-endian systems and
  640. * SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
  641. *
  642. * \since This struct is available since SDL 3.0.0.
  643. */
  644. typedef struct SDL_Color
  645. {
  646. Uint8 r;
  647. Uint8 g;
  648. Uint8 b;
  649. Uint8 a;
  650. } SDL_Color;
  651. /**
  652. * The bits of this structure can be directly reinterpreted as a float-packed
  653. * color which uses the SDL_PIXELFORMAT_RGBA128_FLOAT format
  654. *
  655. * \since This struct is available since SDL 3.0.0.
  656. */
  657. typedef struct SDL_FColor
  658. {
  659. float r;
  660. float g;
  661. float b;
  662. float a;
  663. } SDL_FColor;
  664. /**
  665. * A set of indexed colors representing a palette.
  666. *
  667. * \since This struct is available since SDL 3.0.0.
  668. *
  669. * \sa SDL_SetPaletteColors
  670. */
  671. typedef struct SDL_Palette
  672. {
  673. int ncolors; /**< number of elements in `colors`. */
  674. SDL_Color *colors; /**< an array of colors, `ncolors` long. */
  675. Uint32 version; /**< internal use only, do not touch. */
  676. int refcount; /**< internal use only, do not touch. */
  677. } SDL_Palette;
  678. /**
  679. * Details about the format of a pixel.
  680. *
  681. * \since This struct is available since SDL 3.0.0.
  682. */
  683. typedef struct SDL_PixelFormatDetails
  684. {
  685. SDL_PixelFormat format;
  686. Uint8 bits_per_pixel;
  687. Uint8 bytes_per_pixel;
  688. Uint8 padding[2];
  689. Uint32 Rmask;
  690. Uint32 Gmask;
  691. Uint32 Bmask;
  692. Uint32 Amask;
  693. Uint8 Rbits;
  694. Uint8 Gbits;
  695. Uint8 Bbits;
  696. Uint8 Abits;
  697. Uint8 Rshift;
  698. Uint8 Gshift;
  699. Uint8 Bshift;
  700. Uint8 Ashift;
  701. } SDL_PixelFormatDetails;
  702. /**
  703. * Get the human readable name of a pixel format.
  704. *
  705. * The returned string follows the SDL_GetStringRule.
  706. *
  707. * \param format the pixel format to query.
  708. * \returns the human readable name of the specified pixel format or
  709. * `SDL_PIXELFORMAT_UNKNOWN` if the format isn't recognized.
  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. extern SDL_DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat format);
  716. /**
  717. * Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
  718. *
  719. * \param format one of the SDL_PixelFormat values.
  720. * \param bpp a bits per pixel value; usually 15, 16, or 32.
  721. * \param Rmask a pointer filled in with the red mask for the format.
  722. * \param Gmask a pointer filled in with the green mask for the format.
  723. * \param Bmask a pointer filled in with the blue mask for the format.
  724. * \param Amask a pointer filled in with the alpha mask for the format.
  725. * \returns 0 on success or a negative error code on failure; call
  726. * SDL_GetError() for more information.
  727. *
  728. * \threadsafety It is safe to call this function from any thread.
  729. *
  730. * \since This function is available since SDL 3.0.0.
  731. *
  732. * \sa SDL_GetPixelFormatForMasks
  733. */
  734. extern SDL_DECLSPEC int SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask);
  735. /**
  736. * Convert a bpp value and RGBA masks to an enumerated pixel format.
  737. *
  738. * This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't
  739. * possible.
  740. *
  741. * \param bpp a bits per pixel value; usually 15, 16, or 32.
  742. * \param Rmask the red mask for the format.
  743. * \param Gmask the green mask for the format.
  744. * \param Bmask the blue mask for the format.
  745. * \param Amask the alpha mask for the format.
  746. * \returns the SDL_PixelFormat value corresponding to the format masks, or
  747. * SDL_PIXELFORMAT_UNKNOWN if there isn't a match.
  748. *
  749. * \threadsafety It is safe to call this function from any thread.
  750. *
  751. * \since This function is available since SDL 3.0.0.
  752. *
  753. * \sa SDL_GetMasksForPixelFormat
  754. */
  755. extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
  756. /**
  757. * Create an SDL_PixelFormatDetails structure corresponding to a pixel format.
  758. *
  759. * Returned structure may come from a shared global cache (i.e. not newly
  760. * allocated), and hence should not be modified, especially the palette. Weird
  761. * errors such as `Blit combination not supported` may occur.
  762. *
  763. * \param format one of the SDL_PixelFormat values.
  764. * \returns a pointer to a SDL_PixelFormatDetails structure or NULL on
  765. * failure; call SDL_GetError() for more information.
  766. *
  767. * \threadsafety It is safe to call this function from any thread.
  768. *
  769. * \since This function is available since SDL 3.0.0.
  770. */
  771. extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDetails(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. * \threadsafety It is safe to call this function from any thread.
  783. *
  784. * \since This function is available since SDL 3.0.0.
  785. *
  786. * \sa SDL_DestroyPalette
  787. * \sa SDL_SetPaletteColors
  788. * \sa SDL_SetSurfacePalette
  789. */
  790. extern SDL_DECLSPEC SDL_Palette *SDLCALL SDL_CreatePalette(int ncolors);
  791. /**
  792. * Set a range of colors in a palette.
  793. *
  794. * \param palette the SDL_Palette structure to modify.
  795. * \param colors an array of SDL_Color structures to copy into the palette.
  796. * \param firstcolor the index of the first palette entry to modify.
  797. * \param ncolors the number of entries to modify.
  798. * \returns 0 on success or a negative error code on failure; call
  799. * SDL_GetError() for more information.
  800. *
  801. * \threadsafety It is safe to call this function from any thread, as long as
  802. * the palette is not modified or destroyed in another thread.
  803. *
  804. * \since This function is available since SDL 3.0.0.
  805. */
  806. extern SDL_DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors);
  807. /**
  808. * Free a palette created with SDL_CreatePalette().
  809. *
  810. * \param palette the SDL_Palette structure to be freed.
  811. *
  812. * \threadsafety It is safe to call this function from any thread, as long as
  813. * the palette is not modified or destroyed in another thread.
  814. *
  815. * \since This function is available since SDL 3.0.0.
  816. *
  817. * \sa SDL_CreatePalette
  818. */
  819. extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette *palette);
  820. /**
  821. * Map an RGB triple to an opaque pixel value for a given pixel format.
  822. *
  823. * This function maps the RGB color value to the specified pixel format and
  824. * returns the pixel value best approximating the given RGB color value for
  825. * the given pixel format.
  826. *
  827. * If the format has a palette (8-bit) the index of the closest matching color
  828. * in the palette will be returned.
  829. *
  830. * If the specified pixel format has an alpha component it will be returned as
  831. * all 1 bits (fully opaque).
  832. *
  833. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  834. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  835. * format the return value can be assigned to a Uint16, and similarly a Uint8
  836. * for an 8-bpp format).
  837. *
  838. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  839. * format.
  840. * \param palette an optional palette for indexed formats, may be NULL.
  841. * \param r the red component of the pixel in the range 0-255.
  842. * \param g the green component of the pixel in the range 0-255.
  843. * \param b the blue component of the pixel in the range 0-255.
  844. * \returns a pixel value.
  845. *
  846. * \threadsafety It is safe to call this function from any thread, as long as
  847. * the palette is not modified.
  848. *
  849. * \since This function is available since SDL 3.0.0.
  850. *
  851. * \sa SDL_GetRGB
  852. * \sa SDL_MapRGBA
  853. * \sa SDL_MapSurfaceRGB
  854. */
  855. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b);
  856. /**
  857. * Map an RGBA quadruple to a pixel value for a given pixel format.
  858. *
  859. * This function maps the RGBA color value to the specified pixel format and
  860. * returns the pixel value best approximating the given RGBA color value for
  861. * the given pixel format.
  862. *
  863. * If the specified pixel format has no alpha component the alpha value will
  864. * be ignored (as it will be in formats with a palette).
  865. *
  866. * If the format has a palette (8-bit) the index of the closest matching color
  867. * in the palette will be returned.
  868. *
  869. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  870. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  871. * format the return value can be assigned to a Uint16, and similarly a Uint8
  872. * for an 8-bpp format).
  873. *
  874. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  875. * format.
  876. * \param palette an optional palette for indexed formats, may be NULL.
  877. * \param r the red component of the pixel in the range 0-255.
  878. * \param g the green component of the pixel in the range 0-255.
  879. * \param b the blue component of the pixel in the range 0-255.
  880. * \param a the alpha component of the pixel in the range 0-255.
  881. * \returns a pixel value.
  882. *
  883. * \threadsafety It is safe to call this function from any thread, as long as
  884. * the palette is not modified.
  885. *
  886. * \since This function is available since SDL 3.0.0.
  887. *
  888. * \sa SDL_GetRGBA
  889. * \sa SDL_MapRGB
  890. * \sa SDL_MapSurfaceRGBA
  891. */
  892. extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, 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 a pointer to SDL_PixelFormatDetails describing the pixel
  903. * format.
  904. * \param palette an optional palette for indexed formats, may be NULL.
  905. * \param r a pointer filled in with the red component, may be NULL.
  906. * \param g a pointer filled in with the green component, may be NULL.
  907. * \param b a pointer filled in with the blue component, may be NULL.
  908. *
  909. * \threadsafety It is safe to call this function from any thread, as long as
  910. * the palette is not modified.
  911. *
  912. * \since This function is available since SDL 3.0.0.
  913. *
  914. * \sa SDL_GetRGBA
  915. * \sa SDL_MapRGB
  916. * \sa SDL_MapRGBA
  917. */
  918. extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
  919. /**
  920. * Get RGBA values from a pixel in the specified format.
  921. *
  922. * This function uses the entire 8-bit [0..255] range when converting color
  923. * components from pixel formats with less than 8-bits per RGB component
  924. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  925. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  926. *
  927. * If the surface has no alpha component, the alpha will be returned as 0xff
  928. * (100% opaque).
  929. *
  930. * \param pixel a pixel value.
  931. * \param format a pointer to SDL_PixelFormatDetails describing the pixel
  932. * format.
  933. * \param palette an optional palette for indexed formats, may be NULL.
  934. * \param r a pointer filled in with the red component, may be NULL.
  935. * \param g a pointer filled in with the green component, may be NULL.
  936. * \param b a pointer filled in with the blue component, may be NULL.
  937. * \param a a pointer filled in with the alpha component, may be NULL.
  938. *
  939. * \threadsafety It is safe to call this function from any thread, as long as
  940. * the palette is not modified.
  941. *
  942. * \since This function is available since SDL 3.0.0.
  943. *
  944. * \sa SDL_GetRGB
  945. * \sa SDL_MapRGB
  946. * \sa SDL_MapRGBA
  947. */
  948. 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);
  949. /* Ends C function definitions when using C++ */
  950. #ifdef __cplusplus
  951. }
  952. #endif
  953. #include <SDL3/SDL_close_code.h>
  954. #endif /* SDL_pixels_h_ */