texture.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2017, 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. #include "types.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. // --------------------------------------------------------------------------------
  50. /** \def AI_EMBEDDED_TEXNAME_PREFIX
  51. * \ref AI_MAKE_EMBEDDED_TEXNAME
  52. */
  53. #ifndef AI_EMBEDDED_TEXNAME_PREFIX
  54. # define AI_EMBEDDED_TEXNAME_PREFIX "*"
  55. #endif
  56. /** @def AI_MAKE_EMBEDDED_TEXNAME
  57. * Used to build the reserved path name used by the material system to
  58. * reference textures that are embedded into their corresponding
  59. * model files. The parameter specifies the index of the texture
  60. * (zero-based, in the aiScene::mTextures array)
  61. */
  62. #if (!defined AI_MAKE_EMBEDDED_TEXNAME)
  63. # define AI_MAKE_EMBEDDED_TEXNAME(_n_) AI_EMBEDDED_TEXNAME_PREFIX # _n_
  64. #endif
  65. #include "./Compiler/pushpack1.h"
  66. // --------------------------------------------------------------------------------
  67. /** @brief Helper structure to represent a texel in a ARGB8888 format
  68. *
  69. * Used by aiTexture.
  70. */
  71. struct aiTexel
  72. {
  73. unsigned char b,g,r,a;
  74. #ifdef __cplusplus
  75. //! Comparison operator
  76. bool operator== (const aiTexel& other) const
  77. {
  78. return b == other.b && r == other.r &&
  79. g == other.g && a == other.a;
  80. }
  81. //! Inverse comparison operator
  82. bool operator!= (const aiTexel& other) const
  83. {
  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. {
  90. return aiColor4D(r/255.f,g/255.f,b/255.f,a/255.f);
  91. }
  92. #endif // __cplusplus
  93. } PACK_STRUCT;
  94. #include "./Compiler/poppack1.h"
  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. {
  111. /** Width of the texture, in pixels
  112. *
  113. * If mHeight is zero the texture is compressed in a format
  114. * like JPEG. In this case mWidth specifies the size of the
  115. * memory area pcData is pointing to, in bytes.
  116. */
  117. unsigned int mWidth;
  118. /** Height of the texture, in pixels
  119. *
  120. * If this value is zero, pcData points to an compressed texture
  121. * in any format (e.g. JPEG).
  122. */
  123. unsigned int mHeight;
  124. /** A hint from the loader to make it easier for applications
  125. * to determine the type of embedded textures.
  126. *
  127. * If mHeight != 0 this member is show how data is packed. Hint will consist of
  128. * two parts: channel order and channel bitness (count of the bits for every
  129. * color channel). For simple parsing by the viewer it's better to not omit
  130. * absent color channel and just use 0 for bitness. For example:
  131. * 1. Image contain RGBA and 8 bit per channel, achFormatHint == "rgba8888";
  132. * 2. Image contain ARGB and 8 bit per channel, achFormatHint == "argb8888";
  133. * 3. Image contain RGB and 5 bit for R and B channels and 6 bit for G channel, achFormatHint == "rgba5650";
  134. * 4. One color image with B channel and 1 bit for it, achFormatHint == "rgba0010";
  135. * If mHeight == 0 then achFormatHint is set set to '\\0\\0\\0\\0' if the loader has no additional
  136. * information about the texture file format used OR the
  137. * file extension of the format without a trailing dot. If there
  138. * are multiple file extensions for a format, the shortest
  139. * extension is chosen (JPEG maps to 'jpg', not to 'jpeg').
  140. * E.g. 'dds\\0', 'pcx\\0', 'jpg\\0'. All characters are lower-case.
  141. * The fourth character will always be '\\0'.
  142. */
  143. char achFormatHint[9];// 8 for string + 1 for terminator.
  144. /** Data of the texture.
  145. *
  146. * Points to an array of mWidth * mHeight aiTexel's.
  147. * The format of the texture data is always ARGB8888 to
  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. #ifdef __cplusplus
  155. //! For compressed textures (mHeight == 0): compare the
  156. //! format hint against a given string.
  157. //! @param s Input string. 3 characters are maximally processed.
  158. //! Example values: "jpg", "png"
  159. //! @return true if the given string matches the format hint
  160. bool CheckFormat(const char* s) const
  161. {
  162. return (0 == ::strncmp(achFormatHint, s, sizeof(achFormatHint)));
  163. }
  164. // Construction
  165. aiTexture ()
  166. : mWidth (0)
  167. , mHeight (0)
  168. , pcData (NULL)
  169. {
  170. achFormatHint[0] = achFormatHint[1] = 0;
  171. achFormatHint[2] = achFormatHint[3] = 0;
  172. }
  173. // Destruction
  174. ~aiTexture ()
  175. {
  176. delete[] pcData;
  177. }
  178. #endif
  179. };
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183. #endif // AI_TEXTURE_H_INC