Some initial RGB and RGBA floating point texture formats.
[mesa.git] / src / mesa / main / convolve.c
index c496e6c8f55fd3dd407c0d4e25087492e2a707ca..e6b19fabd42a477b2bdff24a2c36168a1c239c86 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: convolve.c,v 1.16 2000/12/10 19:23:19 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  5.1
  *
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -33,9 +31,6 @@
  */
 
 
-#ifdef PC_HEADER
-#include "all.h"
-#else
 #include "glheader.h"
 #include "colormac.h"
 #include "convolve.h"
@@ -43,8 +38,6 @@
 #include "image.h"
 #include "mtypes.h"
 #include "state.h"
-#include "swrast/s_span.h" /* XXX SWRAST hack */
-#endif
 
 
 /*
@@ -107,31 +100,31 @@ base_filter_format( GLenum format )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *image)
 {
-   GLenum baseFormat;
+   GLint baseFormat;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glConvolutionFilter1D");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (target != GL_CONVOLUTION_1D) {
-      gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(target)");
       return;
    }
 
    baseFormat = base_filter_format(internalFormat);
    if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
-      gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(internalFormat)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(internalFormat)");
       return;
    }
 
    if (width < 0 || width > MAX_CONVOLUTION_WIDTH) {
-      gl_error(ctx, GL_INVALID_VALUE, "glConvolutionFilter1D(width)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glConvolutionFilter1D(width)");
       return;
    }
 
    if (!_mesa_is_legal_format_and_type(format, type)) {
-      gl_error(ctx, GL_INVALID_OPERATION, "glConvolutionFilter1D(format or type)");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glConvolutionFilter1D(format or type)");
       return;
    }
 
@@ -140,7 +133,7 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G
        format == GL_DEPTH_COMPONENT ||
        format == GL_INTENSITY ||
        type == GL_BITMAP) {
-      gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(format or type)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(format or type)");
       return;
    }
 
@@ -180,36 +173,36 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image)
 {
-   GLenum baseFormat;
-   GLint i, components;
+   GLint baseFormat;
+   GLint i;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glConvolutionFilter2D");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (target != GL_CONVOLUTION_2D) {
-      gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(target)");
       return;
    }
 
    baseFormat = base_filter_format(internalFormat);
    if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
-      gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(internalFormat)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(internalFormat)");
       return;
    }
 
    if (width < 0 || width > MAX_CONVOLUTION_WIDTH) {
-      gl_error(ctx, GL_INVALID_VALUE, "glConvolutionFilter2D(width)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glConvolutionFilter2D(width)");
       return;
    }
    if (height < 0 || height > MAX_CONVOLUTION_HEIGHT) {
-      gl_error(ctx, GL_INVALID_VALUE, "glConvolutionFilter2D(height)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glConvolutionFilter2D(height)");
       return;
    }
 
    if (!_mesa_is_legal_format_and_type(format, type)) {
-      gl_error(ctx, GL_INVALID_OPERATION, "glConvolutionFilter2D(format or type)");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glConvolutionFilter2D(format or type)");
       return;
    }
    if (format == GL_COLOR_INDEX ||
@@ -217,12 +210,12 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
        format == GL_DEPTH_COMPONENT ||
        format == GL_INTENSITY ||
        type == GL_BITMAP) {
-      gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(format or type)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(format or type)");
       return;
    }
 
-   components = _mesa_components_in_format(format);
-   assert(components > 0);  /* this should have been caught earlier */
+   /* this should have been caught earlier */
+   assert(_mesa_components_in_format(format));
 
    ctx->Convolution2D.Format = format;
    ctx->Convolution2D.InternalFormat = internalFormat;
@@ -243,7 +236,7 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
    {
       const GLfloat *scale = ctx->Pixel.ConvolutionFilterScale[1];
       const GLfloat *bias = ctx->Pixel.ConvolutionFilterBias[1];
-      for (i = 0; i < width * height * 4; i++) {
+      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];
@@ -263,13 +256,12 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLuint c;
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glConvolutionParameterf");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
       case GL_CONVOLUTION_1D:
@@ -282,7 +274,7 @@ _mesa_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
          c = 2;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterf(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterf(target)");
          return;
    }
 
@@ -294,12 +286,12 @@ _mesa_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
             ctx->Pixel.ConvolutionBorderMode[c] = (GLenum) param;
          }
          else {
-            gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterf(params)");
+            _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterf(params)");
             return;
          }
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterf(pname)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterf(pname)");
          return;
    }
 
@@ -307,30 +299,25 @@ _mesa_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ConvolutionParameterfv(GLenum target, GLenum pname, const GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
-   struct gl_convolution_attrib *conv;
    GLuint c;
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glConvolutionParameterfv");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
       case GL_CONVOLUTION_1D:
          c = 0;
-         conv = &ctx->Convolution1D;
          break;
       case GL_CONVOLUTION_2D:
          c = 1;
-         conv = &ctx->Convolution2D;
          break;
       case GL_SEPARABLE_2D:
          c = 2;
-         conv = &ctx->Separable2D;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterfv(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterfv(target)");
          return;
    }
 
@@ -345,7 +332,7 @@ _mesa_ConvolutionParameterfv(GLenum target, GLenum pname, const GLfloat *params)
             ctx->Pixel.ConvolutionBorderMode[c] = (GLenum) params[0];
          }
          else {
-            gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterfv(params)");
+            _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterfv(params)");
             return;
          }
          break;
@@ -356,7 +343,7 @@ _mesa_ConvolutionParameterfv(GLenum target, GLenum pname, const GLfloat *params)
          COPY_4V(ctx->Pixel.ConvolutionFilterBias[c], params);
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterfv(pname)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameterfv(pname)");
          return;
    }
 
@@ -364,13 +351,12 @@ _mesa_ConvolutionParameterfv(GLenum target, GLenum pname, const GLfloat *params)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLuint c;
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glConvolutionParameteri");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
       case GL_CONVOLUTION_1D:
@@ -383,7 +369,7 @@ _mesa_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
          c = 2;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteri(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteri(target)");
          return;
    }
 
@@ -395,12 +381,12 @@ _mesa_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
             ctx->Pixel.ConvolutionBorderMode[c] = (GLenum) param;
          }
          else {
-            gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteri(params)");
+            _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteri(params)");
             return;
          }
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteri(pname)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteri(pname)");
          return;
    }
 
@@ -408,30 +394,25 @@ _mesa_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
 {
    GET_CURRENT_CONTEXT(ctx);
-   struct gl_convolution_attrib *conv;
    GLuint c;
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glConvolutionParameteriv");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
       case GL_CONVOLUTION_1D:
          c = 0;
-         conv = &ctx->Convolution1D;
          break;
       case GL_CONVOLUTION_2D:
          c = 1;
-         conv = &ctx->Convolution2D;
          break;
       case GL_SEPARABLE_2D:
          c = 2;
-         conv = &ctx->Separable2D;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteriv(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteriv(target)");
          return;
    }
 
@@ -449,18 +430,28 @@ _mesa_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
             ctx->Pixel.ConvolutionBorderMode[c] = (GLenum) params[0];
          }
          else {
-            gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteriv(params)");
+            _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteriv(params)");
             return;
          }
          break;
       case GL_CONVOLUTION_FILTER_SCALE:
-         COPY_4V(ctx->Pixel.ConvolutionFilterScale[c], params);
+        /* COPY_4V(ctx->Pixel.ConvolutionFilterScale[c], params); */
+        /* need cast to prevent compiler warnings */  
+        ctx->Pixel.ConvolutionFilterScale[c][0] = (GLfloat) params[0]; 
+        ctx->Pixel.ConvolutionFilterScale[c][1] = (GLfloat) params[1]; 
+        ctx->Pixel.ConvolutionFilterScale[c][2] = (GLfloat) params[2]; 
+        ctx->Pixel.ConvolutionFilterScale[c][3] = (GLfloat) params[3]; 
          break;
       case GL_CONVOLUTION_FILTER_BIAS:
-         COPY_4V(ctx->Pixel.ConvolutionFilterBias[c], params);
+        /* COPY_4V(ctx->Pixel.ConvolutionFilterBias[c], params); */
+        /* need cast to prevent compiler warnings */  
+        ctx->Pixel.ConvolutionFilterBias[c][0] = (GLfloat) params[0]; 
+        ctx->Pixel.ConvolutionFilterBias[c][1] = (GLfloat) params[1]; 
+        ctx->Pixel.ConvolutionFilterBias[c][2] = (GLfloat) params[2]; 
+        ctx->Pixel.ConvolutionFilterBias[c][3] = (GLfloat) params[3]; 
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteriv(pname)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glConvolutionParameteriv(pname)");
          return;
    }
 
@@ -468,116 +459,81 @@ _mesa_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_CopyConvolutionFilter1D(GLenum target, GLenum internalFormat, GLint x, GLint y, GLsizei width)
 {
-   GLenum baseFormat;
-   GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
+   GLint baseFormat;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyConvolutionFilter1D");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (target != GL_CONVOLUTION_1D) {
-      gl_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter1D(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter1D(target)");
       return;
    }
 
    baseFormat = base_filter_format(internalFormat);
    if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
-      gl_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter1D(internalFormat)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter1D(internalFormat)");
       return;
    }
 
    if (width < 0 || width > MAX_CONVOLUTION_WIDTH) {
-      gl_error(ctx, GL_INVALID_VALUE, "glCopyConvolutionFilter1D(width)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glCopyConvolutionFilter1D(width)");
       return;
    }
 
-   /* read pixels from framebuffer */
-   RENDER_START(ctx);
-   gl_read_rgba_span(ctx, ctx->ReadBuffer, width, x, y, (GLchan (*)[4]) rgba);
-   RENDER_FINISH(ctx);
-
-   /* store as convolution filter */
-   _mesa_ConvolutionFilter1D(target, internalFormat, width,
-                             GL_RGBA, CHAN_TYPE, rgba);
+   ctx->Driver.CopyConvolutionFilter1D( ctx, target, 
+                                       internalFormat, x, y, width);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_CopyConvolutionFilter2D(GLenum target, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height)
 {
-   GLenum baseFormat;
-   GLint i;
-   struct gl_pixelstore_attrib packSave;
-   GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
+   GLint baseFormat;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyConvolutionFilter2D");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (target != GL_CONVOLUTION_2D) {
-      gl_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter2D(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter2D(target)");
       return;
    }
 
    baseFormat = base_filter_format(internalFormat);
    if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
-      gl_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter2D(internalFormat)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyConvolutionFilter2D(internalFormat)");
       return;
    }
 
    if (width < 0 || width > MAX_CONVOLUTION_WIDTH) {
-      gl_error(ctx, GL_INVALID_VALUE, "glCopyConvolutionFilter2D(width)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glCopyConvolutionFilter2D(width)");
       return;
    }
    if (height < 0 || height > MAX_CONVOLUTION_HEIGHT) {
-      gl_error(ctx, GL_INVALID_VALUE, "glCopyConvolutionFilter2D(height)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glCopyConvolutionFilter2D(height)");
       return;
    }
 
-   /* read pixels from framebuffer */
-   RENDER_START(ctx);
-   for (i = 0; i < height; i++) {
-      gl_read_rgba_span(ctx, ctx->ReadBuffer, width, x, y + i,
-                        (GLchan (*)[4]) rgba[i]);
-   }
-   RENDER_FINISH(ctx);
-
-   /*
-    * store as convolution filter
-    */
-   packSave = ctx->Unpack;  /* save pixel packing params */
-
-   ctx->Unpack.Alignment = 1;
-   ctx->Unpack.RowLength = MAX_CONVOLUTION_WIDTH;
-   ctx->Unpack.SkipPixels = 0;
-   ctx->Unpack.SkipRows = 0;
-   ctx->Unpack.ImageHeight = 0;
-   ctx->Unpack.SkipImages = 0;
-   ctx->Unpack.SwapBytes = GL_FALSE;
-   ctx->Unpack.LsbFirst = GL_FALSE;
-   ctx->NewState |= _NEW_PACKUNPACK;   
-
-   _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
-                             GL_RGBA, CHAN_TYPE, rgba);
-
-   ctx->Unpack = packSave;  /* restore pixel packing params */
-   ctx->NewState |= _NEW_PACKUNPACK;   
+   ctx->Driver.CopyConvolutionFilter2D( ctx, target, internalFormat, x, y, 
+                                       width, height );
+
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type, GLvoid *image)
 {
    const struct gl_convolution_attrib *filter;
-   GLint row;
+   GLuint row;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetConvolutionFilter");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (ctx->NewState) {
-      gl_update_state(ctx);
+      _mesa_update_state(ctx);
    }
 
    if (!_mesa_is_legal_format_and_type(format, type)) {
-      gl_error(ctx, GL_INVALID_OPERATION, "glGetConvolutionFilter(format or type)");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetConvolutionFilter(format or type)");
       return;
    }
 
@@ -586,7 +542,7 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type, GLvoid *im
        format == GL_DEPTH_COMPONENT ||
        format == GL_INTENSITY ||
        type == GL_BITMAP) {
-      gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(format or type)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(format or type)");
       return;
    }
 
@@ -598,7 +554,7 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type, GLvoid *im
          filter = &(ctx->Convolution2D);
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(target)");
          return;
    }
 
@@ -614,14 +570,13 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type, GLvoid *im
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
    const struct gl_convolution_attrib *conv;
    GLuint c;
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetConvolutionParameterfv");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    switch (target) {
       case GL_CONVOLUTION_1D:
@@ -637,7 +592,7 @@ _mesa_GetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat *params)
          conv = &ctx->Separable2D;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameterfv(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameterfv(target)");
          return;
    }
 
@@ -670,20 +625,19 @@ _mesa_GetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat *params)
          *params = (GLfloat) ctx->Const.MaxConvolutionHeight;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameterfv(pname)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameterfv(pname)");
          return;
    }
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params)
 {
    GET_CURRENT_CONTEXT(ctx);
    const struct gl_convolution_attrib *conv;
    GLuint c;
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetConvolutionParameteriv");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    switch (target) {
       case GL_CONVOLUTION_1D:
@@ -699,7 +653,7 @@ _mesa_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params)
          conv = &ctx->Separable2D;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameteriv(target)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameteriv(target)");
          return;
    }
 
@@ -741,31 +695,31 @@ _mesa_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params)
          *params = (GLint) ctx->Const.MaxConvolutionHeight;
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameteriv(pname)");
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionParameteriv(pname)");
          return;
    }
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span)
 {
    const GLint colStart = MAX_CONVOLUTION_WIDTH * 4;
    const struct gl_convolution_attrib *filter;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetSeparableFilter");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (ctx->NewState) {
-      gl_update_state(ctx);
+      _mesa_update_state(ctx);
    }
 
    if (target != GL_SEPARABLE_2D) {
-      gl_error(ctx, GL_INVALID_ENUM, "glGetSeparableFilter(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetSeparableFilter(target)");
       return;
    }
 
    if (!_mesa_is_legal_format_and_type(format, type)) {
-      gl_error(ctx, GL_INVALID_OPERATION, "glGetConvolutionFilter(format or type)");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetConvolutionFilter(format or type)");
       return;
    }
 
@@ -774,7 +728,7 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type, GLvoid *row,
        format == GL_DEPTH_COMPONENT ||
        format == GL_INTENSITY ||
        type == GL_BITMAP) {
-      gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(format or type)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(format or type)");
       return;
    }
 
@@ -805,36 +759,36 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type, GLvoid *row,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column)
 {
    const GLint colStart = MAX_CONVOLUTION_WIDTH * 4;
-   GLenum baseFormat;
+   GLint baseFormat;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glSeparableFilter2D");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (target != GL_SEPARABLE_2D) {
-      gl_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(target)");
       return;
    }
 
    baseFormat = base_filter_format(internalFormat);
    if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
-      gl_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(internalFormat)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(internalFormat)");
       return;
    }
 
    if (width < 0 || width > MAX_CONVOLUTION_WIDTH) {
-      gl_error(ctx, GL_INVALID_VALUE, "glSeparableFilter2D(width)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glSeparableFilter2D(width)");
       return;
    }
    if (height < 0 || height > MAX_CONVOLUTION_HEIGHT) {
-      gl_error(ctx, GL_INVALID_VALUE, "glSeparableFilter2D(height)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glSeparableFilter2D(height)");
       return;
    }
 
    if (!_mesa_is_legal_format_and_type(format, type)) {
-      gl_error(ctx, GL_INVALID_OPERATION, "glSeparableFilter2D(format or type)");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glSeparableFilter2D(format or type)");
       return;
    }
 
@@ -843,7 +797,7 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLs
        format == GL_DEPTH_COMPONENT ||
        format == GL_INTENSITY ||
        type == GL_BITMAP) {
-      gl_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(format or type)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(format or type)");
       return;
    }
 
@@ -1426,3 +1380,33 @@ _mesa_convolve_sep_image(const GLcontext *ctx,
          ;
    }
 }
+
+
+
+/*
+ * This function computes an image's size after convolution.
+ * If the convolution border mode is GL_REDUCE, the post-convolution
+ * image will be smaller than the original.
+ */
+void
+_mesa_adjust_image_for_convolution(const GLcontext *ctx, GLuint dimensions,
+                                   GLsizei *width, GLsizei *height)
+{
+   if (ctx->Pixel.Convolution1DEnabled
+       && dimensions == 1
+       && ctx->Pixel.ConvolutionBorderMode[0] == GL_REDUCE) {
+      *width = *width - (MAX2(ctx->Convolution1D.Width, 1) - 1);
+   }
+   else if (ctx->Pixel.Convolution2DEnabled
+            && dimensions > 1
+            && ctx->Pixel.ConvolutionBorderMode[1] == GL_REDUCE) {
+      *width = *width - (MAX2(ctx->Convolution2D.Width, 1) - 1);
+      *height = *height - (MAX2(ctx->Convolution2D.Height, 1) - 1);
+   }
+   else if (ctx->Pixel.Separable2DEnabled
+            && dimensions > 1
+            && ctx->Pixel.ConvolutionBorderMode[2] == GL_REDUCE) {
+      *width = *width - (MAX2(ctx->Separable2D.Width, 1) - 1);
+      *height = *height - (MAX2(ctx->Separable2D.Height, 1) - 1);
+   }
+}