Ptex
PtexIO.h
Go to the documentation of this file.
1#ifndef PtexIO_h
2#define PtexIO_h
3
4/*
5PTEX SOFTWARE
6Copyright 2014 Disney Enterprises, Inc. All rights reserved
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are
10met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19
20 * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
21 Studios" or the names of its contributors may NOT be used to
22 endorse or promote products derived from this software without
23 specific prior written permission from Walt Disney Pictures.
24
25Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
26CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
27BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
28FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
29IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
30CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
34THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37*/
38
39#include "Ptexture.h"
40
42
43#pragma pack(push, 1)
44struct Header {
45 uint32_t magic;
46 uint32_t version;
47 uint32_t meshtype;
48 uint32_t datatype;
49 int32_t alphachan;
50 uint16_t nchannels;
51 uint16_t nlevels;
52 uint32_t nfaces;
53 uint32_t extheadersize;
54 uint32_t faceinfosize;
55 uint32_t constdatasize;
56 uint32_t levelinfosize;
57 uint32_t minorversion;
58 uint64_t leveldatasize;
61 int pixelSize() const { return DataSize(DataType(datatype)) * nchannels; }
62 bool hasAlpha() const { return alphachan >= 0 && alphachan < nchannels; }
63};
64struct ExtHeader {
65 uint16_t ubordermode;
66 uint16_t pad;
67 uint16_t vbordermode;
71 uint64_t lmddatasize;
72 uint64_t obsolete;
73 uint64_t obsolete2;
74};
75struct LevelInfo {
76 uint64_t leveldatasize;
78 uint32_t nfaces;
80};
83 uint32_t data; // bits 0..29 = blocksize, bits 30..31 = encoding
84 static constexpr uint32_t blocksizeMax = 0x3fffffff;
85 uint32_t blocksize() const { return data & blocksizeMax; }
86 Encoding encoding() const { return Encoding((data >> 30) & 0x3); }
87 uint32_t& val() { return *(uint32_t*) this; }
88 const uint32_t& val() const { return *(const uint32_t*) this; }
89 void set(size_t blocksizeArg, Encoding encodingArg) {
90 data = uint32_t(std::min(blocksizeArg, size_t(blocksizeMax)) | ((encodingArg & 0x3) << 30));
91 }
92 // if a face size is >= blocksizeMax, it is considered a "large face" and
93 // its size will be stored in a separate large-face header
94 bool isLargeFace() const { return blocksize() == blocksizeMax; }
96};
97#pragma pack(pop)
98
99const uint32_t Magic = 'P' | ('t'<<8) | ('e'<<16) | ('x'<<24);
100const int HeaderSize = sizeof(Header);
101const int ExtHeaderSize = sizeof(ExtHeader);
102const int LevelInfoSize = sizeof(LevelInfo);
104
105// these constants can be tuned for performance
106const int IBuffSize = 65536; // default input buffer size
107const int BlockSize = 65536; // target block size for file I/O
108const int TileSize = 65536; // target tile size (uncompressed)
109const int AllocaMax = 65536; // max size for using alloca
110const int MetaDataThreshold = 1024; // cutoff for large meta data
111
112inline bool LittleEndian() {
113 short word = 0x0201;
114 return *(char*)&word == 1;
115}
116
118
119#endif
const uint32_t Magic
Definition PtexIO.h:99
const int FaceDataHeaderSize
Definition PtexIO.h:103
const int ExtHeaderSize
Definition PtexIO.h:101
const int AllocaMax
Definition PtexIO.h:109
const int HeaderSize
Definition PtexIO.h:100
const int IBuffSize
Definition PtexIO.h:106
const int LevelInfoSize
Definition PtexIO.h:102
const int BlockSize
Definition PtexIO.h:107
bool LittleEndian()
Definition PtexIO.h:112
const int TileSize
Definition PtexIO.h:108
Encoding
Definition PtexIO.h:81
@ enc_diffzipped
Definition PtexIO.h:81
@ enc_zipped
Definition PtexIO.h:81
@ enc_constant
Definition PtexIO.h:81
@ enc_tiled
Definition PtexIO.h:81
const int MetaDataThreshold
Definition PtexIO.h:110
#define PTEX_NAMESPACE_END
Definition PtexVersion.h:62
Public API classes for reading, writing, caching, and filtering Ptex files.
uint16_t edgefiltermode
Definition PtexIO.h:68
uint64_t obsolete
Definition PtexIO.h:72
uint16_t vbordermode
Definition PtexIO.h:67
uint16_t ubordermode
Definition PtexIO.h:65
uint64_t lmddatasize
Definition PtexIO.h:71
uint16_t pad
Definition PtexIO.h:66
uint32_t lmdheadermemsize
Definition PtexIO.h:70
uint32_t lmdheaderzipsize
Definition PtexIO.h:69
uint64_t obsolete2
Definition PtexIO.h:73
Encoding encoding() const
Definition PtexIO.h:86
uint32_t & val()
Definition PtexIO.h:87
uint32_t blocksize() const
Definition PtexIO.h:85
const uint32_t & val() const
Definition PtexIO.h:88
static constexpr uint32_t blocksizeMax
Definition PtexIO.h:84
bool isLargeFace() const
Definition PtexIO.h:94
void set(size_t blocksizeArg, Encoding encodingArg)
Definition PtexIO.h:89
uint32_t data
Definition PtexIO.h:83
uint32_t metadatamemsize
Definition PtexIO.h:60
uint32_t faceinfosize
Definition PtexIO.h:54
uint16_t nlevels
Definition PtexIO.h:51
uint16_t nchannels
Definition PtexIO.h:50
uint32_t meshtype
Definition PtexIO.h:47
uint32_t constdatasize
Definition PtexIO.h:55
uint32_t levelinfosize
Definition PtexIO.h:56
uint32_t extheadersize
Definition PtexIO.h:53
uint32_t minorversion
Definition PtexIO.h:57
uint32_t metadatazipsize
Definition PtexIO.h:59
uint32_t datatype
Definition PtexIO.h:48
int pixelSize() const
Definition PtexIO.h:61
int32_t alphachan
Definition PtexIO.h:49
uint32_t magic
Definition PtexIO.h:45
uint32_t nfaces
Definition PtexIO.h:52
uint64_t leveldatasize
Definition PtexIO.h:58
uint32_t version
Definition PtexIO.h:46
bool hasAlpha() const
Definition PtexIO.h:62
uint32_t levelheadersize
Definition PtexIO.h:77
LevelInfo()
Definition PtexIO.h:79
uint64_t leveldatasize
Definition PtexIO.h:76
uint32_t nfaces
Definition PtexIO.h:78