Ptex
PtexReader.h
Go to the documentation of this file.
1#ifndef PtexReader_h
2#define PtexReader_h
3
4/*
5PTEX SOFTWARE
6Copyright 2014 Disney Enterprises, Inc. All rights reserved
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are
10met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19
20 * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
21 Studios" or the names of its contributors may NOT be used to
22 endorse or promote products derived from this software without
23 specific prior written permission from Walt Disney Pictures.
24
25Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
26CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
27BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
28FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
29IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
30CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
34THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37*/
38#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
51
52class PtexReader : public PtexTexture {
53public:
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); }
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);
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:
123 : _reader(reader) {}
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
267 {
268 return sizeof(*this) + sizeof(Entry*) * _entries.capacity();
269 }
270
271 protected:
273 {
274 public:
276 : _data(new char [size]) {}
277 virtual ~LargeMetaData() { delete [] _data; }
278 void* data() { return _data; }
279 private:
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
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 PTEXAPI Entry* getEntry(int index);
337
339 typedef std::map<std::string, Entry> MetaMap;
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;
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
398 char* _data;
399 };
400
401 class ConstantFace : public PackedFace {
402 public:
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 {
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);
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
460 DataType _dt;
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;
493 std::vector<FaceDataHeader> _fdh;
494 std::vector<FilePos> _offsets;
495 };
496
497
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 }
508 {
509 }
510 virtual PtexFaceData* getTile(int tile);
511
512 size_t memUsed() { return sizeof(*this) + baseExtraMemUsed(); }
513
514 protected:
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
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
545protected:
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
612 {
613 char* buffer;
614 public:
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
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
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
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 {
674 };
675 std::vector<MetaEdit> _metaedits;
676
677 struct FaceEdit
678 {
682 };
683 std::vector<FaceEdit> _faceedits;
684
686 int64_t _val;
687 public:
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 };
714 std::vector<char> _errorPixel; // referenced by errorData()
715
716 z_stream_s _zstream;
718 volatile size_t _memUsed;
719 volatile size_t _opens;
720 volatile size_t _blockReads;
721};
722
724
725#endif
#define PTEXAPI
Definition PtexExports.h:60
Contains PtexHashMap, a lightweight multi-threaded hash table.
const int IBuffSize
Definition PtexIO.h:113
off_t FilePos
PTEX_INLINE T AtomicAdd(volatile T *target, T value)
PTEX_INLINE T AtomicIncrement(volatile T *target)
#define PTEX_NAMESPACE_END
Definition PtexVersion.h:62
Public API classes for reading, writing, caching, and filtering Ptex files.
Custom handler interface redirecting Ptex error messages.
Definition Ptexture.h:658
virtual void reportError(const char *error)=0
Per-face texture data accessor.
Definition Ptexture.h:406
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition Ptexture.h:619
virtual void seek(Handle handle, int64_t pos)=0
Seek to an absolute byte position in the input stream.
Meta data accessor.
Definition Ptexture.h:328
virtual bool isConstant()
True if this data block is constant.
Definition PtexReader.h:351
virtual Ptex::Res res()
Resolution of the texture held by this data block.
Definition PtexReader.h:350
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition PtexReader.h:349
virtual bool isTiled()
True if this data block is tiled.
Definition PtexReader.h:355
virtual void * getData()
Access the data from this data block.
Definition PtexReader.h:354
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Definition PtexReader.h:352
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition PtexReader.h:356
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
Definition PtexReader.h:357
ConstDataPtr(void *data, int pixelsize)
Definition PtexReader.h:347
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Definition PtexReader.h:406
ConstantFace(int pixelsize)
Definition PtexReader.h:403
virtual bool isConstant()
True if this data block is constant.
Definition PtexReader.h:405
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual void seek(Handle handle, int64_t pos)
Seek to an absolute byte position in the input stream.
Definition PtexReader.h:625
virtual bool close(Handle handle)
Close a file.
Definition PtexReader.h:629
virtual size_t read(void *bufferArg, size_t size, Handle handle)
Read a number of bytes from the file.
Definition PtexReader.h:626
virtual Handle open(const char *path)
Open a file in read mode.
Definition PtexReader.h:616
virtual const char * lastError()
Return the last error message encountered.
Definition PtexReader.h:634
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition PtexReader.h:418
ErrorFace(void *errorPixel, int pixelsize, bool deleteOnRelease)
Definition PtexReader.h:413
virtual Ptex::Res res()
Resolution of the texture held by this data block.
Definition PtexReader.h:371
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)=0
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition PtexReader.h:370
FaceData(Res resArg)
Definition PtexReader.h:367
Level(int nfaces)
Definition PtexReader.h:526
std::vector< FilePos > offsets
Definition PtexReader.h:523
std::vector< FaceDataHeader > fdh
Definition PtexReader.h:522
std::vector< FaceData * > faces
Definition PtexReader.h:524
LargeMetaData(const LargeMetaData &)
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
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition PtexReader.h:125
Entry * newEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, size_t &metaDataMemUsed)
Definition PtexReader.h:313
virtual void getKey(int index, const char *&key, MetaDataType &type)
Definition PtexReader.h:128
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
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
virtual void getValue(int index, const char *&value)
Query the value of a given meta data entry by index.
Definition PtexReader.h:163
void addEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, const void *data, size_t &metaDataMemUsed)
Definition PtexReader.h:246
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
void getValue(const char *key, MetaDataType requestedType, const T *&value, int &count)
Definition PtexReader.h:188
virtual bool findKey(const char *key, int &index, MetaDataType &type)
Definition PtexReader.h:138
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
MetaData(PtexReader *reader)
Definition PtexReader.h:122
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
virtual int numKeys()
Query number of meta data entries stored in file.
Definition PtexReader.h:127
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
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 * _reader
Definition PtexReader.h:338
virtual void getValue(const char *key, const char *&value)
Query the value of a given meta data entry.
Definition PtexReader.h:150
std::map< std::string, Entry > MetaMap
Definition PtexReader.h:339
virtual void getValue(const char *key, const float *&value, int &count)
Query the value of a given meta data entry.
Definition PtexReader.h:226
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
void getValue(int index, MetaDataType requestedType, const T *&value, int &count)
Definition PtexReader.h:172
Entry * getEntry(int index)
std::vector< Entry * > _entries
Definition PtexReader.h:341
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
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
Definition PtexReader.h:391
PackedFace(Res resArg, int pixelsize, int size)
Definition PtexReader.h:379
virtual bool isTiled()
True if this data block is tiled.
Definition PtexReader.h:389
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition PtexReader.h:390
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual bool isConstant()
True if this data block is constant.
Definition PtexReader.h:383
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
Definition PtexReader.h:384
virtual void * getData()
Access the data from this data block.
Definition PtexReader.h:388
bool isEmpty() volatile
Definition PtexReader.h:706
ReductionKey(uint32_t faceid, Res res)
Definition PtexReader.h:689
void move(volatile ReductionKey &key) volatile
Definition PtexReader.h:697
uint32_t hash() volatile
Definition PtexReader.h:707
bool matches(const ReductionKey &key) volatile
Definition PtexReader.h:702
void copy(volatile ReductionKey &key) volatile
Definition PtexReader.h:692
TiledFaceBase(PtexReader *reader, Res resArg, Res tileresArg)
Definition PtexReader.h:423
std::vector< FaceData * > _tiles
Definition PtexReader.h:466
virtual bool isTiled()
True if this data block is tiled.
Definition PtexReader.h:441
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual void * getData()
Access the data from this data block.
Definition PtexReader.h:440
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition PtexReader.h:437
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition PtexReader.h:442
virtual bool isConstant()
True if this data block is constant.
Definition PtexReader.h:438
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
std::vector< FaceDataHeader > _fdh
Definition PtexReader.h:493
TiledFace(PtexReader *reader, Res resArg, Res tileresArg, int levelid)
Definition PtexReader.h:472
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
Definition PtexReader.h:479
void readTile(int tile, FaceData *&data)
std::vector< FilePos > _offsets
Definition PtexReader.h:494
TiledFaceBase * _parentface
Definition PtexReader.h:515
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
PtexUtils::ReduceFn * _reducefn
Definition PtexReader.h:516
TiledReducedFace(PtexReader *reader, Res resArg, Res tileresArg, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
Definition PtexReader.h:500
void readLevelInfo()
ReductionMap _reductions
Definition PtexReader.h:713
bool reopenFP()
bool ok() const
Definition PtexReader.h:64
DataType datatype() const
Definition PtexReader.h:113
void readEditFaceData()
bool _premultiply
Definition PtexReader.h:641
FilePos _constdatapos
Definition PtexReader.h:651
void readMetaDataBlock(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
const ExtHeader & extheader() const
Definition PtexReader.h:117
virtual int numFaces()
Number of faces stored in file.
Definition PtexReader.h:97
void setPendingPurge()
Definition PtexReader.h:61
void readFaceInfo()
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
Definition PtexReader.h:93
std::string _path
Definition PtexReader.h:647
uint8_t * _constdata
Definition PtexReader.h:659
std::vector< FilePos > _levelpos
Definition PtexReader.h:666
void readEditData()
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)
Access a single texel from the highest resolution texture .
virtual Info getInfo()
Definition PtexReader.h:77
std::vector< FaceEdit > _faceedits
Definition PtexReader.h:683
volatile size_t _opens
Definition PtexReader.h:719
bool isOpen()
Definition PtexReader.h:65
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition PtexReader.h:56
void increaseMemUsed(size_t amount)
Definition PtexReader.h:71
virtual const char * path()
Path that file was opened with.
Definition PtexReader.h:75
FaceData * getFace(int levelid, Level *level, int faceid, Res res)
Definition PtexReader.h:580
FilePos _editdatapos
Definition PtexReader.h:657
FilePos tell()
Definition PtexReader.h:557
Level * getLevel(int levelid)
Definition PtexReader.h:572
FaceData * errorData(bool deleteOnRelease=false)
Definition PtexReader.h:600
virtual ~PtexReader()
bool _hasEdits
Definition PtexReader.h:661
bool _needToOpen
Definition PtexReader.h:643
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
Definition PtexReader.h:92
void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
Definition PtexReader.h:605
void readConstData()
virtual PtexMetaData * getMetaData()
Access meta data.
bool needToOpen() const
Definition PtexReader.h:57
virtual int alphaChannel()
Index of alpha channel (if any).
Definition PtexReader.h:95
ExtHeader _extheader
Definition PtexReader.h:649
FilePos _leveldatapos
Definition PtexReader.h:653
virtual void getData(int faceid, void *buffer, int stride)
Access texture data for a face at highest-resolution.
PtexErrorHandler * _err
Definition PtexReader.h:640
const Header & header() const
Definition PtexReader.h:116
void readEditMetaData()
FilePos _faceinfopos
Definition PtexReader.h:650
std::vector< LevelInfo > _levelinfo
Definition PtexReader.h:665
PtexHashMap< ReductionKey, FaceData * > ReductionMap
Definition PtexReader.h:712
virtual bool hasMipMaps()
True if the file has mipmaps.
Definition PtexReader.h:99
z_stream_s _zstream
Definition PtexReader.h:716
PtexInputHandler * _io
Definition PtexReader.h:639
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)
Access resolution and adjacency information about a face.
FilePos _metadatapos
Definition PtexReader.h:654
void readLargeMetaDataHeaders(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
void closeFP()
bool _pendingPurge
Definition PtexReader.h:644
bool pendingPurge() const
Definition PtexReader.h:62
Mutex readlock
Definition PtexReader.h:637
void readFace(int levelid, Level *level, int faceid, Res res)
FilePos _levelinfopos
Definition PtexReader.h:652
FilePos _lmdheaderpos
Definition PtexReader.h:655
virtual bool hasEdits()
True if the file has edit blocks.
Definition PtexReader.h:98
int nchannels() const
Definition PtexReader.h:114
FilePos _lmddatapos
Definition PtexReader.h:656
std::vector< uint32_t > _rfaceids
Definition PtexReader.h:664
std::vector< MetaEdit > _metaedits
Definition PtexReader.h:675
volatile size_t _memUsed
Definition PtexReader.h:718
DefaultInputHandler _defaultIo
Definition PtexReader.h:638
volatile size_t _blockReads
Definition PtexReader.h:720
Header _header
Definition PtexReader.h:648
void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData *&face)
void seek(FilePos pos)
Definition PtexReader.h:558
bool readBlock(void *data, int size, bool reportError=true)
MetaData * _metadata
Definition PtexReader.h:660
std::vector< Level * > _levels
Definition PtexReader.h:667
size_t _baseMemUsed
Definition PtexReader.h:717
std::vector< FaceInfo > _faceinfo
Definition PtexReader.h:663
void invalidate()
Definition PtexReader.h:66
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
Definition PtexReader.h:90
virtual Ptex::EdgeFilterMode edgeFilterMode()
Mode for filtering textures across edges.
Definition PtexReader.h:94
int pixelsize() const
Definition PtexReader.h:115
PtexInputHandler::Handle _fp
Definition PtexReader.h:645
bool readZipBlock(void *data, int zipsize, int unzipsize)
void readMetaData()
void logBlockRead()
Definition PtexReader.h:73
void logOpen()
Definition PtexReader.h:72
void readLevel(int levelid, Level *&level)
virtual Ptex::DataType dataType()
Type of data stored in file.
Definition PtexReader.h:91
std::vector< char > _errorPixel
Definition PtexReader.h:714
uint8_t * getConstData()
Definition PtexReader.h:579
virtual int numChannels()
Number of channels stored in file.
Definition PtexReader.h:96
FilePos _pos
Definition PtexReader.h:646
bool open(const char *path, Ptex::String &error)
const LevelInfo & levelinfo(int level) const
Definition PtexReader.h:118
bool tryClose()
void setError(const char *error)
Definition PtexReader.h:546
Interface for reading data from a ptex file.
Definition Ptexture.h:457
Memory-managed string.
Definition Ptexture.h:296
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
Definition PtexUtils.h:185
DataType
Type of data stored in texture file.
Definition Ptexture.h:72
MeshType
Type of base mesh for which the textures are defined.
Definition Ptexture.h:66
BorderMode
How to handle mesh border when filtering.
Definition Ptexture.h:86
EdgeFilterMode
How to handle transformation across edges when filtering.
Definition Ptexture.h:80
uint16_t edgefiltermode
Definition PtexIO.h:68
uint16_t vbordermode
Definition PtexIO.h:67
uint16_t ubordermode
Definition PtexIO.h:65
uint32_t blocksize() const
Definition PtexIO.h:84
uint16_t nlevels
Definition PtexIO.h:51
uint16_t nchannels
Definition PtexIO.h:50
uint32_t meshtype
Definition PtexIO.h:47
uint32_t datatype
Definition PtexIO.h:48
int32_t alphachan
Definition PtexIO.h:49
uint32_t nfaces
Definition PtexIO.h:52
FaceDataHeader fdh
Definition PtexReader.h:681
Get most commonly used info in a single call for convenience / efficiency.
Definition Ptexture.h:486
BorderMode uBorderMode
Definition Ptexture.h:489
BorderMode vBorderMode
Definition Ptexture.h:490
EdgeFilterMode edgeFilterMode
Definition Ptexture.h:491
DataType dataType
Definition Ptexture.h:488
MeshType meshType
Definition Ptexture.h:487
Information about a face, as stored in the Ptex file header.
Definition Ptexture.h:229
Pixel resolution of a given texture.
Definition Ptexture.h:159