SDL_pixels.h 26 KB

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