You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

198 rivejä
6.1 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file texture.h
  35. * @brief Defines texture helper structures for the library
  36. *
  37. * Used for file formats which embed their textures into the model file.
  38. * Supported are both normal textures, which are stored as uncompressed
  39. * pixels, and "compressed" textures, which are stored in a file format
  40. * such as PNG or TGA.
  41. */
  42. #ifndef AI_TEXTURE_H_INC
  43. #define AI_TEXTURE_H_INC
  44. #include "types.h"
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. // --------------------------------------------------------------------------------
  49. /** @def AI_MAKE_EMBEDDED_TEXNAME
  50. * Used to build the reserved path name used by the material system to
  51. * reference textures that are embedded into their corresponding
  52. * model files. The parameter specifies the index of the texture
  53. * (zero-based, in the aiScene::mTextures array)
  54. */
  55. #if (!defined AI_MAKE_EMBEDDED_TEXNAME)
  56. # define AI_MAKE_EMBEDDED_TEXNAME(_n_) "*" # _n_
  57. #endif
  58. #include "./Compiler/pushpack1.h"
  59. // --------------------------------------------------------------------------------
  60. /** @brief Helper structure to represent a texel in a ARGB8888 format
  61. *
  62. * Used by aiTexture.
  63. */
  64. struct aiTexel
  65. {
  66. unsigned char b,g,r,a;
  67. #ifdef __cplusplus
  68. //! Comparison operator
  69. bool operator== (const aiTexel& other) const
  70. {
  71. return b == other.b && r == other.r &&
  72. g == other.g && a == other.a;
  73. }
  74. //! Inverse comparison operator
  75. bool operator!= (const aiTexel& other) const
  76. {
  77. return b != other.b || r != other.r ||
  78. g != other.g || a != other.a;
  79. }
  80. //! Conversion to a floating-point 4d color
  81. operator aiColor4D() const
  82. {
  83. return aiColor4D(r/255.f,g/255.f,b/255.f,a/255.f);
  84. }
  85. #endif // __cplusplus
  86. } PACK_STRUCT;
  87. #include "./Compiler/poppack1.h"
  88. // --------------------------------------------------------------------------------
  89. /** Helper structure to describe an embedded texture
  90. *
  91. * Normally textures are contained in external files but some file formats embed
  92. * them directly in the model file. There are two types of embedded textures:
  93. * 1. Uncompressed textures. The color data is given in an uncompressed format.
  94. * 2. Compressed textures stored in a file format like png or jpg. The raw file
  95. * bytes are given so the application must utilize an image decoder (e.g. DevIL) to
  96. * get access to the actual color data.
  97. */
  98. struct aiTexture
  99. {
  100. /** Width of the texture, in pixels
  101. *
  102. * If mHeight is zero the texture is compressed in a format
  103. * like JPEG. In this case mWidth specifies the size of the
  104. * memory area pcData is pointing to, in bytes.
  105. */
  106. unsigned int mWidth;
  107. /** Height of the texture, in pixels
  108. *
  109. * If this value is zero, pcData points to an compressed texture
  110. * in any format (e.g. JPEG).
  111. */
  112. unsigned int mHeight;
  113. /** A hint from the loader to make it easier for applications
  114. * to determine the type of embedded compressed textures.
  115. *
  116. * If mHeight != 0 this member is undefined. Otherwise it
  117. * is set set to '\\0\\0\\0\\0' if the loader has no additional
  118. * information about the texture file format used OR the
  119. * file extension of the format without a trailing dot. If there
  120. * are multiple file extensions for a format, the shortest
  121. * extension is chosen (JPEG maps to 'jpg', not to 'jpeg').
  122. * E.g. 'dds\\0', 'pcx\\0', 'jpg\\0'. All characters are lower-case.
  123. * The fourth character will always be '\\0'.
  124. */
  125. char achFormatHint[4];
  126. /** Data of the texture.
  127. *
  128. * Points to an array of mWidth * mHeight aiTexel's.
  129. * The format of the texture data is always ARGB8888 to
  130. * make the implementation for user of the library as easy
  131. * as possible. If mHeight = 0 this is a pointer to a memory
  132. * buffer of size mWidth containing the compressed texture
  133. * data. Good luck, have fun!
  134. */
  135. C_STRUCT aiTexel* pcData;
  136. #ifdef __cplusplus
  137. //! For compressed textures (mHeight == 0): compare the
  138. //! format hint against a given string.
  139. //! @param s Input string. 3 characters are maximally processed.
  140. //! Example values: "jpg", "png"
  141. //! @return true if the given string matches the format hint
  142. bool CheckFormat(const char* s) const
  143. {
  144. return (0 == ::strncmp(achFormatHint,s,3));
  145. }
  146. // Construction
  147. aiTexture ()
  148. : mWidth (0)
  149. , mHeight (0)
  150. , pcData (NULL)
  151. {
  152. achFormatHint[0] = achFormatHint[1] = 0;
  153. achFormatHint[2] = achFormatHint[3] = 0;
  154. }
  155. // Destruction
  156. ~aiTexture ()
  157. {
  158. delete[] pcData;
  159. }
  160. #endif
  161. };
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif // AI_TEXTURE_H_INC