From: Brian Paul Date: Wed, 22 Aug 2012 02:22:27 +0000 (-0600) Subject: mesa: rename texpal.[ch] to texcompress_cpal.[ch] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c1a9e6010baceeff78f72ac0692aefc4312d815f;p=mesa.git mesa: rename texpal.[ch] to texcompress_cpal.[ch] To be consistent with other files related to texture compression. --- diff --git a/src/mesa/SConscript b/src/mesa/SConscript index 1b98b04c152..938eea5d606 100644 --- a/src/mesa/SConscript +++ b/src/mesa/SConscript @@ -116,6 +116,7 @@ main_sources = [ 'main/stencil.c', 'main/syncobj.c', 'main/texcompress.c', + 'main/texcompress_cpal.c', 'main/texcompress_rgtc.c', 'main/texcompress_s3tc.c', 'main/texcompress_fxt1.c', @@ -126,7 +127,6 @@ main_sources = [ 'main/texgetimage.c', 'main/teximage.c', 'main/texobj.c', - 'main/texpal.c', 'main/texparam.c', 'main/texstate.c', 'main/texstorage.c', diff --git a/src/mesa/main/texcompress_cpal.c b/src/mesa/main/texcompress_cpal.c new file mode 100644 index 00000000000..2398ded69f4 --- /dev/null +++ b/src/mesa/main/texcompress_cpal.c @@ -0,0 +1,231 @@ +/* + * Mesa 3-D graphics library + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * Code to convert compressed/paletted texture images to ordinary images. + * See the GL_OES_compressed_paletted_texture spec at + * http://khronos.org/registry/gles/extensions/OES/OES_compressed_paletted_texture.txt + * + * XXX this makes it impossible to add hardware support... + */ + + +#include "glheader.h" +#include "compiler.h" /* for ASSERT */ +#include "context.h" +#include "mfeatures.h" +#include "mtypes.h" +#include "imports.h" +#include "pixelstore.h" +#include "texcompress_cpal.h" +#include "teximage.h" + +#if FEATURE_ES + + +static const struct cpal_format_info { + GLenum cpal_format; + GLenum format; + GLenum type; + GLuint palette_size; + GLuint size; +} formats[] = { + { GL_PALETTE4_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 16, 3 }, + { GL_PALETTE4_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 16, 4 }, + { GL_PALETTE4_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, 2 }, + { GL_PALETTE4_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, 2 }, + { GL_PALETTE4_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, 2 }, + { GL_PALETTE8_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 256, 3 }, + { GL_PALETTE8_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 256, 4 }, + { GL_PALETTE8_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 256, 2 }, + { GL_PALETTE8_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 256, 2 }, + { GL_PALETTE8_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 256, 2 } +}; + + +/** + * Get a color/entry from the palette. + */ +static GLuint +get_palette_entry(const struct cpal_format_info *info, const GLubyte *palette, + GLuint index, GLubyte *pixel) +{ + memcpy(pixel, palette + info->size * index, info->size); + return info->size; +} + + +/** + * Convert paletted texture to color texture. + */ +static void +paletted_to_color(const struct cpal_format_info *info, const GLubyte *palette, + const void *indices, GLuint num_pixels, GLubyte *image) +{ + GLubyte *pix = image; + GLuint remain, i; + + if (info->palette_size == 16) { + /* 4 bits per index */ + const GLubyte *ind = (const GLubyte *) indices; + + /* two pixels per iteration */ + remain = num_pixels % 2; + for (i = 0; i < num_pixels / 2; i++) { + pix += get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); + pix += get_palette_entry(info, palette, ind[i] & 0xf, pix); + } + if (remain) { + get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); + } + } + else { + /* 8 bits per index */ + const GLubyte *ind = (const GLubyte *) indices; + for (i = 0; i < num_pixels; i++) + pix += get_palette_entry(info, palette, ind[i], pix); + } +} + +unsigned +_mesa_cpal_compressed_size(int level, GLenum internalFormat, + unsigned width, unsigned height) +{ + const struct cpal_format_info *info; + 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); + + expect_size = info->palette_size * info->size; + for (lvl = 0; lvl < num_levels; lvl++) { + w = width >> lvl; + if (!w) + w = 1; + h = height >> lvl; + if (!h) + h = 1; + + if (info->palette_size == 16) + expect_size += (w * h + 1) / 2; + else + expect_size += w * h; + } + + return expect_size; +} + +void +_mesa_cpal_compressed_format_type(GLenum internalFormat, GLenum *format, + GLenum *type) +{ + const struct cpal_format_info *info; + + if (internalFormat < GL_PALETTE4_RGB8_OES + || internalFormat > GL_PALETTE8_RGB5_A1_OES) { + return; + } + + info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; + *format = info->format; + *type = info->type; +} + +/** + * Convert a call to glCompressedTexImage2D() where internalFormat is a + * compressed palette format into a regular GLubyte/RGBA glTexImage2D() call. + */ +void +_mesa_cpal_compressed_teximage2d(GLenum target, GLint level, + GLenum internalFormat, + GLsizei width, GLsizei height, + GLsizei imageSize, const void *palette) +{ + const struct cpal_format_info *info; + GLint lvl, num_levels; + const GLubyte *indices; + GLint saved_align, align; + GET_CURRENT_CONTEXT(ctx); + + /* By this point, the internalFormat should have been validated. + */ + assert(internalFormat >= GL_PALETTE4_RGB8_OES + && internalFormat <= GL_PALETTE8_RGB5_A1_OES); + + info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; + + num_levels = -level + 1; + + /* first image follows the palette */ + indices = (const GLubyte *) palette + info->palette_size * info->size; + + saved_align = ctx->Unpack.Alignment; + align = saved_align; + + for (lvl = 0; lvl < num_levels; lvl++) { + GLsizei w, h; + GLuint num_texels; + GLubyte *image = NULL; + + w = width >> lvl; + if (!w) + w = 1; + h = height >> lvl; + if (!h) + h = 1; + num_texels = w * h; + if (w * info->size % align) { + _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, 1); + align = 1; + } + + /* allocate and fill dest image buffer */ + if (palette) { + image = (GLubyte *) malloc(num_texels * info->size); + paletted_to_color(info, palette, indices, num_texels, image); + } + + _mesa_TexImage2D(target, lvl, info->format, w, h, 0, + info->format, info->type, image); + if (image) + free(image); + + /* advance index pointer to point to next src mipmap */ + if (info->palette_size == 16) + indices += (num_texels + 1) / 2; + else + indices += num_texels; + } + + if (saved_align != align) + _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, saved_align); +} + +#endif diff --git a/src/mesa/main/texcompress_cpal.h b/src/mesa/main/texcompress_cpal.h new file mode 100644 index 00000000000..7507d5c1b65 --- /dev/null +++ b/src/mesa/main/texcompress_cpal.h @@ -0,0 +1,45 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 1999-2010 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef TEXCOMPRESS_CPAL_H +#define TEXCOMPRESS_CPAL_H + + +#include "main/glheader.h" +extern void +_mesa_cpal_compressed_teximage2d(GLenum target, GLint level, + GLenum internalFormat, + GLsizei width, GLsizei height, + GLsizei imageSize, const void *palette); + +extern unsigned +_mesa_cpal_compressed_size(int level, GLenum internalFormat, + unsigned width, unsigned height); + +extern void +_mesa_cpal_compressed_format_type(GLenum internalFormat, GLenum *format, + GLenum *type); + +#endif /* TEXCOMPRESS_CPAL_H */ diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index eff6fb7c6e8..be01fb9c4e1 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -42,10 +42,10 @@ #include "mfeatures.h" #include "state.h" #include "texcompress.h" +#include "texcompress_cpal.h" #include "teximage.h" #include "texobj.h" #include "texstate.h" -#include "texpal.h" #include "mtypes.h" #include "glformats.h" diff --git a/src/mesa/main/texpal.c b/src/mesa/main/texpal.c deleted file mode 100644 index ed2261b01cb..00000000000 --- a/src/mesa/main/texpal.c +++ /dev/null @@ -1,216 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - **************************************************************************/ - - -/** - * Code to convert compressed/paletted texture images to ordinary images. - * See the GL_OES_compressed_paletted_texture spec at - * http://khronos.org/registry/gles/extensions/OES/OES_compressed_paletted_texture.txt - * - * XXX this makes it impossible to add hardware support... - */ - - -#include "glheader.h" -#include "compiler.h" /* for ASSERT */ -#include "context.h" -#include "mfeatures.h" -#include "mtypes.h" -#include "imports.h" -#include "pixelstore.h" -#include "teximage.h" -#include "texpal.h" - -#if FEATURE_ES - - -static const struct cpal_format_info { - GLenum cpal_format; - GLenum format; - GLenum type; - GLuint palette_size; - GLuint size; -} formats[] = { - { GL_PALETTE4_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 16, 3 }, - { GL_PALETTE4_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 16, 4 }, - { GL_PALETTE4_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, 2 }, - { GL_PALETTE4_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, 2 }, - { GL_PALETTE4_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, 2 }, - { GL_PALETTE8_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 256, 3 }, - { GL_PALETTE8_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 256, 4 }, - { GL_PALETTE8_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 256, 2 }, - { GL_PALETTE8_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 256, 2 }, - { GL_PALETTE8_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 256, 2 } -}; - - -/** - * Get a color/entry from the palette. - */ -static GLuint -get_palette_entry(const struct cpal_format_info *info, const GLubyte *palette, - GLuint index, GLubyte *pixel) -{ - memcpy(pixel, palette + info->size * index, info->size); - return info->size; -} - - -/** - * Convert paletted texture to color texture. - */ -static void -paletted_to_color(const struct cpal_format_info *info, const GLubyte *palette, - const void *indices, GLuint num_pixels, GLubyte *image) -{ - GLubyte *pix = image; - GLuint remain, i; - - if (info->palette_size == 16) { - /* 4 bits per index */ - const GLubyte *ind = (const GLubyte *) indices; - - /* two pixels per iteration */ - remain = num_pixels % 2; - for (i = 0; i < num_pixels / 2; i++) { - pix += get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); - pix += get_palette_entry(info, palette, ind[i] & 0xf, pix); - } - if (remain) { - get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); - } - } - else { - /* 8 bits per index */ - const GLubyte *ind = (const GLubyte *) indices; - for (i = 0; i < num_pixels; i++) - pix += get_palette_entry(info, palette, ind[i], pix); - } -} - -unsigned -_mesa_cpal_compressed_size(int level, GLenum internalFormat, - unsigned width, unsigned height) -{ - const struct cpal_format_info *info; - 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); - - expect_size = info->palette_size * info->size; - for (lvl = 0; lvl < num_levels; lvl++) { - w = width >> lvl; - if (!w) - w = 1; - h = height >> lvl; - if (!h) - h = 1; - - if (info->palette_size == 16) - expect_size += (w * h + 1) / 2; - else - expect_size += w * h; - } - - return expect_size; -} - -void -_mesa_cpal_compressed_format_type(GLenum internalFormat, GLenum *format, - GLenum *type) -{ - const struct cpal_format_info *info; - - if (internalFormat < GL_PALETTE4_RGB8_OES - || internalFormat > GL_PALETTE8_RGB5_A1_OES) { - return; - } - - info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; - *format = info->format; - *type = info->type; -} - -/** - * Convert a call to glCompressedTexImage2D() where internalFormat is a - * compressed palette format into a regular GLubyte/RGBA glTexImage2D() call. - */ -void -_mesa_cpal_compressed_teximage2d(GLenum target, GLint level, - GLenum internalFormat, - GLsizei width, GLsizei height, - GLsizei imageSize, const void *palette) -{ - const struct cpal_format_info *info; - GLint lvl, num_levels; - const GLubyte *indices; - GLint saved_align, align; - GET_CURRENT_CONTEXT(ctx); - - /* By this point, the internalFormat should have been validated. - */ - assert(internalFormat >= GL_PALETTE4_RGB8_OES - && internalFormat <= GL_PALETTE8_RGB5_A1_OES); - - info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; - - num_levels = -level + 1; - - /* first image follows the palette */ - indices = (const GLubyte *) palette + info->palette_size * info->size; - - saved_align = ctx->Unpack.Alignment; - align = saved_align; - - for (lvl = 0; lvl < num_levels; lvl++) { - GLsizei w, h; - GLuint num_texels; - GLubyte *image = NULL; - - w = width >> lvl; - if (!w) - w = 1; - h = height >> lvl; - if (!h) - h = 1; - num_texels = w * h; - if (w * info->size % align) { - _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, 1); - align = 1; - } - - /* allocate and fill dest image buffer */ - if (palette) { - image = (GLubyte *) malloc(num_texels * info->size); - paletted_to_color(info, palette, indices, num_texels, image); - } - - _mesa_TexImage2D(target, lvl, info->format, w, h, 0, - info->format, info->type, image); - if (image) - free(image); - - /* advance index pointer to point to next src mipmap */ - if (info->palette_size == 16) - indices += (num_texels + 1) / 2; - else - indices += num_texels; - } - - if (saved_align != align) - _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, saved_align); -} - -#endif diff --git a/src/mesa/main/texpal.h b/src/mesa/main/texpal.h deleted file mode 100644 index acfaa313ec5..00000000000 --- a/src/mesa/main/texpal.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.8 - * - * Copyright (C) 1999-2010 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef TEXPAL_H -#define TEXPAL_H - - -#include "main/glheader.h" -extern void -_mesa_cpal_compressed_teximage2d(GLenum target, GLint level, - GLenum internalFormat, - GLsizei width, GLsizei height, - GLsizei imageSize, const void *palette); - -extern unsigned -_mesa_cpal_compressed_size(int level, GLenum internalFormat, - unsigned width, unsigned height); - -extern void -_mesa_cpal_compressed_format_type(GLenum internalFormat, GLenum *format, - GLenum *type); - -#endif /* TEXPAL_H */ diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak index ee260cbfd8f..dedeed998b1 100644 --- a/src/mesa/sources.mak +++ b/src/mesa/sources.mak @@ -85,6 +85,7 @@ MAIN_FILES = \ $(SRCDIR)main/stencil.c \ $(SRCDIR)main/syncobj.c \ $(SRCDIR)main/texcompress.c \ + $(SRCDIR)main/texcompress_cpal.c \ $(SRCDIR)main/texcompress_rgtc.c \ $(SRCDIR)main/texcompress_s3tc.c \ $(SRCDIR)main/texcompress_fxt1.c \ @@ -95,7 +96,6 @@ MAIN_FILES = \ $(SRCDIR)main/texgetimage.c \ $(SRCDIR)main/teximage.c \ $(SRCDIR)main/texobj.c \ - $(SRCDIR)main/texpal.c \ $(SRCDIR)main/texparam.c \ $(SRCDIR)main/texstate.c \ $(SRCDIR)main/texstorage.c \