SDL_pixels.h 26 KB

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