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 2009 Disney Enterprises, Inc. All rights reserved
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
10 met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14 
15  * Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in
17  the documentation and/or other materials provided with the
18  distribution.
19 
20  * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
21  Studios" or the names of its contributors may NOT be used to
22  endorse or promote products derived from this software without
23  specific prior written permission from Walt Disney Pictures.
24 
25 Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
26 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
27 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
28 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
29 IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37 */
38 #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 "PtexCache.h"
47 #include "PtexUtils.h"
48 
49 #include "PtexHashMap.h"
50 using namespace PtexInternal;
51 
52 #ifndef NDEBUG
53 #include <assert.h>
54 template<typename T> class safevector : public std::vector<T>
55 {
56 public:
57  safevector() : std::vector<T>() {}
58  safevector(size_t n, const T& val = T()) : std::vector<T>(n, val) {}
59  const T& operator[] (size_t n) const {
60  assert(n < std::vector<T>::size());
61  return std::vector<T>::operator[](n);
62  }
63  T& operator[] (size_t n) {
64  assert(n < std::vector<T>::size());
65  return std::vector<T>::operator[](n);
66  }
67 };
68 #else
69 #define safevector std::vector
70 #endif
71 
72 class PtexReader : public PtexCachedFile, public PtexTexture, public PtexIO {
73 public:
74  PtexReader(void** parent, PtexCacheImpl* cache, bool premultiply,
75  PtexInputHandler* handler);
76  bool open(const char* path, Ptex::String& error);
77 
78  void setOwnsCache() { _ownsCache = true; }
79  virtual void release();
80  virtual const char* path() { return _path.c_str(); }
81  virtual Ptex::MeshType meshType() { return MeshType(_header.meshtype); }
82  virtual Ptex::DataType dataType() { return DataType(_header.datatype); }
83  virtual Ptex::BorderMode uBorderMode() { return BorderMode(_extheader.ubordermode); }
84  virtual Ptex::BorderMode vBorderMode() { return BorderMode(_extheader.vbordermode); }
85  virtual int alphaChannel() { return _header.alphachan; }
86  virtual int numChannels() { return _header.nchannels; }
87  virtual int numFaces() { return _header.nfaces; }
88  virtual bool hasEdits() { return _hasEdits; }
89  virtual bool hasMipMaps() { return _header.nlevels > 1; }
90 
91  virtual PtexMetaData* getMetaData();
92  virtual const Ptex::FaceInfo& getFaceInfo(int faceid);
93  virtual void getData(int faceid, void* buffer, int stride);
94  virtual void getData(int faceid, void* buffer, int stride, Res res);
95  virtual PtexFaceData* getData(int faceid);
96  virtual PtexFaceData* getData(int faceid, Res res);
97  virtual void getPixel(int faceid, int u, int v,
98  float* result, int firstchan, int nchannels);
99  virtual void getPixel(int faceid, int u, int v,
100  float* result, int firstchan, int nchannels,
101  Ptex::Res res);
102 
103  DataType datatype() const { return _header.datatype; }
104  int nchannels() const { return _header.nchannels; }
105  int pixelsize() const { return _pixelsize; }
106  const Header& header() const { return _header; }
107  const ExtHeader& extheader() const { return _extheader; }
108  const LevelInfo& levelinfo(int level) const { return _levelinfo[level]; }
109 
110  class MetaData : public PtexCachedData, public PtexMetaData {
111  public:
112  MetaData(MetaData** parent, PtexCacheImpl* cache, int size, PtexReader* reader)
113  : PtexCachedData((void**)parent, cache, (int)sizeof(*this) + size),
114  _reader(reader) {}
115  virtual void release() {
116  AutoLockCache lock(_cache->cachelock);
117  // first, unref all lmdData refs
118  for (size_t i = 0, n = _lmdRefs.size(); i < n; i++)
119  _lmdRefs[i]->unref();
120  _lmdRefs.resize(0);
121 
122  // finally, unref self
123  unref();
124  }
125 
126  virtual int numKeys() { return int(_entries.size()); }
127  virtual void getKey(int n, const char*& key, MetaDataType& type)
128  {
129  Entry* e = _entries[n];
130  key = e->key;
131  type = e->type;
132  }
133 
134  virtual void getValue(const char* key, const char*& value)
135  {
136  Entry* e = getEntry(key);
137  if (e) value = (const char*) e->data;
138  else value = 0;
139  }
140 
141  virtual void getValue(const char* key, const int8_t*& value, int& count)
142  {
143  Entry* e = getEntry(key);
144  if (e) { value = (const int8_t*) e->data; count = e->datasize; }
145  else { value = 0; count = 0; }
146  }
147 
148  virtual void getValue(const char* key, const int16_t*& value, int& count)
149  {
150  Entry* e = getEntry(key);
151  if (e) {
152  value = (const int16_t*) e->data;
153  count = int(e->datasize/sizeof(int16_t));
154  }
155  else { value = 0; count = 0; }
156  }
157 
158  virtual void getValue(const char* key, const int32_t*& value, int& count)
159  {
160  Entry* e = getEntry(key);
161  if (e) {
162  value = (const int32_t*) e->data;
163  count = int(e->datasize/sizeof(int32_t));
164  }
165  else { value = 0; count = 0; }
166  }
167 
168  virtual void getValue(const char* key, const float*& value, int& count)
169  {
170  Entry* e = getEntry(key);
171  if (e) {
172  value = (const float*) e->data;
173  count = int(e->datasize/sizeof(float));
174  }
175  else { value = 0; count = 0; }
176  }
177 
178  virtual void getValue(const char* key, const double*& value, int& count)
179  {
180  Entry* e = getEntry(key);
181  if (e) {
182  value = (const double*) e->data;
183  count = int(e->datasize/sizeof(double));
184  }
185  else { value = 0; count = 0; }
186  }
187 
188  void addEntry(uint8_t keysize, const char* key, uint8_t datatype,
189  uint32_t datasize, void* data)
190  {
191  Entry* e = newEntry(keysize, key, datatype, datasize);
192  e->data = malloc(datasize);
193  memcpy(e->data, data, datasize);
194  }
195 
196  void addLmdEntry(uint8_t keysize, const char* key, uint8_t datatype,
197  uint32_t datasize, FilePos filepos, uint32_t zipsize)
198  {
199  Entry* e = newEntry(keysize, key, datatype, datasize);
200  e->isLmd = true;
201  e->lmdData = 0;
202  e->lmdPos = filepos;
203  e->lmdZipSize = zipsize;
204  }
205 
206  protected:
208  {
209  public:
210  LargeMetaData(void** parent, PtexCacheImpl* cache, int size)
211  : PtexCachedData(parent, cache, size), _data(malloc(size)) {}
212  void* data() { return _data; }
213  private:
214  virtual ~LargeMetaData() { free(_data); }
215  void* _data;
216  };
217 
218  struct Entry {
219  const char* key; // ptr to map key string
220  MetaDataType type; // meta data type
221  uint32_t datasize; // size of data in bytes
222  void* data; // if lmd, data only valid when lmd is loaded and ref'ed
223  bool isLmd; // true if data is a large meta data block
224  LargeMetaData* lmdData; // large meta data (lazy-loaded, lru-cached)
225  FilePos lmdPos; // large meta data file position
226  uint32_t lmdZipSize; // large meta data size on disk
227 
228  Entry() :
229  key(0), type(MetaDataType(0)), datasize(0), data(0),
230  isLmd(0), lmdData(0), lmdPos(0), lmdZipSize(0) {}
231  ~Entry() { clear(); }
232  void clear() {
233  if (isLmd) {
234  isLmd = 0;
235  if (lmdData) { lmdData->orphan(); lmdData = 0; }
236  lmdPos = 0;
237  lmdZipSize = 0;
238  }
239  else {
240  free(data);
241  }
242  data = 0;
243  }
244  };
245 
246  Entry* newEntry(uint8_t keysize, const char* key, uint8_t datatype, uint32_t datasize)
247  {
248  std::pair<MetaMap::iterator,bool> result =
249  _map.insert(std::make_pair(std::string(key, keysize), Entry()));
250  Entry* e = &result.first->second;
251  bool newEntry = result.second;
252  if (newEntry) _entries.push_back(e);
253  else e->clear();
254  e->key = result.first->first.c_str();
255  e->type = MetaDataType(datatype);
256  e->datasize = datasize;
257  return e;
258  }
259 
260  Entry* getEntry(const char* key);
261 
263  typedef std::map<std::string, Entry> MetaMap;
264  MetaMap _map;
265  safevector<Entry*> _entries;
266  std::vector<LargeMetaData*> _lmdRefs;
267  };
268 
269 
270  class ConstDataPtr : public PtexFaceData {
271  public:
272  ConstDataPtr(void* data, int pixelsize)
273  : _data(data), _pixelsize(pixelsize) {}
274  virtual void release() { delete this; }
275  virtual Ptex::Res res() { return 0; }
276  virtual bool isConstant() { return true; }
277  virtual void getPixel(int, int, void* result)
278  { memcpy(result, _data, _pixelsize); }
279  virtual void* getData() { return _data; }
280  virtual bool isTiled() { return false; }
281  virtual Ptex::Res tileRes() { return 0; }
282  virtual PtexFaceData* getTile(int) { return 0; }
283 
284  protected:
285  void* _data;
287  };
288 
289 
290  class FaceData : public PtexCachedData, public PtexFaceData {
291  public:
292  FaceData(void** parent, PtexCacheImpl* cache, Res res, int size)
293  : PtexCachedData(parent, cache, size), _res(res) {}
294  virtual void release() { AutoLockCache lock(_cache->cachelock); unref(); }
295  virtual Ptex::Res res() { return _res; }
296  virtual void reduce(FaceData*&, PtexReader*,
297  Res newres, PtexUtils::ReduceFn) = 0;
298  protected:
300  };
301 
302  class PackedFace : public FaceData {
303  public:
304  PackedFace(void** parent, PtexCacheImpl* cache, Res res, int pixelsize, int size)
305  : FaceData(parent, cache, res, (int)sizeof(*this)+size),
306  _pixelsize(pixelsize), _data(malloc(size)) {}
307  void* data() { return _data; }
308  virtual bool isConstant() { return false; }
309  virtual void getPixel(int u, int v, void* result)
310  {
311  memcpy(result, (char*)_data + (v*_res.u() + u) * _pixelsize, _pixelsize);
312  }
313  virtual void* getData() { return _data; }
314  virtual bool isTiled() { return false; }
315  virtual Ptex::Res tileRes() { return _res; }
316  virtual PtexFaceData* getTile(int) { return 0; }
317  virtual void reduce(FaceData*&, PtexReader*,
318  Res newres, PtexUtils::ReduceFn);
319 
320  protected:
321  virtual ~PackedFace() { free(_data); }
322 
324  void* _data;
325  };
326 
327  class ConstantFace : public PackedFace {
328  public:
329  ConstantFace(void** parent, PtexCacheImpl* cache, int pixelsize)
330  : PackedFace(parent, cache, 0, pixelsize, pixelsize) {}
331  virtual bool isConstant() { return true; }
332  virtual void getPixel(int, int, void* result) { memcpy(result, _data, _pixelsize); }
333  virtual void reduce(FaceData*&, PtexReader*,
334  Res newres, PtexUtils::ReduceFn);
335  };
336 
337 
338  class TiledFaceBase : public FaceData {
339  public:
340  TiledFaceBase(void** parent, PtexCacheImpl* cache, Res res,
341  Res tileres, DataType dt, int nchan)
342  : FaceData(parent, cache, res, sizeof(*this)),
343  _tileres(tileres),
344  _dt(dt),
345  _nchan(nchan),
346  _pixelsize(DataSize(dt)*nchan)
347  {
348  _ntilesu = _res.ntilesu(tileres);
349  _ntilesv = _res.ntilesv(tileres);
350  _ntiles = _ntilesu*_ntilesv;
351  _tiles.resize(_ntiles);
352  incSize((int)sizeof(FaceData*)*_ntiles);
353  }
354 
355  virtual void release() {
356  // Tiled faces ref the reader (directly or indirectly) and
357  // thus may trigger cache deletion on release. Call cache
358  // to check for pending delete.
359  // Note: release() may delete "this", so save _cache in
360  // local var.
361  PtexCacheImpl* cache = _cache;
362  FaceData::release();
363  cache->handlePendingDelete();
364  }
365  virtual bool isConstant() { return false; }
366  virtual void getPixel(int u, int v, void* result);
367  virtual void* getData() { return 0; }
368  virtual bool isTiled() { return true; }
369  virtual Ptex::Res tileRes() { return _tileres; }
370  virtual void reduce(FaceData*&, PtexReader*,
371  Res newres, PtexUtils::ReduceFn);
372  Res tileres() const { return _tileres; }
373  int ntilesu() const { return _ntilesu; }
374  int ntilesv() const { return _ntilesv; }
375  int ntiles() const { return _ntiles; }
376 
377  protected:
378  virtual ~TiledFaceBase() { orphanList(_tiles); }
379 
382  int _nchan;
383  int _ntilesu;
384  int _ntilesv;
385  int _ntiles;
387  safevector<FaceData*> _tiles;
388  };
389 
390 
391  class TiledFace : public TiledFaceBase {
392  public:
393  TiledFace(void** parent, PtexCacheImpl* cache, Res res, Res tileres,
394  int levelid, PtexReader* reader)
395  : TiledFaceBase(parent, cache, res, tileres,
396  reader->datatype(), reader->nchannels()),
397  _reader(reader),
398  _levelid(levelid)
399  {
400  _fdh.resize(_ntiles),
401  _offsets.resize(_ntiles);
402  incSize((int)(sizeof(FaceDataHeader)+sizeof(FilePos))*_ntiles);
403  }
404  virtual PtexFaceData* getTile(int tile)
405  {
406  AutoLockCache locker(_cache->cachelock);
407  FaceData*& f = _tiles[tile];
408  if (!f) readTile(tile, f);
409  else f->ref();
410  return f;
411  }
412  void readTile(int tile, FaceData*& data);
413 
414  protected:
415  friend class PtexReader;
417  int _levelid;
418  safevector<FaceDataHeader> _fdh;
419  safevector<FilePos> _offsets;
420  };
421 
422 
424  public:
425  TiledReducedFace(void** parent, PtexCacheImpl* cache, Res res,
426  Res tileres, DataType dt, int nchan,
427  TiledFaceBase* parentface, PtexUtils::ReduceFn reducefn)
428  : TiledFaceBase(parent, cache, res, tileres, dt, nchan),
429  _parentface(parentface),
430  _reducefn(reducefn)
431  {
432  AutoLockCache locker(_cache->cachelock);
433  _parentface->ref();
434  }
436  {
437  _parentface->unref();
438  }
439  virtual PtexFaceData* getTile(int tile);
440 
441  protected:
444  };
445 
446 
447  class Level : public PtexCachedData {
448  public:
449  safevector<FaceDataHeader> fdh;
450  safevector<FilePos> offsets;
451  safevector<FaceData*> faces;
452 
453  Level(void** parent, PtexCacheImpl* cache, int nfaces)
454  : PtexCachedData(parent, cache,
455  (int)(sizeof(*this) + (size_t)nfaces * (sizeof(FaceDataHeader) +
456  sizeof(FilePos) +
457  sizeof(FaceData*)))),
458  fdh(nfaces),
459  offsets(nfaces),
460  faces(nfaces) {}
461  protected:
462  virtual ~Level() { orphanList(faces); }
463  };
464 
467 
468 protected:
469  virtual ~PtexReader();
470  void setError(const char* error)
471  {
472  _error = error; _error += " PtexFile: "; _error += _path;
473  _ok = 0;
474  }
475 
476  FilePos tell() { return _pos; }
477  void seek(FilePos pos)
478  {
479  if (pos != _pos) {
480  _io->seek(_fp, pos);
481  _pos = pos;
482  STATS_INC(nseeks);
483  }
484  }
485 
486  bool readBlock(void* data, int size, bool reportError=true);
487  bool readZipBlock(void* data, int zipsize, int unzipsize);
488  Level* getLevel(int levelid)
489  {
490  Level*& level = _levels[levelid];
491  if (!level) readLevel(levelid, level);
492  else level->ref();
493  return level;
494  }
495 
496  uint8_t* getConstData() { if (!_constdata) readConstData(); return _constdata; }
497  FaceData* getFace(int levelid, Level* level, int faceid)
498  {
499  FaceData*& face = level->faces[faceid];
500  if (!face) readFace(levelid, level, faceid);
501  else face->ref();
502  return face;
503  }
504 
505  Res getRes(int levelid, int faceid)
506  {
507  if (levelid == 0) return _faceinfo[faceid].res;
508  else {
509  // for reduction level, look up res via rfaceid
510  Res res = _res_r[faceid];
511  // and adjust for number of reductions
512  return Res((uint8_t)(res.ulog2 - levelid), (uint8_t)(res.vlog2 - levelid));
513  }
514  }
515 
516  int unpackedSize(FaceDataHeader fdh, int levelid, int faceid)
517  {
518  if (fdh.encoding() == enc_constant)
519  // level 0 constant faces are not stored
520  return levelid == 0 ? 0 : _pixelsize;
521  else
522  return getRes(levelid, faceid).size() * _pixelsize;
523  }
524 
525  void readFaceInfo();
526  void readLevelInfo();
527  void readConstData();
528  void readLevel(int levelid, Level*& level);
529  void readFace(int levelid, Level* level, int faceid);
530  void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData*& face);
531  void readMetaData();
532  void readMetaDataBlock(MetaData* metadata, FilePos pos, int zipsize, int memsize);
533  void readLargeMetaDataHeaders(MetaData* metadata, FilePos pos, int zipsize, int memsize);
534  void readEditData();
535  void readEditFaceData();
536  void readEditMetaData();
537 
538  void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader* fdh, FilePos* offsets)
539  {
540  FilePos* end = offsets + noffsets;
541  while (offsets != end) { *offsets++ = pos; pos += fdh->blocksize(); fdh++; }
542  }
543  void blendFaces(FaceData*& face, int faceid, Res res, bool blendu);
544 
546  {
547  char* buffer;
548  public:
549  virtual Handle open(const char* path) {
550  FILE* fp = fopen(path, "rb");
551  if (fp) {
552  buffer = (char*) malloc(IBuffSize);
553  setvbuf(fp, buffer, _IOFBF, IBuffSize);
554  }
555  else buffer = 0;
556  return (Handle) fp;
557  }
558  virtual void seek(Handle handle, int64_t pos) { fseeko((FILE*)handle, pos, SEEK_SET); }
559  virtual size_t read(void* buffer, size_t size, Handle handle) {
560  return fread(buffer, size, 1, (FILE*)handle) == 1 ? size : 0;
561  }
562  virtual bool close(Handle handle) {
563  bool ok = handle && (fclose((FILE*)handle) == 0);
564  if (buffer) free(buffer);
565  buffer = 0;
566  return ok;
567  }
568  virtual const char* lastError() { return strerror(errno); }
569  };
570 
571  DefaultInputHandler _defaultIo; // Default IO handler
572  PtexInputHandler* _io; // IO handler
573  bool _premultiply; // true if reader should premultiply the alpha chan
574  bool _ownsCache; // true if reader owns the cache
575  bool _ok; // flag set if read error occurred)
576  std::string _error; // error string (if !_ok)
577  PtexInputHandler::Handle _fp; // file pointer
578  FilePos _pos; // current seek position
579  std::string _path; // current file path
580  Header _header; // the header
581  ExtHeader _extheader; // extended header
582  FilePos _faceinfopos; // file positions of data sections
590  int _pixelsize; // size of a pixel in bytes
591  uint8_t* _constdata; // constant pixel value per face
592  MetaData* _metadata; // meta data (read on demand)
593  bool _hasEdits; // has edit blocks
594 
595  safevector<FaceInfo> _faceinfo; // per-face header info
596  safevector<uint32_t> _rfaceids; // faceids sorted in reduction order
597  safevector<Res> _res_r; // face res indexed by rfaceid
598  safevector<LevelInfo> _levelinfo; // per-level header info
599  safevector<FilePos> _levelpos; // file position of each level's data
600  safevector<Level*> _levels; // level data (read on demand)
601 
602  struct MetaEdit
603  {
605  int zipsize;
606  int memsize;
607  };
608  safevector<MetaEdit> _metaedits;
609 
610  struct FaceEdit
611  {
613  int faceid;
614  FaceDataHeader fdh;
615  };
616  safevector<FaceEdit> _faceedits;
617 
618  struct ReductionKey {
619  int faceid;
621  ReductionKey() : faceid(0), res(0,0) {}
622  ReductionKey(uint32_t faceid, Res res) : faceid(faceid), res(res) {}
623  bool operator==(const ReductionKey& k) const
624  { return k.faceid == faceid && k.res == res; }
625  struct Hasher {
626  uint32_t operator() (const ReductionKey& key) const
627  {
628  // constants from Knuth
629  static uint32_t M = 1664525, C = 1013904223;
630  uint32_t val = (key.res.ulog2 * M + key.res.vlog2 + C) * M + key.faceid;
631  return val;
632  }
633  };
634  };
636  ReductionMap _reductions;
637 
638  z_stream_s _zstream;
639 };
640 
641 #endif
DefaultInputHandler _defaultIo
Definition: PtexReader.h:571
void handlePendingDelete()
Definition: PtexCache.h:220
FaceData * getFace(int levelid, Level *level, int faceid)
Definition: PtexReader.h:497
virtual int numFaces()
Number of faces stored in file.
Definition: PtexReader.h:87
bool _ownsCache
Definition: PtexReader.h:574
ExtHeader _extheader
Definition: PtexReader.h:581
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:294
void setOwnsCache()
Definition: PtexReader.h:78
virtual bool hasMipMaps()
True if the file has mipmaps.
Definition: PtexReader.h:89
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
Definition: PtexReader.h:282
virtual void getValue(const char *key, const float *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:168
const ExtHeader & extheader() const
Definition: PtexReader.h:107
safevector< FaceData * > _tiles
Definition: PtexReader.h:387
std::string _error
Definition: PtexReader.h:576
safevector< LevelInfo > _levelinfo
Definition: PtexReader.h:598
std::vector< LargeMetaData * > _lmdRefs
Definition: PtexReader.h:266
virtual void * getData()
Access the data from this data block.
Definition: PtexReader.h:367
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:274
virtual bool hasEdits()
True if the file has edit blocks.
Definition: PtexReader.h:88
Mutex reducelock
Definition: PtexReader.h:466
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition: PtexReader.h:369
PtexInputHandler * _io
Definition: PtexReader.h:572
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:190
ReductionKey(uint32_t faceid, Res res)
Definition: PtexReader.h:622
Memory-managed string.
Definition: Ptexture.h:303
FaceData(void **parent, PtexCacheImpl *cache, Res res, int size)
Definition: PtexReader.h:292
#define safevector
Definition: PtexReader.h:69
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
Definition: PtexReader.h:316
safevector< FilePos > _levelpos
Definition: PtexReader.h:599
safevector< FilePos > _offsets
Definition: PtexReader.h:419
DataType
Type of data stored in texture file.
Definition: Ptexture.h:83
virtual size_t read(void *buffer, size_t size, Handle handle)
Read a number of bytes from the file.
Definition: PtexReader.h:559
safevector< MetaEdit > _metaedits
Definition: PtexReader.h:608
virtual ~Level()
Definition: PtexReader.h:462
FilePos _leveldatapos
Definition: PtexReader.h:585
LargeMetaData(void **parent, PtexCacheImpl *cache, int size)
Definition: PtexReader.h:210
safevector< Level * > _levels
Definition: PtexReader.h:600
Meta data accessor.
Definition: Ptexture.h:337
Entry * newEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize)
Definition: PtexReader.h:246
MetaData * _metadata
Definition: PtexReader.h:592
virtual int alphaChannel()
Index of alpha channel (if any).
Definition: PtexReader.h:85
virtual bool close(Handle handle)
Close a file.
Definition: PtexReader.h:562
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:365
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:115
virtual const char * path()
Path that file was opened with.
Definition: PtexReader.h:80
std::string _path
Definition: PtexReader.h:579
virtual const char * lastError()
Return the last error message encountered.
Definition: PtexReader.h:568
virtual int numChannels()
Number of channels stored in file.
Definition: PtexReader.h:86
uint8_t * _constdata
Definition: PtexReader.h:591
Pixel resolution of a given texture.
Definition: Ptexture.h:274
virtual void getValue(const char *key, const int32_t *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:158
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:107
LargeMetaData * lmdData
Definition: PtexReader.h:224
#define STATS_INC(x)
Definition: PtexCache.h:97
virtual Ptex::Res res()
Resolution of the texture held by this data block.
Definition: PtexReader.h:295
int8_t vlog2
log base 2 of v resolution, in texels
Definition: Ptexture.h:276
#define C(eid, aeid)
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Definition: PtexReader.h:277
virtual void getValue(const char *key, const double *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:178
PackedFace(void **parent, PtexCacheImpl *cache, Res res, int pixelsize, int size)
Definition: PtexReader.h:304
ReductionMap _reductions
Definition: PtexReader.h:636
virtual Ptex::DataType dataType()
Type of data stored in file.
Definition: PtexReader.h:82
off_t FilePos
Definition: PtexPlatform.h:85
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:91
safevector< FaceEdit > _faceedits
Definition: PtexReader.h:616
uint32_t blocksize() const
Definition: PtexIO.h:80
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Definition: PtexReader.h:355
safevector< uint32_t > _rfaceids
Definition: PtexReader.h:596
static int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:245
z_stream_s _zstream
Definition: PtexReader.h:638
Per-face texture data accessor.
Definition: Ptexture.h:388
Res getRes(int levelid, int faceid)
Definition: PtexReader.h:505
MetaData(MetaData **parent, PtexCacheImpl *cache, int size, PtexReader *reader)
Definition: PtexReader.h:112
int8_t vlog2
log base 2 of v resolution, in texels
Definition: Ptexture.h:163
FilePos _lmdheaderpos
Definition: PtexReader.h:587
PtexReader * _reader
Definition: PtexReader.h:416
virtual void seek(Handle handle, int64_t pos)
Seek to an absolute byte position in the input stream.
Definition: PtexReader.h:558
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
Definition: PtexReader.h:84
const LevelInfo & levelinfo(int level) const
Definition: PtexReader.h:108
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
Definition: PtexReader.h:309
virtual bool isTiled()
True if this data block is tiled.
Definition: PtexReader.h:280
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
Definition: PtexReader.h:83
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:308
int8_t ulog2
log base 2 of u resolution, in texels
Definition: Ptexture.h:275
virtual void * getData()
Access the data from this data block.
Definition: PtexReader.h:279
Cache entry for allocated memory block.
Definition: PtexCache.h:282
DataType
Type of data stored in texture file.
Definition: Ptexture.h:196
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:276
safevector< FilePos > offsets
Definition: PtexReader.h:450
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:204
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition: PtexReader.h:315
void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
Definition: PtexReader.h:538
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
Definition: PtexUtils.h:132
Definition: PtexIO.h:41
Mutex readlock
Definition: PtexReader.h:465
safevector< FaceDataHeader > fdh
Definition: PtexReader.h:449
bool _hasEdits
Definition: PtexReader.h:593
FilePos _faceinfopos
Definition: PtexReader.h:582
void setError(const char *error)
Definition: PtexReader.h:470
Encoding encoding() const
Definition: PtexIO.h:81
FilePos _editdatapos
Definition: PtexReader.h:589
virtual Ptex::Res res()
Resolution of the texture held by this data block.
Definition: PtexReader.h:275
safevector< Res > _res_r
Definition: PtexReader.h:597
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
Definition: PtexReader.h:404
FilePos _levelinfopos
Definition: PtexReader.h:584
DataType datatype() const
Definition: PtexReader.h:103
virtual bool isConstant()
True if this data block is constant.
Definition: PtexReader.h:331
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:77
bool _premultiply
Definition: PtexReader.h:573
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:220
virtual bool isTiled()
True if this data block is tiled.
Definition: PtexReader.h:314
FilePos _constdatapos
Definition: PtexReader.h:583
Level * getLevel(int levelid)
Definition: PtexReader.h:488
virtual bool isTiled()
True if this data block is tiled.
Definition: PtexReader.h:368
PtexInputHandler::Handle _fp
Definition: PtexReader.h:577
For internal use only.
Definition: PtexCache.h:48
int nchannels() const
Definition: PtexReader.h:104
const Header & header() const
Definition: PtexReader.h:106
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Definition: PtexReader.h:332
PtexUtils::ReduceFn * _reducefn
Definition: PtexReader.h:443
bool operator==(const ReductionKey &k) const
Definition: PtexReader.h:623
virtual Handle open(const char *path)
Open a file in read mode.
Definition: PtexReader.h:549
virtual int numKeys()
Query number of meta data entries stored in file.
Definition: PtexReader.h:126
virtual void getValue(const char *key, const int16_t *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:148
FilePos _metadatapos
Definition: PtexReader.h:586
virtual void * getData()
Access the data from this data block.
Definition: PtexReader.h:313
Header _header
Definition: PtexReader.h:580
int _pixelsize
Definition: PtexReader.h:590
virtual void getValue(const char *key, const int8_t *&value, int &count)
Query the value of a given meta data entry.
Definition: PtexReader.h:141
int8_t ulog2
log base 2 of u resolution, in texels
Definition: Ptexture.h:162
FaceDataHeader fdh
Definition: PtexReader.h:614
Interface for reading data from a ptex file.
Definition: Ptexture.h:439
uint8_t * getConstData()
Definition: PtexReader.h:496
PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher > ReductionMap
Definition: PtexReader.h:635
safevector< FaceData * > faces
Definition: PtexReader.h:451
Pixel resolution of a given texture.
Definition: Ptexture.h:161
safevector< FaceDataHeader > _fdh
Definition: PtexReader.h:418
Cache entry for open file handle.
Definition: PtexCache.h:265
safevector< FaceInfo > _faceinfo
Definition: PtexReader.h:595
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
Definition: PtexReader.h:81
Contains PtexHashMap, a lightweight hash table.
ConstDataPtr(void *data, int pixelsize)
Definition: PtexReader.h:272
Ptex cache implementation.
Definition: PtexCache.h:192
void orphan()
Definition: PtexCache.h:107
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
Definition: PtexReader.h:281
Automatically acquire and release lock within enclosing scope.
Definition: PtexMutex.h:58
virtual void getKey(int n, const char *&key, MetaDataType &type)
Query the name and type of a meta data entry.
Definition: PtexReader.h:127
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:237
TiledFaceBase(void **parent, PtexCacheImpl *cache, Res res, Res tileres, DataType dt, int nchan)
Definition: PtexReader.h:340
virtual void getValue(const char *key, const char *&value)
Query the value of a given meta data entry.
Definition: PtexReader.h:134
int pixelsize() const
Definition: PtexReader.h:105
void addEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, void *data)
Definition: PtexReader.h:188
TiledFace(void **parent, PtexCacheImpl *cache, Res res, Res tileres, int levelid, PtexReader *reader)
Definition: PtexReader.h:393
void addLmdEntry(uint8_t keysize, const char *key, uint8_t datatype, uint32_t datasize, FilePos filepos, uint32_t zipsize)
Definition: PtexReader.h:196
void seek(FilePos pos)
Definition: PtexReader.h:477
safevector< Entry * > _entries
Definition: PtexReader.h:265
FilePos tell()
Definition: PtexReader.h:476
Level(void **parent, PtexCacheImpl *cache, int nfaces)
Definition: PtexReader.h:453
FilePos _pos
Definition: PtexReader.h:578
Public API classes for reading, writing, caching, and filtering Ptex files.
int unpackedSize(FaceDataHeader fdh, int levelid, int faceid)
Definition: PtexReader.h:516
ConstantFace(void **parent, PtexCacheImpl *cache, int pixelsize)
Definition: PtexReader.h:329
TiledReducedFace(void **parent, PtexCacheImpl *cache, Res res, Res tileres, DataType dt, int nchan, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
Definition: PtexReader.h:425
std::map< std::string, Entry > MetaMap
Definition: PtexReader.h:263
PtexReader * _reader
Definition: PtexReader.h:262
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition: Ptexture.h:585
FilePos _lmddatapos
Definition: PtexReader.h:588
TiledFaceBase * _parentface
Definition: PtexReader.h:442