oops- forgot convolution for glGetTexImage. Done now.

This commit is contained in:
Brian Paul 2000-09-06 15:15:43 +00:00
parent c52fc9b49c
commit f96ce6a707

View file

@ -1,4 +1,4 @@
/* $Id: teximage.c,v 1.48 2000/09/05 22:11:38 brianp Exp $ */ /* $Id: teximage.c,v 1.49 2000/09/06 15:15:43 brianp Exp $ */
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
@ -2148,92 +2148,161 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
if (texImage->Data) { if (texImage->Data) {
GLint width = texImage->Width; GLint width = texImage->Width;
GLint height = texImage->Height; GLint height = texImage->Height;
GLint row; GLint depth = texImage->Depth;
GLint img, row;
if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE) if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
_mesa_update_image_transfer_state(ctx); _mesa_update_image_transfer_state(ctx);
for (row = 0; row < height; row++) { if (ctx->ImageTransferState & IMAGE_CONVOLUTION_BIT) {
/* compute destination address in client memory */ /* convert texture image to GL_RGBA, GL_FLOAT */
GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, GLfloat *tmpImage, *convImage;
width, height, const GLint comps = components_in_intformat(texImage->Format);
format, type, 0, row, 0);
assert(dest); tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
if (texImage->Format == GL_RGBA) { if (!tmpImage) {
const GLubyte *src = texImage->Data + row * width * 4 * sizeof(GLubyte); gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
/* XXX convolution */ return;
_mesa_pack_rgba_span( ctx, width, (CONST GLubyte (*)[4]) src,
format, type, dest, &ctx->Pack,
ctx->ImageTransferState );
} }
else { convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
/* fetch RGBA row from texture image then pack it in client mem */ if (!convImage) {
GLubyte rgba[MAX_WIDTH][4]; FREE(tmpImage);
GLint i; gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
const GLubyte *src; return;
switch (texImage->Format) { }
case GL_ALPHA:
src = texImage->Data + row * width * sizeof(GLubyte); for (img = 0; img < depth; img++) {
for (i = 0; i < width; i++) { GLint convWidth, convHeight;
rgba[i][RCOMP] = 255;
rgba[i][GCOMP] = 255; /* convert to GL_RGBA */
rgba[i][BCOMP] = 255; for (row = 0; row < height; row++) {
rgba[i][ACOMP] = src[i]; const GLubyte *src = texImage->Data
} + (img * height + row ) * width * comps;
break; GLfloat *dst = tmpImage + row * width * 4;
case GL_LUMINANCE: _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst,
src = texImage->Data + row * width * sizeof(GLubyte); texImage->Format, GL_UNSIGNED_BYTE,
for (i = 0; i < width; i++) { src, &_mesa_native_packing,
rgba[i][RCOMP] = src[i]; ctx->ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS,
rgba[i][GCOMP] = src[i]; GL_FALSE);
rgba[i][BCOMP] = src[i]; }
rgba[i][ACOMP] = 255;
} convWidth = width;
break; convHeight = height;
case GL_LUMINANCE_ALPHA:
src = texImage->Data + row * 2 * width * sizeof(GLubyte); /* convolve */
for (i = 0; i < width; i++) { if (target == GL_TEXTURE_1D) {
rgba[i][RCOMP] = src[i*2+0]; if (ctx->Pixel.Convolution1DEnabled) {
rgba[i][GCOMP] = src[i*2+0]; _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage);
rgba[i][BCOMP] = src[i*2+0]; }
rgba[i][ACOMP] = src[i*2+1]; }
} else {
break; if (ctx->Pixel.Convolution2DEnabled) {
case GL_INTENSITY: _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,
src = texImage->Data + row * width * sizeof(GLubyte); tmpImage, convImage);
for (i = 0; i < width; i++) { }
rgba[i][RCOMP] = src[i]; else if (ctx->Pixel.Separable2DEnabled) {
rgba[i][GCOMP] = src[i]; _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,
rgba[i][BCOMP] = src[i]; tmpImage, convImage);
rgba[i][ACOMP] = 255; }
} }
break;
case GL_RGB: /* pack convolved image */
src = texImage->Data + row * 3 * width * sizeof(GLubyte); for (row = 0; row < convHeight; row++) {
for (i = 0; i < width; i++) { const GLfloat *src = convImage + row * convWidth * 4;
rgba[i][RCOMP] = src[i*3+0]; GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels,
rgba[i][GCOMP] = src[i*3+1]; convWidth, convHeight,
rgba[i][BCOMP] = src[i*3+2]; format, type, img, row, 0);
rgba[i][ACOMP] = 255; _mesa_pack_float_rgba_span(ctx, convWidth,
} (const GLfloat(*)[4]) src,
break; format, type, dest, &ctx->Pack,
case GL_RGBA: ctx->ImageTransferState & IMAGE_POST_CONVOLUTION_BITS);
/* this special case should have been handled above! */
gl_problem( ctx, "error 1 in gl_GetTexImage" );
break;
case GL_COLOR_INDEX:
gl_problem( ctx, "GL_COLOR_INDEX not implemented in gl_GetTexImage" );
break;
default:
gl_problem( ctx, "bad format in gl_GetTexImage" );
} }
/* XXX convolution */
_mesa_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba,
format, type, dest, &ctx->Pack,
ctx->ImageTransferState );
} }
FREE(tmpImage);
FREE(convImage);
} }
else {
/* no convolution */
for (img = 0; img < depth; img++) {
for (row = 0; row < height; row++) {
/* compute destination address in client memory */
GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels,
width, height, format, type, img, row, 0);
assert(dest);
if (texImage->Format == GL_RGBA) {
/* simple case */
const GLubyte *src = texImage->Data
+ (img * height + row ) * width * 4;
_mesa_pack_rgba_span( ctx, width, (CONST GLubyte (*)[4]) src,
format, type, dest, &ctx->Pack,
ctx->ImageTransferState );
}
else {
/* general case: convert row to RGBA format */
GLubyte rgba[MAX_WIDTH][4];
GLint i;
const GLubyte *src;
switch (texImage->Format) {
case GL_ALPHA:
src = texImage->Data + row * width * sizeof(GLubyte);
for (i = 0; i < width; i++) {
rgba[i][RCOMP] = 255;
rgba[i][GCOMP] = 255;
rgba[i][BCOMP] = 255;
rgba[i][ACOMP] = src[i];
}
break;
case GL_LUMINANCE:
src = texImage->Data + row * width * sizeof(GLubyte);
for (i = 0; i < width; i++) {
rgba[i][RCOMP] = src[i];
rgba[i][GCOMP] = src[i];
rgba[i][BCOMP] = src[i];
rgba[i][ACOMP] = 255;
}
break;
case GL_LUMINANCE_ALPHA:
src = texImage->Data + row * 2 * width * sizeof(GLubyte);
for (i = 0; i < width; i++) {
rgba[i][RCOMP] = src[i*2+0];
rgba[i][GCOMP] = src[i*2+0];
rgba[i][BCOMP] = src[i*2+0];
rgba[i][ACOMP] = src[i*2+1];
}
break;
case GL_INTENSITY:
src = texImage->Data + row * width * sizeof(GLubyte);
for (i = 0; i < width; i++) {
rgba[i][RCOMP] = src[i];
rgba[i][GCOMP] = src[i];
rgba[i][BCOMP] = src[i];
rgba[i][ACOMP] = 255;
}
break;
case GL_RGB:
src = texImage->Data + row * 3 * width * sizeof(GLubyte);
for (i = 0; i < width; i++) {
rgba[i][RCOMP] = src[i*3+0];
rgba[i][GCOMP] = src[i*3+1];
rgba[i][BCOMP] = src[i*3+2];
rgba[i][ACOMP] = 255;
}
break;
case GL_COLOR_INDEX:
gl_problem( ctx, "GL_COLOR_INDEX not implemented in gl_GetTexImage" );
break;
case GL_RGBA:
default:
gl_problem( ctx, "bad format in gl_GetTexImage" );
}
_mesa_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba,
format, type, dest, &ctx->Pack,
ctx->ImageTransferState );
} /* format */
} /* row */
} /* img */
} /* convolution */
/* if we got the teximage from the device driver we'll discard it now */ /* if we got the teximage from the device driver we'll discard it now */
if (discardImage) { if (discardImage) {