Ptex
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;
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 {
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  };
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  };
90  uint32_t faceid;
93  };
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
uint64_t leveldatasize
Definition: PtexIO.h:72
void set(uint32_t blocksize, Encoding encoding)
Definition: PtexIO.h:84
MeshType meshtype
Definition: PtexIO.h:45
uint64_t editdatapos
Definition: PtexIO.h:69
uint32_t nfaces
Definition: PtexIO.h:50
uint32_t levelinfosize
Definition: PtexIO.h:54
Common data structures and enums used throughout the API.
Definition: Ptexture.h:73
const uint32_t & val() const
Definition: PtexIO.h:83
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:190
uint16_t nlevels
Definition: PtexIO.h:49
static int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:132
uint32_t lmdheaderzipsize
Definition: PtexIO.h:65
static const int AllocaMax
Definition: PtexIO.h:111
uint16_t nchannels
Definition: PtexIO.h:48
uint32_t metadatamemsize
Definition: PtexIO.h:96
static const int HeaderSize
Definition: PtexIO.h:100
uint32_t constdatasize
Definition: PtexIO.h:53
uint32_t & val()
Definition: PtexIO.h:82
int pixelSize() const
Definition: PtexIO.h:59
BorderMode ubordermode
Definition: PtexIO.h:63
uint32_t faceinfosize
Definition: PtexIO.h:52
static const int LevelInfoSize
Definition: PtexIO.h:102
static const int EditMetaDataHeaderSize
Definition: PtexIO.h:105
uint32_t metadatazipsize
Definition: PtexIO.h:57
Encoding
Definition: PtexIO.h:77
uint32_t levelheadersize
Definition: PtexIO.h:73
uint32_t metadatazipsize
Definition: PtexIO.h:95
uint32_t lmdheadermemsize
Definition: PtexIO.h:66
uint32_t blocksize() const
Definition: PtexIO.h:80
static const int ExtHeaderSize
Definition: PtexIO.h:101
static const int MetaDataThreshold
Definition: PtexIO.h:112
uint32_t version
Definition: PtexIO.h:44
uint32_t nfaces
Definition: PtexIO.h:74
DataType
Type of data stored in texture file.
Definition: Ptexture.h:196
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:350
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:204
bool hasAlpha() const
Definition: PtexIO.h:60
DataType datatype
Definition: PtexIO.h:46
Definition: PtexIO.h:41
Encoding encoding() const
Definition: PtexIO.h:81
static const uint32_t Magic
Definition: PtexIO.h:99
uint32_t magic
Definition: PtexIO.h:43
int32_t alphachan
Definition: PtexIO.h:47
static const int TileSize
Definition: PtexIO.h:110
uint32_t minorversion
Definition: PtexIO.h:55
BorderMode vbordermode
Definition: PtexIO.h:64
uint64_t lmddatasize
Definition: PtexIO.h:67
uint32_t metadatamemsize
Definition: PtexIO.h:58
uint64_t editdatasize
Definition: PtexIO.h:68
uint32_t extheadersize
Definition: PtexIO.h:51
static const int BlockSize
Definition: PtexIO.h:109
static const int IBuffSize
Definition: PtexIO.h:108
static const int FaceDataHeaderSize
Definition: PtexIO.h:103
EditType
Definition: PtexIO.h:88
uint64_t leveldatasize
Definition: PtexIO.h:56
static bool LittleEndian()
Definition: PtexIO.h:114
static const int EditFaceDataHeaderSize
Definition: PtexIO.h:104
FaceDataHeader fdh
Definition: PtexIO.h:92
Public API classes for reading, writing, caching, and filtering Ptex files.