🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

644 lines
24 KiB

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