52 #include "ColorTranslator.hh" 53 #include <ACG/GL/GLState.hh> 71 if(_state->compatibilityProfile())
73 glGetIntegerv( GL_RED_BITS, &red_bits_ );
74 glGetIntegerv( GL_GREEN_BITS, &green_bits_ );
75 glGetIntegerv( GL_BLUE_BITS, &blue_bits_ );
76 glGetIntegerv( GL_ALPHA_BITS, &alpha_bits_ );
86 if (red_bits_ > 8) red_bits_ = 8;
87 if (green_bits_ > 8) green_bits_ = 8;
88 if (blue_bits_ > 8) blue_bits_ = 8;
89 if (alpha_bits_ > 8) alpha_bits_ = 8;
92 red_mask_ = ((1 << red_bits_) - 1);
93 green_mask_ = ((1 << green_bits_) - 1);
94 blue_mask_ = ((1 << blue_bits_) - 1);
95 alpha_mask_ = ((1 << alpha_bits_) - 1);
98 red_shift_ = 8 - red_bits_;
99 green_shift_ = 8 - green_bits_;
100 blue_shift_ = 8 - blue_bits_;
101 alpha_shift_ = 8 - alpha_bits_;
104 red_round_ = 1 << (red_shift_ - 1);
105 green_round_ = 1 << (green_shift_ - 1);
106 blue_round_ = 1 << (blue_shift_ - 1);
107 alpha_round_ = 1 << (alpha_shift_ - 1);
121 unsigned char r, g, b, a;
124 if ( _idx > std::numeric_limits<unsigned int>::max() ) {
125 std::cerr <<
"Can't convert index " << _idx <<
" to RGBA. Number too large for unsigned int \n";
126 return Vec4uc(0, 0, 0, 0);
129 unsigned int idx = (
static_cast<unsigned int>(_idx) + 1);
131 b = ((idx & blue_mask_) << blue_shift_) | blue_round_;
133 g = ((idx & green_mask_) << green_shift_) | green_round_;
135 r = ((idx & red_mask_) << red_shift_) | red_round_;
137 a = ((idx & alpha_mask_) << alpha_shift_) | alpha_round_;
141 return Vec4uc(r, g, b, a);
145 std::cerr <<
"Can't convert index " << _idx <<
" to RGBA\n";
146 return Vec4uc(0, 0, 0, 0);
166 result = _rgba[3] >> alpha_shift_;
167 result <<= red_bits_;
168 result = _rgba[0] >> red_shift_;
169 result <<= green_bits_;
170 result |= _rgba[1] >> green_shift_;
171 result <<= blue_bits_;
172 result |= _rgba[2] >> blue_shift_;
175 return ( static_cast<size_t>(result-1) );
186 if (red_bits_+green_bits_+blue_bits_+alpha_bits_ == 32)
189 return (1 << (red_bits_+green_bits_+blue_bits_+alpha_bits_))-1;
Namespace providing different geometric functions concerning angles.
VectorT< unsigned char, 4 > Vec4uc
void initialize(ACG::GLState *)
Vec4uc index2color(const size_t _idx) const
index -> color (one buffer)
size_t color2index(const Vec4uc _rgba) const
color -> index (one buffer)
size_t max_index() const
returns maximal convertible index
bool initialized() const
has it been initialized?