62 #include "ColorTranslator.hh" 79 glGetIntegerv( GL_RED_BITS, &red_bits_ );
80 glGetIntegerv( GL_GREEN_BITS, &green_bits_ );
81 glGetIntegerv( GL_BLUE_BITS, &blue_bits_ );
82 glGetIntegerv( GL_ALPHA_BITS, &alpha_bits_ );
84 if (red_bits_ > 8) red_bits_ = 8;
85 if (green_bits_ > 8) green_bits_ = 8;
86 if (blue_bits_ > 8) blue_bits_ = 8;
87 if (alpha_bits_ > 8) alpha_bits_ = 8;
89 red_mask_ = ((1 << red_bits_) - 1);
90 green_mask_ = ((1 << green_bits_) - 1);
91 blue_mask_ = ((1 << blue_bits_) - 1);
92 alpha_mask_ = ((1 << alpha_bits_) - 1);
94 red_shift_ = 8 - red_bits_;
95 green_shift_ = 8 - green_bits_;
96 blue_shift_ = 8 - blue_bits_;
97 alpha_shift_ = 8 - alpha_bits_;
99 red_round_ = 1 << (red_shift_ - 1);
100 green_round_ = 1 << (green_shift_ - 1);
101 blue_round_ = 1 << (blue_shift_ - 1);
102 alpha_round_ = 1 << (alpha_shift_ - 1);
116 unsigned char r, g, b, a;
117 unsigned int idx(_idx+1);
119 b = ((idx & blue_mask_) << blue_shift_) | blue_round_;
121 g = ((idx & green_mask_) << green_shift_) | green_round_;
123 r = ((idx & red_mask_) << red_shift_) | red_round_;
125 a = ((idx & alpha_mask_) << alpha_shift_) | alpha_round_;
129 return Vec4uc(r, g, b, a);
133 std::cerr <<
"Can't convert index " << _idx <<
" to RGBA\n";
134 return Vec4uc(0, 0, 0, 0);
149 result = _rgba[3] >> alpha_shift_;
150 result <<= red_bits_;
151 result = _rgba[0] >> red_shift_;
152 result <<= green_bits_;
153 result |= _rgba[1] >> green_shift_;
154 result <<= blue_bits_;
155 result |= _rgba[2] >> blue_shift_;
168 if (red_bits_+green_bits_+blue_bits_+alpha_bits_ == 32)
171 return (1 << (red_bits_+green_bits_+blue_bits_+alpha_bits_))-1;
bool initialized() const
has it been initialized?
void initialize()
init (takes current GL context)
VectorT< unsigned char, 4 > Vec4uc
Namespace providing different geometric functions concerning angles.
Vec4uc index2color(unsigned int _idx) const
index -> color (one buffer)
unsigned int max_index() const
returns maximal convertable index
int color2index(Vec4uc _rgba) const
color -> index (one buffer)