}
+/*
+ * 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
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 ||
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);
}
}
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);
}
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);
}
}
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);
}
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) {
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;
}
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) {
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;
}
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;
}
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;
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;
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) {
_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) {
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;
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) {
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;
ASSERT(width <= MAX_WIDTH);
if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
- const GLbitfield transferOps = ctx->_ImageTransferState;
GLfloat *dest, *src, *tmpImage, *convImage;
GLint row;
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,
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);
}