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