55 #include "QtColorTranslator.hh" 71 glGetIntegerv( GL_RED_BITS, &redBits_ );
72 glGetIntegerv( GL_GREEN_BITS, &greenBits_ );
73 glGetIntegerv( GL_BLUE_BITS, &blueBits_ );
75 if (redBits_ > 8) redBits_ = 8;
76 if (greenBits_ > 8) greenBits_ = 8;
77 if (blueBits_ > 8) blueBits_ = 8;
79 redMask_ = ((1 << redBits_) - 1);
80 greenMask_ = ((1 << greenBits_) - 1);
81 blueMask_ = ((1 << blueBits_) - 1);
82 redShift_ = 8 - redBits_;
83 greenShift_ = 8 - greenBits_;
84 blueShift_ = 8 - blueBits_;
85 redRound_ = 1 << (redShift_ - 1);
86 greenRound_ = 1 << (greenShift_ - 1);
87 blueRound_ = 1 << (blueShift_ - 1);
91 if (redBits_ > 8) std::cerr <<
"error: more than 8 red bits\n";
92 if (greenBits_ > 8) std::cerr <<
"error: more than 8 green bits\n";
93 if (blueBits_ > 8) std::cerr <<
"error: more than 8 blue bits\n";
104 unsigned char r, g, b;
105 unsigned int idx(_idx+1);
107 b = ((idx & blueMask_) << blueShift_) | blueRound_;
109 g = ((idx & greenMask_) << greenShift_) | greenRound_;
111 r = ((idx & redMask_) << redShift_) | redRound_;
116 _col = qRgb(r, g, b);
120 std::cerr <<
"Can't convert index " << _idx <<
" to RGB\n";
134 unsigned char r, g, b;
135 unsigned int idx(_idx+1);
137 b = ((idx & blueMask_) << blueShift_) | blueRound_;
139 g = ((idx & greenMask_) << greenShift_) | greenRound_;
141 r = ((idx & redMask_) << redShift_) | redRound_;
154 b = ((idx & blueMask_) << blueShift_) | blueRound_;
156 g = ((idx & greenMask_) << greenShift_) | greenRound_;
158 r = ((idx & redMask_) << redShift_) | redRound_;
168 std::cerr <<
"Can't convert index " << _idx <<
" to RGB\n";
186 result = qRed(_c) >> redShift_;
187 result <<= greenBits_;
188 result |= qGreen(_c) >> greenShift_;
189 result <<= blueBits_;
190 result |= qBlue(_c) >> blueShift_;
205 result = qRed(_fc) >> redShift_;
206 result <<= greenBits_;
207 result |= qGreen(_fc) >> greenShift_;
208 result <<= blueBits_;
209 result |= qBlue(_fc) >> blueShift_;
212 result |= qRed(_bc) >> redShift_;
213 result <<= greenBits_;
214 result |= qGreen(_bc) >> greenShift_;
215 result <<= blueBits_;
216 result |= qBlue(_bc) >> blueShift_;
229 unsigned int result(~0);
230 result >>= 32 - redBits_ - greenBits_ - blueBits_;
bool index2color(unsigned int _idx, QRgb &_col) const
index -> color (one buffer)
unsigned int maxIndex() const
returns max convertable index (using ONE buffer)
Namespace providing different geometric functions concerning angles.
bool initialized() const
has it been initialized?
void initialize()
init (takes current QGLcontext)
int color2index(QRgb _c) const
color -> index (one buffer)