Home | History | Annotate | Download | only in common
      1 #ifndef _TCUCOMPRESSEDTEXTURE_HPP
      2 #define _TCUCOMPRESSEDTEXTURE_HPP
      3 /*-------------------------------------------------------------------------
      4  * drawElements Quality Program Tester Core
      5  * ----------------------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief Compressed Texture Utilities.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "tcuDefs.hpp"
     27 #include "tcuTexture.hpp"
     28 
     29 #include <vector>
     30 
     31 namespace tcu
     32 {
     33 
     34 /*--------------------------------------------------------------------*//*!
     35  * \brief Compressed texture
     36  *
     37  * This class implements container for common compressed texture formats.
     38  * Reference decoding to uncompressed formats is supported.
     39  *//*--------------------------------------------------------------------*/
     40 class CompressedTexture
     41 {
     42 public:
     43 	enum Format
     44 	{
     45 		ETC1_RGB8 = 0,
     46 		EAC_R11,
     47 		EAC_SIGNED_R11,
     48 		EAC_RG11,
     49 		EAC_SIGNED_RG11,
     50 		ETC2_RGB8,
     51 		ETC2_SRGB8,
     52 		ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
     53 		ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
     54 		ETC2_EAC_RGBA8,
     55 		ETC2_EAC_SRGB8_ALPHA8,
     56 
     57 		ASTC_4x4_RGBA,
     58 		ASTC_5x4_RGBA,
     59 		ASTC_5x5_RGBA,
     60 		ASTC_6x5_RGBA,
     61 		ASTC_6x6_RGBA,
     62 		ASTC_8x5_RGBA,
     63 		ASTC_8x6_RGBA,
     64 		ASTC_8x8_RGBA,
     65 		ASTC_10x5_RGBA,
     66 		ASTC_10x6_RGBA,
     67 		ASTC_10x8_RGBA,
     68 		ASTC_10x10_RGBA,
     69 		ASTC_12x10_RGBA,
     70 		ASTC_12x12_RGBA,
     71 		ASTC_4x4_SRGB8_ALPHA8,
     72 		ASTC_5x4_SRGB8_ALPHA8,
     73 		ASTC_5x5_SRGB8_ALPHA8,
     74 		ASTC_6x5_SRGB8_ALPHA8,
     75 		ASTC_6x6_SRGB8_ALPHA8,
     76 		ASTC_8x5_SRGB8_ALPHA8,
     77 		ASTC_8x6_SRGB8_ALPHA8,
     78 		ASTC_8x8_SRGB8_ALPHA8,
     79 		ASTC_10x5_SRGB8_ALPHA8,
     80 		ASTC_10x6_SRGB8_ALPHA8,
     81 		ASTC_10x8_SRGB8_ALPHA8,
     82 		ASTC_10x10_SRGB8_ALPHA8,
     83 		ASTC_12x10_SRGB8_ALPHA8,
     84 		ASTC_12x12_SRGB8_ALPHA8,
     85 
     86 		FORMAT_LAST
     87 	};
     88 
     89 	struct DecompressionParams
     90 	{
     91 		bool isASTCModeLDR; //!< \note Ignored if not ASTC format.
     92 
     93 		DecompressionParams (bool isASTCModeLDR_) : isASTCModeLDR(isASTCModeLDR_) {}
     94 	};
     95 
     96 
     97 							CompressedTexture			(Format format, int width, int height, int depth = 1);
     98 							CompressedTexture			(void);
     99 							~CompressedTexture			(void);
    100 
    101 	void					setStorage					(Format format, int width, int height, int depth = 1);
    102 
    103 	int						getWidth					(void) const	{ return m_width;				}
    104 	int						getHeight					(void) const	{ return m_height;				}
    105 	Format					getFormat					(void) const	{ return m_format;				}
    106 	int						getDataSize					(void) const	{ return (int)m_data.size();	}
    107 	const void*				getData						(void) const	{ return &m_data[0];			}
    108 	void*					getData						(void)			{ return &m_data[0];			}
    109 
    110 	TextureFormat			getUncompressedFormat		(void) const;
    111 	void					decompress					(const PixelBufferAccess& dst, const DecompressionParams& params = DecompressionParams(false)) const;
    112 
    113 private:
    114 	Format					m_format;
    115 	int						m_width;
    116 	int						m_height;
    117 	int						m_depth;
    118 	std::vector<deUint8>	m_data;
    119 };
    120 
    121 bool						isEtcFormat					(CompressedTexture::Format fmt);
    122 bool						isASTCFormat				(CompressedTexture::Format fmt);
    123 bool						isASTCSRGBFormat			(CompressedTexture::Format fmt);
    124 
    125 IVec3						getASTCBlockSize			(CompressedTexture::Format fmt);
    126 CompressedTexture::Format	getASTCFormatByBlockSize	(int width, int height, int depth, bool isSRGB);
    127 
    128 } // tcu
    129 
    130 #endif // _TCUCOMPRESSEDTEXTURE_HPP
    131