PVRTextureUtilities.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*!***********************************************************************
  2. @file PVRTextureUtilities.h
  3. @copyright Copyright (c) Imagination Technologies Limited.
  4. @brief This is the main PVRTexLib header file. This header contains
  5. a utility function for transcoding textures, as well as
  6. pre-processor utilities such as; resizing, rotating, channel
  7. copying and MIPMap manipulation.
  8. *************************************************************************/
  9. #ifndef _PVRTEXTURE_UTILITIES_H
  10. #define _PVRTEXTURE_UTILITIES_H
  11. #include "PVRTextureFormat.h"
  12. #include "PVRTexture.h"
  13. namespace pvrtexture
  14. {
  15. /*!***********************************************************************
  16. @brief Resizes the texture to new specified dimensions. Filtering
  17. mode is specified with "eResizeMode".
  18. @param[in] sTexture Texture to resize
  19. @param[in] u32NewWidth New width
  20. @param[in] u32NewHeight New height
  21. @param[in] u32NewDepth New depth
  22. @param[in] eResizeMode Filtering mode
  23. @return True if the method succeeds.
  24. *************************************************************************/
  25. bool PVR_DLL Resize(CPVRTexture& sTexture, const uint32& u32NewWidth, const uint32& u32NewHeight, const uint32& u32NewDepth, const EResizeMode eResizeMode);
  26. /*!***********************************************************************
  27. @brief Resizes the canvas of a texture to new specified dimensions. Filtering
  28. mode is specified with "eResizeMode".
  29. @details Offset area is filled with transparent black colour.
  30. @param[in] sTexture Texture
  31. @param[in] u32NewWidth New width
  32. @param[in] u32NewHeight New height
  33. @param[in] u32NewDepth New depth
  34. @param[in] i32XOffset X Offset value from the top left corner
  35. @param[in] i32YOffset Y Offset value from the top left corner
  36. @param[in] i32ZOffset Z Offset value from the top left corner
  37. @return True if the method succeeds.
  38. *************************************************************************/
  39. bool PVR_DLL ResizeCanvas(CPVRTexture& sTexture, const uint32& u32NewWidth, const uint32& u32NewHeight, const uint32& u32NewDepth, const int32& i32XOffset, const int32& i32YOffset, const int32& i32ZOffset);
  40. /*!***********************************************************************
  41. @brief Rotates a texture by 90 degrees around the given axis. bForward controls direction of rotation.
  42. @param[in] sTexture Texture to rotate
  43. @param[in] eRotationAxis Rotation axis
  44. @param[in] bForward Direction of rotation; 1 = clockwise, 0 = anti-clockwise
  45. @return True if the method succeeds or not.
  46. *************************************************************************/
  47. bool PVR_DLL Rotate90(CPVRTexture& sTexture, const EPVRTAxis eRotationAxis, const bool bForward);
  48. /*!***********************************************************************
  49. @brief Flips a texture in a given direction.
  50. @param[in] sTexture Texture to flip
  51. @param[in] eFlipDirection Flip direction
  52. @return True if the method succeeds.
  53. *************************************************************************/
  54. bool PVR_DLL Flip(CPVRTexture& sTexture, const EPVRTAxis eFlipDirection);
  55. /*!***********************************************************************
  56. @brief Adds a user specified border to the texture.
  57. @param[in] sTexture Texture
  58. @param[in] uiBorderX X border
  59. @param[in] uiBorderY Y border
  60. @param[in] uiBorderZ Z border
  61. @return True if the method succeeds.
  62. *************************************************************************/
  63. bool PVR_DLL Border(CPVRTexture& sTexture, uint32 uiBorderX, uint32 uiBorderY, uint32 uiBorderZ);
  64. /*!***********************************************************************
  65. @brief Pre-multiplies a texture's colours by its alpha values.
  66. @param[in] sTexture Texture to premultiply
  67. @return True if the method succeeds.
  68. *************************************************************************/
  69. bool PVR_DLL PreMultiplyAlpha(CPVRTexture& sTexture);
  70. /*!***********************************************************************
  71. @brief Allows a texture's colours to run into any fully transparent areas.
  72. @param[in] sTexture Texture
  73. @return True if the method succeeds.
  74. *************************************************************************/
  75. bool PVR_DLL Bleed(CPVRTexture& sTexture);
  76. /*!***********************************************************************
  77. @brief Sets the specified number of channels to values specified in pValues.
  78. @param[in] sTexture Texture
  79. @param[in] uiNumChannelSets Number of channels to set
  80. @param[in] eChannels Channels to set
  81. @param[in] pValues uint32 values to set channels to
  82. @return True if the method succeeds.
  83. *************************************************************************/
  84. bool PVR_DLL SetChannels(CPVRTexture& sTexture, uint32 uiNumChannelSets, EChannelName *eChannels, uint32 *pValues);
  85. /*!***********************************************************************
  86. @brief Sets the specified number of channels to values specified in float pValues.
  87. @param[in] sTexture Texture
  88. @param[in] uiNumChannelSets Number of channels to set
  89. @param[in] eChannels Channels to set
  90. @param[in] pValues float values to set channels to
  91. @return True if the method succeeds.
  92. *************************************************************************/
  93. bool PVR_DLL SetChannelsFloat(CPVRTexture& sTexture, uint32 uiNumChannelSets, EChannelName *eChannels, float *pValues);
  94. /*!***********************************************************************
  95. @brief Copies the specified channels from sTextureSource into sTexture.
  96. @details sTextureSource is not modified so it is possible to use the
  97. same texture as both input and output. When using the same
  98. texture as source and destination, channels are preserved
  99. between swaps (e.g. copying Red to Green and then Green to Red
  100. will result in the two channels trading places correctly).
  101. Channels in eChannels are set to the value of the channels
  102. in eChannelSource.
  103. @param[in] sTexture Destination texture to copy channels to
  104. @param[in] sTextureSource Source texture to copy channels from
  105. @param[in] uiNumChannelCopies Number of channels to copy
  106. @param[in] eChannels Channels to set
  107. @param[in] eChannelsSource Source channels to copy from
  108. @return True if the method succeeds.
  109. *************************************************************************/
  110. bool PVR_DLL CopyChannels(CPVRTexture& sTexture, const CPVRTexture& sTextureSource, uint32 uiNumChannelCopies, EChannelName *eChannels, EChannelName *eChannelsSource);
  111. /*!***********************************************************************
  112. @brief Generates a Normal Map from a given height map.
  113. @details Assumes the red channel has the height values.
  114. By default outputs to red/green/blue = x/y/z,
  115. this can be overridden by specifying a channel
  116. order in sChannelOrder. The channels specified
  117. will output to red/green/blue/alpha in that order.
  118. So "xyzh" maps x to red, y to green, z to blue
  119. and h to alpha. 'h' is used to specify that the
  120. original height map data should be preserved in
  121. the given channel.
  122. @param[in] sTexture Texture
  123. @param[in] fScale Scale factor
  124. @param[in] sChannelOrder Channel order
  125. @return True if the method succeeds.
  126. *************************************************************************/
  127. bool PVR_DLL GenerateNormalMap(CPVRTexture& sTexture, const float fScale, CPVRTString sChannelOrder);
  128. /*!***********************************************************************
  129. @brief Generates MIPMaps for a source texture. Default is to
  130. create a complete MIPMap chain, however this can be
  131. overridden with uiMIPMapsToDo.
  132. @param[in] sTexture Texture
  133. @param[in] eFilterMode Filter mode
  134. @param[in] uiMIPMapsToDo Level of MIPMap chain to create
  135. @return True if the method succeeds.
  136. *************************************************************************/
  137. bool PVR_DLL GenerateMIPMaps(CPVRTexture& sTexture, const EResizeMode eFilterMode, const uint32 uiMIPMapsToDo=PVRTEX_ALLMIPLEVELS);
  138. /*!***********************************************************************
  139. @brief Colours a texture's MIPMap levels with artificial colours
  140. for debugging. MIP levels are coloured in the following order:
  141. Red, Green, Blue, Cyan, Magenta and Yellow
  142. in a repeating pattern.
  143. @param[in] sTexture Texture
  144. @return True if the method succeeds.
  145. *************************************************************************/
  146. bool PVR_DLL ColourMIPMaps(CPVRTexture& sTexture);
  147. /*!***********************************************************************
  148. @brief Transcodes a texture from its original format into a newly specified format.
  149. Will either quantise or dither to lower precisions based on bDoDither.
  150. uiQuality specifies the quality for PVRTC and ETC compression.
  151. @param[in] sTexture Texture
  152. @param[in] ptFormat Pixel format type
  153. @param[in] eChannelType Channel type
  154. @param[in] eColourspace Colour space
  155. @param[in] eQuality Quality for PVRTC and ETC compression
  156. @param[in] bDoDither Dither the texture to lower precisions
  157. @return True if the method succeeds.
  158. *************************************************************************/
  159. bool PVR_DLL Transcode(CPVRTexture& sTexture, const PixelType ptFormat, const EPVRTVariableType eChannelType, const EPVRTColourSpace eColourspace, const ECompressorQuality eQuality=ePVRTCNormal, const bool bDoDither=false);
  160. };
  161. #endif //_PVRTEXTURE_UTILTIES_H