IMAGE_CLAMP_BIT if needed.
Added ClampVertexColors and ClampFragmentColors to GLcontext in anticipation
of upcoming extensions (not fully used yet).
tempTab, /* dest address */
format, type, data, /* src data */
&ctx->Unpack,
- 0, /* transfer ops */
- GL_FALSE); /* clamping */
+ IMAGE_CLAMP_BIT); /* transfer ops */
tableF = (GLfloat *) table->Table;
ctx->ErrorValue = (GLenum) GL_NO_ERROR;
ctx->CatchSignals = GL_TRUE;
ctx->_Facing = 0;
+#if CHAN_TYPE == GL_FLOAT
+ ctx->ClampFragmentColors = GL_FALSE; /* XXX temporary */
+#else
+ ctx->ClampFragmentColors = GL_TRUE;
+#endif
+ ctx->ClampVertexColors = GL_TRUE;
return GL_TRUE;
}
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
_mesa_unpack_color_span_float(ctx, width, GL_RGBA,
ctx->Convolution1D.Filter,
format, type, image, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
/* apply scale and bias */
{
GLfloat *dst = ctx->Convolution2D.Filter + i * width * 4;
_mesa_unpack_color_span_float(ctx, width, GL_RGBA, dst,
format, type, src, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
}
/* apply scale and bias */
_mesa_unpack_color_span_float(ctx, width, GL_RGBA,
ctx->Separable2D.Filter,
format, type, row, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
/* apply scale and bias */
{
_mesa_unpack_color_span_float(ctx, width, GL_RGBA,
&ctx->Separable2D.Filter[colStart],
format, type, column, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
/* apply scale and bias */
{
if (transferOps & IMAGE_MIN_MAX_BIT) {
_mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba);
}
-
-#if CHAN_TYPE != GL_FLOAT
+ /* clamping to [0,1] */
if (transferOps & IMAGE_CLAMP_BIT) {
GLuint i;
for (i = 0; i < n; i++) {
rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F);
}
}
-#endif
}
rgba = (const GLfloat (*)[4]) rgbaIn;
}
- /* XXX clamp rgba to [0,1]? */
-
if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
/* compute luminance values */
- for (i = 0; i < n; i++) {
- GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
-#if CHAN_TYPE == GL_FLOAT
- luminance[i] = sum;
-#else
- luminance[i] = CLAMP(sum, 0.0F, 1.0F);
-#endif
+ if (ctx->ClampFragmentColors) {
+ for (i = 0; i < n; i++) {
+ GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ luminance[i] = CLAMP(sum, 0.0F, 1.0F);
+ }
+ }
+ else {
+ for (i = 0; i < n; i++) {
+ luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ }
}
}
srcPacking->SwapBytes);
}
+ /* Need to clamp if returning GLubytes or GLushorts */
#if CHAN_TYPE != GL_FLOAT
transferOps |= IMAGE_CLAMP_BIT;
#endif
GLenum srcFormat, GLenum srcType,
const GLvoid *source,
const struct gl_pixelstore_attrib *srcPacking,
- GLuint transferOps, GLboolean clamp )
+ GLuint transferOps )
{
ASSERT(dstFormat == GL_ALPHA ||
dstFormat == GL_LUMINANCE ||
srcPacking->SwapBytes);
}
-#if CHAN_TYPE != GL_FLOAT
- if (clamp) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
-#endif
-
if (transferOps) {
_mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
}
extern void
_mesa_pack_rgba_span_chan( GLcontext *ctx,
- GLuint n, CONST GLchan rgba[][4],
- GLenum dstFormat, GLenum dstType, GLvoid *dstAddr,
- const struct gl_pixelstore_attrib *dstPacking,
- GLuint transferOps );
+ GLuint n, CONST GLchan rgba[][4],
+ GLenum dstFormat, GLenum dstType, GLvoid *dstAddr,
+ const struct gl_pixelstore_attrib *dstPacking,
+ GLuint transferOps );
extern void
GLenum srcFormat, GLenum srcType,
const GLvoid *source,
const struct gl_pixelstore_attrib *srcPacking,
- GLuint transferOps, GLboolean clamp );
+ GLuint transferOps );
extern void
GLfloat MRD; /**< minimum resolvable difference in Z values */
/*@}*/
+ /** \name Color clamping (tentative part of GL_ARB_color_clamp_control) */
+ /*@{*/
+ GLboolean ClampFragmentColors;
+ GLboolean ClampVertexColors;
+ /*@}*/
+
/** Should 3Dfx Glide driver catch signals? */
GLboolean CatchSignals;
srcAddr, srcWidth, srcHeight,
srcFormat, srcType, img, row, 0);
_mesa_unpack_color_span_float(ctx, srcWidth, GL_RGBA, dstf,
- srcFormat, srcType, src, srcPacking,
- transferOps & IMAGE_PRE_CONVOLUTION_BITS,
- GL_TRUE);
+ srcFormat, srcType, src, srcPacking,
+ (transferOps & IMAGE_PRE_CONVOLUTION_BITS) | IMAGE_CLAMP_BIT);
dstf += srcWidth * 4;
}
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
#include "glheader.h"
#include "context.h"
+#include "colormac.h"
#include "convolve.h"
#include "histogram.h"
+#include "image.h"
#include "macros.h"
#include "imports.h"
#include "pixel.h"
}
+/**
+ * Convert GLfloat[n][4] colors to GLchan[n][4].
+ * XXX maybe move into image.c
+ */
+static void
+float_span_to_chan(GLuint n, CONST GLfloat in[][4], GLchan out[][4])
+{
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][RCOMP], in[i][RCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][GCOMP], in[i][GCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][BCOMP], in[i][BCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][ACOMP], in[i][ACOMP]);
+ }
+}
+
+
+/**
+ * Convert GLchan[n][4] colors to GLfloat[n][4].
+ * XXX maybe move into image.c
+ */
+static void
+chan_span_to_float(GLuint n, CONST GLchan in[][4], GLfloat out[][4])
+{
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ out[i][RCOMP] = CHAN_TO_FLOAT(in[i][RCOMP]);
+ out[i][GCOMP] = CHAN_TO_FLOAT(in[i][GCOMP]);
+ out[i][BCOMP] = CHAN_TO_FLOAT(in[i][BCOMP]);
+ out[i][ACOMP] = CHAN_TO_FLOAT(in[i][ACOMP]);
+ }
+}
+
+
/*
* RGBA copypixels with convolution.
dest = tmpImage;
for (row = 0; row < height; row++) {
GLchan rgba[MAX_WIDTH][4];
- GLint i;
- _swrast_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx, srcy + row, rgba);
- /* convert GLchan to GLfloat */
- for (i = 0; i < width; i++) {
- *dest++ = (GLfloat) rgba[i][RCOMP] * (1.0F / CHAN_MAXF);
- *dest++ = (GLfloat) rgba[i][GCOMP] * (1.0F / CHAN_MAXF);
- *dest++ = (GLfloat) rgba[i][BCOMP] * (1.0F / CHAN_MAXF);
- *dest++ = (GLfloat) rgba[i][ACOMP] * (1.0F / CHAN_MAXF);
- }
+ /* Read GLchan and convert to GLfloat */
+ _swrast_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx,
+ srcy + row, rgba);
+ chan_span_to_float(width, (CONST GLchan (*)[4]) rgba,
+ (GLfloat (*)[4]) dest);
}
if (changeBuffer) {
/* write the new image */
for (row = 0; row < height; row++) {
const GLfloat *src = convImage + row * width * 4;
- GLint i, dy;
+ GLint dy;
- /* clamp to [0,1] and convert float back to chan */
- for (i = 0; i < width; i++) {
- GLint r = (GLint) (src[i * 4 + RCOMP] * CHAN_MAXF);
- GLint g = (GLint) (src[i * 4 + GCOMP] * CHAN_MAXF);
- GLint b = (GLint) (src[i * 4 + BCOMP] * CHAN_MAXF);
- GLint a = (GLint) (src[i * 4 + ACOMP] * CHAN_MAXF);
- span.array->rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX);
- span.array->rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX);
- span.array->rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX);
- span.array->rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
- }
+ /* convert floats back to chan */
+ float_span_to_chan(width, (const GLfloat (*)[4]) src, span.array->rgba);
if (ctx->Pixel.PixelTextureEnabled && ctx->Texture._EnabledUnits) {
span.end = width;
}
if (transferOps) {
- const GLfloat scale = (1.0F / CHAN_MAXF);
- GLint k;
DEFMARRAY(GLfloat, rgbaFloat, MAX_WIDTH, 4); /* mac 32k limitation */
CHECKARRAY(rgbaFloat, return);
- /* convert chan to float */
- for (k = 0; k < width; k++) {
- rgbaFloat[k][RCOMP] = (GLfloat) span.array->rgba[k][RCOMP] * scale;
- rgbaFloat[k][GCOMP] = (GLfloat) span.array->rgba[k][GCOMP] * scale;
- rgbaFloat[k][BCOMP] = (GLfloat) span.array->rgba[k][BCOMP] * scale;
- rgbaFloat[k][ACOMP] = (GLfloat) span.array->rgba[k][ACOMP] * scale;
- }
-
+ /* convert to float, transfer, convert back to chan */
+ chan_span_to_float(width, (CONST GLchan (*)[4]) span.array->rgba,
+ rgbaFloat);
_mesa_apply_rgba_transfer_ops(ctx, transferOps, width, rgbaFloat);
+ float_span_to_chan(width, (CONST GLfloat (*)[4]) rgbaFloat,
+ span.array->rgba);
- /* clamp to [0,1] and convert float back to chan */
- for (k = 0; k < width; k++) {
- GLint r = (GLint) (rgbaFloat[k][RCOMP] * CHAN_MAXF);
- GLint g = (GLint) (rgbaFloat[k][GCOMP] * CHAN_MAXF);
- GLint b = (GLint) (rgbaFloat[k][BCOMP] * CHAN_MAXF);
- GLint a = (GLint) (rgbaFloat[k][ACOMP] * CHAN_MAXF);
- span.array->rgba[k][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX);
- span.array->rgba[k][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX);
- span.array->rgba[k][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX);
- span.array->rgba[k][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
- }
UNDEFARRAY(rgbaFloat); /* mac 32k limitation */
}
const GLvoid *source = _mesa_image_address(unpack,
pixels, width, height, format, type, 0, row, 0);
_mesa_unpack_color_span_float(ctx, width, GL_RGBA, (GLfloat *) dest,
- format, type, source, unpack,
- transferOps & IMAGE_PRE_CONVOLUTION_BITS,
- GL_FALSE);
+ format, type, source, unpack,
+ transferOps & IMAGE_PRE_CONVOLUTION_BITS);
dest += width * 4;
}