xref: /haiku/headers/private/interface/ColorConversion.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
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 IndexForGray(uint8 gray) const;
42 
43 	inline const rgb_color &RGBColorForIndex(uint8 index) const;
44 	inline uint16 RGB15ColorForIndex(uint8 index) const;
45 	inline uint16 RGB16ColorForIndex(uint8 index) const;
46 	inline uint32 RGBA32ColorForIndex(uint8 index) const;
47 	inline void RGBA32ColorForIndex(uint8 index, uint8 &red, uint8 &green,
48 								   uint8 &blue, uint8 &alpha) const;
49 	inline uint8 GrayColorForIndex(uint8 index) const;
50 
51 	static status_t InitializeDefault(bool useServer = false);
52 
53 private:
54 	const color_map	*fColorMap;
55 	color_map		*fOwnColorMap;
56 	status_t		fCStatus;
57 };
58 
59 }	// namespace BPrivate
60 
61 #endif
62