vrshoot

view libs/assimp/assimp/texture.h @ 0:b2f14e535253

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