texture.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, 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. #pragma once
  43. #ifndef AI_TEXTURE_H_INC
  44. #define AI_TEXTURE_H_INC
  45. #ifdef __GNUC__
  46. # pragma GCC system_header
  47. #endif
  48. #include <assimp/types.h>
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. // --------------------------------------------------------------------------------
  53. /** \def AI_EMBEDDED_TEXNAME_PREFIX
  54. * \ref AI_MAKE_EMBEDDED_TEXNAME
  55. */
  56. #ifndef AI_EMBEDDED_TEXNAME_PREFIX
  57. # define AI_EMBEDDED_TEXNAME_PREFIX "*"
  58. #endif
  59. /** @def AI_MAKE_EMBEDDED_TEXNAME
  60. * Used to build the reserved path name used by the material system to
  61. * reference textures that are embedded into their corresponding
  62. * model files. The parameter specifies the index of the texture
  63. * (zero-based, in the aiScene::mTextures array)
  64. */
  65. #if (!defined AI_MAKE_EMBEDDED_TEXNAME)
  66. # define AI_MAKE_EMBEDDED_TEXNAME(_n_) AI_EMBEDDED_TEXNAME_PREFIX # _n_
  67. #endif
  68. #include "./Compiler/pushpack1.h"
  69. // --------------------------------------------------------------------------------
  70. /** @brief Helper structure to represent a texel in a ARGB8888 format
  71. *
  72. * Used by aiTexture.
  73. */
  74. struct aiTexel {
  75. unsigned char b,g,r,a;
  76. #ifdef __cplusplus
  77. //! Comparison operator
  78. bool operator== (const aiTexel& other) const {
  79. return b == other.b && r == other.r &&
  80. g == other.g && a == other.a;
  81. }
  82. //! Inverse comparison operator
  83. bool operator!= (const aiTexel& other) const {
  84. return b != other.b || r != other.r ||
  85. g != other.g || a != other.a;
  86. }
  87. //! Conversion to a floating-point 4d color
  88. operator aiColor4D() const {
  89. return aiColor4D(r/255.f,g/255.f,b/255.f,a/255.f);
  90. }
  91. #endif // __cplusplus
  92. } PACK_STRUCT;
  93. #include "./Compiler/poppack1.h"
  94. #define HINTMAXTEXTURELEN 9
  95. // --------------------------------------------------------------------------------
  96. /** Helper structure to describe an embedded texture
  97. *
  98. * Normally textures are contained in external files but some file formats embed
  99. * them directly in the model file. There are two types of embedded textures:
  100. * 1. Uncompressed textures. The color data is given in an uncompressed format.
  101. * 2. Compressed textures stored in a file format like png or jpg. The raw file
  102. * bytes are given so the application must utilize an image decoder (e.g. DevIL) to
  103. * get access to the actual color data.
  104. *
  105. * Embedded textures are referenced from materials using strings like "*0", "*1", etc.
  106. * as the texture paths (a single asterisk character followed by the
  107. * zero-based index of the texture in the aiScene::mTextures array).
  108. */
  109. struct aiTexture {
  110. /** Width of the texture, in pixels
  111. *
  112. * If mHeight is zero the texture is compressed in a format
  113. * like JPEG. In this case mWidth specifies the size of the
  114. * memory area pcData is pointing to, in bytes.
  115. */
  116. unsigned int mWidth;
  117. /** Height of the texture, in pixels
  118. *
  119. * If this value is zero, pcData points to an compressed texture
  120. * in any format (e.g. JPEG).
  121. */
  122. unsigned int mHeight;
  123. /** A hint from the loader to make it easier for applications
  124. * to determine the type of embedded textures.
  125. *
  126. * If mHeight != 0 this member is show how data is packed. Hint will consist of
  127. * two parts: channel order and channel bitness (count of the bits for every
  128. * color channel). For simple parsing by the viewer it's better to not omit
  129. * absent color channel and just use 0 for bitness. For example:
  130. * 1. Image contain RGBA and 8 bit per channel, achFormatHint == "rgba8888";
  131. * 2. Image contain ARGB and 8 bit per channel, achFormatHint == "argb8888";
  132. * 3. Image contain RGB and 5 bit for R and B channels and 6 bit for G channel, achFormatHint == "rgba5650";
  133. * 4. One color image with B channel and 1 bit for it, achFormatHint == "rgba0010";
  134. * If mHeight == 0 then achFormatHint is set set to '\\0\\0\\0\\0' if the loader has no additional
  135. * information about the texture file format used OR the
  136. * file extension of the format without a trailing dot. If there
  137. * are multiple file extensions for a format, the shortest
  138. * extension is chosen (JPEG maps to 'jpg', not to 'jpeg').
  139. * E.g. 'dds\\0', 'pcx\\0', 'jpg\\0'. All characters are lower-case.
  140. * The fourth character will always be '\\0'.
  141. */
  142. char achFormatHint[ HINTMAXTEXTURELEN ];// 8 for string + 1 for terminator.
  143. /** Data of the texture.
  144. *
  145. * Points to an array of mWidth * mHeight aiTexel's.
  146. * The format of the texture data shall always be ARGB8888 if the texture-hint of the type is empty.
  147. * If the hint is not empty you can interpret the format by looking into this hint.
  148. * make the implementation for user of the library as easy
  149. * as possible. If mHeight = 0 this is a pointer to a memory
  150. * buffer of size mWidth containing the compressed texture
  151. * data. Good luck, have fun!
  152. */
  153. C_STRUCT aiTexel* pcData;
  154. /** Texture original filename
  155. *
  156. * Used to get the texture reference
  157. */
  158. C_STRUCT aiString mFilename;
  159. #ifdef __cplusplus
  160. //! For compressed textures (mHeight == 0): compare the
  161. //! format hint against a given string.
  162. //! @param s Input string. 3 characters are maximally processed.
  163. //! Example values: "jpg", "png"
  164. //! @return true if the given string matches the format hint
  165. bool CheckFormat(const char* s) const {
  166. if (nullptr == s) {
  167. return false;
  168. }
  169. return (0 == ::strncmp(achFormatHint, s, sizeof(achFormatHint)));
  170. }
  171. // Construction
  172. aiTexture() AI_NO_EXCEPT :
  173. mWidth(0),
  174. mHeight(0),
  175. pcData(nullptr),
  176. mFilename() {
  177. memset(achFormatHint, 0, sizeof(achFormatHint));
  178. }
  179. // Destruction
  180. ~aiTexture () {
  181. delete[] pcData;
  182. }
  183. #endif
  184. };
  185. #ifdef __cplusplus
  186. }
  187. #endif
  188. #endif // AI_TEXTURE_H_INC