Use the _mesa_scale_and_bias_rgba() function in the convolution functions.
authorBrian Paul <brian.paul@tungstengraphics.com>
Sun, 31 Oct 2004 18:40:55 +0000 (18:40 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sun, 31 Oct 2004 18:40:55 +0000 (18:40 +0000)
Minor clean-ups.

src/mesa/main/convolve.c
src/mesa/main/image.c
src/mesa/main/pixel.c
src/mesa/main/pixel.h

index afa550a4812eec22cd95ac30e1669712795e6557..1f4eaf439b8790f18309166980de0e2b9fa67aae 100644 (file)
@@ -38,6 +38,7 @@
 #include "context.h"
 #include "image.h"
 #include "mtypes.h"
+#include "pixel.h"
 #include "state.h"
 
 
@@ -177,26 +178,16 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G
                               ctx->Unpack.BufferObj);
    }
 
-   /* apply scale and bias */
-   {
-      const GLfloat *scale = ctx->Pixel.ConvolutionFilterScale[0];
-      const GLfloat *bias = ctx->Pixel.ConvolutionFilterBias[0];
-      GLint i;
-      for (i = 0; i < width; i++) {
-         GLfloat r = ctx->Convolution1D.Filter[i * 4 + 0];
-         GLfloat g = ctx->Convolution1D.Filter[i * 4 + 1];
-         GLfloat b = ctx->Convolution1D.Filter[i * 4 + 2];
-         GLfloat a = ctx->Convolution1D.Filter[i * 4 + 3];
-         r = r * scale[0] + bias[0];
-         g = g * scale[1] + bias[1];
-         b = b * scale[2] + bias[2];
-         a = a * scale[3] + bias[3];
-         ctx->Convolution1D.Filter[i * 4 + 0] = r;
-         ctx->Convolution1D.Filter[i * 4 + 1] = g;
-         ctx->Convolution1D.Filter[i * 4 + 2] = b;
-         ctx->Convolution1D.Filter[i * 4 + 3] = a;
-      }
-   }
+   _mesa_scale_and_bias_rgba(width,
+                             (GLfloat (*)[4]) ctx->Convolution1D.Filter,
+                             ctx->Pixel.ConvolutionFilterScale[0][0],
+                             ctx->Pixel.ConvolutionFilterScale[0][1],
+                             ctx->Pixel.ConvolutionFilterScale[0][2],
+                             ctx->Pixel.ConvolutionFilterScale[0][3],
+                             ctx->Pixel.ConvolutionFilterBias[0][0],
+                             ctx->Pixel.ConvolutionFilterBias[0][1],
+                             ctx->Pixel.ConvolutionFilterBias[0][2],
+                             ctx->Pixel.ConvolutionFilterBias[0][3]);
 
    ctx->NewState |= _NEW_PIXEL;
 }
@@ -290,25 +281,16 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
                               ctx->Unpack.BufferObj);
    }
 
-   /* apply scale and bias */
-   {
-      const GLfloat *scale = ctx->Pixel.ConvolutionFilterScale[1];
-      const GLfloat *bias = ctx->Pixel.ConvolutionFilterBias[1];
-      for (i = 0; i < width * height; i++) {
-         GLfloat r = ctx->Convolution2D.Filter[i * 4 + 0];
-         GLfloat g = ctx->Convolution2D.Filter[i * 4 + 1];
-         GLfloat b = ctx->Convolution2D.Filter[i * 4 + 2];
-         GLfloat a = ctx->Convolution2D.Filter[i * 4 + 3];
-         r = r * scale[0] + bias[0];
-         g = g * scale[1] + bias[1];
-         b = b * scale[2] + bias[2];
-         a = a * scale[3] + bias[3];
-         ctx->Convolution2D.Filter[i * 4 + 0] = r;
-         ctx->Convolution2D.Filter[i * 4 + 1] = g;
-         ctx->Convolution2D.Filter[i * 4 + 2] = b;
-         ctx->Convolution2D.Filter[i * 4 + 3] = a;
-      }
-   }
+   _mesa_scale_and_bias_rgba(width * height,
+                             (GLfloat (*)[4]) ctx->Convolution2D.Filter,
+                             ctx->Pixel.ConvolutionFilterScale[1][0],
+                             ctx->Pixel.ConvolutionFilterScale[1][1],
+                             ctx->Pixel.ConvolutionFilterScale[1][2],
+                             ctx->Pixel.ConvolutionFilterScale[1][3],
+                             ctx->Pixel.ConvolutionFilterBias[1][0],
+                             ctx->Pixel.ConvolutionFilterBias[1][1],
+                             ctx->Pixel.ConvolutionFilterBias[1][2],
+                             ctx->Pixel.ConvolutionFilterBias[1][3]);
 
    ctx->NewState |= _NEW_PIXEL;
 }
@@ -958,26 +940,16 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLs
                                     format, type, row, &ctx->Unpack,
                                     0);  /* transferOps */
 
-      /* apply scale and bias */
-      {
-         const GLfloat *scale = ctx->Pixel.ConvolutionFilterScale[2];
-         const GLfloat *bias = ctx->Pixel.ConvolutionFilterBias[2];
-         GLint i;
-         for (i = 0; i < width; i++) {
-            GLfloat r = ctx->Separable2D.Filter[i * 4 + 0];
-            GLfloat g = ctx->Separable2D.Filter[i * 4 + 1];
-            GLfloat b = ctx->Separable2D.Filter[i * 4 + 2];
-            GLfloat a = ctx->Separable2D.Filter[i * 4 + 3];
-            r = r * scale[0] + bias[0];
-            g = g * scale[1] + bias[1];
-            b = b * scale[2] + bias[2];
-            a = a * scale[3] + bias[3];
-            ctx->Separable2D.Filter[i * 4 + 0] = r;
-            ctx->Separable2D.Filter[i * 4 + 1] = g;
-            ctx->Separable2D.Filter[i * 4 + 2] = b;
-            ctx->Separable2D.Filter[i * 4 + 3] = a;
-         }
-      }
+      _mesa_scale_and_bias_rgba(width,
+                             (GLfloat (*)[4]) ctx->Separable2D.Filter,
+                             ctx->Pixel.ConvolutionFilterScale[2][0],
+                             ctx->Pixel.ConvolutionFilterScale[2][1],
+                             ctx->Pixel.ConvolutionFilterScale[2][2],
+                             ctx->Pixel.ConvolutionFilterScale[2][3],
+                             ctx->Pixel.ConvolutionFilterBias[2][0],
+                             ctx->Pixel.ConvolutionFilterBias[2][1],
+                             ctx->Pixel.ConvolutionFilterBias[2][2],
+                             ctx->Pixel.ConvolutionFilterBias[2][3]);
    }
 
    /* unpack column filter */
@@ -987,26 +959,16 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLs
                                    format, type, column, &ctx->Unpack,
                                    0); /* transferOps */
 
-     /* apply scale and bias */
-     {
-        const GLfloat *scale = ctx->Pixel.ConvolutionFilterScale[2];
-        const GLfloat *bias = ctx->Pixel.ConvolutionFilterBias[2];
-        GLint i;
-        for (i = 0; i < height; i++) {
-           GLfloat r = ctx->Separable2D.Filter[i * 4 + 0 + colStart];
-           GLfloat g = ctx->Separable2D.Filter[i * 4 + 1 + colStart];
-           GLfloat b = ctx->Separable2D.Filter[i * 4 + 2 + colStart];
-           GLfloat a = ctx->Separable2D.Filter[i * 4 + 3 + colStart];
-           r = r * scale[0] + bias[0];
-           g = g * scale[1] + bias[1];
-           b = b * scale[2] + bias[2];
-           a = a * scale[3] + bias[3];
-           ctx->Separable2D.Filter[i * 4 + 0 + colStart] = r;
-           ctx->Separable2D.Filter[i * 4 + 1 + colStart] = g;
-           ctx->Separable2D.Filter[i * 4 + 2 + colStart] = b;
-           ctx->Separable2D.Filter[i * 4 + 3 + colStart] = a;
-        }
-     }
+      _mesa_scale_and_bias_rgba(height,
+                       (GLfloat (*)[4]) (ctx->Separable2D.Filter + colStart),
+                       ctx->Pixel.ConvolutionFilterScale[2][0],
+                       ctx->Pixel.ConvolutionFilterScale[2][1],
+                       ctx->Pixel.ConvolutionFilterScale[2][2],
+                       ctx->Pixel.ConvolutionFilterScale[2][3],
+                       ctx->Pixel.ConvolutionFilterBias[2][0],
+                       ctx->Pixel.ConvolutionFilterBias[2][1],
+                       ctx->Pixel.ConvolutionFilterBias[2][2],
+                       ctx->Pixel.ConvolutionFilterBias[2][3]);
    }
 
    if (ctx->Unpack.BufferObj->Name) {
index 81cf985e6b7610dbd535b06315d48a55908ad4d6..fcc5d4e3b4479df20cbd1164d2ef1d24a08e9efc 100644 (file)
@@ -503,7 +503,7 @@ _mesa_image_address( const struct gl_pixelstore_attrib *packing,
    skippixels = packing->SkipPixels;
    skipimages = packing->SkipImages;
 
-   if (type==GL_BITMAP) {
+   if (type == GL_BITMAP) {
       /* BITMAP data */
       GLint comp_per_pixel;   /* components per pixel */
       GLint bytes_per_comp;   /* bytes per component */
@@ -512,13 +512,13 @@ _mesa_image_address( const struct gl_pixelstore_attrib *packing,
 
       /* Compute bytes per component */
       bytes_per_comp = _mesa_sizeof_packed_type( type );
-      if (bytes_per_comp<0) {
+      if (bytes_per_comp < 0) {
          return NULL;
       }
 
       /* Compute number of components per pixel */
       comp_per_pixel = _mesa_components_in_format( format );
-      if (comp_per_pixel<0 && type != GL_BITMAP) {
+      if (comp_per_pixel < 0) {
          return NULL;
       }
 
@@ -922,7 +922,7 @@ _mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLuint transferOps,
 {
    /* scale & bias */
    if (transferOps & IMAGE_SCALE_BIAS_BIT) {
-      _mesa_scale_and_bias_rgba(ctx, n, rgba,
+      _mesa_scale_and_bias_rgba(n, rgba,
                                 ctx->Pixel.RedScale, ctx->Pixel.GreenScale,
                                 ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale,
                                 ctx->Pixel.RedBias, ctx->Pixel.GreenBias,
@@ -943,7 +943,7 @@ _mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLuint transferOps,
    }
    /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
    if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) {
-      _mesa_scale_and_bias_rgba(ctx, n, rgba,
+      _mesa_scale_and_bias_rgba(n, rgba,
                                 ctx->Pixel.PostConvolutionScale[RCOMP],
                                 ctx->Pixel.PostConvolutionScale[GCOMP],
                                 ctx->Pixel.PostConvolutionScale[BCOMP],
index 3d36c66e5be3b194be893e13ba64091ed397c857..2a0df1f34702823940f047ea9e580744e64942e9 100644 (file)
@@ -1074,14 +1074,12 @@ _mesa_PixelTransferi( GLenum pname, GLint param )
  * Apply scale and bias factors to an array of RGBA pixels.
  */
 void
-_mesa_scale_and_bias_rgba(GLcontext *ctx, GLuint n, GLfloat rgba[][4],
+_mesa_scale_and_bias_rgba(GLuint n, GLfloat rgba[][4],
                           GLfloat rScale, GLfloat gScale,
                           GLfloat bScale, GLfloat aScale,
                           GLfloat rBias, GLfloat gBias,
                           GLfloat bBias, GLfloat aBias)
 {
-   (void) ctx;
-
    if (rScale != 1.0 || rBias != 0.0) {
       GLuint i;
       for (i = 0; i < n; i++) {
index 13dee25510032ed0da1fbd5e0c9565d0e2813756..9eef0cff5af7ece68dbca3541c2ca6c3dbfb0f12 100644 (file)
@@ -5,7 +5,7 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  6.1
+ * Version:  6.3
  *
  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
@@ -79,7 +79,7 @@ _mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor );
 /*@{*/
 
 extern void
-_mesa_scale_and_bias_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4],
+_mesa_scale_and_bias_rgba(GLuint n, GLfloat rgba[][4],
                           GLfloat rScale, GLfloat gScale,
                           GLfloat bScale, GLfloat aScale,
                           GLfloat rBias, GLfloat gBias,