Ptex

PtexReader.h
Go to the documentation of this file.
1 #ifndef PtexReader_h
2 #define PtexReader_h
3
4 /*
5 PTEX SOFTWARE
6 Copyright 2014 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 #include <stdio.h>
39 #include <zlib.h>
40 #include <vector>
41 #include <string>
42 #include <map>
43 #include <errno.h>
44 #include "Ptexture.h"
45 #include "PtexIO.h"
46 #include "PtexUtils.h"
47
48 #include "PtexHashMap.h"
49
50 PTEX_NAMESPACE_BEGIN
51
52 class PtexReader : public PtexTexture {
53 public:
54 PtexReader(bool premultiply, PtexInputHandler* inputHandler, PtexErrorHandler* errorHandler);
55 virtual ~PtexReader();
56 virtual void release() { delete this; }
57 bool needToOpen() const { return _needToOpen; }
58 bool open(const char* path, Ptex::String& error);
59 void prune();
60 void purge();
61 void setPendingPurge() { _pendingPurge = true; }
62 bool pendingPurge() const { return _pendingPurge; }
63 bool tryClose();
64 bool ok() const { return _ok; }
65 bool isOpen() { return _fp; }
66 void invalidate() {
67 _ok = false;
68 _needToOpen = false;
69 }
70
71 void increaseMemUsed(size_t amount) { if (amount) AtomicAdd(&_memUsed, amount); }
72 void logOpen() { AtomicIncrement(&_opens); }
73 void logBlockRead() { AtomicIncrement(&_blockReads); }
74
75 virtual const char* path() { return _path.c_str(); }
76
77 virtual Info getInfo() {
78 Info info;
79 info.meshType = MeshType(_header.meshtype);
80 info.dataType = DataType(_header.datatype);
81 info.uBorderMode = BorderMode(_extheader.ubordermode);
82 info.vBorderMode = BorderMode(_extheader.vbordermode);
83 info.edgeFilterMode = EdgeFilterMode(_extheader.edgefiltermode);
84 info.alphaChannel = _header.alphachan;
85 info.numChannels = _header.nchannels;
86 info.numFaces = _header.nfaces;
87 return info;
88 }
89
90 virtual Ptex::MeshType meshType() { return MeshType(_header.meshtype); }
91 virtual Ptex::DataType dataType() { return DataType(_header.datatype); }
92 virtual Ptex::BorderMode uBorderMode() { return BorderMode(_extheader.ubordermode); }
93 virtual Ptex::BorderMode vBorderMode() { return BorderMode(_extheader.vbordermode); }
94 virtual Ptex::EdgeFilterMode edgeFilterMode() { return EdgeFilterMode(_extheader.edgefiltermode); }
95 virtual int alphaChannel() { return _header.alphachan; }
96 virtual int numChannels() { return _header.nchannels; }
97 virtual int numFaces() { return _header.nfaces; }
98 virtual bool hasEdits() { return _hasEdits; }
99 virtual bool hasMipMaps() { return _header.nlevels > 1; }
100
101 virtual PtexMetaData* getMetaData();
102 virtual const Ptex::FaceInfo& getFaceInfo(int faceid);
103 virtual void getData(int faceid, void* buffer, int stride);
104 virtual void getData(int faceid, void* buffer, int stride, Res res);
105 virtual PtexFaceData* getData(int faceid);
106 virtual PtexFaceData* getData(int faceid, Res res);
107 virtual void getPixel(int faceid, int u, int v,
108 float* result, int firstchan, int nchannels);
109 virtual void getPixel(int faceid, int u, int v,
110 float* result, int firstchan, int nchannels,
111 Ptex::Res res);
112
113 DataType datatype() const { return DataType(_header.datatype); }
114 int nchannels() const { return _header.nchannels; }
115 int pixelsize() const { return _pixelsize; }
116 const Header& header() const { return _header; }
117 const ExtHeader& extheader() const { return _extheader; }
118 const LevelInfo& levelinfo(int level) const { return _levelinfo[level]; }
119
120 class MetaData : public PtexMetaData {
121 public:
122 MetaData(PtexReader* reader)
123 : _reader(reader) {}
124 ~MetaData() {}
125 virtual void release() {}
126
127 virtual int numKeys() { return int(_entries.size()); }
128 virtual void getKey(int index, const char*& key, MetaDataType& type)
129 {
130 if (index < 0 || index >= int(_entries.size())) {
131 return;
132 }
133 Entry* e = _entries[index];
134 key = e->key;
135 type = e->type;
136 }
137
138 virtual bool findKey(const char* key, int& index, MetaDataType& type)
139 {
140 MetaMap::iterator iter = _map.find(key);
141 if (iter==_map.end()) {
142 index = -1;
143 return false;
144 }
145 index = iter->second.index;
146 type = iter->second.type;
147 return true;
148 }
149
150 virtual void getValue(const char* key, const char*& value)
151 {
152 int index = -1;
153 MetaDataType type;
154 if (!findKey(key, index, type)) {
155 value = 0;
156 return;
157 }
158 Entry* e = getEntry(index);
159 if (e && e->type == mdt_string) value = (const char*) e->data;
160 else value = 0;
161 }
162
163 virtual void getValue(int index, const char*& value)
164 {
165 if (index < 0 || index >= int(_entries.size())) { value = 0; return; }
166 Entry* e = getEntry(index);
167 if (e && e->type == mdt_string) value = (const char*) e->data;
168 else value = 0;
169 }
170
171 template<typename T>
172 void getValue(int index, MetaDataType requestedType, const T*& value, int& count)
173 {
174 if (index < 0 || index >= int(_entries.size())) {
175 value = 0;
176 count = 0;
177 return;
178 }
179 Entry* e = getEntry(index);
180 if (e && e->type == requestedType) {
181 value = (const T*) e->data;
182 count = int(e->datasize/sizeof(T));
183 }
184 else { value = 0; count = 0; }
185 }
186
187 template<typename T>
188 void getValue(const char* key, MetaDataType requestedType, const T*& value, int& count)
189 {
190 int index = -1;
191 MetaDataType type;
192 findKey(key, index, type);
193 getValue<T>(index, requestedType, value, count);
194 }
195
196 virtual void getValue(const char* key, const int8_t*& value, int& count)
197 {
198 getValue<int8_t>(key, mdt_int8, value, count);
199 }
200
201 virtual void getValue(int index, const int8_t*& value, int& count)
202 {
203 getValue<int8_t>(index, mdt_int8, value, count);
204 }
205
206 virtual void getValue(const char* key, const int16_t*& value, int& count)
207 {
208 getValue<int16_t>(key, mdt_int16, value, count);
209 }
210
211 virtual void getValue(int index, const int16_t*& value, int& count)
212 {
213 getValue<int16_t>(index, mdt_int16, value, count);
214 }
215
216 virtual void getValue(const char* key, const int32_t*& value, int& count)
217 {
218 getValue<int32_t>(key, mdt_int32, value, count);
219 }
220
221 virtual void getValue(int index, const int32_t*& value, int& count)
222 {
223 getValue<int32_t>(index, mdt_int32, value, count);
224 }
225
226 virtual void getValue(const char* key, const float*& value, int& count)
227 {
228 getValue<float>(key, mdt_float, value, count);
229 }
230
231 virtual void getValue(int index, const float*& value, int& count)
232 {
233 getValue<float>(index, mdt_float, value, count);
234 }
235
236 virtual void getValue(const char* key, const double*& value, int& count)
237 {
238 getValue<double>(key, mdt_double, value, count);
239 }
240
241 virtual void getValue(int index, const double*& value, int& count)
242 {
243 getValue<double>(index, mdt_double, value, count);
244 }
245
246 void addEntry(uint8_t keysize, const char* key, uint8_t datatype,
247 uint32_t datasize, const void* data, size_t& metaDataMemUsed)
248 {
249 Entry* e = newEntry(keysize, key, datatype, datasize, metaDataMemUsed);
250 e->data = new char[datasize];
251 memcpy(e->data, data, datasize);
252 metaDataMemUsed += datasize;
253 }
254
255 void addLmdEntry(uint8_t keysize, const char* key, uint8_t datatype,
256 uint32_t datasize, FilePos filepos, uint32_t zipsize,
257 size_t& metaDataMemUsed)
258 {
259 Entry* e = newEntry(keysize, key, datatype, datasize, metaDataMemUsed);
260 e->isLmd = true;
261 e->lmdData = 0;
262 e->lmdPos = filepos;
263 e->lmdZipSize = zipsize;
264 }
265
266 size_t selfDataSize()
267 {
268 return sizeof(*this) + sizeof(Entry*) * _entries.capacity();
269 }
270
271 protected:
272 class LargeMetaData
273 {
274 public:
275 LargeMetaData(int size)
276 : _data(new char [size]) {}
277 virtual ~LargeMetaData() { delete [] _data; }
278 void* data() { return _data; }
279 private:
280 LargeMetaData(const LargeMetaData&);
281 char* _data;
282 };
283
284 struct Entry {
285 const char* key; // ptr to map key string
286 MetaDataType type; // meta data type
287 uint32_t datasize; // size of data in bytes
288 char* data; // if lmd, data only valid when lmd is loaded and ref'ed
289 bool isLmd; // true if data is a large meta data block
290 LargeMetaData* lmdData; // large meta data (lazy-loaded)
291 FilePos lmdPos; // large meta data file position
292 uint32_t lmdZipSize; // large meta data size on disk
293 uint32_t index; // index in vector
294
295 Entry() :
296 key(0), type(MetaDataType(0)), datasize(0), data(0),
297 isLmd(0), lmdData(0), lmdPos(0), lmdZipSize(0) {}
298 ~Entry() { clear(); }
299 void clear() {
300 if (isLmd) {
301 isLmd = 0;
302 if (lmdData) { delete lmdData; lmdData = 0; }
303 lmdPos = 0;
304 lmdZipSize = 0;
305 }
306 else {
307 if (data) { delete [] data; }
308 }
309 data = 0;
310 }
311 };
312
313 Entry* newEntry(uint8_t keysize, const char* key, uint8_t datatype, uint32_t datasize, size_t& metaDataMemUsed)
314 {
315 std::pair<MetaMap::iterator,bool> result =
316 _map.insert(std::make_pair(std::string(key, keysize), Entry()));
317 Entry* e = &result.first->second;
318 bool newentry = result.second;
319 uint32_t index = 0;
320 if (newentry) {
321 index = uint32_t(_entries.size());
322 _entries.push_back(e);
323 }
324 else {
325 index = e->index;
326 e->clear();
327 }
328 e->key = result.first->first.c_str();
329 e->type = MetaDataType(datatype);
330 e->datasize = datasize;
331 e->index = index;
332 metaDataMemUsed += sizeof(std::string) + keysize + 1 + sizeof(Entry);
333 return e;
334 }
335
336 Entry* getEntry(int index);
337
338 PtexReader* _reader;
339 typedef std::map<std::string, Entry> MetaMap;
340 MetaMap _map;
341 std::vector<Entry*> _entries;
342 };
343
344
345 class ConstDataPtr : public PtexFaceData {
346 public:
347 ConstDataPtr(void* data, int pixelsize)
348 : _data(data), _pixelsize(pixelsize) {}
349 virtual void release() { delete this; }
350 virtual Ptex::Res res() { return 0; }
351 virtual bool isConstant() { return true; }
352 virtual void getPixel(int, int, void* result)
353 { memcpy(result, _data, _pixelsize); }
354 virtual void* getData() { return _data; }
355 virtual bool isTiled() { return false; }
356 virtual Ptex::Res tileRes() { return 0; }
357 virtual PtexFaceData* getTile(int) { return 0; }
358
359 protected:
360 void* _data;
361 int _pixelsize;
362 };
363
364
365 class FaceData : public PtexFaceData {
366 public:
367 FaceData(Res resArg)
368 : _res(resArg) {}
369 virtual ~FaceData() {}
370 virtual void release() { }
371 virtual Ptex::Res res() { return _res; }
372 virtual FaceData* reduce(PtexReader*, Res newres, PtexUtils::ReduceFn, size_t& newMemUsed) = 0;
373 protected:
374 Res _res;
375 };
376
377 class PackedFace : public FaceData {
378 public:
379 PackedFace(Res resArg, int pixelsize, int size)
380 : FaceData(resArg),
381 _pixelsize(pixelsize), _data(new char [size]) {}
382 void* data() { return _data; }
383 virtual bool isConstant() { return false; }
384 virtual void getPixel(int u, int v, void* result)
385 {
386 memcpy(result, _data + (v*_res.u() + u) * _pixelsize, _pixelsize);
387 }
388 virtual void* getData() { return _data; }
389 virtual bool isTiled() { return false; }
390 virtual Ptex::Res tileRes() { return _res; }
391 virtual PtexFaceData* getTile(int) { return 0; }
392 virtual FaceData* reduce(PtexReader*, Res newres, PtexUtils::ReduceFn, size_t& newMemUsed);
393
394 protected:
395 virtual ~PackedFace() { delete [] _data; }
396
397 int _pixelsize;
398 char* _data;
399 };
400
401 class ConstantFace : public PackedFace {
402 public:
403 ConstantFace(int pixelsize)
404 : PackedFace(0, pixelsize, pixelsize) {}
405 virtual bool isConstant() { return true; }
406 virtual void getPixel(int, int, void* result) { memcpy(result, _data, _pixelsize); }
407 virtual FaceData* reduce(PtexReader*, Res newres, PtexUtils::ReduceFn, size_t& newMemUsed);
408 };
409
410 class ErrorFace : public ConstantFace {
411 bool _deleteOnRelease;
412 public:
413 ErrorFace(void* errorPixel, int pixelsize, bool deleteOnRelease)
414 : ConstantFace(pixelsize), _deleteOnRelease(deleteOnRelease)
415 {
416 memcpy(_data, errorPixel, pixelsize);
417 }
418 virtual void release() { if (_deleteOnRelease) delete this; }
419 };
420
421 class TiledFaceBase : public FaceData {
422 public:
423 TiledFaceBase(PtexReader* reader, Res resArg, Res tileresArg)
424 : FaceData(resArg),
425 _reader(reader),
426 _tileres(tileresArg)
427 {
428 _dt = reader->datatype();
429 _nchan = reader->nchannels();
430 _pixelsize = DataSize(_dt)*_nchan;
431 _ntilesu = _res.ntilesu(tileresArg);
432 _ntilesv = _res.ntilesv(tileresArg);
433 _ntiles = _ntilesu*_ntilesv;
434 _tiles.resize(_ntiles);
435 }
436
437 virtual void release() { }
438 virtual bool isConstant() { return false; }
439 virtual void getPixel(int u, int v, void* result);
440 virtual void* getData() { return 0; }
441 virtual bool isTiled() { return true; }
442 virtual Ptex::Res tileRes() { return _tileres; }
443 virtual FaceData* reduce(PtexReader*, Res newres, PtexUtils::ReduceFn, size_t& newMemUsed);
444 Res tileres() const { return _tileres; }
445 int ntilesu() const { return _ntilesu; }
446 int ntilesv() const { return _ntilesv; }
447 int ntiles() const { return _ntiles; }
448
449 protected:
450 size_t baseExtraMemUsed() { return _tiles.size() * sizeof(_tiles[0]); }
451
452 virtual ~TiledFaceBase() {
453 for (std::vector<FaceData*>::iterator i = _tiles.begin(); i != _tiles.end(); ++i) {
454 if (*i) delete *i;
455 }
456 }
457
458 PtexReader* _reader;
459 Res _tileres;
460 DataType _dt;
461 int _nchan;
462 int _ntilesu;
463 int _ntilesv;
464 int _ntiles;
465 int _pixelsize;
466 std::vector<FaceData*> _tiles;
467 };
468
469
470 class TiledFace : public TiledFaceBase {
471 public:
472 TiledFace(PtexReader* reader, Res resArg, Res tileresArg, int levelid)
473 : TiledFaceBase(reader, resArg, tileresArg),
474 _levelid(levelid)
475 {
476 _fdh.resize(_ntiles),
477 _offsets.resize(_ntiles);
478 }
479 virtual PtexFaceData* getTile(int tile)
480 {
481 FaceData*& f = _tiles[tile];
482 if (!f) readTile(tile, f);
483 return f;
484 }
485 void readTile(int tile, FaceData*& data);
486 size_t memUsed() {
487 return sizeof(*this) + baseExtraMemUsed() + _fdh.size() * (sizeof(_fdh[0]) + sizeof(_offsets[0]));
488 }
489
490 protected:
491 friend class PtexReader;
492 int _levelid;
493 std::vector<FaceDataHeader> _fdh;
494 std::vector<FilePos> _offsets;
495 };
496
497
498 class TiledReducedFace : public TiledFaceBase {
499 public:
500 TiledReducedFace(PtexReader* reader, Res resArg, Res tileresArg,
501 TiledFaceBase* parentface, PtexUtils::ReduceFn reducefn)
502 : TiledFaceBase(reader, resArg, tileresArg),
503 _parentface(parentface),
504 _reducefn(reducefn)
505 {
506 }
507 ~TiledReducedFace()
508 {
509 }
510 virtual PtexFaceData* getTile(int tile);
511
512 size_t memUsed() { return sizeof(*this) + baseExtraMemUsed(); }
513
514 protected:
515 TiledFaceBase* _parentface;
516 PtexUtils::ReduceFn* _reducefn;
517 };
518
519
520 class Level {
521 public:
522 std::vector<FaceDataHeader> fdh;
523 std::vector<FilePos> offsets;
524 std::vector<FaceData*> faces;
525
526 Level(int nfaces)
527 : fdh(nfaces),
528 offsets(nfaces),
529 faces(nfaces) {}
530
531 ~Level() {
532 for (std::vector<FaceData*>::iterator i = faces.begin(); i != faces.end(); ++i) {
533 if (*i) delete *i;
534 }
535 }
536
537 size_t memUsed() {
538 return sizeof(*this) + fdh.size() * (sizeof(fdh[0]) +
539 sizeof(offsets[0]) +
540 sizeof(faces[0]));
541 }
542 };
543
544
545 protected:
546 void setError(const char* error)
547 {
548 std::string msg = error;
549 msg += " PtexFile: ";
550 msg += _path;
551 msg += "\n";
552 if (_err) _err->reportError(msg.c_str());
553 else std::cerr << msg;
554 _ok = 0;
555 }
556
557 FilePos tell() { return _pos; }
558 void seek(FilePos pos)
559 {
560 if (!_fp && !reopenFP()) return;
561 logBlockRead();
562 if (pos != _pos) {
563 _io->seek(_fp, pos);
564 _pos = pos;
565 }
566 }
567
568 void closeFP();
569 bool reopenFP();
570 bool readBlock(void* data, int size, bool reportError=true);
571 bool readZipBlock(void* data, int zipsize, int unzipsize);
572 Level* getLevel(int levelid)
573 {
574 Level*& level = _levels[levelid];
575 if (!level) readLevel(levelid, level);
576 return level;
577 }
578
579 uint8_t* getConstData() { return _constdata; }
580 FaceData* getFace(int levelid, Level* level, int faceid, Res res)
581 {
582 FaceData*& face = level->faces[faceid];
583 if (!face) readFace(levelid, level, faceid, res);
584 return face;
585 }
586
587 void readFaceInfo();
588 void readLevelInfo();
589 void readConstData();
590 void readLevel(int levelid, Level*& level);
591 void readFace(int levelid, Level* level, int faceid, Res res);
592 void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData*& face);
593 void readMetaData();
594 void readMetaDataBlock(MetaData* metadata, FilePos pos, int zipsize, int memsize, size_t& metaDataMemUsed);
595 void readLargeMetaDataHeaders(MetaData* metadata, FilePos pos, int zipsize, int memsize, size_t& metaDataMemUsed);
596 void readEditData();
597 void readEditFaceData();
598 void readEditMetaData();
599
600 FaceData* errorData(bool deleteOnRelease=false)
601 {
602 return new ErrorFace(&_errorPixel[0], _pixelsize, deleteOnRelease);
603 }
604
605 void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader* fdh, FilePos* offsets)
606 {
607 FilePos* end = offsets + noffsets;
608 while (offsets != end) { *offsets++ = pos; pos += fdh->blocksize(); fdh++; }
609 }
610
611 class DefaultInputHandler : public PtexInputHandler
612 {
613 char* buffer;
614 public:
615 DefaultInputHandler() : buffer(0) {}
616 virtual Handle open(const char* path) {
617 FILE* fp = fopen(path, "rb");
618 if (fp) {
619 buffer = new char [IBuffSize];
620 setvbuf(fp, buffer, _IOFBF, IBuffSize);
621 }
622 else buffer = 0;
623 return (Handle) fp;
624 }
625 virtual void seek(Handle handle, int64_t pos) { fseeko((FILE*)handle, pos, SEEK_SET); }
626 virtual size_t read(void* bufferArg, size_t size, Handle handle) {
627 return fread(bufferArg, size, 1, (FILE*)handle) == 1 ? size : 0;
628 }
629 virtual bool close(Handle handle) {
630 bool ok = handle && (fclose((FILE*)handle) == 0);
631 if (buffer) { delete [] buffer; buffer = 0; }
632 return ok;
633 }
634 virtual const char* lastError() { return strerror(errno); }
635 };
636
637 Mutex readlock;
638 DefaultInputHandler _defaultIo; // Default IO handler
639 PtexInputHandler* _io; // IO handler
640 PtexErrorHandler* _err; // Error handler
641 bool _premultiply; // true if reader should premultiply the alpha chan
642 bool _ok; // flag set to false if open or read error occurred
643 bool _needToOpen; // true if file needs to be opened (or reopened after a purge)
644 bool _pendingPurge; // true if a purge attempt was made but file was busy
645 PtexInputHandler::Handle _fp; // file pointer
646 FilePos _pos; // current seek position
647 std::string _path; // current file path
648 Header _header; // the header
649 ExtHeader _extheader; // extended header
650 FilePos _faceinfopos; // file positions of data sections
651 FilePos _constdatapos; // ...
652 FilePos _levelinfopos;
653 FilePos _leveldatapos;
654 FilePos _metadatapos;
655 FilePos _lmdheaderpos;
656 FilePos _lmddatapos;
657 FilePos _editdatapos;
658 int _pixelsize; // size of a pixel in bytes
659 uint8_t* _constdata; // constant pixel value per face
660 MetaData* _metadata; // meta data (read on demand)
661 bool _hasEdits; // has edit blocks
662
663 std::vector<FaceInfo> _faceinfo; // per-face header info
664 std::vector<uint32_t> _rfaceids; // faceids sorted in reduction order
665 std::vector<LevelInfo> _levelinfo; // per-level header info
666 std::vector<FilePos> _levelpos; // file position of each level's data
667 std::vector<Level*> _levels; // level data (read on demand)
668
669 struct MetaEdit
670 {
671 FilePos pos;
672 int zipsize;
673 int memsize;
674 };
675 std::vector<MetaEdit> _metaedits;
676
677 struct FaceEdit
678 {
679 FilePos pos;
680 int faceid;
681 FaceDataHeader fdh;
682 };
683 std::vector<FaceEdit> _faceedits;
684
685 class ReductionKey {
686 int64_t _val;
687 public:
688 ReductionKey() : _val(-1) {}
689 ReductionKey(uint32_t faceid, Res res)
690 : _val( int64_t(faceid)<<32 | uint32_t(16777619*((res.val()<<16) ^ faceid)) ) {}
691
692 void copy(volatile ReductionKey& key) volatile
693 {
694 _val = key._val;
695 }
696
697 void move(volatile ReductionKey& key) volatile
698 {
699 _val = key._val;
700 }
701
702 bool matches(const ReductionKey& key) volatile
703 {
704 return _val == key._val;
705 }
706 bool isEmpty() volatile { return _val==-1; }
707 uint32_t hash() volatile
708 {
709 return uint32_t(_val);
710 }
711 };
712 typedef PtexHashMap<ReductionKey, FaceData*> ReductionMap;
713 ReductionMap _reductions;
714 std::vector<char> _errorPixel; // referenced by errorData()
715
716 z_stream_s _zstream;
717 size_t _baseMemUsed;
718 volatile size_t _memUsed;
719 volatile size_t _opens;
720 volatile size_t _blockReads;
721 };
722
723 PTEX_NAMESPACE_END
724
725 #endif
PtexReader::_defaultIo
DefaultInputHandler _defaultIo
Definition: PtexReader.h:638
PtexReader::ConstDataPtr::_pixelsize
int _pixelsize
Definition: PtexReader.h:361
PtexTexture::Info::edgeFilterMode
EdgeFilterMode edgeFilterMode
Definition: Ptexture.h:504
PtexReader::setPendingPurge
void setPendingPurge()
Definition: PtexReader.h:61
PtexReader::numFaces
virtual int numFaces()
Number of faces stored in file.
Definition: PtexReader.h:97
PtexReader::PackedFace::~PackedFace
virtual ~PackedFace()
Definition: PtexReader.h:395
PtexReader::_extheader
ExtHeader _extheader
Definition: PtexReader.h:649
PtexReader::FaceData::release
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:370
PtexReader::ReductionKey::ReductionKey
ReductionKey()
Definition: PtexReader.h:688
PtexReader::_errorPixel
std::vector< char > _errorPixel
Definition: PtexReader.h:714
PtexReader::ConstantFace::reduce
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
Definition: PtexReader.cpp:966
Ptex::mdt_int32
Signed 32-bit integer.
Definition: Ptexture.h:119
PtexReader::hasMipMaps
virtual bool hasMipMaps()
True if the file has mipmaps.
Definition: PtexReader.h:99
PtexReader::MetaData::getValue
void getValue(const char *key, MetaDataType requestedType, const T *&value, int &count)
Definition: PtexReader.h:188
PtexTexture::Info::dataType
DataType dataType
Definition: Ptexture.h:501
PtexReader::ConstDataPtr::getTile
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
Definition: PtexReader.h:357
PtexReader::MetaData::getValue
virtual void getValue(const char *key, const float *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:226
PtexReader::ConstantFace::ConstantFace
ConstantFace(int pixelsize)
Definition: PtexReader.h:403
PtexReader::TiledReducedFace::~TiledReducedFace
~TiledReducedFace()
Definition: PtexReader.h:507
PtexReader::MetaData::Entry::index
uint32_t index
Definition: PtexReader.h:293
Header::meshtype
uint32_t meshtype
Definition: PtexIO.h:47
PtexReader::MetaData::_entries
std::vector< Entry * > _entries
Definition: PtexReader.h:341
PtexReader::TiledFaceBase::getData
virtual void * getData()
Access the data from this data block.
Definition: PtexReader.h:440
PtexUtils::ReduceFn
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
Definition: PtexUtils.h:174
PtexReader::ConstDataPtr::release
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:349
PtexReader::hasEdits
virtual bool hasEdits()
True if the file has edit blocks.
Definition: PtexReader.h:98
PtexReader::TiledFaceBase::tileRes
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition: PtexReader.h:442
PtexReader::ErrorFace::release
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:418
PtexReader::_io
PtexInputHandler * _io
Definition: PtexReader.h:639
PtexReader::extheader
const ExtHeader & extheader() const
Definition: PtexReader.h:117
PtexReader::readFaceInfo
void readFaceInfo()
Definition: PtexReader.cpp:277
PtexReader::FaceData::FaceData
FaceData(Res resArg)
Definition: PtexReader.h:367
Ptex::String
Memory-managed string.
Definition: Ptexture.h:308
PtexReader::ErrorFace
Definition: PtexReader.h:410
PtexReader::getFaceInfo
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)
Access resolution and adjacency information about a face.
Definition: PtexReader.cpp:267
PtexReader::logOpen
void logOpen()
Definition: PtexReader.h:72
Header::nlevels
uint16_t nlevels
Definition: PtexIO.h:51
PtexReader::readLevelInfo
void readLevelInfo()
Definition: PtexReader.cpp:298
PtexReader::DefaultInputHandler::buffer
char * buffer
Definition: PtexReader.h:613
PtexReader::_opens
volatile size_t _opens
Definition: PtexReader.h:719
PtexReader::MetaData::LargeMetaData::~LargeMetaData
virtual ~LargeMetaData()
Definition: PtexReader.h:277
PtexReader::PackedFace::getTile
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
Definition: PtexReader.h:391
PtexReader::PackedFace::PackedFace
PackedFace(Res resArg, int pixelsize, int size)
Definition: PtexReader.h:379
PtexTexture::Info::vBorderMode
BorderMode vBorderMode
Definition: Ptexture.h:503
ExtHeader::ubordermode
uint16_t ubordermode
Definition: PtexIO.h:65
Header::alphachan
int32_t alphachan
Definition: PtexIO.h:49
PtexReader::TiledFaceBase::ntilesv
int ntilesv() const
Definition: PtexReader.h:446
Header
Definition: PtexIO.h:44
PtexReader::TiledFace
Definition: PtexReader.h:470
PtexReader::_leveldatapos
FilePos _leveldatapos
Definition: PtexReader.h:653
FaceDataHeader::blocksize
uint32_t blocksize() const
Definition: PtexIO.h:84
PtexMetaData
Meta data accessor.
Definition: Ptexture.h:341
PtexReader::TiledFaceBase::_ntilesv
int _ntilesv
Definition: PtexReader.h:463
ExtHeader::edgefiltermode
uint16_t edgefiltermode
Definition: PtexIO.h:68
PtexReader::PackedFace::data
void * data()
Definition: PtexReader.h:382
PtexReader::MetaData
Definition: PtexReader.h:120
PtexReader::TiledReducedFace::memUsed
size_t memUsed()
Definition: PtexReader.h:512
PtexReader::_metadata
MetaData * _metadata
Definition: PtexReader.h:660
PtexReader::alphaChannel
virtual int alphaChannel()
Index of alpha channel (if any).
Definition: PtexReader.h:95
PtexReader::closeFP
void closeFP()
Definition: PtexReader.cpp:230
PtexReader::Level::~Level
~Level()
Definition: PtexReader.h:531
PtexReader::TiledFaceBase::_dt
DataType _dt
Definition: PtexReader.h:460
PtexReader::DefaultInputHandler::close
virtual bool close(Handle handle)
Close a file.
Definition: PtexReader.h:629
PtexReader::PtexReader
PtexReader(bool premultiply, PtexInputHandler *inputHandler, PtexErrorHandler *errorHandler)
Definition: PtexReader.cpp:71
PtexReader::TiledFaceBase::isConstant
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:438
PtexReader::Level::memUsed
size_t memUsed()
Definition: PtexReader.h:537
PtexReader::readConstData
void readConstData()
Definition: PtexReader.cpp:319
PtexReader::levelinfo
const LevelInfo & levelinfo(int level) const
Definition: PtexReader.h:118
PtexReader::readBlock
bool readBlock(void *data, int size, bool reportError=true)
Definition: PtexReader.cpp:548
PtexReader::ReductionKey::hash
uint32_t hash() volatile
Definition: PtexReader.h:707
PtexReader::MetaData::release
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:125
PtexReader::Level::offsets
std::vector< FilePos > offsets
Definition: PtexReader.h:523
AtomicIncrement
PTEX_INLINE T AtomicIncrement(volatile T *target)
Definition: PtexPlatform.h:213
PtexReader::_ok
bool _ok
Definition: PtexReader.h:642
PtexReader::path
virtual const char * path()
Path that file was opened with.
Definition: PtexReader.h:75
PtexReader::TiledFaceBase
Definition: PtexReader.h:421
PtexReader::_path
std::string _path
Definition: PtexReader.h:647
PtexReader::MetaData::Entry::clear
void clear()
Definition: PtexReader.h:299
PtexReader::DefaultInputHandler::lastError
virtual const char * lastError()
Return the last error message encountered.
Definition: PtexReader.h:634
PtexReader::ReductionKey
Definition: PtexReader.h:685
PtexReader::numChannels
virtual int numChannels()
Number of channels stored in file.
Definition: PtexReader.h:96
PtexReader::_constdata
uint8_t * _constdata
Definition: PtexReader.h:659
PtexReader::readLevel
void readLevel(int levelid, Level *&level)
Definition: PtexReader.cpp:595
PtexReader::FaceData
Definition: PtexReader.h:365
PtexReader::_levelpos
std::vector< FilePos > _levelpos
Definition: PtexReader.h:666
PtexReader::MetaEdit::zipsize
int zipsize
Definition: PtexReader.h:672
Mutex
Definition: PtexPlatform.h:125
PtexReader::MetaData::getValue
virtual void getValue(const char *key, const int32_t *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:216
PtexReader::DefaultInputHandler
Definition: PtexReader.h:611
Ptex::mdt_int8
Signed 8-bit integer.
Definition: Ptexture.h:117
PtexReader::pixelsize
int pixelsize() const
Definition: PtexReader.h:115
PtexReader::getMetaData
virtual PtexMetaData * getMetaData()
Access meta data.
Definition: PtexReader.cpp:335
PtexReader::readMetaDataBlock
void readMetaDataBlock(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
Definition: PtexReader.cpp:414
PtexReader::TiledFaceBase::reduce
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
Definition: PtexReader.cpp:979
PtexReader::TiledFace::memUsed
size_t memUsed()
Definition: PtexReader.h:486
Ptex::EdgeFilterMode
EdgeFilterMode
How to handle transformation across edges when filtering.
Definition: Ptexture.h:93
PtexTexture::Info
Get most commonly used info in a single call for convenience / efficiency.
Definition: Ptexture.h:499
PtexReader::MetaData::Entry::lmdData
LargeMetaData * lmdData
Definition: PtexReader.h:290
AtomicAdd
PTEX_INLINE T AtomicAdd(volatile T *target, T value)
Definition: PtexPlatform.h:197
PtexReader::FaceData::res
virtual Ptex::Res res()
Resolution of the texture held by this data block.
Definition: PtexReader.h:371
PtexReader::_needToOpen
bool _needToOpen
Definition: PtexReader.h:643
PtexReader::_baseMemUsed
size_t _baseMemUsed
Definition: PtexReader.h:717
PtexReader::_rfaceids
std::vector< uint32_t > _rfaceids
Definition: PtexReader.h:664
PtexReader::MetaData::selfDataSize
size_t selfDataSize()
Definition: PtexReader.h:266
PtexReader::edgeFilterMode
virtual Ptex::EdgeFilterMode edgeFilterMode()
Mode for filtering textures across edges.
Definition: PtexReader.h:94
PtexReader::ConstDataPtr::getPixel
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Definition: PtexReader.h:352
PtexIO.h
PtexReader::MetaData::getValue
virtual void getValue(const char *key, const double *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:236
PtexReader::ReductionKey::_val
int64_t _val
Definition: PtexReader.h:686
PtexReader::_reductions
ReductionMap _reductions
Definition: PtexReader.h:713
Ptex::mdt_double
Double-precision (32-bit) floating point.
Definition: Ptexture.h:121
PtexReader::TiledFaceBase::_nchan
int _nchan
Definition: PtexReader.h:461
PtexReader::dataType
virtual Ptex::DataType dataType()
Type of data stored in file.
Definition: PtexReader.h:91
FilePos
off_t FilePos
Definition: PtexPlatform.h:87
PtexErrorHandler::reportError
virtual void reportError(const char *error)=0
PtexReader::MetaData::getValue
virtual void getValue(int index, const float *&value, int &count)
Query the value of a given meta data entry by index.
Definition: PtexReader.h:231
PtexReader::invalidate
void invalidate()
Definition: PtexReader.h:66
PtexReader::PackedFace::_pixelsize
int _pixelsize
Definition: PtexReader.h:397
PtexReader::TiledFace::_levelid
int _levelid
Definition: PtexReader.h:492
PtexReader::errorData
FaceData * errorData(bool deleteOnRelease=false)
Definition: PtexReader.h:600
PtexReader::MetaData::getValue
void getValue(int index, MetaDataType requestedType, const T *&value, int &count)
Definition: PtexReader.h:172
PtexReader::TiledFaceBase::release
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:437
PtexReader::readFace
void readFace(int levelid, Level *level, int faceid, Res res)
Definition: PtexReader.cpp:627
PtexReader::MetaData::LargeMetaData::_data
char * _data
Definition: PtexReader.h:281
PtexReader::ErrorFace::ErrorFace
ErrorFace(void *errorPixel, int pixelsize, bool deleteOnRelease)
Definition: PtexReader.h:413
PtexReader::_zstream
z_stream_s _zstream
Definition: PtexReader.h:716
PtexFaceData
Per-face texture data accessor.
Definition: Ptexture.h:419
ExtHeader::vbordermode
uint16_t vbordermode
Definition: PtexIO.h:67
PtexReader::MetaData::Entry::datasize
uint32_t datasize
Definition: PtexReader.h:287
PtexReader::ReductionKey::isEmpty
bool isEmpty() volatile
Definition: PtexReader.h:706
PtexReader::increaseMemUsed
void increaseMemUsed(size_t amount)
Definition: PtexReader.h:71
PtexErrorHandler
Custom handler interface redirecting Ptex error messages.
Definition: Ptexture.h:671
PtexReader::TiledFace::TiledFace
TiledFace(PtexReader *reader, Res resArg, Res tileresArg, int levelid)
Definition: PtexReader.h:472
PtexReader::_lmdheaderpos
FilePos _lmdheaderpos
Definition: PtexReader.h:655
PtexReader::DefaultInputHandler::seek
virtual void seek(Handle handle, int64_t pos)
Seek to an absolute byte position in the input stream.
Definition: PtexReader.h:625
PtexReader::vBorderMode
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
Definition: PtexReader.h:93
PtexReader::PackedFace::getPixel
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
Definition: PtexReader.h:384
PtexReader::TiledFaceBase::tileres
Res tileres() const
Definition: PtexReader.h:444
PtexReader::TiledFaceBase::_tiles
std::vector< FaceData * > _tiles
Definition: PtexReader.h:466
PtexReader::MetaData::Entry::Entry
Entry()
Definition: PtexReader.h:295
PtexReader::ConstDataPtr::isTiled
virtual bool isTiled()
True if this data block is tiled.
Definition: PtexReader.h:355
PtexReader::MetaData::Entry::lmdPos
FilePos lmdPos
Definition: PtexReader.h:291
PtexReader::uBorderMode
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
Definition: PtexReader.h:92
PtexReader::FaceEdit::faceid
int faceid
Definition: PtexReader.h:680
PtexReader::PackedFace::isConstant
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:383
Ptex::MeshType
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:79
PtexReader::DefaultInputHandler::read
virtual size_t read(void *bufferArg, size_t size, Handle handle)
Read a number of bytes from the file.
Definition: PtexReader.h:626
PtexReader::ConstDataPtr::getData
virtual void * getData()
Access the data from this data block.
Definition: PtexReader.h:354
PtexReader::MetaData::MetaData
MetaData(PtexReader *reader)
Definition: PtexReader.h:122
PtexReader::ConstDataPtr::isConstant
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:351
PtexReader::TiledFaceBase::_pixelsize
int _pixelsize
Definition: PtexReader.h:465
PtexTexture::Info::numChannels
int numChannels
Definition: Ptexture.h:506
PtexReader::TiledFace::readTile
void readTile(int tile, FaceData *&data)
Definition: PtexReader.cpp:635
PtexReader::MetaData::Entry::data
char * data
Definition: PtexReader.h:288
PtexReader::readMetaData
void readMetaData()
Definition: PtexReader.cpp:381
PtexReader::getInfo
virtual Info getInfo()
Definition: PtexReader.h:77
PtexReader::readLargeMetaDataHeaders
void readLargeMetaDataHeaders(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
Definition: PtexReader.cpp:440
PtexReader::MetaData::LargeMetaData
Definition: PtexReader.h:272
PtexReader::~PtexReader
virtual ~PtexReader()
Definition: PtexReader.cpp:93
PtexReader::_metaedits
std::vector< MetaEdit > _metaedits
Definition: PtexReader.h:675
PtexReader::ConstDataPtr::_data
void * _data
Definition: PtexReader.h:360
PtexReader::TiledFaceBase::_ntilesu
int _ntilesu
Definition: PtexReader.h:462
PtexReader::MetaEdit::pos
FilePos pos
Definition: PtexReader.h:671
PtexReader::PackedFace::tileRes
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition: PtexReader.h:390
Ptex::BorderMode
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:99
PtexReader::computeOffsets
void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
Definition: PtexReader.h:605
PtexReader
Definition: PtexReader.h:52
PtexReader::MetaData::addLmdEntry
void addLmdEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, FilePos filepos, uint32_t zipsize, size_t &metaDataMemUsed)
Definition: PtexReader.h:255
PtexReader::readlock
Mutex readlock
Definition: PtexReader.h:637
PtexReader::ReductionMap
PtexHashMap< ReductionKey, FaceData * > ReductionMap
Definition: PtexReader.h:712
PtexReader::MetaData::Entry
Definition: PtexReader.h:284
PtexReader::TiledFaceBase::~TiledFaceBase
virtual ~TiledFaceBase()
Definition: PtexReader.h:452
PtexReader::_hasEdits
bool _hasEdits
Definition: PtexReader.h:661
PtexReader::prune
void prune()
Definition: PtexReader.cpp:104
PtexReader::_faceinfopos
FilePos _faceinfopos
Definition: PtexReader.h:650
PtexReader::MetaData::~MetaData
~MetaData()
Definition: PtexReader.h:124
PtexReader::needToOpen
bool needToOpen() const
Definition: PtexReader.h:57
PtexReader::MetaData::Entry::type
MetaDataType type
Definition: PtexReader.h:286
PtexReader::isOpen
bool isOpen()
Definition: PtexReader.h:65
PtexReader::setError
void setError(const char *error)
Definition: PtexReader.h:546
PtexReader::release
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:56
PtexReader::_err
PtexErrorHandler * _err
Definition: PtexReader.h:640
PtexReader::FaceEdit
Definition: PtexReader.h:677
PtexReader::TiledReducedFace::TiledReducedFace
TiledReducedFace(PtexReader *reader, Res resArg, Res tileresArg, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
Definition: PtexReader.h:500
PtexReader::_editdatapos
FilePos _editdatapos
Definition: PtexReader.h:657
PtexReader::TiledFaceBase::_reader
PtexReader * _reader
Definition: PtexReader.h:458
PtexReader::logBlockRead
void logBlockRead()
Definition: PtexReader.h:73
PtexInputHandler::Handle
void * Handle
Definition: Ptexture.h:637
PtexReader::ConstDataPtr::res
virtual Ptex::Res res()
Resolution of the texture held by this data block.
Definition: PtexReader.h:350
PtexReader::MetaData::addEntry
void addEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, const void *data, size_t &metaDataMemUsed)
Definition: PtexReader.h:246
PtexReader::readZipBlock
bool readZipBlock(void *data, int zipsize, int unzipsize)
Definition: PtexReader.cpp:563
PtexReader::_faceedits
std::vector< FaceEdit > _faceedits
Definition: PtexReader.h:683
PtexReader::MetaData::getValue
virtual void getValue(int index, const int8_t *&value, int &count)
Query the value of a given meta data entry by index.
Definition: PtexReader.h:201
PtexReader::PackedFace::_data
char * _data
Definition: PtexReader.h:398
PtexReader::TiledFace::getTile
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
Definition: PtexReader.h:479
PtexReader::_levelinfopos
FilePos _levelinfopos
Definition: PtexReader.h:652
Header::datatype
uint32_t datatype
Definition: PtexIO.h:48
PtexReader::ConstantFace::isConstant
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:405
PtexTexture::Info::meshType
MeshType meshType
Definition: Ptexture.h:500
FaceDataHeader
Definition: PtexIO.h:82
PtexReader::ErrorFace::_deleteOnRelease
bool _deleteOnRelease
Definition: PtexReader.h:411
PtexReader::getData
virtual void getData(int faceid, void *buffer, int stride)
Access texture data for a face at highest-resolution.
Definition: PtexReader.cpp:711
PtexReader::_premultiply
bool _premultiply
Definition: PtexReader.h:641
PtexReader::TiledFaceBase::getPixel
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
Definition: PtexReader.cpp:1104
PtexTexture::Info::alphaChannel
int alphaChannel
Definition: Ptexture.h:505
PtexReader::Level
Definition: PtexReader.h:520
PtexReader::PackedFace::isTiled
virtual bool isTiled()
True if this data block is tiled.
Definition: PtexReader.h:389
PtexReader::MetaData::getValue
virtual void getValue(int index, const int16_t *&value, int &count)
Query the value of a given meta data entry by index.
Definition: PtexReader.h:211
PtexReader::_constdatapos
FilePos _constdatapos
Definition: PtexReader.h:651
PtexReader::_levels
std::vector< Level * > _levels
Definition: PtexReader.h:667
PtexReader::Level::fdh
std::vector< FaceDataHeader > fdh
Definition: PtexReader.h:522
PtexReader::getLevel
Level * getLevel(int levelid)
Definition: PtexReader.h:572
PtexReader::TiledFaceBase::isTiled
virtual bool isTiled()
True if this data block is tiled.
Definition: PtexReader.h:441
PtexReader::_fp
PtexInputHandler::Handle _fp
Definition: PtexReader.h:645
PtexReader::MetaData::getKey
virtual void getKey(int index, const char *&key, MetaDataType &type)
Definition: PtexReader.h:128
PtexReader::ConstantFace
Definition: PtexReader.h:401
PtexReader::_faceinfo
std::vector< FaceInfo > _faceinfo
Definition: PtexReader.h:663
PtexReader::getPixel
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)
Access a single texel from the highest resolution texture .
Definition: PtexReader.cpp:893
PtexReader::purge
void purge()
Definition: PtexReader.cpp:115
PtexReader::MetaData::getEntry
Entry * getEntry(int index)
Definition: PtexReader.cpp:343
PtexReader::TiledFace::_fdh
std::vector< FaceDataHeader > _fdh
Definition: PtexReader.h:493
PtexReader::PackedFace
Definition: PtexReader.h:377
PtexReader::MetaData::Entry::key
const char * key
Definition: PtexReader.h:285
PtexReader::getFace
FaceData * getFace(int levelid, Level *level, int faceid, Res res)
Definition: PtexReader.h:580
PtexReader::ConstantFace::getPixel
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Definition: PtexReader.h:406
PtexReader::TiledReducedFace::_reducefn
PtexUtils::ReduceFn * _reducefn
Definition: PtexReader.h:516
ExtHeader
Definition: PtexIO.h:64
PtexReader::MetaData::newEntry
Entry * newEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, size_t &metaDataMemUsed)
Definition: PtexReader.h:313
PtexReader::tryClose
bool tryClose()
Definition: PtexReader.cpp:219
PtexReader::DefaultInputHandler::open
virtual Handle open(const char *path)
Open a file in read mode.
Definition: PtexReader.h:616
PtexReader::MetaData::numKeys
virtual int numKeys()
Query number of meta data entries stored in file.
Definition: PtexReader.h:127
PtexInputHandler::seek
virtual void seek(Handle handle, int64_t pos)=0
Seek to an absolute byte position in the input stream.
PtexReader::MetaData::getValue
virtual void getValue(const char *key, const int16_t *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:206
PtexReader::_metadatapos
FilePos _metadatapos
Definition: PtexReader.h:654
PtexReader::FaceData::~FaceData
virtual ~FaceData()
Definition: PtexReader.h:369
PtexReader::readFaceData
void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData *&face)
Definition: PtexReader.cpp:641
PtexReader::ReductionKey::ReductionKey
ReductionKey(uint32_t faceid, Res res)
Definition: PtexReader.h:689
PtexReader::PackedFace::getData
virtual void * getData()
Access the data from this data block.
Definition: PtexReader.h:388
Ptex::mdt_string
Null-terminated string.
Definition: Ptexture.h:116
PtexReader::_header
Header _header
Definition: PtexReader.h:648
PtexReader::ReductionKey::matches
bool matches(const ReductionKey &key) volatile
Definition: PtexReader.h:702
PtexReader::MetaData::getValue
virtual void getValue(int index, const int32_t *&value, int &count)
Query the value of a given meta data entry by index.
Definition: PtexReader.h:221
PtexReader::_pixelsize
int _pixelsize
Definition: PtexReader.h:658
PtexReader::MetaData::getValue
virtual void getValue(const char *key, const int8_t *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:196
PtexReader::_memUsed
volatile size_t _memUsed
Definition: PtexReader.h:718
PtexReader::header
const Header & header() const
Definition: PtexReader.h:116
PtexReader::TiledReducedFace::getTile
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
Definition: PtexReader.cpp:1115
PtexReader::TiledFaceBase::TiledFaceBase
TiledFaceBase(PtexReader *reader, Res resArg, Res tileresArg)
Definition: PtexReader.h:423
PtexReader::FaceEdit::fdh
FaceDataHeader fdh
Definition: PtexReader.h:681
PtexTexture
Interface for reading data from a ptex file.
Definition: Ptexture.h:470
PtexReader::MetaData::LargeMetaData::LargeMetaData
LargeMetaData(int size)
Definition: PtexReader.h:275
PtexReader::MetaData::Entry::isLmd
bool isLmd
Definition: PtexReader.h:289
PtexReader::TiledFace::_offsets
std::vector< FilePos > _offsets
Definition: PtexReader.h:494
PtexReader::getConstData
uint8_t * getConstData()
Definition: PtexReader.h:579
PtexReader::MetaData::findKey
virtual bool findKey(const char *key, int &index, MetaDataType &type)
Definition: PtexReader.h:138
PtexReader::datatype
DataType datatype() const
Definition: PtexReader.h:113
Header::nchannels
uint16_t nchannels
Definition: PtexIO.h:50
Ptex::Res
Pixel resolution of a given texture.
Definition: Ptexture.h:172
PtexReader::TiledFaceBase::ntiles
int ntiles() const
Definition: PtexReader.h:447
PtexReader::meshType
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
Definition: PtexReader.h:90
PtexReader::TiledReducedFace
Definition: PtexReader.h:498
PtexReader::MetaData::_map
MetaMap _map
Definition: PtexReader.h:340
PtexReader::PackedFace::reduce
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
Definition: PtexReader.cpp:949
PtexReader::pendingPurge
bool pendingPurge() const
Definition: PtexReader.h:62
PtexHashMap.h
Contains PtexHashMap, a lightweight multi-threaded hash table.
PtexReader::FaceEdit::pos
FilePos pos
Definition: PtexReader.h:679
PtexReader::ConstDataPtr::ConstDataPtr
ConstDataPtr(void *data, int pixelsize)
Definition: PtexReader.h:347
PtexReader::ReductionKey::copy
void copy(volatile ReductionKey &key) volatile
Definition: PtexReader.h:692
PtexReader::open
bool open(const char *path, Ptex::String &error)
Definition: PtexReader.cpp:137
PtexReader::ConstDataPtr
Definition: PtexReader.h:345
PtexReader::TiledFaceBase::_ntiles
int _ntiles
Definition: PtexReader.h:464
Ptex::mdt_float
Single-precision (32-bit) floating point.
Definition: Ptexture.h:120
Header::nfaces
uint32_t nfaces
Definition: PtexIO.h:52
Ptex::DataSize
int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:143
PtexReader::ConstDataPtr::tileRes
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition: PtexReader.h:356
PtexReader::nchannels
int nchannels() const
Definition: PtexReader.h:114
PtexReader::MetaEdit::memsize
int memsize
Definition: PtexReader.h:673
Ptex::MetaDataType
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:115
PtexReader::_levelinfo
std::vector< LevelInfo > _levelinfo
Definition: PtexReader.h:665
PtexReader::Level::faces
std::vector< FaceData * > faces
Definition: PtexReader.h:524
PtexReader::MetaData::getValue
virtual void getValue(int index, const char *&value)
Query the value of a given meta data entry by index.
Definition: PtexReader.h:163
PtexReader::ReductionKey::move
void move(volatile ReductionKey &key) volatile
Definition: PtexReader.h:697
Ptex::FaceInfo
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:242
PtexReader::MetaData::Entry::~Entry
~Entry()
Definition: PtexReader.h:298
PtexReader::TiledFaceBase::_tileres
Res _tileres
Definition: PtexReader.h:459
PtexReader::MetaData::getValue
virtual void getValue(const char *key, const char *&value)
Query the value of a given meta data entry.
Definition: PtexReader.h:150
IBuffSize
const int IBuffSize
Definition: PtexIO.h:113
LevelInfo
Definition: PtexIO.h:75
PtexReader::MetaData::getValue
virtual void getValue(int index, const double *&value, int &count)
Query the value of a given meta data entry by index.
Definition: PtexReader.h:241
PtexReader::MetaData::LargeMetaData::data
void * data()
Definition: PtexReader.h:278
PtexReader::readEditFaceData
void readEditFaceData()
Definition: PtexReader.cpp:502
PtexReader::readEditData
void readEditData()
Definition: PtexReader.cpp:468
PtexReader::ok
bool ok() const
Definition: PtexReader.h:64
PtexReader::TiledFaceBase::baseExtraMemUsed
size_t baseExtraMemUsed()
Definition: PtexReader.h:450
PtexReader::FaceData::_res
Res _res
Definition: PtexReader.h:374
Ptex::mdt_int16
Signed 16-bit integer.
Definition: Ptexture.h:118
PtexReader::seek
void seek(FilePos pos)
Definition: PtexReader.h:558
PtexReader::Level::Level
Level(int nfaces)
Definition: PtexReader.h:526
Ptex::DataType
DataType
Type of data stored in texture file.
Definition: Ptexture.h:85
PTEX_NAMESPACE_BEGIN
Definition: PtexSeparableKernel.cpp:42
PtexReader::MetaData::Entry::lmdZipSize
uint32_t lmdZipSize
Definition: PtexReader.h:292
PtexUtils.h
PtexReader::DefaultInputHandler::DefaultInputHandler
DefaultInputHandler()
Definition: PtexReader.h:615
PtexReader::FaceData::reduce
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)=0
PTEX_NAMESPACE_END
#define PTEX_NAMESPACE_END
Definition: PtexVersion.h:62
PtexReader::reopenFP
bool reopenFP()
Definition: PtexReader.cpp:240
PtexReader::readEditMetaData
void readEditMetaData()
Definition: PtexReader.cpp:533
PtexReader::tell
FilePos tell()
Definition: PtexReader.h:557
PtexReader::_blockReads
volatile size_t _blockReads
Definition: PtexReader.h:720
PtexReader::_pos
FilePos _pos
Definition: PtexReader.h:646
Ptexture.h
Public API classes for reading, writing, caching, and filtering Ptex files.
PtexTexture::Info::uBorderMode
BorderMode uBorderMode
Definition: Ptexture.h:502
PtexReader::MetaData::MetaMap
std::map< std::string, Entry > MetaMap
Definition: PtexReader.h:339
PtexReader::_pendingPurge
bool _pendingPurge
Definition: PtexReader.h:644
PtexHashMap< ReductionKey, FaceData * >
PtexReader::MetaData::_reader
PtexReader * _reader
Definition: PtexReader.h:338
PtexReader::TiledFaceBase::ntilesu
int ntilesu() const
Definition: PtexReader.h:445
PtexReader::MetaEdit
Definition: PtexReader.h:669
PtexInputHandler
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition: Ptexture.h:632
PtexReader::_lmddatapos
FilePos _lmddatapos
Definition: PtexReader.h:656
PtexReader::TiledReducedFace::_parentface
TiledFaceBase * _parentface
Definition: PtexReader.h:515
PtexTexture::Info::numFaces
int numFaces
Definition: Ptexture.h:507