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