Ptex: PtexIO.h Source File

Ptex

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

PtexIO.h
Go to the documentation of this file.
1 #ifndef PtexIO_h
2 #define PtexIO_h
3
4 /*
5 PTEX SOFTWARE
6 Copyright 2009 Disney Enterprises, Inc. All rights reserved
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
10 met:
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
25 Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
26 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
27 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
28 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
29 IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37 */
38
39 #include "Ptexture.h"
40
41 struct PtexIO : public Ptex {
42 struct Header {
43 uint32_t magic;
44 uint32_t version;
45 MeshType meshtype:32;
46 DataType datatype:32;
47 int32_t alphachan;
48 uint16_t nchannels;
49 uint16_t nlevels;
50 uint32_t nfaces;
51 uint32_t extheadersize;
52 uint32_t faceinfosize;
53 uint32_t constdatasize;
54 uint32_t levelinfosize;
55 uint32_t minorversion;
56 uint64_t leveldatasize;
57 uint32_t metadatazipsize;
58 uint32_t metadatamemsize;
59 int pixelSize() const { return DataSize(datatype) * nchannels; }
60 bool hasAlpha() const { return alphachan >= 0 && alphachan < nchannels; }
61 };
62 struct ExtHeader {
63 BorderMode ubordermode:32;
64 BorderMode vbordermode:32;
65 uint32_t lmdheaderzipsize;
66 uint32_t lmdheadermemsize;
67 uint64_t lmddatasize;
68 uint64_t editdatasize;
69 uint64_t editdatapos;
70 };
71 struct LevelInfo {
72 uint64_t leveldatasize;
73 uint32_t levelheadersize;
74 uint32_t nfaces;
75 LevelInfo() : leveldatasize(0), levelheadersize(0), nfaces(0) {}
76 };
77 enum Encoding { enc_constant, enc_zipped, enc_diffzipped, enc_tiled };
78 struct FaceDataHeader {
79 uint32_t data; // bits 0..29 = blocksize, bits 30..31 = encoding
80 uint32_t blocksize() const { return data & 0x3fffffff; }
81 Encoding encoding() const { return Encoding((data >> 30) & 0x3); }
82 uint32_t& val() { return *(uint32_t*) this; }
83 const uint32_t& val() const { return *(uint32_t*) this; }
84 void set(uint32_t blocksize, Encoding encoding)
85 { data = (blocksize & 0x3fffffff) | ((encoding & 0x3) << 30); }
86 FaceDataHeader() : data(0) {}
87 };
88 enum EditType { et_editfacedata, et_editmetadata };
89 struct EditFaceDataHeader {
90 uint32_t faceid;
91 FaceInfo faceinfo;
92 FaceDataHeader fdh;
93 };
94 struct EditMetaDataHeader {
95 uint32_t metadatazipsize;
96 uint32_t metadatamemsize;
97 };
98
99 static const uint32_t Magic = 'P' | ('t'<<8) | ('e'<<16) | ('x'<<24);
100 static const int HeaderSize = sizeof(Header);
101 static const int ExtHeaderSize = sizeof(ExtHeader);
102 static const int LevelInfoSize = sizeof(LevelInfo);
103 static const int FaceDataHeaderSize = sizeof(FaceDataHeader);
104 static const int EditFaceDataHeaderSize = sizeof(EditFaceDataHeader);
105 static const int EditMetaDataHeaderSize = sizeof(EditMetaDataHeader);
106
107 // these constants can be tuned for performance
108 static const int IBuffSize = 8192; // default input buffer size
109 static const int BlockSize = 16384; // target block size for file I/O
110 static const int TileSize = 65536; // target tile size (uncompressed)
111 static const int AllocaMax = 16384; // max size for using alloca
112 static const int MetaDataThreshold = 1024; // cutoff for large meta data
113
114 static bool LittleEndian() {
115 short word = 0x0201;
116 return *(char*)&word == 1;
117 }
118 };
119
120 #endif
PtexIO::LevelInfo::leveldatasize
uint64_t leveldatasize
Definition: PtexIO.h:72
PtexIO::FaceDataHeader::set
void set(uint32_t blocksize, Encoding encoding)
Definition: PtexIO.h:84
PtexIO::Header::meshtype
MeshType meshtype
Definition: PtexIO.h:45
PtexIO::ExtHeader::editdatapos
uint64_t editdatapos
Definition: PtexIO.h:69
PtexIO::EditFaceDataHeader::faceinfo
FaceInfo faceinfo
Definition: PtexIO.h:91
PtexIO::Header::nfaces
uint32_t nfaces
Definition: PtexIO.h:50
PtexIO::Header::levelinfosize
uint32_t levelinfosize
Definition: PtexIO.h:54
PtexIO::FaceDataHeader
Definition: PtexIO.h:78
Ptex
Common data structures and enums used throughout the API.
Definition: Ptexture.h:73
PtexIO::FaceDataHeader::val
const uint32_t & val() const
Definition: PtexIO.h:83
MeshType
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:190
PtexIO::Header::nlevels
uint16_t nlevels
Definition: PtexIO.h:49
Ptex::DataSize
static int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:132
PtexIO::ExtHeader::lmdheaderzipsize
uint32_t lmdheaderzipsize
Definition: PtexIO.h:65
PtexIO::AllocaMax
static const int AllocaMax
Definition: PtexIO.h:111
PtexIO::Header::nchannels
uint16_t nchannels
Definition: PtexIO.h:48
PtexIO::EditMetaDataHeader::metadatamemsize
uint32_t metadatamemsize
Definition: PtexIO.h:96
PtexIO::HeaderSize
static const int HeaderSize
Definition: PtexIO.h:100
PtexIO::Header::constdatasize
uint32_t constdatasize
Definition: PtexIO.h:53
PtexIO::FaceDataHeader::val
uint32_t & val()
Definition: PtexIO.h:82
PtexIO::Header::pixelSize
int pixelSize() const
Definition: PtexIO.h:59
PtexIO::ExtHeader::ubordermode
BorderMode ubordermode
Definition: PtexIO.h:63
PtexIO::Header::faceinfosize
uint32_t faceinfosize
Definition: PtexIO.h:52
PtexIO::LevelInfoSize
static const int LevelInfoSize
Definition: PtexIO.h:102
PtexIO::et_editfacedata
Definition: PtexIO.h:88
PtexIO::EditMetaDataHeaderSize
static const int EditMetaDataHeaderSize
Definition: PtexIO.h:105
PtexIO::Header::metadatazipsize
uint32_t metadatazipsize
Definition: PtexIO.h:57
PtexIO::EditFaceDataHeader
Definition: PtexIO.h:89
PtexIO::enc_constant
Definition: PtexIO.h:77
PtexIO::Encoding
Encoding
Definition: PtexIO.h:77
PtexIO::LevelInfo::levelheadersize
uint32_t levelheadersize
Definition: PtexIO.h:73
PtexIO::EditMetaDataHeader::metadatazipsize
uint32_t metadatazipsize
Definition: PtexIO.h:95
PtexIO::ExtHeader::lmdheadermemsize
uint32_t lmdheadermemsize
Definition: PtexIO.h:66
PtexIO::FaceDataHeader::blocksize
uint32_t blocksize() const
Definition: PtexIO.h:80
PtexIO::ExtHeaderSize
static const int ExtHeaderSize
Definition: PtexIO.h:101
PtexIO::MetaDataThreshold
static const int MetaDataThreshold
Definition: PtexIO.h:112
PtexIO::Header::version
uint32_t version
Definition: PtexIO.h:44
PtexIO::ExtHeader
Definition: PtexIO.h:62
PtexIO::LevelInfo::nfaces
uint32_t nfaces
Definition: PtexIO.h:74
DataType
DataType
Type of data stored in texture file.
Definition: Ptexture.h:196
FaceInfo
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:350
BorderMode
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:204
PtexIO::Header::hasAlpha
bool hasAlpha() const
Definition: PtexIO.h:60
PtexIO::Header::datatype
DataType datatype
Definition: PtexIO.h:46
PtexIO
Definition: PtexIO.h:41
PtexIO::enc_zipped
Definition: PtexIO.h:77
PtexIO::Header
Definition: PtexIO.h:42
PtexIO::FaceDataHeader::encoding
Encoding encoding() const
Definition: PtexIO.h:81
PtexIO::Magic
static const uint32_t Magic
Definition: PtexIO.h:99
PtexIO::Header::magic
uint32_t magic
Definition: PtexIO.h:43
PtexIO::Header::alphachan
int32_t alphachan
Definition: PtexIO.h:47
PtexIO::TileSize
static const int TileSize
Definition: PtexIO.h:110
PtexIO::Header::minorversion
uint32_t minorversion
Definition: PtexIO.h:55
PtexIO::EditFaceDataHeader::faceid
uint32_t faceid
Definition: PtexIO.h:90
PtexIO::ExtHeader::vbordermode
BorderMode vbordermode
Definition: PtexIO.h:64
PtexIO::ExtHeader::lmddatasize
uint64_t lmddatasize
Definition: PtexIO.h:67
PtexIO::Header::metadatamemsize
uint32_t metadatamemsize
Definition: PtexIO.h:58
PtexIO::ExtHeader::editdatasize
uint64_t editdatasize
Definition: PtexIO.h:68
PtexIO::Header::extheadersize
uint32_t extheadersize
Definition: PtexIO.h:51
PtexIO::BlockSize
static const int BlockSize
Definition: PtexIO.h:109
PtexIO::IBuffSize
static const int IBuffSize
Definition: PtexIO.h:108
PtexIO::FaceDataHeader::data
uint32_t data
Definition: PtexIO.h:79
PtexIO::FaceDataHeaderSize
static const int FaceDataHeaderSize
Definition: PtexIO.h:103
PtexIO::enc_tiled
Definition: PtexIO.h:77
PtexIO::LevelInfo::LevelInfo
LevelInfo()
Definition: PtexIO.h:75
PtexIO::EditType
EditType
Definition: PtexIO.h:88
PtexIO::EditMetaDataHeader
Definition: PtexIO.h:94
PtexIO::Header::leveldatasize
uint64_t leveldatasize
Definition: PtexIO.h:56
PtexIO::enc_diffzipped
Definition: PtexIO.h:77
PtexIO::LevelInfo
Definition: PtexIO.h:71
PtexIO::LittleEndian
static bool LittleEndian()
Definition: PtexIO.h:114
PtexIO::EditFaceDataHeaderSize
static const int EditFaceDataHeaderSize
Definition: PtexIO.h:104
PtexIO::FaceDataHeader::FaceDataHeader
FaceDataHeader()
Definition: PtexIO.h:86
PtexIO::et_editmetadata
Definition: PtexIO.h:88
PtexIO::EditFaceDataHeader::fdh
FaceDataHeader fdh
Definition: PtexIO.h:92
Ptexture.h
Public API classes for reading, writing, caching, and filtering Ptex files.