/** * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image. * \param srcRowStride stride in bytes between rows of blocks in the * compressed source image. */ void _mesa_decompress_image(mesa_format format, GLuint width, GLuint height, const GLubyte *src, GLint srcRowStride, GLfloat *dest) { compressed_fetch_func fetch; GLuint i, j; GLuint bytes, bw, bh; GLint stride; bytes = _mesa_get_format_bytes(format); _mesa_get_format_block_size(format, &bw, &bh); fetch = _mesa_get_compressed_fetch_func(format); if (!fetch) { _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()"); return; } stride = srcRowStride * bh / bytes; for (j = 0; j < height; j++) { for (i = 0; i < width; i++) { fetch(src, stride, i, j, dest); dest += 4; } } }
/** * Initialize the texture image's FetchTexel methods. */ static void set_fetch_functions(const struct gl_sampler_object *samp, struct swrast_texture_image *texImage, GLuint dims) { gl_format format = texImage->Base.TexFormat; #ifdef DEBUG /* check that the table entries are sorted by format name */ gl_format fmt; for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) { assert(texfetch_funcs[fmt].Name == fmt); } #endif STATIC_ASSERT(Elements(texfetch_funcs) == MESA_FORMAT_COUNT); if (samp->sRGBDecode == GL_SKIP_DECODE_EXT && _mesa_get_format_color_encoding(format) == GL_SRGB) { format = _mesa_get_srgb_format_linear(format); } assert(format < MESA_FORMAT_COUNT); switch (dims) { case 1: texImage->FetchTexel = texfetch_funcs[format].Fetch1D; break; case 2: texImage->FetchTexel = texfetch_funcs[format].Fetch2D; break; case 3: texImage->FetchTexel = texfetch_funcs[format].Fetch3D; break; default: assert(!"Bad dims in set_fetch_functions()"); } texImage->FetchCompressedTexel = _mesa_get_compressed_fetch_func(format); ASSERT(texImage->FetchTexel); }