Bug 4996.
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 9 Nov 2005 16:30:50 +0000 (16:30 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 9 Nov 2005 16:30:50 +0000 (16:30 +0000)
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/drivers/dri/sis/sis6326_clear.c
src/mesa/drivers/dri/sis/sis_clear.c
src/mesa/main/image.c
src/mesa/main/macros.h
src/mesa/main/pixel.c

index 29b95f94d940639864ce4e086f1f53278c9a95de..be5addb7cf2a65b2df544b440c5622d37a9710a2 100644 (file)
@@ -65,7 +65,7 @@ set_color_pattern( sisContextPtr smesa, GLubyte red, GLubyte green,
 void
 sis6326UpdateZPattern(sisContextPtr smesa, GLclampd z)
 {
-   smesa->clearZStencilPattern = FLOAT_TO_USHORT(z * 65535.0);
+   CLAMPED_FLOAT_TO_USHORT(smesa->clearZStencilPattern, z * 65535.0);
 }
 
 void
index f24454641de18be0911f3fba4917429ec9466c61..d7807b157e9fcd923bffb949267d274267ff3de6 100644 (file)
@@ -78,7 +78,7 @@ sisUpdateZStencilPattern( sisContextPtr smesa, GLclampd z, GLint stencil )
    switch (smesa->zFormat)
    {
    case SiS_ZFORMAT_Z16:
-      zPattern = FLOAT_TO_USHORT(z);
+      CLAMPED_FLOAT_TO_USHORT(zPattern, z);
       zPattern |= zPattern << 16;
       break;
    case SiS_ZFORMAT_S8Z24:
index 3523505cfcb9339d06754c67465faa13f5aebc12..b9a032307c2c528ab1be7d05e13f526cfa352bfd 100644 (file)
@@ -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;i<n;i++)
-                     dst[i] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][RCOMP]);
                   break;
                case GL_GREEN:
                   for (i=0;i<n;i++)
-                     dst[i] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][GCOMP]);
                   break;
                case GL_BLUE:
                   for (i=0;i<n;i++)
-                     dst[i] = FLOAT_TO_USHORT(rgba[i][BCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][BCOMP]);
                   break;
                case GL_ALPHA:
                   for (i=0;i<n;i++)
-                     dst[i] = FLOAT_TO_USHORT(rgba[i][ACOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][ACOMP]);
                   break;
                case GL_LUMINANCE:
                   for (i=0;i<n;i++)
-                     dst[i] = FLOAT_TO_USHORT(luminance[i]);
+                     UNCLAMPED_FLOAT_TO_USHORT(dst[i], luminance[i]);
                   break;
                case GL_LUMINANCE_ALPHA:
                   for (i=0;i<n;i++) {
-                     dst[i*2+0] = FLOAT_TO_USHORT(luminance[i]);
-                     dst[i*2+1] = FLOAT_TO_USHORT(rgba[i][ACOMP]);
+                     UNCLAMPED_FLOAT_TO_USHORT(dst[i*2+0], luminance[i]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][ACOMP]);
                   }
                   break;
                case GL_RGB:
                   for (i=0;i<n;i++) {
-                     dst[i*3+0] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
-                     dst[i*3+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
-                     dst[i*3+2] = FLOAT_TO_USHORT(rgba[i][BCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][RCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][BCOMP]);
                   }
                   break;
                case GL_RGBA:
                   for (i=0;i<n;i++) {
-                     dst[i*4+0] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
-                     dst[i*4+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
-                     dst[i*4+2] = FLOAT_TO_USHORT(rgba[i][BCOMP]);
-                     dst[i*4+3] = FLOAT_TO_USHORT(rgba[i][ACOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][RCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][BCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
                   }
                   break;
                case GL_BGR:
                   for (i=0;i<n;i++) {
-                     dst[i*3+0] = FLOAT_TO_USHORT(rgba[i][BCOMP]);
-                     dst[i*3+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
-                     dst[i*3+2] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][BCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][RCOMP]);
                   }
                   break;
                case GL_BGRA:
                   for (i=0;i<n;i++) {
-                     dst[i*4+0] = FLOAT_TO_USHORT(rgba[i][BCOMP]);
-                     dst[i*4+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
-                     dst[i*4+2] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
-                     dst[i*4+3] = FLOAT_TO_USHORT(rgba[i][ACOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][BCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][RCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
                   }
                   break;
                case GL_ABGR_EXT:
                   for (i=0;i<n;i++) {
-                     dst[i*4+0] = FLOAT_TO_USHORT(rgba[i][ACOMP]);
-                     dst[i*4+1] = FLOAT_TO_USHORT(rgba[i][BCOMP]);
-                     dst[i*4+2] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
-                     dst[i*4+3] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][ACOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][BCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][GCOMP]);
+                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][RCOMP]);
                   }
                   break;
                default:
@@ -4011,7 +4012,7 @@ _mesa_pack_depth_span( const GLcontext *ctx, GLuint n, GLvoid *dest,
          GLushort *dst = (GLushort *) dest;
          GLuint i;
          for (i = 0; i < n; i++) {
-            dst[i] = FLOAT_TO_USHORT( depthSpan[i] );
+            CLAMPED_FLOAT_TO_USHORT(dst[i], depthSpan[i]);
          }
          if (dstPacking->SwapBytes) {
             _mesa_swap2( (GLushort *) dst, n );
index dab58818fb75a5d91415589ea69b89a86ea92c2d..672a2f8bd2f375a8e69de65e22e0061ed34cffbf 100644 (file)
@@ -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))
 
index b6b2fc516a0669aeace357f3baafb7b05bd01f4a..14eca650b1f802a2c0c38cd8ce2b79f00d676dd5 100644 (file)
@@ -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: