-/* $Id: xm_api.c,v 1.19 2001/03/19 02:25:36 keithw Exp $ */
+/* $Id: xm_api.c,v 1.20 2001/04/10 15:25:45 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "glthread.h"
#include "matrix.h"
#include "mem.h"
+#include "mmath.h"
#include "mtypes.h"
#ifdef HAVE_CONFIG_H
#include "conf.h"
}
else {
double x = (double) value / (double) max;
- return (GLint) ((GLfloat) max * pow( x, 1.0F/gamma ) + 0.5F);
+ return IROUND_POS((GLfloat) max * pow(x, 1.0F/gamma));
}
}
g = 1.0 / v->RedGamma;
for (i=0; i<256; i++) {
- GLint red = (GLint) (255.0 * pow( hpcr_rgbTbl[0][i]/255.0, g ) + 0.5);
+ GLint red = IROUND_POS(255.0 * pow( hpcr_rgbTbl[0][i]/255.0, g ));
v->hpcr_rgbTbl[0][i] = CLAMP( red, 16, 239 );
}
g = 1.0 / v->GreenGamma;
for (i=0; i<256; i++) {
- GLint green = (GLint) (255.0 * pow( hpcr_rgbTbl[1][i]/255.0, g ) + 0.5);
+ GLint green = IROUND_POS(255.0 * pow( hpcr_rgbTbl[1][i]/255.0, g ));
v->hpcr_rgbTbl[1][i] = CLAMP( green, 16, 239 );
}
g = 1.0 / v->BlueGamma;
for (i=0; i<256; i++) {
- GLint blue = (GLint) (255.0 * pow( hpcr_rgbTbl[2][i]/255.0, g ) + 0.5);
+ GLint blue = IROUND_POS(255.0 * pow( hpcr_rgbTbl[2][i]/255.0, g ));
v->hpcr_rgbTbl[2][i] = CLAMP( blue, 32, 223 );
}
v->undithered_pf = PF_HPCR; /* can't really disable dithering for now */
-/* $Id: colortab.c,v 1.38 2001/03/19 02:25:35 keithw Exp $ */
+/* $Id: colortab.c,v 1.39 2001/04/10 15:25:45 brianp Exp $ */
/*
* Mesa 3-D graphics library
rgba[i][RCOMP] = 0;
rgba[i][GCOMP] = 0;
rgba[i][BCOMP] = 0;
- rgba[i][ACOMP] = (GLint) (tableF[i] * CHAN_MAXF);
+ rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
}
}
else {
const GLfloat *tableF = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = (GLint) (tableF[i] * CHAN_MAXF);
- rgba[i][GCOMP] = (GLint) (tableF[i] * CHAN_MAXF);
- rgba[i][BCOMP] = (GLint) (tableF[i] * CHAN_MAXF);
+ rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
+ rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
+ rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
rgba[i][ACOMP] = CHAN_MAX;
}
}
const GLfloat *tableF = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = (GLint) (tableF[i*2+0] * CHAN_MAXF);
- rgba[i][GCOMP] = (GLint) (tableF[i*2+0] * CHAN_MAXF);
- rgba[i][BCOMP] = (GLint) (tableF[i*2+0] * CHAN_MAXF);
- rgba[i][ACOMP] = (GLint) (tableF[i*2+1] * CHAN_MAXF);
+ rgba[i][RCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
+ rgba[i][GCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
+ rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
+ rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF);
}
}
else {
const GLfloat *tableF = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = (GLint) (tableF[i] * CHAN_MAXF);
- rgba[i][GCOMP] = (GLint) (tableF[i] * CHAN_MAXF);
- rgba[i][BCOMP] = (GLint) (tableF[i] * CHAN_MAXF);
- rgba[i][ACOMP] = (GLint) (tableF[i] * CHAN_MAXF);
+ rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
+ rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
+ rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
+ rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
}
}
else {
const GLfloat *tableF = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = (GLint) (tableF[i*3+0] * CHAN_MAXF);
- rgba[i][GCOMP] = (GLint) (tableF[i*3+1] * CHAN_MAXF);
- rgba[i][BCOMP] = (GLint) (tableF[i*3+2] * CHAN_MAXF);
+ rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF);
+ rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF);
+ rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF);
rgba[i][ACOMP] = CHAN_MAX;
}
}
const GLfloat *tableF = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = (GLint) (tableF[i*4+0] * CHAN_MAXF + 0.5F);
- rgba[i][GCOMP] = (GLint) (tableF[i*4+1] * CHAN_MAXF + 0.5F);
- rgba[i][BCOMP] = (GLint) (tableF[i*4+2] * CHAN_MAXF + 0.5F);
- rgba[i][ACOMP] = (GLint) (tableF[i*4+3] * CHAN_MAXF + 0.5F);
+ rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF);
+ rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF);
+ rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF);
+ rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF);
}
}
else {
-/* $Id: drawpix.c,v 1.51 2001/03/19 02:25:35 keithw Exp $ */
+/* $Id: drawpix.c,v 1.52 2001/04/10 15:25:45 brianp Exp $ */
/*
* Mesa 3-D graphics library
_mesa_update_state(ctx);
}
- x = (GLint) (ctx->Current.RasterPos[0] + 0.5F);
- y = (GLint) (ctx->Current.RasterPos[1] + 0.5F);
+ x = IROUND(ctx->Current.RasterPos[0]);
+ y = IROUND(ctx->Current.RasterPos[1]);
ctx->OcclusionResult = GL_TRUE;
ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
-/* $Id: pixel.c,v 1.27 2001/03/12 00:48:38 gareth Exp $ */
+/* $Id: pixel.c,v 1.28 2001/04/10 15:25:45 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[(GLint) (rgba[i][RCOMP] * rscale + 0.5F)];
- rgba[i][GCOMP] = gMap[(GLint) (rgba[i][GCOMP] * gscale + 0.5F)];
- rgba[i][BCOMP] = bMap[(GLint) (rgba[i][BCOMP] * bscale + 0.5F)];
- rgba[i][ACOMP] = aMap[(GLint) (rgba[i][ACOMP] * ascale + 0.5F)];
+ 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)];
}
}
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint j = IROUND(rgba[i][RCOMP] * scale);
GLfloat c = CHAN_TO_FLOAT(lut[j]);
rgba[i][RCOMP] = rgba[i][GCOMP] =
rgba[i][BCOMP] = rgba[i][ACOMP] = c;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint j = IROUND(rgba[i][RCOMP] * scale);
GLfloat c = lut[j];
rgba[i][RCOMP] = rgba[i][GCOMP] =
rgba[i][BCOMP] = rgba[i][ACOMP] = c;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint j = IROUND(rgba[i][RCOMP] * scale);
GLfloat c = CHAN_TO_FLOAT(lut[j]);
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint j = IROUND(rgba[i][RCOMP] * scale);
GLfloat c = lut[j];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ GLint j = IROUND(rgba[i][ACOMP] * scale);
rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[j]);
}
}
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ GLint j = IROUND(rgba[i][ACOMP] * scale);
rgba[i][ACOMP] = lut[j];
}
}
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ 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]);
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ 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];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
- GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F);
+ GLint jR = IROUND(rgba[i][RCOMP] * scale);
+ GLint jG = IROUND(rgba[i][GCOMP] * scale);
+ GLint jB = IROUND(rgba[i][BCOMP] * scale);
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]);
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
- GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F);
+ GLint jR = IROUND(rgba[i][RCOMP] * scale);
+ GLint jG = IROUND(rgba[i][GCOMP] * scale);
+ GLint jB = IROUND(rgba[i][BCOMP] * scale);
rgba[i][RCOMP] = lut[jR * 3 + 0];
rgba[i][GCOMP] = lut[jG * 3 + 1];
rgba[i][BCOMP] = lut[jB * 3 + 2];
const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
- GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F);
- GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ GLint jR = IROUND(rgba[i][RCOMP] * scale);
+ GLint jG = IROUND(rgba[i][GCOMP] * scale);
+ GLint jB = IROUND(rgba[i][BCOMP] * scale);
+ GLint jA = IROUND(rgba[i][ACOMP] * scale);
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]);
const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
- GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
- GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F);
- GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ GLint jR = IROUND(rgba[i][RCOMP] * scale);
+ GLint jG = IROUND(rgba[i][GCOMP] * scale);
+ GLint jB = IROUND(rgba[i][BCOMP] * scale);
+ GLint jA = IROUND(rgba[i][ACOMP] * scale);
rgba[i][RCOMP] = lut[jR * 4 + 0];
rgba[i][GCOMP] = lut[jG * 4 + 1];
rgba[i][BCOMP] = lut[jB * 4 + 2];
-/* $Id: s_accum.c,v 1.9 2001/03/19 02:25:36 keithw Exp $ */
+/* $Id: s_accum.c,v 1.10 2001/04/10 15:25:45 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "context.h"
#include "macros.h"
+#include "mmath.h"
#include "mem.h"
#include "s_accum.h"
GLint j;
if (mult != prevMult) {
for (j = 0; j < max; j++)
- multTable[j] = (GLint) ((GLfloat) j * mult + 0.5F);
+ multTable[j] = IROUND((GLfloat) j * mult);
prevMult = mult;
}
for (j=0;j<height;j++) {
const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4;
for (i=0;i<width;i++) {
- GLint r, g, b, a;
- r = (GLint) ( (GLfloat) (*acc++) * rscale + 0.5F );
- g = (GLint) ( (GLfloat) (*acc++) * gscale + 0.5F );
- b = (GLint) ( (GLfloat) (*acc++) * bscale + 0.5F );
- a = (GLint) ( (GLfloat) (*acc++) * ascale + 0.5F );
+ GLint r = IROUND( (GLfloat) (acc[0]) * rscale );
+ GLint g = IROUND( (GLfloat) (acc[1]) * gscale );
+ GLint b = IROUND( (GLfloat) (acc[2]) * bscale );
+ GLint a = IROUND( (GLfloat) (acc[3]) * ascale );
+ acc += 4;
rgba[i][RCOMP] = CLAMP( r, 0, iChanMax );
rgba[i][GCOMP] = CLAMP( g, 0, iChanMax );
rgba[i][BCOMP] = CLAMP( b, 0, iChanMax );
-/* $Id: s_drawpix.c,v 1.15 2001/03/19 02:25:36 keithw Exp $ */
+/* $Id: s_drawpix.c,v 1.16 2001/04/10 15:25:45 brianp Exp $ */
/*
* Mesa 3-D graphics library
zSpan[i] = z;
/* save Y value of first row */
- zoomY0 = (GLint) (ctx->Current.RasterPos[1] + 0.5F);
+ zoomY0 = IROUND(ctx->Current.RasterPos[1]);
}
-/* $Id: s_texture.c,v 1.21 2001/03/28 20:40:52 gareth Exp $ */
+/* $Id: s_texture.c,v 1.22 2001/04/10 15:25:45 brianp Exp $ */
/*
* Mesa 3-D graphics library
}
{
- const GLfloat a = FRAC(u);
+ const GLfloat a = FRAC(u + 1.0F);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
- const GLint w0 = IROUND((1.0F-a) * WEIGHT_SCALE);
- const GLint w1 = IROUND( a * WEIGHT_SCALE);
+ const GLint w0 = IROUND_POS((1.0F-a) * WEIGHT_SCALE);
+ const GLint w1 = IROUND_POS( a * WEIGHT_SCALE);
GLchan t0[4], t1[4]; /* texels */
}
{
- const GLfloat a = FRAC(u);
- const GLfloat b = FRAC(v);
+ const GLfloat a = FRAC(u + 1.0F); /* add one in case u is just below 0 */
+ const GLfloat b = FRAC(v + 1.0F);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
- const GLint w00 = IROUND((1.0F-a) * (1.0F-b) * WEIGHT_SCALE);
- const GLint w10 = IROUND( a * (1.0F-b) * WEIGHT_SCALE);
- const GLint w01 = IROUND((1.0F-a) * b * WEIGHT_SCALE);
- const GLint w11 = IROUND( a * b * WEIGHT_SCALE);
+ const GLint w00 = IROUND_POS((1.0F-a) * (1.0F-b) * WEIGHT_SCALE);
+ const GLint w10 = IROUND_POS( a * (1.0F-b) * WEIGHT_SCALE);
+ const GLint w01 = IROUND_POS((1.0F-a) * b * WEIGHT_SCALE);
+ const GLint w11 = IROUND_POS( a * b * WEIGHT_SCALE);
GLchan t00[4];
GLchan t10[4];
GLchan t01[4];
}
{
- const GLfloat a = FRAC(u);
- const GLfloat b = FRAC(v);
- const GLfloat c = FRAC(w);
+ const GLfloat a = FRAC(u + 1.0F);
+ const GLfloat b = FRAC(v + 1.0F);
+ const GLfloat c = FRAC(w + 1.0F);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
- GLint w000 = IROUND((1.0F-a) * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE);
- GLint w100 = IROUND( a * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE);
- GLint w010 = IROUND((1.0F-a) * b * (1.0F-c) * WEIGHT_SCALE);
- GLint w110 = IROUND( a * b * (1.0F-c) * WEIGHT_SCALE);
- GLint w001 = IROUND((1.0F-a) * (1.0F-b) * c * WEIGHT_SCALE);
- GLint w101 = IROUND( a * (1.0F-b) * c * WEIGHT_SCALE);
- GLint w011 = IROUND((1.0F-a) * b * c * WEIGHT_SCALE);
- GLint w111 = IROUND( a * b * c * WEIGHT_SCALE);
+ GLint w000 = IROUND_POS((1.0F-a) * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE);
+ GLint w100 = IROUND_POS( a * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE);
+ GLint w010 = IROUND_POS((1.0F-a) * b * (1.0F-c) * WEIGHT_SCALE);
+ GLint w110 = IROUND_POS( a * b * (1.0F-c) * WEIGHT_SCALE);
+ GLint w001 = IROUND_POS((1.0F-a) * (1.0F-b) * c * WEIGHT_SCALE);
+ GLint w101 = IROUND_POS( a * (1.0F-b) * c * WEIGHT_SCALE);
+ GLint w011 = IROUND_POS((1.0F-a) * b * c * WEIGHT_SCALE);
+ GLint w111 = IROUND_POS( a * b * c * WEIGHT_SCALE);
GLchan t000[4], t010[4], t001[4], t011[4];
GLchan t100[4], t110[4], t101[4], t111[4];
if (0) {
/* compute a single weighted depth sample and do one comparison */
- const GLfloat a = FRAC(u);
- const GLfloat b = FRAC(v);
+ const GLfloat a = FRAC(u + 1.0F);
+ const GLfloat b = FRAC(v + 1.0F);
const GLfloat w00 = (1.0F - a) * (1.0F - b);
const GLfloat w10 = ( a) * (1.0F - b);
const GLfloat w01 = (1.0F - a) * ( b);