61 #include "QtColorTranslator.hh" 77 glGetIntegerv( GL_RED_BITS, &redBits_ );
78 glGetIntegerv( GL_GREEN_BITS, &greenBits_ );
79 glGetIntegerv( GL_BLUE_BITS, &blueBits_ );
81 if (redBits_ > 8) redBits_ = 8;
82 if (greenBits_ > 8) greenBits_ = 8;
83 if (blueBits_ > 8) blueBits_ = 8;
85 redMask_ = ((1 << redBits_) - 1);
86 greenMask_ = ((1 << greenBits_) - 1);
87 blueMask_ = ((1 << blueBits_) - 1);
88 redShift_ = 8 - redBits_;
89 greenShift_ = 8 - greenBits_;
90 blueShift_ = 8 - blueBits_;
91 redRound_ = 1 << (redShift_ - 1);
92 greenRound_ = 1 << (greenShift_ - 1);
93 blueRound_ = 1 << (blueShift_ - 1);
97 if (redBits_ > 8) std::cerr <<
"error: more than 8 red bits\n";
98 if (greenBits_ > 8) std::cerr <<
"error: more than 8 green bits\n";
99 if (blueBits_ > 8) std::cerr <<
"error: more than 8 blue bits\n";
110 unsigned char r, g, b;
111 unsigned int idx(_idx+1);
113 b = ((idx & blueMask_) << blueShift_) | blueRound_;
115 g = ((idx & greenMask_) << greenShift_) | greenRound_;
117 r = ((idx & redMask_) << redShift_) | redRound_;
122 _col = qRgb(r, g, b);
126 std::cerr <<
"Can't convert index " << _idx <<
" to RGB\n";
140 unsigned char r, g, b;
141 unsigned int idx(_idx+1);
143 b = ((idx & blueMask_) << blueShift_) | blueRound_;
145 g = ((idx & greenMask_) << greenShift_) | greenRound_;
147 r = ((idx & redMask_) << redShift_) | redRound_;
160 b = ((idx & blueMask_) << blueShift_) | blueRound_;
162 g = ((idx & greenMask_) << greenShift_) | greenRound_;
164 r = ((idx & redMask_) << redShift_) | redRound_;
174 std::cerr <<
"Can't convert index " << _idx <<
" to RGB\n";
192 result = qRed(_c) >> redShift_;
193 result <<= greenBits_;
194 result |= qGreen(_c) >> greenShift_;
195 result <<= blueBits_;
196 result |= qBlue(_c) >> blueShift_;
211 result = qRed(_fc) >> redShift_;
212 result <<= greenBits_;
213 result |= qGreen(_fc) >> greenShift_;
214 result <<= blueBits_;
215 result |= qBlue(_fc) >> blueShift_;
218 result |= qRed(_bc) >> redShift_;
219 result <<= greenBits_;
220 result |= qGreen(_bc) >> greenShift_;
221 result <<= blueBits_;
222 result |= qBlue(_bc) >> blueShift_;
235 unsigned int result(~0);
236 result >>= 32 - redBits_ - greenBits_ - blueBits_;
bool initialized() const
has it been initialized?
Namespace providing different geometric functions concerning angles.
void initialize()
init (takes current QGLcontext)
int color2index(QRgb _c) const
color -> index (one buffer)
bool index2color(unsigned int _idx, QRgb &_col) const
index -> color (one buffer)
unsigned int maxIndex() const
returns max convertable index (using ONE buffer)