summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2006-10-13 17:41:23 +0000
committerBrian Paul <[email protected]>2006-10-13 17:41:23 +0000
commit5b0edff412f45fe64bd42fb481adeda7d34b0fa8 (patch)
tree141c7825eb0f289f69a4fc5fb206e6c7415d51c7
parent461651357713b1408400669d6a809f2e367182fe (diff)
Consolidate, move, fix code related to color index and stencil image transfer
operations (shift, offset, table lookup, etc).
-rw-r--r--src/mesa/main/image.c159
-rw-r--r--src/mesa/main/image.h11
-rw-r--r--src/mesa/main/pixel.c81
-rw-r--r--src/mesa/main/pixel.h18
-rw-r--r--src/mesa/swrast/s_copypix.c30
-rw-r--r--src/mesa/swrast/s_drawpix.c8
-rw-r--r--src/mesa/swrast/s_readpix.c14
7 files changed, 135 insertions, 186 deletions
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index af116af7e81..bb0dd4ae958 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -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;
}
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index 5d50f5df156..990398a7c45 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -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,
diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c
index e0a90843260..d20f89c543a 100644
--- a/src/mesa/main/pixel.c
+++ b/src/mesa/main/pixel.c
@@ -1407,49 +1407,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.
*/
void
@@ -1500,44 +1457,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[])
{
diff --git a/src/mesa/main/pixel.h b/src/mesa/main/pixel.h
index 87f54ed8b3f..09155cfd70d 100644
--- a/src/mesa/main/pixel.h
+++ b/src/mesa/main/pixel.h
@@ -103,15 +103,6 @@ _mesa_lookup_rgba_ubyte(const struct gl_color_table *table,
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]);
@@ -122,15 +113,6 @@ _mesa_map_ci8_to_rgba8(const GLcontext *ctx, GLuint n, const GLubyte index[],
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[]);
diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index accf59f3076..1a17b75c702 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -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) {
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 4270d23f064..bdb25583515 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -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);
diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
index fb39427b621..0189b0e797d 100644
--- a/src/mesa/swrast/s_readpix.c
+++ b/src/mesa/swrast/s_readpix.c
@@ -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);
}