xref: /haiku/headers/private/interface/ColorConversion.h (revision 9c274ccd098ee3b2674efde2d1582d4e0c68d878)
1 #ifndef _COLOR_CONVERSION_H_
2 #define _COLOR_CONVERSION_H_
3 
4 
5 #include <GraphicsDefs.h>
6 
7 #include <math.h>
8 
9 
10 class BPoint;
11 
12 
13 namespace BPrivate {
14 
15 status_t ConvertBits(const void *srcBits, void *dstBits, int32 srcBitsLength,
16 	int32 dstBitsLength, int32 srcBytesPerRow, int32 dstBytesPerRow,
17 	color_space srcColorSpace, color_space dstColorSpace, int32 width,
18 	int32 height);
19 status_t ConvertBits(const void *srcBits, void *dstBits, int32 srcBitsLength,
20 	int32 dstBitsLength, int32 srcBytesPerRow, int32 dstBytesPerRow,
21 	color_space srcColorSpace, color_space dstColorSpace, BPoint srcOffset,
22 	BPoint dstOffset, int32 width, int32 height);
23 
24 
25 /*!	\brief Helper class for conversion between RGB and palette colors.
26 */
27 class PaletteConverter {
28 public:
29 	PaletteConverter();
30 	PaletteConverter(const rgb_color *palette);
31 	PaletteConverter(const color_map *colorMap);
32 	~PaletteConverter();
33 
34 	status_t SetTo(const rgb_color *palette);
35 	status_t SetTo(const color_map *colorMap);
36 	status_t InitCheck() const;
37 
38 	inline uint8 IndexForRGB15(uint16 rgb) const;
39 	inline uint8 IndexForRGB15(uint8 red, uint8 green, uint8 blue) const;
40 	inline uint8 IndexForRGB16(uint16 rgb) const;
41 	inline uint8 IndexForRGB16(uint8 red, uint8 green, uint8 blue) const;
42 	inline uint8 IndexForRGB24(uint32 rgb) const;
43 	inline uint8 IndexForRGB24(uint8 red, uint8 green, uint8 blue) const;
44 	inline uint8 IndexForRGBA32(uint32 rgba) const;
45 	inline uint8 IndexForGray(uint8 gray) const;
46 
47 	inline const rgb_color &RGBColorForIndex(uint8 index) const;
48 	inline uint16 RGB15ColorForIndex(uint8 index) const;
49 	inline uint16 RGB16ColorForIndex(uint8 index) const;
50 	inline uint32 RGBA32ColorForIndex(uint8 index) const;
51 	inline void RGBA32ColorForIndex(uint8 index, uint8 &red, uint8 &green,
52 								   uint8 &blue, uint8 &alpha) const;
53 	inline uint8 GrayColorForIndex(uint8 index) const;
54 
55 	static status_t InitializeDefault(bool useServer = false);
56 
57 private:
58 	static void _InitializeDefaultAppServer();
59 	static void _InitializeDefaultNoAppServer();
60 
61 private:
62 	const color_map	*fColorMap;
63 	color_map		*fOwnColorMap;
64 	status_t		fCStatus;
65 };
66 
67 
68 }	// namespace BPrivate
69 
70 #endif
71