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