-/* $Id: s_imaging.c,v 1.2 2000/11/05 18:24:40 keithw Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.4
+ * Version: 4.1
*
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2002 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"),
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-
-/*
- * Histogram, Min/max and convolution for GL_ARB_imaging subset
- *
+/* KW: Moved these here to remove knowledge of swrast from core mesa.
+ * Should probably pull the entire software implementation of these
+ * extensions into either swrast or a sister module.
*/
-
-#include "glheader.h"
-#include "colormac.h"
-#include "image.h"
-#include "mmath.h"
-
#include "s_context.h"
-#include "s_imaging.h"
#include "s_span.h"
+void
+_swrast_CopyColorTable( GLcontext *ctx,
+ GLenum target, GLenum internalformat,
+ GLint x, GLint y, GLsizei width)
+{
+ GLchan data[MAX_WIDTH][4];
+ /* Select buffer to read from */
+ _swrast_use_read_buffer(ctx);
+
+ if (width > MAX_WIDTH)
+ width = MAX_WIDTH;
+
+ /* read the data from framebuffer */
+ _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
+
+ /* Restore reading from draw buffer (the default) */
+ _swrast_use_draw_buffer(ctx);
+
+ glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
+}
-/*
- * Update the min/max values from an array of fragment colors.
- */
void
-_mesa_update_minmax(GLcontext *ctx, GLuint n, const GLfloat rgba[][4])
+_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
+ GLint x, GLint y, GLsizei width)
{
- GLuint i;
- for (i = 0; i < n; i++) {
- /* update mins */
- if (rgba[i][RCOMP] < ctx->MinMax.Min[RCOMP])
- ctx->MinMax.Min[RCOMP] = rgba[i][RCOMP];
- if (rgba[i][GCOMP] < ctx->MinMax.Min[GCOMP])
- ctx->MinMax.Min[GCOMP] = rgba[i][GCOMP];
- if (rgba[i][BCOMP] < ctx->MinMax.Min[BCOMP])
- ctx->MinMax.Min[BCOMP] = rgba[i][BCOMP];
- if (rgba[i][ACOMP] < ctx->MinMax.Min[ACOMP])
- ctx->MinMax.Min[ACOMP] = rgba[i][ACOMP];
-
- /* update maxs */
- if (rgba[i][RCOMP] > ctx->MinMax.Max[RCOMP])
- ctx->MinMax.Max[RCOMP] = rgba[i][RCOMP];
- if (rgba[i][GCOMP] > ctx->MinMax.Max[GCOMP])
- ctx->MinMax.Max[GCOMP] = rgba[i][GCOMP];
- if (rgba[i][BCOMP] > ctx->MinMax.Max[BCOMP])
- ctx->MinMax.Max[BCOMP] = rgba[i][BCOMP];
- if (rgba[i][ACOMP] > ctx->MinMax.Max[ACOMP])
- ctx->MinMax.Max[ACOMP] = rgba[i][ACOMP];
- }
+ GLchan data[MAX_WIDTH][4];
+
+ /* Select buffer to read from */
+ _swrast_use_read_buffer(ctx);
+
+ if (width > MAX_WIDTH)
+ width = MAX_WIDTH;
+
+ /* read the data from framebuffer */
+ _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
+
+ /* Restore reading from draw buffer (the default) */
+ _swrast_use_draw_buffer(ctx);
+
+ glColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
}
-/*
- * Update the histogram values from an array of fragment colors.
- */
void
-_mesa_update_histogram(GLcontext *ctx, GLuint n, const GLfloat rgba[][4])
+_swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width)
{
- const GLint max = ctx->Histogram.Width - 1;
- GLfloat w = (GLfloat) max;
- GLuint i;
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
+
+ /* Select buffer to read from */
+ _swrast_use_read_buffer(ctx);
- if (ctx->Histogram.Width == 0)
- return;
+ RENDER_START( swrast, ctx );
+
+ /* read the data from framebuffer */
+ _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y,
+ (GLchan (*)[4]) rgba );
- for (i = 0; i < n; i++) {
- GLint ri = (GLint) (rgba[i][RCOMP] * w + 0.5F);
- GLint gi = (GLint) (rgba[i][GCOMP] * w + 0.5F);
- GLint bi = (GLint) (rgba[i][BCOMP] * w + 0.5F);
- GLint ai = (GLint) (rgba[i][ACOMP] * w + 0.5F);
- ri = CLAMP(ri, 0, max);
- gi = CLAMP(gi, 0, max);
- bi = CLAMP(bi, 0, max);
- ai = CLAMP(ai, 0, max);
- ctx->Histogram.Count[ri][RCOMP]++;
- ctx->Histogram.Count[gi][GCOMP]++;
- ctx->Histogram.Count[bi][BCOMP]++;
- ctx->Histogram.Count[ai][ACOMP]++;
- }
+ RENDER_FINISH( swrast, ctx );
+
+ /* Restore reading from draw buffer (the default) */
+ _swrast_use_draw_buffer(ctx);
+
+ /* store as convolution filter */
+ glConvolutionFilter1D(target, internalFormat, width,
+ GL_RGBA, CHAN_TYPE, rgba);
}
+void
+_swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ struct gl_pixelstore_attrib packSave;
+ GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
+ GLint i;
+
+ /* Select buffer to read from */
+ _swrast_use_read_buffer(ctx);
+
+ RENDER_START(swrast,ctx);
+
+ /* read pixels from framebuffer */
+ for (i = 0; i < height; i++) {
+ _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
+ (GLchan (*)[4]) rgba[i] );
+ }
+
+ RENDER_FINISH(swrast,ctx);
+
+ /* Restore reading from draw buffer (the default) */
+ _swrast_use_draw_buffer(ctx);
+ /*
+ * HACK: save & restore context state so we can store this as a
+ * convolution filter via the GL api. Doesn't call any callbacks
+ * hanging off ctx->Unpack statechanges.
+ */
+
+ 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;
+
+ glConvolutionFilter2D(target, internalFormat, width, height,
+ GL_RGBA, CHAN_TYPE, rgba);
+
+ ctx->Unpack = packSave; /* restore pixel packing params */
+ ctx->NewState |= _NEW_PACKUNPACK;
+}