CPVRTextureHeader.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /******************************************************************************
  2. @File CPVRTextureHeader.h
  3. @Title Console Log
  4. @Version @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI
  7. @Description Class to represent header information of a pvr texture file.
  8. Typically associated with a CPVRTextureData instance or part of a
  9. CPVRTexture instance
  10. ******************************************************************************/
  11. #ifndef CPVRTEXTUREHEADER_H
  12. #define CPVRTEXTUREHEADER_H
  13. #include <stdio.h>
  14. #include "PVRTexLibGlobals.h"
  15. struct PVR_Texture_Header;
  16. namespace pvrtexlib
  17. {
  18. #ifdef __APPLE__
  19. /* The classes below are exported */
  20. #pragma GCC visibility push(default)
  21. #endif
  22. class PVR_DLL PVRTextureUtilities;
  23. class PVR_DLL CPVRTextureHeader
  24. {
  25. public:
  26. /*******************************************************************************
  27. * Constructor
  28. * Description : Blank constructor that allows the creation of a
  29. * valid but blank CPVRHeader
  30. *******************************************************************************/
  31. CPVRTextureHeader();
  32. /*******************************************************************************
  33. * Constructor
  34. * In
  35. : u32Width : width of topmost image in pixels
  36. : u32Height : height of topmost image
  37. : u32MipMapCount : count of MIP-map levels
  38. : u32NumSurfaces : number of surfaces present in texture
  39. : bBorder : does the texture have an added border (se PVRTC compression documentation)
  40. : bTwiddled : is the texture twiddled (use morton order)
  41. : bCubeMap : is the texture a cube map
  42. : bVolume : is the texture a volume texture (little support right now)
  43. : bFalseMips : are false-coloured MIP-map levels encoded
  44. : ePixelType : which pixel format is used for the data
  45. : fNormalMap : multiplier when used in normal map creation for this texture.
  46. : 0.0f implies that this is not a normal map texture
  47. * Description : Manual constructor that allows the creation of a CPVRHeader
  48. *******************************************************************************/
  49. CPVRTextureHeader(
  50. const unsigned int u32Width,
  51. const unsigned int u32Height,
  52. const unsigned int u32MipMapCount,
  53. const unsigned int u32NumSurfaces,
  54. const bool bBorder,
  55. const bool bTwiddled,
  56. const bool bCubeMap,
  57. const bool bVolume,
  58. const bool bFalseMips,
  59. const bool bAlpha,
  60. const bool bFlipped,
  61. const PixelType ePixelType,
  62. const float fNormalMap);
  63. /*******************************************************************************
  64. * Constructor
  65. * In
  66. : u32Width : width of topmost image in pixels
  67. : u32Height : height of topmost image
  68. : u32MipMapCount : count of MIP-map levels
  69. : u32NumSurfaces : number of surfaces present in texture
  70. : bBorder : does the texture have an added border (se PVRTC compression documentation)
  71. : bTwiddled : is the texture twiddled (use morton order)
  72. : bCubeMap : is the texture a cube map
  73. : bVolume : is the texture a volume texture (little support right now)
  74. : bFalseMips : are false-coloured MIP-map levels encoded
  75. : ePixelType : which pixel format is used for the data
  76. : fNormalMap : multiplier when used in normal map creation for this texture.
  77. : 0.0f implies that this is not a normal map texture
  78. * Description : Manual constructor that allows the creation of a CPVRHeader,
  79. : : similar to previous constructor but sets default values for
  80. : : tidier code!
  81. *******************************************************************************/
  82. CPVRTextureHeader(
  83. const unsigned int u32Width,
  84. const unsigned int u32Height,
  85. const unsigned int u32MipMapCount=0,
  86. const unsigned int u32NumSurfaces=1,
  87. const PixelType ePixelType=DX10_R8G8B8A8_UNORM,
  88. const float fNormalMap=0.0f,
  89. const bool bBorder=false,
  90. const bool bTwiddled=false,
  91. const bool bCubeMap=false,
  92. const bool bVolume=false,
  93. const bool bFalseMips=false,
  94. const bool bAlpha=false,
  95. const bool bFlipped=false);
  96. /*******************************************************************************
  97. * Constructor
  98. * In
  99. : fFile : open FILE pointer to PVR header data (beginning of a .pvr file)
  100. * Description : Reads a header from the passed FILE pointer leaving this
  101. * at the beginning of any data following the header.
  102. *******************************************************************************/
  103. CPVRTextureHeader(FILE *const fFile);
  104. /*******************************************************************************
  105. * Constructor
  106. * In
  107. : fFile : pointer to PVR header data (beginning of a .pvr file)
  108. * Description : Reads a header from the passed pointer.
  109. *******************************************************************************/
  110. CPVRTextureHeader(const uint8* const pPVRData);
  111. /*******************************************************************************
  112. * Accessor Methods for basic properties
  113. *******************************************************************************/
  114. unsigned int getWidth() const;
  115. void setWidth(unsigned int u32Width);
  116. unsigned int getHeight() const;
  117. void setHeight(unsigned int u32Height);
  118. unsigned int getMipWidth(const unsigned int u32MIPLevel) const;
  119. unsigned int getMipHeight(const unsigned int u32MIPLevel) const;
  120. void getDimensions(unsigned int& width, unsigned int& height) const;
  121. void setDimensions(const unsigned int u32Width, const unsigned int u32Height);
  122. unsigned int getMipMapCount() const;
  123. void setMipMapCount(unsigned int u32MipMapCount);
  124. PixelType getPixelType() const;
  125. void setPixelType(const PixelType ePixelType);
  126. unsigned int getNumSurfaces() const;
  127. void setNumSurfaces(unsigned int u32NumSurfaces);
  128. /*******************************************************************************
  129. * sets to the standard pixel type for the passed prcision mode
  130. *******************************************************************************/
  131. void setPixelType(const E_PRECMODE ePrecMode);
  132. /*******************************************************************************
  133. * Accessor Methods for preprocessing properties etc.
  134. *******************************************************************************/
  135. bool isBordered() const;
  136. void setBorder(bool bBorder);
  137. bool isTwiddled() const;
  138. void setTwiddled(bool bTwiddled);
  139. bool isCubeMap() const;
  140. void setCubeMap(bool bCubeMap);
  141. bool isVolume() const;
  142. void setVolume(const bool bVolume);
  143. float getNormalMap() const;
  144. void setNormalMap(const float fNormalMap);
  145. bool isNormalMap() const;
  146. bool hasMips() const;
  147. bool hasFalseMips() const;
  148. void setFalseMips(const bool bFalseMips);
  149. bool hasAlpha() const;
  150. void setAlpha(const bool bAlpha);
  151. void setFlipped(const bool bFlipped);
  152. bool isFlipped() const;
  153. /*******************************************************************************
  154. * Other Accessor Methods
  155. *******************************************************************************/
  156. unsigned int getOriginalVersionNumber(); // only relevant for files loaded from disk
  157. unsigned int getCurrentVersionNumber();
  158. /*******************************************************************************
  159. * Function Name : getSurfaceSize
  160. * Returns : size of an individual surface (including MIP-map levels)
  161. * described by the header in bytes
  162. *******************************************************************************/
  163. size_t getSurfaceSize() const;
  164. /*******************************************************************************
  165. * Function Name : getMIPSize
  166. * Returns : size of an individual surface (top level MIP-map only)
  167. * described by the header in bytes
  168. *******************************************************************************/
  169. size_t getMIPSize(unsigned int mipNumber) const;
  170. /*******************************************************************************
  171. * Function Name : getMIPSizeInPixels
  172. * Returns : size of an individual surface (top level MIP-map only)
  173. * described by the header in bytes
  174. *******************************************************************************/
  175. size_t getMIPSizeInPixels(unsigned int mipNumber) const;
  176. /*******************************************************************************
  177. * Function Name : getSurfaceSizeInPixels
  178. * Returns : the number of pixels described by a surface in this texture
  179. *******************************************************************************/
  180. unsigned int getSurfaceSizeInPixels() const;
  181. /*******************************************************************************
  182. * Function Name : getTotalTextureSize
  183. * Returns : sum of the size of all individual surfaces (including MIP-map
  184. * levels) described by the header
  185. *******************************************************************************/
  186. size_t getTotalTextureSize() const;
  187. /*******************************************************************************
  188. * Function Name : getFileHeaderSize
  189. * Returns : returns file size from original header version
  190. *******************************************************************************/
  191. size_t getFileHeaderSize();
  192. /*******************************************************************************
  193. * Function Name : getPrecMode
  194. * Returns : returns the precision mode of the pixel type of this header
  195. *******************************************************************************/
  196. E_PRECMODE getPrecMode() const;
  197. /*******************************************************************************
  198. * Function Name : isStandardFormat
  199. * Returns : returns the precision mode of the pixel type of this header
  200. *******************************************************************************/
  201. bool isStandardPixelType() const;
  202. /*******************************************************************************
  203. * Function Name : getBitsPerPixel
  204. * Returns : returns the number of bits of data per pixel required by the
  205. * pixel type of this header
  206. *******************************************************************************/
  207. unsigned int getBitsPerPixel() const;
  208. /*******************************************************************************
  209. * Function Name : hasSurfaceCompatibleWith
  210. * Returns : returns whether this header describes a texture with surfaces
  211. that are compatible for appending etc with the ones described
  212. in the passed header.
  213. *******************************************************************************/
  214. bool hasSurfaceCompatibleWith(const CPVRTextureHeader & sHeader) const;
  215. /*******************************************************************************
  216. * Function Name : writeToFile
  217. * Returns : writes this pvr header to the FILE* passed leaving the FILE
  218. pointer at the end of the header data. Returns the size
  219. of data written
  220. *******************************************************************************/
  221. size_t writeToFile(FILE* const fFile)const;
  222. /*******************************************************************************
  223. * Function Name : writeToPointer
  224. * Returns : writes this pvr header to the pointer passed. Returns the size
  225. of the data written
  226. *******************************************************************************/
  227. size_t writeToPointer(uint8 * const pPointer)const;
  228. /*******************************************************************************
  229. * Function Name : writeToIncludeFile
  230. * Returns : writes this pvr header to the FILE* passed leaving the FILE
  231. pointer at the end of the header data. Writes this as the
  232. beginning of a c++ compatible header file. Returns the size
  233. of data written
  234. *******************************************************************************/
  235. size_t writeToIncludeFile(FILE* const fFile)const;
  236. /* static utility functions */
  237. /*******************************************************************************
  238. * Function Name : getFileHeaderSize
  239. * Returns : returns file size from passed header version (if possible)
  240. * otherwise PVRTHROWs
  241. *******************************************************************************/
  242. static size_t getFileHeaderSize(int u32HeaderVersion);
  243. const static unsigned int u32CURRENT_VERSION = 2; // currentlt v2 of .pvr files is used
  244. private:
  245. unsigned int m_u32Height, m_u32Width, m_u32MipMapCount,m_u32NumSurfaces;
  246. unsigned int m_u32OriginalVersionNumber; // the file header version on the disk from which this class was constructed
  247. bool m_bTwiddled, m_bCubeMap, m_bVolume, m_bFalseMips, m_bBorder, m_bAlpha, m_bFlipped;
  248. PixelType m_ePixelType;
  249. float m_fNormalMap;
  250. void InitBlank();
  251. void InitFromPointer(const uint8* const pData);
  252. void DoBitMasks(PVR_Texture_Header *phPVR, bool bAlpha) const;
  253. };
  254. #ifdef __APPLE__
  255. #pragma GCC visibility pop
  256. #endif
  257. }
  258. #endif // CPVRTEXTUREHEADER_H
  259. /*****************************************************************************
  260. End of file (PVRTexture.h)
  261. *****************************************************************************/