diff options
author | Roland Scheidegger <sroland@tungstengraphics.com> | 2009-02-09 17:57:22 +0100 |
---|---|---|
committer | Roland Scheidegger <sroland@vmware.com> | 2009-02-09 23:17:43 +0100 |
commit | cb3c54ea86344242545dd29f936e53853d3a5ea4 (patch) | |
tree | 5b39f7c32c48c43ba16692374191ae50b574b4cb | |
parent | 123299546fccc0814d08c6258ed9e64a356f7607 (diff) |
fix _mesa_get_teximage for srgb textures
-rw-r--r-- | src/mesa/main/texstore.c | 63 |
1 files changed, 52 insertions, 11 deletions
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 2b06796aba..6360ca15f8 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -3699,14 +3699,37 @@ is_srgb_teximage(const struct gl_texture_image *texImage) case MESA_FORMAT_SARGB8: case MESA_FORMAT_SL8: case MESA_FORMAT_SLA8: + case MESA_FORMAT_SRGB_DXT1: + case MESA_FORMAT_SRGBA_DXT1: + case MESA_FORMAT_SRGBA_DXT3: + case MESA_FORMAT_SRGBA_DXT5: return GL_TRUE; default: return GL_FALSE; } } -#endif /* FEATURE_EXT_texture_sRGB */ +/** + * Convert a float value from linear space to a + * non-linear sRGB value in [0, 255]. + * Not terribly efficient. + */ +static INLINE GLfloat +linear_to_nonlinear(GLfloat cl) +{ + /* can't have values outside [0, 1] */ + GLfloat cs; + if (cl < 0.0031308) { + cs = 12.92 * cl; + } + else { + cs = 1.055 * _mesa_pow(cl, 0.41666) - 0.055; + } + return cs; +} + +#endif /* FEATURE_EXT_texture_sRGB */ /** * This is the software fallback for Driver.GetTexImage(). @@ -3823,16 +3846,34 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level, } #if FEATURE_EXT_texture_sRGB else if (is_srgb_teximage(texImage)) { - /* no pixel transfer and no non-linear to linear conversion */ - const GLint comps = texImage->TexFormat->TexelBytes; - const GLint rowstride = comps * texImage->RowStride; - MEMCPY(dest, - (const GLubyte *) texImage->Data + row * rowstride, - comps * width * sizeof(GLubyte)); - /* FIXME: isn't it necessary to still do component assigning - according to format/type? */ - /* FIXME: need to do something else for compressed srgb textures - (currently will return values converted to linear) */ + /* special case this since need to backconvert values */ + /* convert row to RGBA format */ + GLfloat rgba[MAX_WIDTH][4]; + GLint col; + GLbitfield transferOps = 0x0; + + for (col = 0; col < width; col++) { + (*texImage->FetchTexelf)(texImage, col, row, img, rgba[col]); + if (texImage->TexFormat->BaseFormat == GL_LUMINANCE) { + rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]); + rgba[col][GCOMP] = 0.0; + rgba[col][BCOMP] = 0.0; + } + else if (texImage->TexFormat->BaseFormat == GL_LUMINANCE_ALPHA) { + rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]); + rgba[col][GCOMP] = 0.0; + rgba[col][BCOMP] = 0.0; + } + else if (texImage->TexFormat->BaseFormat == GL_RGB || + texImage->TexFormat->BaseFormat == GL_RGBA) { + rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]); + rgba[col][GCOMP] = linear_to_nonlinear(rgba[col][GCOMP]); + rgba[col][BCOMP] = linear_to_nonlinear(rgba[col][BCOMP]); + } + } + _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, + format, type, dest, + &ctx->Pack, transferOps /*image xfer ops*/); } #endif /* FEATURE_EXT_texture_sRGB */ else { |