1#ifndef _COLOR_CONVERSION_H_
2#define _COLOR_CONVERSION_H_
3
4
5#include <GraphicsDefs.h>
6
7#include <math.h>
8
9
10class BPoint;
11
12
13namespace BPrivate {
14
15status_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);
19status_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*/
27class PaletteConverter {
28public:
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
57private:
58	static void _InitializeDefaultAppServer();
59	static void _InitializeDefaultNoAppServer();
60
61private:
62	const color_map	*fColorMap;
63	color_map		*fOwnColorMap;
64	status_t		fCStatus;
65};
66
67
68}	// namespace BPrivate
69
70#endif
71