SDL_pixels.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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_endian.h>
  63. #include <SDL3/SDL_begin_code.h>
  64. /* Set up for C function definitions, even when using C++ */
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /**
  69. * \name Transparency definitions
  70. *
  71. * These define alpha as the opacity of a surface.
  72. */
  73. /* @{ */
  74. #define SDL_ALPHA_OPAQUE 255
  75. #define SDL_ALPHA_TRANSPARENT 0
  76. /* @} */
  77. /** Pixel type. */
  78. typedef enum
  79. {
  80. SDL_PIXELTYPE_UNKNOWN,
  81. SDL_PIXELTYPE_INDEX1,
  82. SDL_PIXELTYPE_INDEX4,
  83. SDL_PIXELTYPE_INDEX8,
  84. SDL_PIXELTYPE_PACKED8,
  85. SDL_PIXELTYPE_PACKED16,
  86. SDL_PIXELTYPE_PACKED32,
  87. SDL_PIXELTYPE_ARRAYU8,
  88. SDL_PIXELTYPE_ARRAYU16,
  89. SDL_PIXELTYPE_ARRAYU32,
  90. SDL_PIXELTYPE_ARRAYF16,
  91. SDL_PIXELTYPE_ARRAYF32,
  92. /* appended at the end for compatibility with sdl2-compat: */
  93. SDL_PIXELTYPE_INDEX2
  94. } SDL_PixelType;
  95. /** Bitmap pixel order, high bit -> low bit. */
  96. typedef enum
  97. {
  98. SDL_BITMAPORDER_NONE,
  99. SDL_BITMAPORDER_4321,
  100. SDL_BITMAPORDER_1234
  101. } SDL_BitmapOrder;
  102. /** Packed component order, high bit -> low bit. */
  103. typedef enum
  104. {
  105. SDL_PACKEDORDER_NONE,
  106. SDL_PACKEDORDER_XRGB,
  107. SDL_PACKEDORDER_RGBX,
  108. SDL_PACKEDORDER_ARGB,
  109. SDL_PACKEDORDER_RGBA,
  110. SDL_PACKEDORDER_XBGR,
  111. SDL_PACKEDORDER_BGRX,
  112. SDL_PACKEDORDER_ABGR,
  113. SDL_PACKEDORDER_BGRA
  114. } SDL_PackedOrder;
  115. /** Array component order, low byte -> high byte. */
  116. typedef enum
  117. {
  118. SDL_ARRAYORDER_NONE,
  119. SDL_ARRAYORDER_RGB,
  120. SDL_ARRAYORDER_RGBA,
  121. SDL_ARRAYORDER_ARGB,
  122. SDL_ARRAYORDER_BGR,
  123. SDL_ARRAYORDER_BGRA,
  124. SDL_ARRAYORDER_ABGR
  125. } SDL_ArrayOrder;
  126. /** Packed component layout. */
  127. typedef enum
  128. {
  129. SDL_PACKEDLAYOUT_NONE,
  130. SDL_PACKEDLAYOUT_332,
  131. SDL_PACKEDLAYOUT_4444,
  132. SDL_PACKEDLAYOUT_1555,
  133. SDL_PACKEDLAYOUT_5551,
  134. SDL_PACKEDLAYOUT_565,
  135. SDL_PACKEDLAYOUT_8888,
  136. SDL_PACKEDLAYOUT_2101010,
  137. SDL_PACKEDLAYOUT_1010102
  138. } SDL_PackedLayout;
  139. #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
  140. #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
  141. ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
  142. ((bits) << 8) | ((bytes) << 0))
  143. #define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
  144. #define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
  145. #define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
  146. #define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
  147. #define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
  148. #define SDL_BYTESPERPIXEL(X) \
  149. (SDL_ISPIXELFORMAT_FOURCC(X) ? \
  150. ((((X) == SDL_PIXELFORMAT_YUY2) || \
  151. ((X) == SDL_PIXELFORMAT_UYVY) || \
  152. ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
  153. #define SDL_ISPIXELFORMAT_INDEXED(format) \
  154. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  155. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
  156. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX2) || \
  157. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
  158. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
  159. #define SDL_ISPIXELFORMAT_PACKED(format) \
  160. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  161. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
  162. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
  163. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
  164. #define SDL_ISPIXELFORMAT_ARRAY(format) \
  165. (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  166. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
  167. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
  168. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
  169. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
  170. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
  171. #define SDL_ISPIXELFORMAT_ALPHA(format) \
  172. ((SDL_ISPIXELFORMAT_PACKED(format) && \
  173. ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
  174. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
  175. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
  176. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))))
  177. #define SDL_ISPIXELFORMAT_10BIT(format) \
  178. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
  179. (SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010))
  180. /* The flag is set to 1 because 0x1? is not in the printable ASCII range */
  181. #define SDL_ISPIXELFORMAT_FOURCC(format) \
  182. ((format) && (SDL_PIXELFLAG(format) != 1))
  183. /* Note: If you modify this list, update SDL_GetPixelFormatName() */
  184. typedef enum
  185. {
  186. SDL_PIXELFORMAT_UNKNOWN,
  187. SDL_PIXELFORMAT_INDEX1LSB =
  188. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
  189. 1, 0),
  190. SDL_PIXELFORMAT_INDEX1MSB =
  191. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
  192. 1, 0),
  193. SDL_PIXELFORMAT_INDEX2LSB =
  194. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_4321, 0,
  195. 2, 0),
  196. SDL_PIXELFORMAT_INDEX2MSB =
  197. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_1234, 0,
  198. 2, 0),
  199. SDL_PIXELFORMAT_INDEX4LSB =
  200. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
  201. 4, 0),
  202. SDL_PIXELFORMAT_INDEX4MSB =
  203. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
  204. 4, 0),
  205. SDL_PIXELFORMAT_INDEX8 =
  206. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
  207. SDL_PIXELFORMAT_RGB332 =
  208. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
  209. SDL_PACKEDLAYOUT_332, 8, 1),
  210. SDL_PIXELFORMAT_XRGB4444 =
  211. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  212. SDL_PACKEDLAYOUT_4444, 12, 2),
  213. SDL_PIXELFORMAT_RGB444 = SDL_PIXELFORMAT_XRGB4444,
  214. SDL_PIXELFORMAT_XBGR4444 =
  215. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  216. SDL_PACKEDLAYOUT_4444, 12, 2),
  217. SDL_PIXELFORMAT_BGR444 = SDL_PIXELFORMAT_XBGR4444,
  218. SDL_PIXELFORMAT_XRGB1555 =
  219. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  220. SDL_PACKEDLAYOUT_1555, 15, 2),
  221. SDL_PIXELFORMAT_RGB555 = SDL_PIXELFORMAT_XRGB1555,
  222. SDL_PIXELFORMAT_XBGR1555 =
  223. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  224. SDL_PACKEDLAYOUT_1555, 15, 2),
  225. SDL_PIXELFORMAT_BGR555 = SDL_PIXELFORMAT_XBGR1555,
  226. SDL_PIXELFORMAT_ARGB4444 =
  227. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
  228. SDL_PACKEDLAYOUT_4444, 16, 2),
  229. SDL_PIXELFORMAT_RGBA4444 =
  230. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
  231. SDL_PACKEDLAYOUT_4444, 16, 2),
  232. SDL_PIXELFORMAT_ABGR4444 =
  233. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
  234. SDL_PACKEDLAYOUT_4444, 16, 2),
  235. SDL_PIXELFORMAT_BGRA4444 =
  236. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
  237. SDL_PACKEDLAYOUT_4444, 16, 2),
  238. SDL_PIXELFORMAT_ARGB1555 =
  239. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
  240. SDL_PACKEDLAYOUT_1555, 16, 2),
  241. SDL_PIXELFORMAT_RGBA5551 =
  242. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
  243. SDL_PACKEDLAYOUT_5551, 16, 2),
  244. SDL_PIXELFORMAT_ABGR1555 =
  245. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
  246. SDL_PACKEDLAYOUT_1555, 16, 2),
  247. SDL_PIXELFORMAT_BGRA5551 =
  248. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
  249. SDL_PACKEDLAYOUT_5551, 16, 2),
  250. SDL_PIXELFORMAT_RGB565 =
  251. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
  252. SDL_PACKEDLAYOUT_565, 16, 2),
  253. SDL_PIXELFORMAT_BGR565 =
  254. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
  255. SDL_PACKEDLAYOUT_565, 16, 2),
  256. SDL_PIXELFORMAT_RGB24 =
  257. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
  258. 24, 3),
  259. SDL_PIXELFORMAT_BGR24 =
  260. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
  261. 24, 3),
  262. SDL_PIXELFORMAT_XRGB8888 =
  263. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
  264. SDL_PACKEDLAYOUT_8888, 24, 4),
  265. SDL_PIXELFORMAT_RGBX8888 =
  266. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
  267. SDL_PACKEDLAYOUT_8888, 24, 4),
  268. SDL_PIXELFORMAT_XBGR8888 =
  269. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
  270. SDL_PACKEDLAYOUT_8888, 24, 4),
  271. SDL_PIXELFORMAT_BGRX8888 =
  272. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX,
  273. SDL_PACKEDLAYOUT_8888, 24, 4),
  274. SDL_PIXELFORMAT_ARGB8888 =
  275. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
  276. SDL_PACKEDLAYOUT_8888, 32, 4),
  277. SDL_PIXELFORMAT_RGBA8888 =
  278. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
  279. SDL_PACKEDLAYOUT_8888, 32, 4),
  280. SDL_PIXELFORMAT_ABGR8888 =
  281. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
  282. SDL_PACKEDLAYOUT_8888, 32, 4),
  283. SDL_PIXELFORMAT_BGRA8888 =
  284. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
  285. SDL_PACKEDLAYOUT_8888, 32, 4),
  286. SDL_PIXELFORMAT_XRGB2101010 =
  287. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
  288. SDL_PACKEDLAYOUT_2101010, 32, 4),
  289. SDL_PIXELFORMAT_XBGR2101010 =
  290. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
  291. SDL_PACKEDLAYOUT_2101010, 32, 4),
  292. SDL_PIXELFORMAT_ARGB2101010 =
  293. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
  294. SDL_PACKEDLAYOUT_2101010, 32, 4),
  295. SDL_PIXELFORMAT_ABGR2101010 =
  296. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
  297. SDL_PACKEDLAYOUT_2101010, 32, 4),
  298. SDL_PIXELFORMAT_RGB48 =
  299. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGB, 0,
  300. 48, 3),
  301. SDL_PIXELFORMAT_BGR48 =
  302. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGR, 0,
  303. 48, 3),
  304. SDL_PIXELFORMAT_RGBA64 =
  305. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGBA, 0,
  306. 64, 4),
  307. SDL_PIXELFORMAT_ARGB64 =
  308. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ARGB, 0,
  309. 64, 4),
  310. SDL_PIXELFORMAT_BGRA64 =
  311. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGRA, 0,
  312. 64, 4),
  313. SDL_PIXELFORMAT_ABGR64 =
  314. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ABGR, 0,
  315. 64, 4),
  316. SDL_PIXELFORMAT_RGB48F =
  317. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGB, 0,
  318. 48, 3),
  319. SDL_PIXELFORMAT_BGR48_FLOAT =
  320. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGR, 0,
  321. 48, 3),
  322. SDL_PIXELFORMAT_RGBA64_FLOAT =
  323. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGBA, 0,
  324. 64, 4),
  325. SDL_PIXELFORMAT_ARGB64_FLOAT =
  326. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ARGB, 0,
  327. 64, 4),
  328. SDL_PIXELFORMAT_BGRA64_FLOAT =
  329. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGRA, 0,
  330. 64, 4),
  331. SDL_PIXELFORMAT_ABGR64_FLOAT =
  332. SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ABGR, 0,
  333. 64, 4),
  334. /* Aliases for RGBA byte arrays of color data, for the current platform */
  335. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  336. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
  337. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
  338. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
  339. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
  340. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_RGBX8888,
  341. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_XRGB8888,
  342. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_BGRX8888,
  343. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_XBGR8888,
  344. #else
  345. SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
  346. SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
  347. SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
  348. SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
  349. SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_XBGR8888,
  350. SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_BGRX8888,
  351. SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_XRGB8888,
  352. SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_RGBX8888,
  353. #endif
  354. SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
  355. SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
  356. SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
  357. SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
  358. SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
  359. SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
  360. SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
  361. SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
  362. SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
  363. SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
  364. SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
  365. SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
  366. SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
  367. SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
  368. SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
  369. SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
  370. } SDL_PixelFormatEnum;
  371. /**
  372. * The bits of this structure can be directly reinterpreted as an integer-packed
  373. * color which uses the SDL_PIXELFORMAT_RGBA32 format (SDL_PIXELFORMAT_ABGR8888
  374. * on little-endian systems and SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
  375. */
  376. typedef struct SDL_Color
  377. {
  378. Uint8 r;
  379. Uint8 g;
  380. Uint8 b;
  381. Uint8 a;
  382. } SDL_Color;
  383. #define SDL_Colour SDL_Color
  384. typedef struct SDL_Palette
  385. {
  386. int ncolors;
  387. SDL_Color *colors;
  388. Uint32 version;
  389. int refcount;
  390. } SDL_Palette;
  391. /**
  392. * \note Everything in the pixel format structure is read-only.
  393. */
  394. typedef struct SDL_PixelFormat
  395. {
  396. Uint32 format;
  397. SDL_Palette *palette;
  398. Uint8 BitsPerPixel;
  399. Uint8 BytesPerPixel;
  400. Uint8 padding[2];
  401. Uint32 Rmask;
  402. Uint32 Gmask;
  403. Uint32 Bmask;
  404. Uint32 Amask;
  405. Uint8 Rloss;
  406. Uint8 Gloss;
  407. Uint8 Bloss;
  408. Uint8 Aloss;
  409. Uint8 Rshift;
  410. Uint8 Gshift;
  411. Uint8 Bshift;
  412. Uint8 Ashift;
  413. int refcount;
  414. struct SDL_PixelFormat *next;
  415. } SDL_PixelFormat;
  416. /**
  417. * Get the human readable name of a pixel format.
  418. *
  419. * \param format the pixel format to query
  420. * \returns the human readable name of the specified pixel format or
  421. * `SDL_PIXELFORMAT_UNKNOWN` if the format isn't recognized.
  422. *
  423. * \since This function is available since SDL 3.0.0.
  424. */
  425. extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
  426. /**
  427. * Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
  428. *
  429. * \param format one of the SDL_PixelFormatEnum values
  430. * \param bpp a bits per pixel value; usually 15, 16, or 32
  431. * \param Rmask a pointer filled in with the red mask for the format
  432. * \param Gmask a pointer filled in with the green mask for the format
  433. * \param Bmask a pointer filled in with the blue mask for the format
  434. * \param Amask a pointer filled in with the alpha mask for the format
  435. * \returns SDL_TRUE on success or SDL_FALSE if the conversion wasn't
  436. * possible; call SDL_GetError() for more information.
  437. *
  438. * \since This function is available since SDL 3.0.0.
  439. *
  440. * \sa SDL_GetPixelFormatEnumForMasks
  441. */
  442. extern DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormatEnum(Uint32 format,
  443. int *bpp,
  444. Uint32 * Rmask,
  445. Uint32 * Gmask,
  446. Uint32 * Bmask,
  447. Uint32 * Amask);
  448. /**
  449. * Convert a bpp value and RGBA masks to an enumerated pixel format.
  450. *
  451. * This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't
  452. * possible.
  453. *
  454. * \param bpp a bits per pixel value; usually 15, 16, or 32
  455. * \param Rmask the red mask for the format
  456. * \param Gmask the green mask for the format
  457. * \param Bmask the blue mask for the format
  458. * \param Amask the alpha mask for the format
  459. * \returns one of the SDL_PixelFormatEnum values
  460. *
  461. * \since This function is available since SDL 3.0.0.
  462. *
  463. * \sa SDL_GetMasksForPixelFormatEnum
  464. */
  465. extern DECLSPEC Uint32 SDLCALL SDL_GetPixelFormatEnumForMasks(int bpp,
  466. Uint32 Rmask,
  467. Uint32 Gmask,
  468. Uint32 Bmask,
  469. Uint32 Amask);
  470. /**
  471. * Create an SDL_PixelFormat structure corresponding to a pixel format.
  472. *
  473. * Returned structure may come from a shared global cache (i.e. not newly
  474. * allocated), and hence should not be modified, especially the palette. Weird
  475. * errors such as `Blit combination not supported` may occur.
  476. *
  477. * \param pixel_format one of the SDL_PixelFormatEnum values
  478. * \returns the new SDL_PixelFormat structure or NULL on failure; call
  479. * SDL_GetError() for more information.
  480. *
  481. * \since This function is available since SDL 3.0.0.
  482. *
  483. * \sa SDL_DestroyPixelFormat
  484. */
  485. extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_CreatePixelFormat(Uint32 pixel_format);
  486. /**
  487. * Free an SDL_PixelFormat structure allocated by SDL_CreatePixelFormat().
  488. *
  489. * \param format the SDL_PixelFormat structure to free
  490. *
  491. * \since This function is available since SDL 3.0.0.
  492. *
  493. * \sa SDL_CreatePixelFormat
  494. */
  495. extern DECLSPEC void SDLCALL SDL_DestroyPixelFormat(SDL_PixelFormat *format);
  496. /**
  497. * Create a palette structure with the specified number of color entries.
  498. *
  499. * The palette entries are initialized to white.
  500. *
  501. * \param ncolors represents the number of color entries in the color palette
  502. * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
  503. * there wasn't enough memory); call SDL_GetError() for more
  504. * information.
  505. *
  506. * \since This function is available since SDL 3.0.0.
  507. *
  508. * \sa SDL_DestroyPalette
  509. */
  510. extern DECLSPEC SDL_Palette *SDLCALL SDL_CreatePalette(int ncolors);
  511. /**
  512. * Set the palette for a pixel format structure.
  513. *
  514. * \param format the SDL_PixelFormat structure that will use the palette
  515. * \param palette the SDL_Palette structure that will be used
  516. * \returns 0 on success or a negative error code on failure; call
  517. * SDL_GetError() for more information.
  518. *
  519. * \since This function is available since SDL 3.0.0.
  520. *
  521. * \sa SDL_CreatePalette
  522. * \sa SDL_DestroyPalette
  523. */
  524. extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
  525. SDL_Palette *palette);
  526. /**
  527. * Set a range of colors in a palette.
  528. *
  529. * \param palette the SDL_Palette structure to modify
  530. * \param colors an array of SDL_Color structures to copy into the palette
  531. * \param firstcolor the index of the first palette entry to modify
  532. * \param ncolors the number of entries to modify
  533. * \returns 0 on success or a negative error code on failure; call
  534. * SDL_GetError() for more information.
  535. *
  536. * \since This function is available since SDL 3.0.0.
  537. *
  538. * \sa SDL_CreatePalette
  539. * \sa SDL_CreateSurface
  540. */
  541. extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
  542. const SDL_Color * colors,
  543. int firstcolor, int ncolors);
  544. /**
  545. * Free a palette created with SDL_CreatePalette().
  546. *
  547. * \param palette the SDL_Palette structure to be freed
  548. *
  549. * \since This function is available since SDL 3.0.0.
  550. *
  551. * \sa SDL_CreatePalette
  552. */
  553. extern DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette * palette);
  554. /**
  555. * Map an RGB triple to an opaque pixel value for a given pixel format.
  556. *
  557. * This function maps the RGB color value to the specified pixel format and
  558. * returns the pixel value best approximating the given RGB color value for
  559. * the given pixel format.
  560. *
  561. * If the format has a palette (8-bit) the index of the closest matching color
  562. * in the palette will be returned.
  563. *
  564. * If the specified pixel format has an alpha component it will be returned as
  565. * all 1 bits (fully opaque).
  566. *
  567. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  568. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  569. * format the return value can be assigned to a Uint16, and similarly a Uint8
  570. * for an 8-bpp format).
  571. *
  572. * \param format an SDL_PixelFormat structure describing the pixel format
  573. * \param r the red component of the pixel in the range 0-255
  574. * \param g the green component of the pixel in the range 0-255
  575. * \param b the blue component of the pixel in the range 0-255
  576. * \returns a pixel value
  577. *
  578. * \since This function is available since SDL 3.0.0.
  579. *
  580. * \sa SDL_GetRGB
  581. * \sa SDL_GetRGBA
  582. * \sa SDL_MapRGBA
  583. */
  584. extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
  585. Uint8 r, Uint8 g, Uint8 b);
  586. /**
  587. * Map an RGBA quadruple to a pixel value for a given pixel format.
  588. *
  589. * This function maps the RGBA color value to the specified pixel format and
  590. * returns the pixel value best approximating the given RGBA color value for
  591. * the given pixel format.
  592. *
  593. * If the specified pixel format has no alpha component the alpha value will
  594. * be ignored (as it will be in formats with a palette).
  595. *
  596. * If the format has a palette (8-bit) the index of the closest matching color
  597. * in the palette will be returned.
  598. *
  599. * If the pixel format bpp (color depth) is less than 32-bpp then the unused
  600. * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
  601. * format the return value can be assigned to a Uint16, and similarly a Uint8
  602. * for an 8-bpp format).
  603. *
  604. * \param format an SDL_PixelFormat structure describing the format of the
  605. * pixel
  606. * \param r the red component of the pixel in the range 0-255
  607. * \param g the green component of the pixel in the range 0-255
  608. * \param b the blue component of the pixel in the range 0-255
  609. * \param a the alpha component of the pixel in the range 0-255
  610. * \returns a pixel value
  611. *
  612. * \since This function is available since SDL 3.0.0.
  613. *
  614. * \sa SDL_GetRGB
  615. * \sa SDL_GetRGBA
  616. * \sa SDL_MapRGB
  617. */
  618. extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
  619. Uint8 r, Uint8 g, Uint8 b,
  620. Uint8 a);
  621. /**
  622. * Get RGB values from a pixel in the specified format.
  623. *
  624. * This function uses the entire 8-bit [0..255] range when converting color
  625. * components from pixel formats with less than 8-bits per RGB component
  626. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  627. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  628. *
  629. * \param pixel a pixel value
  630. * \param format an SDL_PixelFormat structure describing the format of the
  631. * pixel
  632. * \param r a pointer filled in with the red component
  633. * \param g a pointer filled in with the green component
  634. * \param b a pointer filled in with the blue component
  635. *
  636. * \since This function is available since SDL 3.0.0.
  637. *
  638. * \sa SDL_GetRGBA
  639. * \sa SDL_MapRGB
  640. * \sa SDL_MapRGBA
  641. */
  642. extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
  643. const SDL_PixelFormat * format,
  644. Uint8 * r, Uint8 * g, Uint8 * b);
  645. /**
  646. * Get RGBA values from a pixel in the specified format.
  647. *
  648. * This function uses the entire 8-bit [0..255] range when converting color
  649. * components from pixel formats with less than 8-bits per RGB component
  650. * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
  651. * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
  652. *
  653. * If the surface has no alpha component, the alpha will be returned as 0xff
  654. * (100% opaque).
  655. *
  656. * \param pixel a pixel value
  657. * \param format an SDL_PixelFormat structure describing the format of the
  658. * pixel
  659. * \param r a pointer filled in with the red component
  660. * \param g a pointer filled in with the green component
  661. * \param b a pointer filled in with the blue component
  662. * \param a a pointer filled in with the alpha component
  663. *
  664. * \since This function is available since SDL 3.0.0.
  665. *
  666. * \sa SDL_GetRGB
  667. * \sa SDL_MapRGB
  668. * \sa SDL_MapRGBA
  669. */
  670. extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
  671. const SDL_PixelFormat * format,
  672. Uint8 * r, Uint8 * g, Uint8 * b,
  673. Uint8 * a);
  674. /* Ends C function definitions when using C++ */
  675. #ifdef __cplusplus
  676. }
  677. #endif
  678. #include <SDL3/SDL_close_code.h>
  679. #endif /* SDL_pixels_h_ */