diff options
author | Ian Romanick <ian.d.romanick@intel.com> | 2011-09-12 11:38:52 -0500 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2011-10-25 18:41:29 -0700 |
commit | 8317a43a752fe3468c95452e03415f7ba9961653 (patch) | |
tree | 5e88fa836f2bf44b051b0e2dcea3a5fa54a2c182 | |
parent | 625fdf58c6fae4c34453a6a6e077293b2fb6ef11 (diff) |
mesa: Refactor expected texture size check in cpal_get_info
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Tested-by: Jin Yang <jin.a.yang@intel.com>
(cherry picked from commit a2cab751beed5d130c4085d4215f8b7ad25d9cb1)
-rw-r--r-- | src/mesa/main/texpal.c | 45 | ||||
-rw-r--r-- | src/mesa/main/texpal.h | 3 |
2 files changed, 35 insertions, 13 deletions
diff --git a/src/mesa/main/texpal.c b/src/mesa/main/texpal.c index b2112f957a2..7608087f43b 100644 --- a/src/mesa/main/texpal.c +++ b/src/mesa/main/texpal.c @@ -92,25 +92,23 @@ paletted_to_color(const struct cpal_format_info *info, const GLubyte *palette, } } - -static const struct cpal_format_info * -cpal_get_info(GLint level, GLenum internalFormat, - GLsizei width, GLsizei height, GLsizei imageSize) +unsigned +_mesa_cpal_compressed_size(int level, GLenum internalFormat, + unsigned width, unsigned height) { const struct cpal_format_info *info; - GLint lvl, num_levels; - GLsizei w, h, expect_size; + const int num_levels = -level + 1; + int lvl; + unsigned w, h, expect_size; + + if (internalFormat < GL_PALETTE4_RGB8_OES + || internalFormat > GL_PALETTE8_RGB5_A1_OES) { + return 0; + } info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; ASSERT(info->cpal_format == internalFormat); - if (level > 0) { - _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, - "glCompressedTexImage2D(level=%d)", level); - return NULL; - } - - num_levels = -level + 1; expect_size = info->palette_size * info->size; for (lvl = 0; lvl < num_levels; lvl++) { w = width >> lvl; @@ -125,6 +123,27 @@ cpal_get_info(GLint level, GLenum internalFormat, else expect_size += w * h; } + + return expect_size; +} + +static const struct cpal_format_info * +cpal_get_info(GLint level, GLenum internalFormat, + GLsizei width, GLsizei height, GLsizei imageSize) +{ + const struct cpal_format_info *info; + + info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; + ASSERT(info->cpal_format == internalFormat); + + if (level > 0) { + _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, + "glCompressedTexImage2D(level=%d)", level); + return NULL; + } + + expect_size = _mesa_cpal_compressed_size(level, internalFormat, + width, height); if (expect_size > imageSize) { _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, "glCompressedTexImage2D(imageSize=%d)", imageSize); diff --git a/src/mesa/main/texpal.h b/src/mesa/main/texpal.h index eeff5a9e24c..e1809995468 100644 --- a/src/mesa/main/texpal.h +++ b/src/mesa/main/texpal.h @@ -34,5 +34,8 @@ _mesa_cpal_compressed_teximage2d(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei imageSize, const void *palette); +extern unsigned +_mesa_cpal_compressed_size(int level, GLenum internalFormat, + unsigned width, unsigned height); #endif /* TEXPAL_H */ |