diff options
author | Brian Paul <[email protected]> | 2000-12-13 00:46:21 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2000-12-13 00:46:21 +0000 |
commit | 062bc07bde9520d12c3cc051779d67a9543c0ff7 (patch) | |
tree | 56136cced70d284b7f14b57b3be752b80375bc43 /src/mesa/main | |
parent | 75639547e70f45b7782cf528b118a39b82b06ba3 (diff) |
improved precision of glReadPixels for colorbuffers < 24bpp
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/pixel.c | 47 | ||||
-rw-r--r-- | src/mesa/main/pixel.h | 7 |
2 files changed, 52 insertions, 2 deletions
diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index efd89cadd42..cb0818c084d 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -1,4 +1,4 @@ -/* $Id: pixel.c,v 1.20 2000/11/28 00:07:51 brianp Exp $ */ +/* $Id: pixel.c,v 1.21 2000/12/13 00:46:21 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1109,3 +1109,48 @@ _mesa_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] ) stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ]; } } + + + +/* + * This function converts an array of GLchan colors to GLfloat colors. + * Most importantly, it undoes the non-uniform quantization of pixel + * values introduced when we convert shallow (< 8 bit) pixel values + * to GLubytes in the ctx->Driver.ReadRGBASpan() functions. + * This fixes a number of OpenGL conformance failures when running on + * 16bpp displays, for example. + */ +void +_mesa_chan_to_float_span(const GLcontext *ctx, GLuint n, + CONST GLchan rgba[][4], GLfloat rgbaf[][4]) +{ + const GLuint rShift = CHAN_BITS - ctx->Visual.RedBits; + const GLuint gShift = CHAN_BITS - ctx->Visual.GreenBits; + const GLuint bShift = CHAN_BITS - ctx->Visual.BlueBits; + GLuint aShift; + const GLfloat rScale = 1.0 / (GLfloat) ((1 << ctx->Visual.RedBits ) - 1); + const GLfloat gScale = 1.0 / (GLfloat) ((1 << ctx->Visual.GreenBits) - 1); + const GLfloat bScale = 1.0 / (GLfloat) ((1 << ctx->Visual.BlueBits ) - 1); + GLfloat aScale; + GLuint i; + + if (ctx->Visual.AlphaBits > 0) { + aShift = CHAN_BITS - ctx->Visual.AlphaBits; + aScale = 1.0 / (GLfloat) ((1 << ctx->Visual.AlphaBits) - 1); + } + else { + aShift = 0; + aScale = 1.0F / CHAN_MAXF; + } + + for (i = 0; i < n; i++) { + const GLint r = rgba[i][RCOMP] >> rShift; + const GLint g = rgba[i][GCOMP] >> gShift; + const GLint b = rgba[i][BCOMP] >> bShift; + const GLint a = rgba[i][ACOMP] >> aShift; + rgbaf[i][RCOMP] = (GLfloat) r * rScale; + rgbaf[i][GCOMP] = (GLfloat) g * gScale; + rgbaf[i][BCOMP] = (GLfloat) b * bScale; + rgbaf[i][ACOMP] = (GLfloat) a * aScale; + } +} diff --git a/src/mesa/main/pixel.h b/src/mesa/main/pixel.h index db6dd78ffdb..6698d8c13f0 100644 --- a/src/mesa/main/pixel.h +++ b/src/mesa/main/pixel.h @@ -1,4 +1,4 @@ -/* $Id: pixel.h,v 1.8 2000/11/28 00:07:51 brianp Exp $ */ +/* $Id: pixel.h,v 1.9 2000/12/13 00:46:21 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -131,4 +131,9 @@ extern void _mesa_map_stencil(const GLcontext *ctx, GLuint n, GLstencil index[]); +extern void +_mesa_chan_to_float_span(const GLcontext *ctx, GLuint n, + CONST GLchan rgba[][4], GLfloat rgbaf[][4]); + + #endif |