-/* $Id: pixel.c,v 1.28 2001/04/10 15:25:45 brianp Exp $ */
+/* $Id: pixel.c,v 1.29 2001/05/23 23:55:01 brianp Exp $ */
/*
* Mesa 3-D graphics library
const GLfloat *aMap = ctx->Pixel.MapAtoA;
GLuint i;
for (i=0;i<n;i++) {
- rgba[i][RCOMP] = rMap[IROUND(rgba[i][RCOMP] * rscale)];
- rgba[i][GCOMP] = gMap[IROUND(rgba[i][GCOMP] * gscale)];
- rgba[i][BCOMP] = bMap[IROUND(rgba[i][BCOMP] * bscale)];
- rgba[i][ACOMP] = aMap[IROUND(rgba[i][ACOMP] * ascale)];
+ GLfloat r = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F);
+ GLfloat g = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F);
+ GLfloat b = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F);
+ GLfloat a = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F);
+ rgba[i][RCOMP] = rMap[IROUND(r * rscale)];
+ rgba[i][GCOMP] = gMap[IROUND(g * gscale)];
+ rgba[i][BCOMP] = bMap[IROUND(b * bscale)];
+ rgba[i][ACOMP] = aMap[IROUND(a * ascale)];
}
}
case GL_INTENSITY:
/* replace RGBA with I */
if (!table->FloatTable) {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = CHAN_TO_FLOAT(lut[j]);
+ GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, 1)]);
rgba[i][RCOMP] = rgba[i][GCOMP] =
rgba[i][BCOMP] = rgba[i][ACOMP] = c;
}
}
else {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = lut[j];
+ GLfloat c = lut[CLAMP(j, 0, max)];
rgba[i][RCOMP] = rgba[i][GCOMP] =
rgba[i][BCOMP] = rgba[i][ACOMP] = c;
}
case GL_LUMINANCE:
/* replace RGB with L */
if (!table->FloatTable) {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = CHAN_TO_FLOAT(lut[j]);
+ GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
}
else {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = lut[j];
+ GLfloat c = lut[CLAMP(j, 0, max)];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
}
case GL_ALPHA:
/* replace A with A */
if (!table->FloatTable) {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][ACOMP] * scale);
- rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[j]);
+ rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
}
}
else {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][ACOMP] * scale);
- rgba[i][ACOMP] = lut[j];
+ rgba[i][ACOMP] = lut[CLAMP(j, 0, max)];
}
}
break;
case GL_LUMINANCE_ALPHA:
/* replace RGBA with LLLA */
if (!table->FloatTable) {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jL = IROUND(rgba[i][RCOMP] * scale);
GLint jA = IROUND(rgba[i][ACOMP] * scale);
- GLfloat luminance = CHAN_TO_FLOAT(lut[jL * 2 + 0]);
- GLfloat alpha = CHAN_TO_FLOAT(lut[jA * 2 + 1]);
+ GLfloat luminance, alpha;
+ jL = CLAMP(jL, 0, max);
+ jA = CLAMP(jA, 0, max);
+ luminance = CHAN_TO_FLOAT(lut[jL * 2 + 0]);
+ alpha = CHAN_TO_FLOAT(lut[jA * 2 + 1]);
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
rgba[i][ACOMP] = alpha;;
}
}
else {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jL = IROUND(rgba[i][RCOMP] * scale);
GLint jA = IROUND(rgba[i][ACOMP] * scale);
- GLfloat luminance = lut[jL * 2 + 0];
- GLfloat alpha = lut[jA * 2 + 1];
+ GLfloat luminance, alpha;
+ jL = CLAMP(jL, 0, max);
+ jA = CLAMP(jA, 0, max);
+ luminance = lut[jL * 2 + 0];
+ alpha = lut[jA * 2 + 1];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
rgba[i][ACOMP] = alpha;;
}
case GL_RGB:
/* replace RGB with RGB */
if (!table->FloatTable) {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jR = IROUND(rgba[i][RCOMP] * scale);
GLint jG = IROUND(rgba[i][GCOMP] * scale);
GLint jB = IROUND(rgba[i][BCOMP] * scale);
+ jR = CLAMP(jR, 0, max);
+ jG = CLAMP(jG, 0, max);
+ jB = CLAMP(jB, 0, max);
rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 3 + 0]);
rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 3 + 1]);
rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 3 + 2]);
}
}
else {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jR = IROUND(rgba[i][RCOMP] * scale);
GLint jG = IROUND(rgba[i][GCOMP] * scale);
GLint jB = IROUND(rgba[i][BCOMP] * scale);
+ jR = CLAMP(jR, 0, max);
+ jG = CLAMP(jG, 0, max);
+ jB = CLAMP(jB, 0, max);
rgba[i][RCOMP] = lut[jR * 3 + 0];
rgba[i][GCOMP] = lut[jG * 3 + 1];
rgba[i][BCOMP] = lut[jB * 3 + 2];
case GL_RGBA:
/* replace RGBA with RGBA */
if (!table->FloatTable) {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jG = IROUND(rgba[i][GCOMP] * scale);
GLint jB = IROUND(rgba[i][BCOMP] * scale);
GLint jA = IROUND(rgba[i][ACOMP] * scale);
+ jR = CLAMP(jR, 0, max);
+ jG = CLAMP(jG, 0, max);
+ jB = CLAMP(jB, 0, max);
+ jA = CLAMP(jA, 0, max);
rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 4 + 0]);
rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 4 + 1]);
rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 4 + 2]);
}
}
else {
- const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLint max = table->Size - 1;
+ const GLfloat scale = (GLfloat) max;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jG = IROUND(rgba[i][GCOMP] * scale);
GLint jB = IROUND(rgba[i][BCOMP] * scale);
GLint jA = IROUND(rgba[i][ACOMP] * scale);
+ jR = CLAMP(jR, 0, max);
+ jG = CLAMP(jG, 0, max);
+ jB = CLAMP(jB, 0, max);
+ jA = CLAMP(jA, 0, max);
rgba[i][RCOMP] = lut[jR * 4 + 0];
rgba[i][GCOMP] = lut[jG * 4 + 1];
rgba[i][BCOMP] = lut[jB * 4 + 2];