diff options
Diffstat (limited to 'src/mesa/swrast/s_copypix.c')
-rw-r--r-- | src/mesa/swrast/s_copypix.c | 95 |
1 files changed, 51 insertions, 44 deletions
diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c index 9176755e353..f715e5a6267 100644 --- a/src/mesa/swrast/s_copypix.c +++ b/src/mesa/swrast/s_copypix.c @@ -1,8 +1,8 @@ /* * 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"), @@ -25,8 +25,10 @@ #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" @@ -86,6 +88,40 @@ regions_overlap(GLint srcx, GLint srcy, } +/** + * 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. @@ -150,15 +186,11 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, 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) { @@ -195,19 +227,10 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, /* 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; @@ -355,32 +378,16 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } 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 */ } |