Browse Source

mesa/colormac: introduce inline helper for 4 unclamped float to ubyte.

This introduces an UNCLAMPED_FLOAT_TO_UBYTE x 4 inline function, as
suggested by Brian. It uses it in a few places I noticed from previous
color changes, and also some core mesa places. I haven't updated other places
yet.

Signed-off-by: Dave Airlie <airlied@redhat.com>
tags/mesa-8.0-rc1
Dave Airlie 14 years ago
parent
commit
81a86aea4f

+ 1
- 4
src/mesa/drivers/dri/intel/intel_blit.c View File

uint8_t clear[4]; uint8_t clear[4];
GLfloat *color = ctx->Color.ClearColor.f; GLfloat *color = ctx->Color.ClearColor.f;


UNCLAMPED_FLOAT_TO_UBYTE(clear[0], color[0]);
UNCLAMPED_FLOAT_TO_UBYTE(clear[1], color[1]);
UNCLAMPED_FLOAT_TO_UBYTE(clear[2], color[2]);
UNCLAMPED_FLOAT_TO_UBYTE(clear[3], color[3]);
_mesa_unclamped_float_rgba_to_ubyte(clear, color);


switch (irb->Base.Format) { switch (irb->Base.Format) {
case MESA_FORMAT_ARGB8888: case MESA_FORMAT_ARGB8888:

+ 3
- 5
src/mesa/drivers/dri/nouveau/nouveau_util.h View File

static inline unsigned static inline unsigned
pack_rgba_clamp_f(gl_format f, float c[]) pack_rgba_clamp_f(gl_format f, float c[])
{ {
return pack_rgba_i(f, (uint8_t []) {
UNCLAMPED_FLOAT_TO_UBYTE(c[RCOMP]),
UNCLAMPED_FLOAT_TO_UBYTE(c[GCOMP]),
UNCLAMPED_FLOAT_TO_UBYTE(c[BCOMP]),
UNCLAMPED_FLOAT_TO_UBYTE(c[ACOMP]) });
GLubyte bytes[4];
_mesa_unclamped_float_rgba_to_ubyte(bytes, c);
return pack_rgba_i(f, bytes);
} }


static inline unsigned static inline unsigned

+ 1
- 4
src/mesa/drivers/dri/r200/r200_state.c View File

rrb = radeon_get_colorbuffer(&rmesa->radeon); rrb = radeon_get_colorbuffer(&rmesa->radeon);
if (!rrb) if (!rrb)
return; return;
UNCLAMPED_FLOAT_TO_UBYTE(color[0], c.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(color[1], c.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(color[2], c.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(color[3], c.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(color, c.f);
rmesa->radeon.state.color.clear = radeonPackColor( rrb->cpp, rmesa->radeon.state.color.clear = radeonPackColor( rrb->cpp,
color[0], color[1], color[0], color[1],
color[2], color[3] ); color[2], color[3] );

+ 1
- 4
src/mesa/drivers/dri/radeon/radeon_state.c View File

if (!rrb) if (!rrb)
return; return;
UNCLAMPED_FLOAT_TO_UBYTE(c[0], color.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(c[1], color.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(c[2], color.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(c[3], color.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(c, color.f);
rmesa->radeon.state.color.clear = radeonPackColor( rrb->cpp, rmesa->radeon.state.color.clear = radeonPackColor( rrb->cpp,
c[0], c[1], c[2], c[3] ); c[0], c[1], c[2], c[3] );
} }

+ 3
- 12
src/mesa/drivers/x11/xm_dd.c View File

const XMesaContext xmesa = XMESA_CONTEXT(ctx); const XMesaContext xmesa = XMESA_CONTEXT(ctx);
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);


UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(xmesa->clearcolor, color.f);
xmesa->clearpixel = xmesa_color_to_pixel( ctx, xmesa->clearpixel = xmesa_color_to_pixel( ctx,
xmesa->clearcolor[0], xmesa->clearcolor[0],
xmesa->clearcolor[1], xmesa->clearcolor[1],
int i; int i;
const XMesaContext xmesa = XMESA_CONTEXT(ctx); const XMesaContext xmesa = XMESA_CONTEXT(ctx);


UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(xmesa->clearcolor, color.f);


if (color.f[0] == 0.0 && color.f[1] == 0.0 && color.f[2] == 0.0) { if (color.f[0] == 0.0 && color.f[1] == 0.0 && color.f[2] == 0.0) {
/* black is black */ /* black is black */
int i; int i;
const XMesaContext xmesa = XMESA_CONTEXT(ctx); const XMesaContext xmesa = XMESA_CONTEXT(ctx);


UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(xmesa->clearcolor, color.f);


if (color.f[0] == 0.0 && color.f[1] == 0.0 && color.f[2] == 0.0) { if (color.f[0] == 0.0 && color.f[1] == 0.0 && color.f[2] == 0.0) {
/* black is black */ /* black is black */

+ 6
- 1
src/mesa/main/colormac.h View File

UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]); \ UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]); \
} while (0) } while (0)



static inline void _mesa_unclamped_float_rgba_to_ubyte(GLubyte dst[4], const GLfloat src[4])
{
int i;
for (i = 0; i < 4; i++)
UNCLAMPED_FLOAT_TO_UBYTE(dst[i], src[i]);
}


/** /**
* \name Generic color packing macros. All inputs should be GLubytes. * \name Generic color packing macros. All inputs should be GLubytes.

+ 2
- 6
src/mesa/main/image.c View File

GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst); GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
GLuint i; GLuint i;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][RCOMP], src4[i][RCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][GCOMP], src4[i][GCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][BCOMP], src4[i][BCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][ACOMP], src4[i][ACOMP]);
}
if (!mask || mask[i])
_mesa_unclamped_float_rgba_to_ubyte(dst1[i], src4[i]);
} }
if (useTemp) if (useTemp)
memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte)); memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));

+ 2
- 6
src/mesa/swrast/s_blend.c View File

blend_general_float(ctx, n, mask, rgbaF, destF, chanType); blend_general_float(ctx, n, mask, rgbaF, destF, chanType);
/* convert back to ubytes */ /* convert back to ubytes */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (mask[i]) {
UNCLAMPED_FLOAT_TO_UBYTE(rgba[i][RCOMP], rgbaF[i][RCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(rgba[i][GCOMP], rgbaF[i][GCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(rgba[i][BCOMP], rgbaF[i][BCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(rgba[i][ACOMP], rgbaF[i][ACOMP]);
}
if (mask[i])
_mesa_unclamped_float_rgba_to_ubyte(rgba[i], rgbaF[i]);
} }
} }
else if (chanType == GL_UNSIGNED_SHORT) { else if (chanType == GL_UNSIGNED_SHORT) {

+ 2
- 8
src/mesa/swrast/s_clear.c View File

span.array->ChanType = rb->DataType; span.array->ChanType = rb->DataType;
if (span.array->ChanType == GL_UNSIGNED_BYTE) { if (span.array->ChanType == GL_UNSIGNED_BYTE) {
GLubyte clearColor[4]; GLubyte clearColor[4];
UNCLAMPED_FLOAT_TO_UBYTE(clearColor[RCOMP], ctx->Color.ClearColor.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(clearColor[GCOMP], ctx->Color.ClearColor.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(clearColor[BCOMP], ctx->Color.ClearColor.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(clearColor[ACOMP], ctx->Color.ClearColor.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(clearColor, ctx->Color.ClearColor.f);
for (i = 0; i < width; i++) { for (i = 0; i < width; i++) {
COPY_4UBV(span.array->rgba[i], clearColor); COPY_4UBV(span.array->rgba[i], clearColor);
} }


switch (rb->DataType) { switch (rb->DataType) {
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
UNCLAMPED_FLOAT_TO_UBYTE(clear8[0], ctx->Color.ClearColor.f[0]);
UNCLAMPED_FLOAT_TO_UBYTE(clear8[1], ctx->Color.ClearColor.f[1]);
UNCLAMPED_FLOAT_TO_UBYTE(clear8[2], ctx->Color.ClearColor.f[2]);
UNCLAMPED_FLOAT_TO_UBYTE(clear8[3], ctx->Color.ClearColor.f[3]);
_mesa_unclamped_float_rgba_to_ubyte(clear8, ctx->Color.ClearColor.f);
clearVal = clear8; clearVal = clear8;
break; break;
case GL_UNSIGNED_SHORT: case GL_UNSIGNED_SHORT:

Loading…
Cancel
Save