Consolidate, move, fix code related to color index and stencil image transfer

operations (shift, offset, table lookup, etc).
This commit is contained in:
Brian Paul 2006-10-13 17:41:23 +00:00
parent 4616513577
commit 5b0edff412
7 changed files with 135 additions and 186 deletions

View file

@ -1059,6 +1059,95 @@ _mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLbitfield transferOps,
}
/*
* Apply color index shift and offset to an array of pixels.
*/
static void
shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] )
{
GLint shift = ctx->Pixel.IndexShift;
GLint offset = ctx->Pixel.IndexOffset;
GLuint i;
if (shift > 0) {
for (i=0;i<n;i++) {
indexes[i] = (indexes[i] << shift) + offset;
}
}
else if (shift < 0) {
shift = -shift;
for (i=0;i<n;i++) {
indexes[i] = (indexes[i] >> shift) + offset;
}
}
else {
for (i=0;i<n;i++) {
indexes[i] = indexes[i] + offset;
}
}
}
/**
* Apply color index shift, offset and table lookup to an array
* of color indexes;
*/
void
_mesa_apply_ci_transfer_ops(const GLcontext *ctx, GLbitfield transferOps,
GLuint n, GLuint indexes[])
{
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
shift_and_offset_ci(ctx, n, indexes);
}
if (transferOps & IMAGE_MAP_COLOR_BIT) {
const GLuint mask = ctx->Pixel.MapItoIsize - 1;
GLuint i;
for (i = 0; i < n; i++) {
const GLuint j = indexes[i] & mask;
indexes[i] = IROUND(ctx->Pixel.MapItoI[j]);
}
}
}
/**
* Apply stencil index shift, offset and table lookup to an array
* of stencil values.
*/
void
_mesa_apply_stencil_transfer_ops(const GLcontext *ctx, GLuint n,
GLstencil stencil[])
{
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) {
const GLint offset = ctx->Pixel.IndexOffset;
GLint shift = ctx->Pixel.IndexShift;
GLuint i;
if (shift > 0) {
for (i = 0; i < n; i++) {
stencil[i] = (stencil[i] << shift) + offset;
}
}
else if (shift < 0) {
shift = -shift;
for (i = 0; i < n; i++) {
stencil[i] = (stencil[i] >> shift) + offset;
}
}
else {
for (i = 0; i < n; i++) {
stencil[i] = stencil[i] + offset;
}
}
}
if (ctx->Pixel.MapStencilFlag) {
GLuint mask = ctx->Pixel.MapStoSsize - 1;
GLuint i;
for (i = 0; i < n; i++) {
stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ];
}
}
}
/**
* Used to pack an array [][4] of RGBA float colors as specified
@ -2013,7 +2102,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
GLenum srcFormat, GLenum srcType, const GLvoid *src,
const struct gl_pixelstore_attrib *unpack )
{
assert(srcFormat == GL_COLOR_INDEX);
ASSERT(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
ASSERT(srcType == GL_BITMAP ||
srcType == GL_UNSIGNED_BYTE ||
@ -2926,17 +3015,10 @@ _mesa_unpack_color_span_chan( GLcontext *ctx,
extract_uint_indexes(n, indexes, srcFormat, srcType, source,
srcPacking);
if (dstFormat == GL_COLOR_INDEX
&& (transferOps & IMAGE_MAP_COLOR_BIT)) {
_mesa_map_ci(ctx, n, indexes);
}
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
_mesa_shift_and_offset_ci(ctx, n, indexes);
}
if (dstFormat == GL_COLOR_INDEX) {
/* convert to GLchan and return */
GLuint i;
_mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
/* convert to GLchan and return */
for (i = 0; i < n; i++) {
dest[i] = (GLchan) (indexes[i] & 0xff);
}
@ -2944,6 +3026,9 @@ _mesa_unpack_color_span_chan( GLcontext *ctx,
}
else {
/* Convert indexes to RGBA */
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
shift_and_offset_ci(ctx, n, indexes);
}
_mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
}
@ -3150,17 +3235,10 @@ _mesa_unpack_color_span_float( GLcontext *ctx,
extract_uint_indexes(n, indexes, srcFormat, srcType, source,
srcPacking);
if (dstFormat == GL_COLOR_INDEX
&& (transferOps & IMAGE_MAP_COLOR_BIT)) {
_mesa_map_ci(ctx, n, indexes);
}
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
_mesa_shift_and_offset_ci(ctx, n, indexes);
}
if (dstFormat == GL_COLOR_INDEX) {
/* convert to GLchan and return */
GLuint i;
_mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
/* convert to GLchan and return */
for (i = 0; i < n; i++) {
dest[i] = (GLchan) (indexes[i] & 0xff);
}
@ -3168,6 +3246,9 @@ _mesa_unpack_color_span_float( GLcontext *ctx,
}
else {
/* Convert indexes to RGBA */
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
shift_and_offset_ci(ctx, n, indexes);
}
_mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
}
@ -3350,14 +3431,8 @@ _mesa_unpack_index_span( const GLcontext *ctx, GLuint n,
extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
srcPacking);
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
/* shift and offset indexes */
_mesa_shift_and_offset_ci(ctx, n, indexes);
}
if (transferOps & IMAGE_MAP_COLOR_BIT) {
/* Apply lookup table */
_mesa_map_ci(ctx, n, indexes);
}
if (transferOps)
_mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
/* convert to dest type */
switch (dstType) {
@ -3404,11 +3479,8 @@ _mesa_pack_index_span( const GLcontext *ctx, GLuint n,
if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) {
/* make a copy of input */
_mesa_memcpy(indexes, source, n * sizeof(GLuint));
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
_mesa_shift_and_offset_ci( ctx, n, indexes);
}
if (transferOps & IMAGE_MAP_COLOR_BIT) {
_mesa_map_ci(ctx, n, indexes);
if (transferOps) {
_mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
}
source = indexes;
}
@ -3570,13 +3642,13 @@ _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n,
GLuint indexes[MAX_WIDTH];
assert(n <= MAX_WIDTH);
extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
extract_uint_indexes(n, indexes, GL_STENCIL_INDEX, srcType, source,
srcPacking);
if (transferOps) {
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
/* shift and offset indexes */
_mesa_shift_and_offset_ci(ctx, n, indexes);
shift_and_offset_ci(ctx, n, indexes);
}
if (ctx->Pixel.MapStencilFlag) {
@ -3632,12 +3704,7 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n,
ctx->Pixel.MapStencilFlag) {
/* make a copy of input */
_mesa_memcpy(stencil, source, n * sizeof(GLstencil));
if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) {
_mesa_shift_and_offset_stencil( ctx, n, stencil );
}
if (ctx->Pixel.MapStencilFlag) {
_mesa_map_stencil( ctx, n, stencil );
}
_mesa_apply_stencil_transfer_ops(ctx, n, stencil);
source = stencil;
}
@ -4066,15 +4133,11 @@ _mesa_pack_depth_stencil_span(const GLcontext *ctx, GLuint n, GLuint *dest,
depthVals = depthCopy;
}
if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) {
if (ctx->Pixel.IndexShift ||
ctx->Pixel.IndexOffset ||
ctx->Pixel.MapStencilFlag) {
_mesa_memcpy(stencilCopy, stencilVals, n * sizeof(GLstencil));
_mesa_shift_and_offset_stencil(ctx, n, stencilCopy);
stencilVals = stencilCopy;
}
if (ctx->Pixel.MapStencilFlag) {
if (stencilVals != stencilCopy)
_mesa_memcpy(stencilCopy, stencilVals, n * sizeof(GLstencil));
_mesa_map_stencil(ctx, n, stencilCopy);
_mesa_apply_stencil_transfer_ops(ctx, n, stencilCopy);
stencilVals = stencilCopy;
}

View file

@ -115,6 +115,17 @@ extern void
_mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLbitfield transferOps,
GLuint n, GLfloat rgba[][4]);
extern void
_mesa_apply_ci_transfer_ops(const GLcontext *ctx, GLbitfield transferOps,
GLuint n, GLuint indexes[]);
extern void
_mesa_apply_stencil_transfer_ops(const GLcontext *ctx, GLuint n,
GLstencil stencil[]);
extern void
_mesa_pack_rgba_span_float( GLcontext *ctx, GLuint n, GLfloat rgba[][4],
GLenum dstFormat, GLenum dstType, GLvoid *dstAddr,

View file

@ -1406,49 +1406,6 @@ _mesa_lookup_rgba_ubyte(const struct gl_color_table *table,
/*
* Apply color index shift and offset to an array of pixels.
*/
void
_mesa_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] )
{
GLint shift = ctx->Pixel.IndexShift;
GLint offset = ctx->Pixel.IndexOffset;
GLuint i;
if (shift > 0) {
for (i=0;i<n;i++) {
indexes[i] = (indexes[i] << shift) + offset;
}
}
else if (shift < 0) {
shift = -shift;
for (i=0;i<n;i++) {
indexes[i] = (indexes[i] >> shift) + offset;
}
}
else {
for (i=0;i<n;i++) {
indexes[i] = indexes[i] + offset;
}
}
}
/*
* Apply color index mapping to color indexes.
*/
void
_mesa_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] )
{
const GLuint mask = ctx->Pixel.MapItoIsize - 1;
GLuint i;
for (i = 0; i < n; i++) {
const GLuint j = index[i] & mask;
index[i] = IROUND(ctx->Pixel.MapItoI[j]);
}
}
/*
* Map color indexes to float rgba values.
*/
@ -1499,44 +1456,6 @@ _mesa_map_ci8_to_rgba8(const GLcontext *ctx, GLuint n, const GLubyte index[],
}
void
_mesa_shift_and_offset_stencil( const GLcontext *ctx, GLuint n,
GLstencil stencil[] )
{
GLuint i;
GLint shift = ctx->Pixel.IndexShift;
GLint offset = ctx->Pixel.IndexOffset;
if (shift > 0) {
for (i=0;i<n;i++) {
stencil[i] = (stencil[i] << shift) + offset;
}
}
else if (shift < 0) {
shift = -shift;
for (i=0;i<n;i++) {
stencil[i] = (stencil[i] >> shift) + offset;
}
}
else {
for (i=0;i<n;i++) {
stencil[i] = stencil[i] + offset;
}
}
}
void
_mesa_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] )
{
GLuint mask = ctx->Pixel.MapStoSsize - 1;
GLuint i;
for (i=0;i<n;i++) {
stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ];
}
}
void
_mesa_scale_and_bias_depth(const GLcontext *ctx, GLuint n,
GLfloat depthValues[])

View file

@ -102,15 +102,6 @@ _mesa_lookup_rgba_ubyte(const struct gl_color_table *table,
GLuint n, GLubyte rgba[][4]);
extern void
_mesa_shift_and_offset_ci(const GLcontext *ctx, GLuint n,
GLuint indexes[]);
extern void
_mesa_map_ci(const GLcontext *ctx, GLuint n, GLuint index[]);
extern void
_mesa_map_ci_to_rgba(const GLcontext *ctx,
GLuint n, const GLuint index[], GLfloat rgba[][4]);
@ -121,15 +112,6 @@ _mesa_map_ci8_to_rgba8(const GLcontext *ctx, GLuint n, const GLubyte index[],
GLubyte rgba[][4]);
extern void
_mesa_shift_and_offset_stencil(const GLcontext *ctx, GLuint n,
GLstencil indexes[]);
extern void
_mesa_map_stencil(const GLcontext *ctx, GLuint n, GLstencil index[]);
extern void
_mesa_scale_and_bias_depth(const GLcontext *ctx, GLuint n,
GLfloat depthValues[]);

View file

@ -312,7 +312,6 @@ copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
GLint sy, dy, stepy;
GLint j;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset;
GLint overlapping;
SWspan span;
@ -382,13 +381,9 @@ copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
width, srcx, sy, span.array->index );
}
/* Apply shift, offset, look-up table */
if (shift_or_offset) {
_mesa_shift_and_offset_ci( ctx, width, span.array->index );
}
if (ctx->Pixel.MapColorFlag) {
_mesa_map_ci( ctx, width, span.array->index );
}
if (ctx->_ImageTransferState)
_mesa_apply_ci_transfer_ops(ctx, ctx->_ImageTransferState,
width, span.array->index);
/* write color indexes */
span.x = destx;
@ -561,7 +556,6 @@ copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
GLint j;
GLstencil *p, *tmpImage;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset;
GLint overlapping;
if (!rb) {
@ -622,13 +616,7 @@ copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
_swrast_read_stencil_span( ctx, rb, width, srcx, sy, stencil );
}
/* Apply shift, offset, look-up table */
if (shift_or_offset) {
_mesa_shift_and_offset_stencil( ctx, width, stencil );
}
if (ctx->Pixel.MapStencilFlag) {
_mesa_map_stencil( ctx, width, stencil );
}
_mesa_apply_stencil_transfer_ops(ctx, width, stencil);
/* Write stencil values */
if (zoom) {
@ -664,8 +652,6 @@ copy_depth_stencil_pixels(GLcontext *ctx,
const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;
const GLuint stencilMask = ctx->Stencil.WriteMask[0];
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
const GLboolean shiftOrOffset
= ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset;
const GLboolean scaleOrBias
= ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
GLint overlapping;
@ -755,13 +741,7 @@ copy_depth_stencil_pixels(GLcontext *ctx,
width, srcX, sy, stencil);
}
/* Apply shift, offset, look-up table */
if (shiftOrOffset) {
_mesa_shift_and_offset_stencil(ctx, width, stencil);
}
if (ctx->Pixel.MapStencilFlag) {
_mesa_map_stencil(ctx, width, stencil);
}
_mesa_apply_stencil_transfer_ops(ctx, width, stencil);
/* Write values */
if (zoom) {

View file

@ -406,13 +406,7 @@ draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y,
_mesa_unpack_index_span(ctx, spanWidth, destType, values,
type, source, unpack,
ctx->_ImageTransferState);
if (ctx->_ImageTransferState & IMAGE_SHIFT_OFFSET_BIT) {
_mesa_shift_and_offset_stencil(ctx, spanWidth, values);
}
if (ctx->Pixel.MapStencilFlag) {
_mesa_map_stencil(ctx, spanWidth, values);
}
_mesa_apply_stencil_transfer_ops(ctx, spanWidth, values);
if (zoom) {
_swrast_write_zoomed_stencil_span(ctx, x, y, spanWidth,
spanX, spanY, values);

View file

@ -309,6 +309,7 @@ read_rgba_pixels( GLcontext *ctx,
const struct gl_pixelstore_attrib *packing )
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
const GLbitfield transferOps = ctx->_ImageTransferState;
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
@ -324,7 +325,6 @@ read_rgba_pixels( GLcontext *ctx,
ASSERT(width <= MAX_WIDTH);
if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
const GLbitfield transferOps = ctx->_ImageTransferState;
GLfloat *dest, *src, *tmpImage, *convImage;
GLint row;
@ -350,9 +350,9 @@ read_rgba_pixels( GLcontext *ctx,
GLuint index[MAX_WIDTH];
ASSERT(rb->DataType == GL_UNSIGNED_INT);
rb->GetRow(ctx, rb, width, x, y, index);
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset !=0 ) {
_mesa_map_ci(ctx, width, index);
}
_mesa_apply_ci_transfer_ops(ctx,
transferOps & IMAGE_SHIFT_OFFSET_BIT,
width, index);
_mesa_map_ci_to_rgba(ctx, width, index, (GLfloat (*)[4]) dest);
}
_mesa_apply_rgba_transfer_ops(ctx,
@ -404,9 +404,9 @@ read_rgba_pixels( GLcontext *ctx,
GLuint index[MAX_WIDTH];
ASSERT(rb->DataType == GL_UNSIGNED_INT);
rb->GetRow(ctx, rb, width, x, y, index);
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) {
_mesa_map_ci(ctx, width, index);
}
_mesa_apply_ci_transfer_ops(ctx,
transferOps & IMAGE_SHIFT_OFFSET_BIT,
width, index);
_mesa_map_ci_to_rgba(ctx, width, index, rgba);
}