From a8717180d9805de3bf1ca30eff5487575fcfb384 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 9 Nov 2005 16:30:50 +0000 Subject: Bug 4996. Replace use of FLOAT_TO_USHORT with either CLAMPED_FLOAT_TO_USHORT or UNCLAMPED_FLOAT_TO_USHORT. Same should be done for UBYTE, UINT, etc. --- src/mesa/main/image.c | 55 +++++++++++++++++++++++++------------------------- src/mesa/main/macros.h | 3 --- src/mesa/main/pixel.c | 20 +++++++++--------- 3 files changed, 38 insertions(+), 40 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index 3523505cfcb..b9a032307c2 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -1042,10 +1042,11 @@ _mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLuint transferOps, -/* +/** * Used to pack an array [][4] of RGBA float colors as specified * by the dstFormat, dstType and dstPacking. Used by glReadPixels, * glGetConvolutionFilter(), etc. + * NOTE: it's assumed the incoming float colors are all in [0,1]. */ void _mesa_pack_rgba_span_float( GLcontext *ctx, @@ -1246,66 +1247,66 @@ _mesa_pack_rgba_span_float( GLcontext *ctx, switch (dstFormat) { case GL_RED: for (i=0;iSwapBytes) { _mesa_swap2( (GLushort *) dst, n ); diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h index dab58818fb7..672a2f8bd2f 100644 --- a/src/mesa/main/macros.h +++ b/src/mesa/main/macros.h @@ -57,9 +57,6 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256]; /** Convert GLushort in [0,65536] to GLfloat in [0.0,1.0] */ #define USHORT_TO_FLOAT(S) ((GLfloat) (S) * (1.0F / 65535.0F)) -/** Convert GLfloat in [0.0,1.0] to GLushort in [0,65536] */ -#define FLOAT_TO_USHORT(X) ((GLushort) (GLint) ((X) * 65535.0F)) - /** Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0] */ #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)) diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index b6b2fc516a0..14eca650b1f 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -795,52 +795,52 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values ) switch (map) { case GL_PIXEL_MAP_I_TO_I: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT(ctx->Pixel.MapItoI[i]); + values[i] = (GLushort) CLAMP(ctx->Pixel.MapItoI[i], 0.0, 65535.0); } break; case GL_PIXEL_MAP_S_TO_S: for (i = 0; i < mapsize; i++) { - values[i] = (GLushort) ctx->Pixel.MapStoS[i]; + values[i] = (GLushort) CLAMP(ctx->Pixel.MapStoS[i], 0.0, 65535.0); } break; case GL_PIXEL_MAP_I_TO_R: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoR[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoR[i] ); } break; case GL_PIXEL_MAP_I_TO_G: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoG[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoG[i] ); } break; case GL_PIXEL_MAP_I_TO_B: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoB[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoB[i] ); } break; case GL_PIXEL_MAP_I_TO_A: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoA[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoA[i] ); } break; case GL_PIXEL_MAP_R_TO_R: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapRtoR[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapRtoR[i] ); } break; case GL_PIXEL_MAP_G_TO_G: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapGtoG[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapGtoG[i] ); } break; case GL_PIXEL_MAP_B_TO_B: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapBtoB[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapBtoB[i] ); } break; case GL_PIXEL_MAP_A_TO_A: for (i = 0; i < mapsize; i++) { - values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapAtoA[i] ); + CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapAtoA[i] ); } break; default: -- cgit v1.2.3