SDL_pixels.h 24 KB

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