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