CPVRTextureData.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /******************************************************************************
  2. @File CPVRTextureData.h
  3. @Title Console Log
  4. @Version @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI
  7. @Description Class to hold the data part of a PVR texture.
  8. ******************************************************************************/
  9. #ifndef CPVRTEXTUREDATA_H
  10. #define CPVRTEXTUREDATA_H
  11. #include <stdio.h>
  12. #include "PVRTexLibGlobals.h"
  13. #include "PVRTGlobal.h"
  14. #include "Pixel.h"
  15. namespace pvrtexlib
  16. {
  17. #ifdef __APPLE__
  18. /* The classes below are exported */
  19. #pragma GCC visibility push(default)
  20. #endif
  21. class PVR_DLL PVRTextureUtilities;
  22. class PVR_DLL CPVRTextureHeader;
  23. class PVR_DLL CPVRTextureData
  24. {
  25. public:
  26. // channel enums
  27. enum E_CHANNELS{
  28. CHAN_R=0,
  29. CHAN_G,
  30. CHAN_B,
  31. CHAN_A,
  32. CHAN_RGB,
  33. CHAN_ARGB,
  34. CHAN_MAXRGB,
  35. CHAN_MAXARGB,
  36. NUM_CHANNELS
  37. };
  38. /*******************************************************************************
  39. * Constructor
  40. * Description : Blank constructor that allows the creation of a
  41. * valid but empty CPVRTextureData instance
  42. *******************************************************************************/
  43. CPVRTextureData();
  44. /*******************************************************************************
  45. * Constructor
  46. * Description : Constructor that initialises an empty buffer to the size passed
  47. *******************************************************************************/
  48. CPVRTextureData(size_t stDataSize);
  49. /*******************************************************************************
  50. * Constructor
  51. * Description : Constructor initialised to the data and size of data passed
  52. *******************************************************************************/
  53. CPVRTextureData(uint8 *pTextureData, size_t stDataSize);
  54. /*******************************************************************************
  55. * Constructor
  56. * Description : Copy constructor
  57. *******************************************************************************/
  58. CPVRTextureData(const CPVRTextureData& original);
  59. /*******************************************************************************
  60. * Constructor
  61. * Description : Assignment operator
  62. *******************************************************************************/
  63. CPVRTextureData& operator=(const CPVRTextureData& sData);
  64. /*******************************************************************************
  65. * Destructor
  66. *******************************************************************************/
  67. ~CPVRTextureData();
  68. /*******************************************************************************
  69. * Function Name : getData
  70. * In/Outputs :
  71. * Description : returns pointer to the data buffer in this instance
  72. *******************************************************************************/
  73. uint8* getData() const;
  74. /*******************************************************************************
  75. * Function Name : getDataSize
  76. * In/Outputs :
  77. * Description : returns the recorded size of the data buffer in this instance
  78. *******************************************************************************/
  79. size_t getDataSize() const;
  80. /*******************************************************************************
  81. * Function Name : clear
  82. * In/Outputs :
  83. * Description : releases any data stored and sets size to 0
  84. *******************************************************************************/
  85. void clear();
  86. /*******************************************************************************
  87. * Function Name : ResizeBuffer
  88. * In/Outputs : stNewSize: new size for the buffer
  89. * Description : Resizes the buffer held by this texture. Copies across
  90. * existing data to the new buffer, truncating it if the new
  91. * buffer is smaller than the last.
  92. *******************************************************************************/
  93. void resizeBuffer(size_t stNewSize);
  94. /*******************************************************************************
  95. * Function Name : convertToPrecMode
  96. * Description : Converts the data held by the buffer to the new precision
  97. * expanding the buffer.
  98. * If the data is not a standard data type PVRTHROWS
  99. *******************************************************************************/
  100. void convertToPrecMode(const E_PRECMODE ePrecMode, CPVRTextureHeader& sHeader);
  101. /*******************************************************************************
  102. * Function Name : WriteToFile
  103. * Description : Writes the data in this instance to the passed file. Returns
  104. * the number of bytes written.
  105. *******************************************************************************/
  106. size_t writeToFile(FILE* const fFile)const;
  107. /*******************************************************************************
  108. * Function Name : writeToIncludeFile
  109. * Description : Writes the data in this instance to the passed file as a series
  110. * of unsigned integers compatible with a C++ header. Returns
  111. * the number of bytes written.
  112. *******************************************************************************/
  113. size_t writeToIncludeFile(FILE* const fFile)const;
  114. /*******************************************************************************
  115. * Function Name : append
  116. * Description : will append the data from newData to the existing data in this
  117. * CPVRTextureData instance. It may be wise to check if the
  118. * pixel types of these two instances match. PVRTHROWs if
  119. * unsuccessful.
  120. *******************************************************************************/
  121. void append(const CPVRTextureData& newData);
  122. /*******************************************************************************
  123. * Function Name : RGBToAlpha
  124. * Description : Dumps the maximum value of the RGB values in the current data
  125. into the alpha channel. Leaves the other channels untouched.
  126. Needs uint8 or PVRTHROWs
  127. *******************************************************************************/
  128. void maxRGBToAlpha( const unsigned int u32SourceSurfaceNum,
  129. const unsigned int u32DestSurfaceNum,
  130. const CPVRTextureHeader& psInputHeader,
  131. const CPVRTextureData& sAlphaData);
  132. /*******************************************************************************
  133. * Function Name : setChannel()
  134. * Description : Allows the data from a single channel in a single texture to
  135. be loaded into another texture.
  136. *******************************************************************************/
  137. void setChannel(
  138. const unsigned int eChannelTo,
  139. const unsigned int eChannelFrom,
  140. const CPVRTextureHeader& sOriginalHeader,
  141. const CPVRTextureHeader& sSourceHeader,
  142. const CPVRTextureData& sSourceData,
  143. const unsigned int u32SourceSurfaceNum=0,
  144. const unsigned int u32DestSurfaceNum=0,
  145. const int i32MipNum=-1);
  146. /*******************************************************************************
  147. * Function Name : setChannel()
  148. * Description : Allows a channel in this texture data to be blanket set to a value (0-255)
  149. *******************************************************************************/
  150. void setChannel(
  151. const unsigned int eChannelTo,
  152. const CPVRTextureHeader& sOriginalHeader,
  153. const unsigned int newValue=255,
  154. const unsigned int u32DestSurfaceNum=0,
  155. const int i32MipNum=-1);
  156. /*******************************************************************************
  157. * Function Name : SwapChannels
  158. * Description : Swaps the two specified channels.
  159. * Data should be in a standard format
  160. *******************************************************************************/
  161. template<class tType>
  162. void SwapChannels(const E_COLOUR_CHANNEL eChannelA, const E_COLOUR_CHANNEL eChannelB)
  163. {
  164. Pixel<tType>* pixelData = (Pixel<tType>*)m_pData;
  165. unsigned int numPixels = m_stDataSize/(4*sizeof(tType));
  166. for(unsigned int i=0 ; i < numPixels ;++i)
  167. {
  168. PVRTswap<tType>((*pixelData)[eChannelA],(*pixelData)[eChannelB]);
  169. ++pixelData;
  170. }
  171. }
  172. /*******************************************************************************
  173. * Function Name : ClearChannel
  174. * Description : Clears the specified channel to white
  175. *******************************************************************************/
  176. void ClearChannel(const CPVRTextureHeader& sHeader,const unsigned int u32Channel);
  177. private:
  178. template<class pType>
  179. void setChannelValBody(
  180. const unsigned int eChannelTo,
  181. const CPVRTextureHeader& sOriginalHeader,
  182. const unsigned int newValue,
  183. const unsigned int u32DestSurfaceNum,
  184. const int i32MipNum=-1);
  185. template<class pType>
  186. void setChannelBody(
  187. const unsigned int eChannelTo,
  188. const unsigned int eChannelFrom,
  189. const CPVRTextureHeader& sOriginalHeader,
  190. const CPVRTextureData& sNewData,
  191. const unsigned int u32SourceSurfaceNum,
  192. const unsigned int u32DestSurfaceNum,
  193. bool isCubeMap=false,
  194. const int i32MipNum=-1,
  195. bool MIPFromFile=false);
  196. uint8 *m_pData; // pointer to image data
  197. size_t m_stDataSize; // size of data in bytes
  198. };
  199. #ifdef __APPLE__
  200. #pragma GCC visibility pop
  201. #endif
  202. }
  203. #endif // CPVRTEXTUREDATA_H
  204. /*****************************************************************************
  205. End of file (CPVRTextureData.h)
  206. *****************************************************************************/