From: Brian P. <br...@va...> - 2001-03-07 03:12:43
|
Gareth Hughes wrote: > > Brian Paul wrote: > > > > OK, this sounds good. I see why you were asking. > > Cool :-) > > > I think it's correct. To convert a GLubyte color in [0,255] to a > > 16-bit GLchan value in [0,65535] you'd do: > > > > chan = b * 65535 / 255; > > > > which is equivalent to: > > > > chan = (b << 8) | b; > > > > Here's the proof: > > > > #include <assert.h> > > int main(int argc, char *argv[]) > > { > > int b; > > for (b = 0; b < 256; b++) { > > int c1 = b * 65535 / 255; > > int c2 = (b << 8) | b; > > assert(c1 == c2); > > } > > } > > > > :) > > I'm not disagreeing re: the math, I'm concerned about shifting GLubytes > up by 8. Maybe it does automatic conversion to GLushort and thus you > won't overflow. On testing this, it appears that this is the case. Oh > well :-) gcc may be doing what I intend but it probably would be safer to put a cast in there for the sake of other compilers. Good catch. -Brian |