[Mesa-dev] [PATCH 02/22] mesa: Add decoding functions for GL_COMPRESSED_RGB8_ETC2

Brian Paul brianp at vmware.com
Mon Nov 12 07:44:13 PST 2012


On 11/10/2012 12:29 AM, Anuj Phogat wrote:
> v2: Use CLAMP macro and stdbool.h
> Signed-off-by: Anuj Phogat<anuj.phogat at gmail.com>
> ---
>   src/mesa/main/texcompress_etc.c |  460 ++++++++++++++++++++++++++++++++++++++-
>   src/mesa/main/texcompress_etc.h |   16 ++-
>   2 files changed, 466 insertions(+), 10 deletions(-)
>
> diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
> index c645f52..bf43edb 100644
> --- a/src/mesa/main/texcompress_etc.c
> +++ b/src/mesa/main/texcompress_etc.c
> @@ -24,9 +24,11 @@
>   /**
>    * \file texcompress_etc.c
>    * GL_OES_compressed_ETC1_RGB8_texture support.
> + * Supported ETC2 texture formats are:
> + * GL_COMPRESSED_RGB8_ETC2
>    */
>
> -
> +#include<stdbool.h>
>   #include "mfeatures.h"
>   #include "texcompress.h"
>   #include "texcompress_etc.h"
> @@ -34,14 +36,22 @@
>   #include "macros.h"
>   #include "swrast/s_context.h"
>
> -GLboolean
> -_mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS)
> -{
> -   /* GL_ETC1_RGB8_OES is only valid in glCompressedTexImage2D */
> -   ASSERT(0);
> +struct etc2_block {
> +   int flipped;

bool?  Maybe add a comment indicating what flipped is for.


> +   int distance;
> +   uint32_t pixel_indices;
> +   const int *modifier_tables[2];
> +   GLboolean is_ind_mode;
> +   GLboolean is_diff_mode;
> +   GLboolean is_t_mode;
> +   GLboolean is_h_mode;
> +   GLboolean is_planar_mode;

probably s/GLboolean/bool/

> +   GLubyte base_colors[3][3];
> +   GLubyte paint_colors[4][3];
> +};

Some of the code using GLubyte, and some uses uint8_t.  Do you think 
it would be better to use just one or the other?


[...]

> +static void
> +etc2_rgb8_parse_block(struct etc2_block *block, const GLubyte *src)
> +{
> +   unsigned i;
> +   GLboolean diffbit = src[3]&  0x2;
> +   static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
> +
> +   const int R_plus_dR = (src[0]>>  3) + lookup[src[0]&  0x7];
> +   const int G_plus_dG = (src[1]>>  3) + lookup[src[1]&  0x7];
> +   const int B_plus_dB = (src[2]>>  3) + lookup[src[2]&  0x7];
> +
> +   /* Reset the mode flags */
> +   block->is_ind_mode = false;
> +   block->is_diff_mode = false;
> +   block->is_t_mode = false;
> +   block->is_h_mode = false;
> +   block->is_planar_mode = false;
> +
> +   if (!diffbit) {
> +      /* individual mode */
> +      block->is_ind_mode = true;
> +
> +      for (i = 0; i<  3; i++) {
> +         /* Texture decode algorithm is same for individual mode in etc1
> +          *&  etc2.
> +          */
> +         block->base_colors[0][i] = etc1_base_color_ind_hi(src[i]);
> +         block->base_colors[1][i] = etc1_base_color_ind_lo(src[i]);
> +      }
> +   }
> +   else if (R_plus_dR<  0 || R_plus_dR>  31){
> +      /* T mode */
> +      block->is_t_mode = true;
> +
> +      for(i = 0; i<  3; i++) {
> +         block->base_colors[0][i] = etc2_base_color1_t_mode(src, i);
> +         block->base_colors[1][i] = etc2_base_color2_t_mode(src, i);
> +      }
> +      /* pick distance */
> +      block->distance =
> +         etc2_distance_table[(((src[3]>>  2)&  0x3)<<  1) |
> +	                     (src[3]&  0x1)];
> +
> +      for (i = 0; i<  3; i++) {
> +         block->paint_colors[0][i] = etc2_clamp(block->base_colors[0][i]);
> +         block->paint_colors[1][i] = etc2_clamp(block->base_colors[1][i] +
> +                                                block->distance);
> +         block->paint_colors[2][i] = etc2_clamp(block->base_colors[1][i]);
> +         block->paint_colors[3][i] = etc2_clamp(block->base_colors[1][i] -
> +                                                block->distance);
> +      }
> +   }
> +   else if (G_plus_dG<  0 || G_plus_dG>  31){
> +      /* H mode */
> +      block->is_h_mode = true;
> +      int base_color_1_value, base_color_2_value;
> +
> +      for(i = 0; i<  3; i++) {
> +         block->base_colors[0][i] = etc2_base_color1_h_mode(src, i);
> +         block->base_colors[1][i] = etc2_base_color2_h_mode(src, i);
> +      }
> +
> +      base_color_1_value = (block->base_colors[0][0]<<  16) +
> +                           (block->base_colors[0][1]<<  8) +
> +			   block->base_colors[0][2];
> +      base_color_2_value = (block->base_colors[1][0]<<  16) +
> +                           (block->base_colors[1][1]<<  8) +
> +			   block->base_colors[1][2];
> +      /* pick distance */
> +      block->distance =
> +         etc2_distance_table[(src[3]&  0x4) |
> +	                     ((src[3]&  0x1)<<  1) |
> +			     (base_color_1_value>= base_color_2_value)];
> +
> +      for (i = 0; i<  3; i++) {
> +         block->paint_colors[0][i] = etc2_clamp(block->base_colors[0][i] +
> +                                                block->distance);
> +         block->paint_colors[1][i] = etc2_clamp(block->base_colors[0][i] -
> +                                                block->distance);
> +         block->paint_colors[2][i] = etc2_clamp(block->base_colors[1][i] +
> +                                                block->distance);
> +         block->paint_colors[3][i] = etc2_clamp(block->base_colors[1][i] -
> +                                                block->distance);
> +      }
> +   }
> +   else if (B_plus_dB<  0 || B_plus_dB>  31){
> +      /* Planar mode */
> +      block->is_planar_mode = true;
> +
> +      for (i = 0; i<  3; i++) {
> +         block->base_colors[0][i] = etc2_base_color_o_planar(src, i);
> +         block->base_colors[1][i] = etc2_base_color_h_planar(src, i);
> +         block->base_colors[2][i] = etc2_base_color_v_planar(src, i);
> +      }
> +   }
> +   else if (diffbit) {
> +      /* differential mode */
> +      block->is_diff_mode = true;
> +
> +      for (i = 0; i<  3; i++) {
> +         /* Texture decode algorithm is same for differential mode in etc1
> +          *&  etc2.
> +          */
> +         block->base_colors[0][i] = etc1_base_color_diff_hi(src[i]);
> +         block->base_colors[1][i] = etc1_base_color_diff_lo(src[i]);
> +     }
> +   }
> +
> +   if(block->is_ind_mode || block->is_diff_mode) {

space after if.


-Brian


More information about the mesa-dev mailing list