VTFLib
A C and C++ API that, with a few simple functions, can open and save .vtf and .vmt files.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VTFFormat.h
Go to the documentation of this file.
1 /*
2  * VTFLib
3  * Copyright (C) 2005-2011 Neil Jedrzejewski & Ryan Gregg
4 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later
9  * version.
10  */
11 
12 // ============================================================
13 // NOTE: This file is commented for compatibility with Doxygen.
14 // ============================================================
34 #ifndef VTFLIB_VTFFORMAT_H
35 #define VTFLIB_VTFFORMAT_H
36 
37 #include "stdafx.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 // VTF version numbers (current version is 7.5)
44 //---------------------------------------------
45 #define VTF_MAJOR_VERSION 7
46 #define VTF_MINOR_VERSION 5
47 #define VTF_MINOR_VERSION_DEFAULT 3
48 
49 #define VTF_MINOR_VERSION_MIN_SPHERE_MAP 1
50 #define VTF_MINOR_VERSION_MIN_VOLUME 2
51 #define VTF_MINOR_VERSION_MIN_RESOURCE 3
52 #define VTF_MINOR_VERSION_MIN_NO_SPHERE_MAP 5
53 
55 
60 typedef enum tagVTFImageFormat
61 {
92  IMAGE_FORMAT_NV_DST16,
93  IMAGE_FORMAT_NV_DST24,
94  IMAGE_FORMAT_NV_INTZ,
95  IMAGE_FORMAT_NV_RAWZ,
96  IMAGE_FORMAT_ATI_DST16,
97  IMAGE_FORMAT_ATI_DST24,
98  IMAGE_FORMAT_NV_NULL,
99  IMAGE_FORMAT_ATI2N,
100  IMAGE_FORMAT_ATI1N,
101  /*
102  XBox:
103  IMAGE_FORMAT_X360_DST16,
104  IMAGE_FORMAT_X360_DST24,
105  IMAGE_FORMAT_X360_DST24F,
106  IMAGE_FORMAT_LINEAR_BGRX8888, //!< = Blue, Green, Red, Unused - 32 bpp
107  IMAGE_FORMAT_LINEAR_RGBA8888, //!< = Red, Green, Blue, Alpha - 32 bpp
108  IMAGE_FORMAT_LINEAR_ABGR8888, //!< = Alpha, Blue, Green, Red - 32 bpp
109  IMAGE_FORMAT_LINEAR_ARGB8888, //!< = Alpha, Red, Green, Blue - 32 bpp
110  IMAGE_FORMAT_LINEAR_BGRA8888, //!< = Blue, Green, Red, Alpha - 32 bpp
111  IMAGE_FORMAT_LINEAR_RGB888, //!< = Red, Green, Blue - 24 bpp
112  IMAGE_FORMAT_LINEAR_BGR888, //!< = Blue, Green, Red - 24 bpp
113  IMAGE_FORMAT_LINEAR_BGRX5551, //!< = Blue, Green, Red, Unused - 16 bpp
114  IMAGE_FORMAT_LINEAR_I8, //!< = Luminance - 8 bpp
115  IMAGE_FORMAT_LINEAR_RGBA16161616, //!< = Red, Green, Blue, Alpha signed with mantissa - 64 bpp
116  IMAGE_FORMAT_LE_BGRX8888, //!< = Blue, Green, Red, Unused - 32 bpp
117  IMAGE_FORMAT_LE_BGRA8888, //!< = Blue, Green, Red, Alpha - 32 bpp
118  */
119  IMAGE_FORMAT_COUNT,
120  IMAGE_FORMAT_NONE = -1
122 
123 
125 typedef enum tagVTFImageFlag
126 {
127  TEXTUREFLAGS_POINTSAMPLE = 0x00000001,
128  TEXTUREFLAGS_TRILINEAR = 0x00000002,
129  TEXTUREFLAGS_CLAMPS = 0x00000004,
130  TEXTUREFLAGS_CLAMPT = 0x00000008,
131  TEXTUREFLAGS_ANISOTROPIC = 0x00000010,
132  TEXTUREFLAGS_HINT_DXT5 = 0x00000020,
133  TEXTUREFLAGS_SRGB = 0x00000040, // Originally internal to VTex as TEXTUREFLAGS_NOCOMPRESS.
134  TEXTUREFLAGS_DEPRECATED_NOCOMPRESS = 0x00000040,
135  TEXTUREFLAGS_NORMAL = 0x00000080,
136  TEXTUREFLAGS_NOMIP = 0x00000100,
137  TEXTUREFLAGS_NOLOD = 0x00000200,
138  TEXTUREFLAGS_MINMIP = 0x00000400,
139  TEXTUREFLAGS_PROCEDURAL = 0x00000800,
142  TEXTUREFLAGS_ENVMAP = 0x00004000,
143  TEXTUREFLAGS_RENDERTARGET = 0x00008000,
144  TEXTUREFLAGS_DEPTHRENDERTARGET = 0x00010000,
145  TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000,
146  TEXTUREFLAGS_SINGLECOPY = 0x00040000,
147  TEXTUREFLAGS_UNUSED0 = 0x00080000,
148  TEXTUREFLAGS_DEPRECATED_ONEOVERMIPLEVELINALPHA = 0x00080000,
149  TEXTUREFLAGS_UNUSED1 = 0x00100000,
150  TEXTUREFLAGS_DEPRECATED_PREMULTCOLORBYONEOVERMIPLEVEL = 0x00100000,
151  TEXTUREFLAGS_UNUSED2 = 0x00200000,
152  TEXTUREFLAGS_DEPRECATED_NORMALTODUDV = 0x00200000,
153  TEXTUREFLAGS_UNUSED3 = 0x00400000,
154  TEXTUREFLAGS_DEPRECATED_ALPHATESTMIPGENERATION = 0x00400000,
155  TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000,
156  TEXTUREFLAGS_UNUSED4 = 0x01000000,
157  TEXTUREFLAGS_DEPRECATED_NICEFILTERED = 0x01000000,
158  TEXTUREFLAGS_CLAMPU = 0x02000000,
159  TEXTUREFLAGS_VERTEXTEXTURE = 0x04000000,
160  TEXTUREFLAGS_SSBUMP = 0x08000000,
161  TEXTUREFLAGS_UNUSED5 = 0x10000000,
162  TEXTUREFLAGS_DEPRECATED_UNFILTERABLE_OK = 0x10000000,
163  TEXTUREFLAGS_BORDER = 0x20000000,
164  TEXTUREFLAGS_DEPRECATED_SPECVAR_RED = 0x40000000,
165  TEXTUREFLAGS_DEPRECATED_SPECVAR_ALPHA = 0x80000000,
166  TEXTUREFLAGS_LAST = 0x20000000,
167  TEXTUREFLAGS_COUNT = 30
168 } VTFImageFlag;
169 
171 typedef enum tagVTFCubeMapFace
172 {
173  CUBEMAP_FACE_RIGHT = 0, // +x
174  CUBEMAP_FACE_LEFT, // -x
175  CUBEMAP_FACE_BACK, // +y
176  CUBEMAP_FACE_FRONT, // -y
177  CUBEMAP_FACE_UP, // +z
178  CUBEMAP_FACE_DOWN, // -z
179  CUBEMAP_FACE_SphereMap, // fall back
180  CUBEMAP_FACE_COUNT
182 
184 typedef enum tagVTFMipmapFilter
185 {
186  MIPMAP_FILTER_POINT = 0,
187  MIPMAP_FILTER_BOX,
188  MIPMAP_FILTER_TRIANGLE,
189  MIPMAP_FILTER_QUADRATIC,
190  MIPMAP_FILTER_CUBIC,
191  MIPMAP_FILTER_CATROM,
192  MIPMAP_FILTER_MITCHELL,
193  MIPMAP_FILTER_GAUSSIAN,
194  MIPMAP_FILTER_SINC,
195  MIPMAP_FILTER_BESSEL,
196  MIPMAP_FILTER_HANNING,
197  MIPMAP_FILTER_HAMMING,
198  MIPMAP_FILTER_BLACKMAN,
199  MIPMAP_FILTER_KAISER,
200  MIPMAP_FILTER_COUNT
202 
204 typedef enum tagVTFSharpenFilter
205 {
206  SHARPEN_FILTER_NONE = 0,
207  SHARPEN_FILTER_NEGATIVE,
208  SHARPEN_FILTER_LIGHTER,
209  SHARPEN_FILTER_DARKER,
210  SHARPEN_FILTER_CONTRASTMORE,
211  SHARPEN_FILTER_CONTRASTLESS,
212  SHARPEN_FILTER_SMOOTHEN,
213  SHARPEN_FILTER_SHARPENSOFT,
214  SHARPEN_FILTER_SHARPENMEDIUM,
215  SHARPEN_FILTER_SHARPENSTRONG,
216  SHARPEN_FILTER_FINDEDGES,
217  SHARPEN_FILTER_CONTOUR,
218  SHARPEN_FILTER_EDGEDETECT,
219  SHARPEN_FILTER_EDGEDETECTSOFT,
220  SHARPEN_FILTER_EMBOSS,
221  SHARPEN_FILTER_MEANREMOVAL,
222  SHARPEN_FILTER_UNSHARP,
223  SHARPEN_FILTER_XSHARPEN,
224  SHARPEN_FILTER_WARPSHARP,
225  SHARPEN_FILTER_COUNT
227 
228 #define DXT_QUALITY_BASE 68
229 
230 typedef enum tagDXTQuality
231 {
232  DXT_QUALITY_LOW,
233  DXT_QUALITY_MEDIUM,
234  DXT_QUALITY_HIGH,
235  DXT_QUALITY_HIGHEST,
236  DXT_QUALITY_COUNT
237 } VTFDXTQuality;
238 
239 #define KERNEL_FILTER_BASE 1040
240 
242 typedef enum tagVTFKernelFilter
243 {
244  KERNEL_FILTER_4X = 0,
245  KERNEL_FILTER_3X3,
246  KERNEL_FILTER_5X5,
247  KERNEL_FILTER_7X7,
248  KERNEL_FILTER_9X9,
249  KERNEL_FILTER_DUDV,
250  KERNEL_FILTER_COUNT
252 
253 #define HEIGHT_CONVERSION_METHOD_BASE 1009
254 
256 typedef enum tagVTFHeightConversionMethod
257 {
258  HEIGHT_CONVERSION_METHOD_ALPHA = 0,
259  HEIGHT_CONVERSION_METHOD_AVERAGE_RGB,
260  HEIGHT_CONVERSION_METHOD_BIASED_RGB,
261  HEIGHT_CONVERSION_METHOD_RED,
262  HEIGHT_CONVERSION_METHOD_GREEN,
263  HEIGHT_CONVERSION_METHOD_BLUE,
264  HEIGHT_CONVERSION_METHOD_MAX_RGB,
265  HEIGHT_CONVERSION_METHOD_COLORSPACE,
266  //HEIGHT_CONVERSION_METHOD_NORMALIZE,
267  HEIGHT_CONVERSION_METHOD_COUNT
269 
270 #define NORMAL_ALPHA_RESULT_BASE 1033
271 
273 typedef enum tagVTFNormalAlphaResult
274 {
275  NORMAL_ALPHA_RESULT_NOCHANGE = 0,
276  NORMAL_ALPHA_RESULT_HEIGHT,
277  NORMAL_ALPHA_RESULT_BLACK,
278  NORMAL_ALPHA_RESULT_WHITE,
279  NORMAL_ALPHA_RESULT_COUNT
281 
283 typedef enum tagVTFResizeMethod
284 {
285  RESIZE_NEAREST_POWER2 = 0,
286  RESIZE_BIGGEST_POWER2,
287  RESIZE_SMALLEST_POWER2,
288  RESIZE_SET,
289  RESIZE_COUNT
291 
293 //--------------------------------------------
294 typedef enum tagVTFLookDir
295 {
296  LOOK_DOWN_X = 0,
297  LOOK_DOWN_NEGX,
298  LOOK_DOWN_Y,
299  LOOK_DOWN_NEGY,
300  LOOK_DOWN_Z,
301  LOOK_DOWN_NEGZ
302 } VTFLookDir;
303 
304 #define MAKE_VTF_RSRC_ID(a, b, c) ((vlUInt)(((vlByte)a) | ((vlByte)b << 8) | ((vlByte)c << 16)))
305 #define MAKE_VTF_RSRC_IDF(a, b, c, d) ((vlUInt)(((vlByte)a) | ((vlByte)b << 8) | ((vlByte)c << 16) | ((vlByte)d << 24)))
306 
308 //--------------------------------------------
309 typedef enum tagVTFResourceEntryTypeFlag
310 {
311  RSRCF_HAS_NO_DATA_CHUNK = 0x02
313 
315 //--------------------------------------------
316 typedef enum tagVTFResourceEntryType
317 {
318  VTF_LEGACY_RSRC_LOW_RES_IMAGE = MAKE_VTF_RSRC_ID(0x01, 0, 0),
319  VTF_LEGACY_RSRC_IMAGE = MAKE_VTF_RSRC_ID(0x30, 0, 0),
320  VTF_RSRC_SHEET = MAKE_VTF_RSRC_ID(0x10, 0, 0),
321  VTF_RSRC_CRC = MAKE_VTF_RSRC_IDF('C', 'R', 'C', RSRCF_HAS_NO_DATA_CHUNK),
322  VTF_RSRC_TEXTURE_LOD_SETTINGS = MAKE_VTF_RSRC_IDF('L', 'O', 'D', RSRCF_HAS_NO_DATA_CHUNK),
323  VTF_RSRC_TEXTURE_SETTINGS_EX = MAKE_VTF_RSRC_IDF('T', 'S', 'O', RSRCF_HAS_NO_DATA_CHUNK),
324  VTF_RSRC_KEY_VALUE_DATA = MAKE_VTF_RSRC_ID('K', 'V', 'D'),
325  VTF_RSRC_MAX_DICTIONARY_ENTRIES = 32
327 
328 #pragma pack(1)
329 
331 
337 {
341 };
342 
344 
349 {
364 };
365 
367 
371 struct VTFLIB_ALIGN16 SVTFHeader_70_A : public SVTFHeader_70 {};
372 
374 
379 {
380 
381 };
382 
384 
388 struct VTFLIB_ALIGN16 SVTFHeader_71_A : public SVTFHeader_71 {};
389 
391 
396 {
398 };
399 
401 
405 struct VTFLIB_ALIGN16 SVTFHeader_72_A : public SVTFHeader_72 {};
406 
408 
413 {
414  vlByte Padding2[3];
416 };
417 
419 
423 struct VTFLIB_ALIGN16 SVTFHeader_73_A : public SVTFHeader_73 {};
424 
426 
431 {
432 
433 };
434 
436 
440 struct VTFLIB_ALIGN16 SVTFHeader_74_A : public SVTFHeader_74 {};
441 
443 
448 {
449 
450 };
451 
453 
457 struct VTFLIB_ALIGN16 SVTFHeader_75_A : public SVTFHeader_75 {};
458 
459 struct SVTFResource
460 {
461  union
462  {
463  vlUInt Type;
464  struct
465  {
466  vlByte ID[3];
467  vlByte Flags;
468  } S;
469  };
470  vlUInt Data;
471 };
472 
473 struct SVTFResourceData
474 {
475  vlUInt Size;
476  vlByte *Data;
477 };
478 
479 typedef struct tagSVTFTextureLODControlResource
480 {
481  vlByte ResolutionClampU;
482  vlByte ResolutionClampV;
483  vlByte Padding[2];
484 } SVTFTextureLODControlResource;
485 
486 typedef struct tagSVTFTextureSettingsExResource
487 {
488  vlByte Flags0;
489  vlByte Flags1;
490  vlByte Flags2;
491  vlByte Flags3;
492 } SVTFTextureSettingsExResource;
493 
494 struct SVTFHeader : public SVTFHeader_74_A
495 {
496  vlByte Padding3[8];
497  SVTFResource Resources[VTF_RSRC_MAX_DICTIONARY_ENTRIES];
498  SVTFResourceData Data[VTF_RSRC_MAX_DICTIONARY_ENTRIES];
499 };
500 
501 #pragma pack()
502 
503 #ifdef __cplusplus
504 }
505 #endif
506 
507 #endif // VTFFORMAT_H
Originally TEXTUREFLAGS_UNFILTERABLE_OK.
Definition: VTFFormat.h:161
= 4 channel format for DuDv/Normal maps - 32 bpp
Definition: VTFFormat.h:88
= DXT1 compressed format with 1-bit alpha - 4 bpp
Definition: VTFFormat.h:82
VTFImageFormat
Image data formats VTFLib supports.
Definition: VTFFormat.h:60
VTFHeader_70_A struct.
Definition: VTFFormat.h:371
= DXT5 compressed format - 8 bpp
Definition: VTFFormat.h:77
unsigned char vlByte
Single unsigned byte.
Definition: stdafx.h:52
vlSingle BumpScale
Bump map scale.
Definition: VTFFormat.h:358
= Red, Green, Blue, Alpha signed with mantissa - 64 bpp
Definition: VTFFormat.h:87
vlUInt HeaderSize
Size of the header struct (currently 80 bytes)
Definition: VTFFormat.h:340
VTFKernelFilter
Normal map creation kernel size indices.
Definition: VTFFormat.h:242
= Blue, Green, Red - 24 bpp
Definition: VTFFormat.h:65
VTFHeader_72 struct.
Definition: VTFFormat.h:395
VTFCubeMapFace
VTF image cubemap face indices.
Definition: VTFFormat.h:171
VTFResizeMethod
Image re-size handling method indices.
Definition: VTFFormat.h:283
char vlChar
Single signed character.
Definition: stdafx.h:51
VTFFileHeader struct.
Definition: VTFFormat.h:336
Automatically generated by VTex.
Definition: VTFFormat.h:140
= Luminance - 32 bpp
Definition: VTFFormat.h:89
= Blue, Green, Red, Unused - 32 bpp
Definition: VTFFormat.h:78
= Red, Green, Blue - 24 bpp
Definition: VTFFormat.h:64
= Blue, Green, Red, Unused - 16 bpp
Definition: VTFFormat.h:80
= Alpha, Blue, Green, Red - 32 bpp
Definition: VTFFormat.h:63
= Alpha- 8 bpp
Definition: VTFFormat.h:70
= 4 channel format for DuDv/Normal maps - 32 bpp
Definition: VTFFormat.h:85
Originally internal to VTex as TEXTUREFLAGS_ONEOVERMIPLEVELINALPHA.
Definition: VTFFormat.h:147
VTFHeader_74 struct.
Definition: VTFFormat.h:430
unsigned int vlUInt
Unsigned integer value.
Definition: stdafx.h:56
= DXT3 compressed format - 8 bpp
Definition: VTFFormat.h:76
vlUInt Flags
Flags for the image.
Definition: VTFFormat.h:352
VTFHeader_71 struct.
Definition: VTFFormat.h:378
Automatically generated by VTex.
Definition: VTFFormat.h:141
= Blue, Green, Red, Alpha - 16 bpp
Definition: VTFFormat.h:83
Originally internal to VTex as TEXTUREFLAGS_NORMALTODUDV.
Definition: VTFFormat.h:151
Application framework header plus VTFLib custom data types.
vlSingle Reflectivity[3]
Reflectivity vector.
Definition: VTFFormat.h:356
= Blue, Green, Red, Alpha - 32 bpp
Definition: VTFFormat.h:74
= Red, Green, Blue - 16 bpp
Definition: VTFFormat.h:66
= Luminance, Alpha - 16 bpp
Definition: VTFFormat.h:68
= 2 channel format for DuDv/Normal maps - 16 bpp
Definition: VTFFormat.h:84
VTFResourceEntryTypeFlag
Resource entry type flags.
Definition: VTFFormat.h:309
vlByte Padding0[4]
Reflectivity padding (16 byte alignment)
Definition: VTFFormat.h:355
= Alpha, Red, Green, Blue - 32 bpp
Definition: VTFFormat.h:73
VTFMipmapFilter
MIP map reduction filter indices.
Definition: VTFFormat.h:184
VTFHeader_73 struct.
Definition: VTFFormat.h:412
= Paletted - 8 bpp
Definition: VTFFormat.h:69
= Red, Green, Blue, Alpha - 32 bpp
Definition: VTFFormat.h:62
vlChar TypeString[4]
"Magic number" identifier- "VTF\0".
Definition: VTFFormat.h:338
VTFImageFormat LowResImageFormat
Image format of the thumbnail image.
Definition: VTFFormat.h:361
= Red, Green, Blue, "BlueScreen" Alpha - 24 bpp
Definition: VTFFormat.h:72
VTFHeightConversionMethod
Normal map height conversion method indices.
Definition: VTFFormat.h:256
Originally internal to VTex as TEXTUREFLAGS_PREMULTCOLORBYONEOVERMIPLEVEL.
Definition: VTFFormat.h:149
= Red, Green, Blue, Alpha - 16 bpp
Definition: VTFFormat.h:81
VTFImageFlag
VTF image header flags.
Definition: VTFFormat.h:125
unsigned short vlUShort
Unsigned short floating point value.
Definition: stdafx.h:54
VTFLookDir
Spheremap creation look direction indices.
Definition: VTFFormat.h:294
vlByte LowResImageHeight
Thumbnail image height.
Definition: VTFFormat.h:363
VTFHeader_72_A struct.
Definition: VTFFormat.h:405
vlUShort StartFrame
Start frame (always 0)
Definition: VTFFormat.h:354
vlUShort Height
Height of the largest image.
Definition: VTFFormat.h:351
vlByte LowResImageWidth
Thumbnail image width.
Definition: VTFFormat.h:362
= DXT1 compressed format - 4 bpp
Definition: VTFFormat.h:75
= Luminance - 8 bpp
Definition: VTFFormat.h:67
VTFHeader_71_A struct.
Definition: VTFFormat.h:388
VTFSharpenFilter
MIP map sharpen filter indices.
Definition: VTFFormat.h:204
vlUInt Version[2]
Version[0].version1
Definition: VTFFormat.h:339
vlByte Padding1[4]
Reflectivity padding (8 byte packing)
Definition: VTFFormat.h:357
vlUShort Frames
Number of frames if animated (1 for no animation)
Definition: VTFFormat.h:353
VTFNormalAlphaResult
Normal map alpha channel handling indices.
Definition: VTFFormat.h:273
VTFHeader_72_A struct.
Definition: VTFFormat.h:423
= Blue, Green, Red - 16 bpp
Definition: VTFFormat.h:79
= Red, Green, Blue - 96 bpp
Definition: VTFFormat.h:90
VTFImageFormat ImageFormat
Image format index.
Definition: VTFFormat.h:359
VTFHeader_75_A struct.
Definition: VTFFormat.h:457
= Red, Green, Blue, Alpha - 128 bpp
Definition: VTFFormat.h:91
vlByte MipCount
Number of MIP levels (including the largest image)
Definition: VTFFormat.h:360
VTFResourceEntryType
Resource entry type idendifiers.
Definition: VTFFormat.h:316
float vlSingle
Floating point number.
Definition: stdafx.h:59
vlUInt ResourceCount
Number of image resources.
Definition: VTFFormat.h:415
vlUShort Depth
Depth of the largest image.
Definition: VTFFormat.h:397
VTFHeader_74_A struct.
Definition: VTFFormat.h:440
Originally internal to VTex as TEXTUREFLAGS_NICEFILTERED.
Definition: VTFFormat.h:156
vlUShort Width
Width of the largest image.
Definition: VTFFormat.h:350
= Red, Green, Blue, "BlueScreen" Alpha - 24 bpp
Definition: VTFFormat.h:71
VTFHeader_75 struct.
Definition: VTFFormat.h:447
Originally internal to VTex as TEXTUREFLAGS_ALPHATESTMIPGENERATION.
Definition: VTFFormat.h:153
VTFHeader_70 struct.
Definition: VTFFormat.h:348
= Red, Green, Blue, Alpha - 64 bpp
Definition: VTFFormat.h:86