49struct libdeflate_decompressor;
76 virtual const char*
path() {
return _path.c_str(); }
104 virtual void getData(
int faceid,
void* buffer,
int stride);
105 virtual void getData(
int faceid,
void* buffer,
int stride, Res res);
109 virtual void getPixel(
int faceid,
int u,
int v,
110 float* result,
int firstchan,
int nchannels);
111 virtual void getPixel(
int faceid,
int u,
int v,
112 float* result,
int firstchan,
int nchannels,
131 virtual void getKey(
int index,
const char*& key, MetaDataType& type)
133 if (index < 0 || index >=
int(
_entries.size())) {
141 virtual bool findKey(
const char* key,
int& index, MetaDataType& type)
143 MetaMap::iterator iter =
_map.find(key);
144 if (iter==
_map.end()) {
148 index = iter->second.index;
149 type = iter->second.type;
153 virtual void getValue(
const char* key,
const char*& value)
157 if (!
findKey(key, index, type)) {
162 if (e && e->
type == mdt_string) value = (
const char*) e->
data;
166 virtual void getValue(
int index,
const char*& value)
168 if (index < 0 || index >=
int(
_entries.size())) { value = 0;
return; }
170 if (e && e->
type == mdt_string) value = (
const char*) e->
data;
175 void getValue(
int index, MetaDataType requestedType,
const T*& value,
int& count)
177 if (index < 0 || index >=
int(
_entries.size())) {
183 if (e && e->
type == requestedType) {
184 value = (
const T*) e->
data;
187 else { value = 0; count = 0; }
191 void getValue(
const char* key, MetaDataType requestedType,
const T*& value,
int& count)
199 virtual void getValue(
const char* key,
const int8_t*& value,
int& count)
204 virtual void getValue(
int index,
const int8_t*& value,
int& count)
209 virtual void getValue(
const char* key,
const int16_t*& value,
int& count)
214 virtual void getValue(
int index,
const int16_t*& value,
int& count)
219 virtual void getValue(
const char* key,
const int32_t*& value,
int& count)
224 virtual void getValue(
int index,
const int32_t*& value,
int& count)
229 virtual void getValue(
const char* key,
const float*& value,
int& count)
234 virtual void getValue(
int index,
const float*& value,
int& count)
239 virtual void getValue(
const char* key,
const double*& value,
int& count)
244 virtual void getValue(
int index,
const double*& value,
int& count)
250 uint32_t datasize,
const void* data,
size_t& metaDataMemUsed)
253 e->
data =
new char[datasize];
254 memcpy(e->
data, data, datasize);
255 metaDataMemUsed += datasize;
259 uint32_t datasize,
FilePos filepos, uint32_t zipsize,
260 size_t& metaDataMemUsed)
279 :
_data(new char [size]) {}
318 std::pair<MetaMap::iterator,bool> result =
319 _map.insert(std::make_pair(std::string(key, keysize),
Entry()));
320 Entry* e = &result.first->second;
321 bool newentry = result.second;
331 e->
key = result.first->first.c_str();
335 metaDataMemUsed +=
sizeof(std::string) + keysize + 1 +
sizeof(
Entry);
442 virtual void getPixel(
int u,
int v,
void* result);
456 for (std::vector<FaceData*>::iterator i =
_tiles.begin(); i !=
_tiles.end(); ++i) {
496 std::vector<FaceDataHeader>
_fdh;
525 std::vector<FaceDataHeader>
fdh;
535 for (std::vector<FaceData*>::iterator i =
faces.begin(); i !=
faces.end(); ++i) {
541 return sizeof(*this) +
fdh.size() * (
sizeof(
fdh[0]) +
549 void setError(
const char* error,
bool ioError =
false)
551 std::string msg = error;
552 msg +=
" PtexFile: ";
556 msg +=
_io->lastError();
559 if (
_err)
_err->reportError(msg.c_str());
560 else std::cerr << msg;
583 bool readZipBlock(
void* data,
int zipsize,
int unzipsize);
594 if (!face)
readFace(levelid, level, faceid, res);
601 void readLevel(
int levelid, Level*& level);
602 void readFace(
int levelid, Level* level,
int faceid, Res res);
615 FilePos* end = offsets + noffsets;
616 while (offsets != end) { *offsets++ = pos; pos += fdh->
blocksize(); fdh++; }
625 FILE* fp = fopen(
path,
"rb");
633 virtual void seek(
Handle handle, int64_t pos) { fseeko((FILE*)handle, pos, SEEK_SET); }
634 virtual size_t read(
void* bufferArg,
size_t size,
Handle handle) {
635 return fread(bufferArg, size, 1, (FILE*)handle) == 1 ? size : 0;
638 bool ok = handle && (fclose((FILE*)handle) == 0);
642 virtual const char*
lastError() {
return strerror(errno); }
680 :
_val( int64_t(faceid)<<32 | uint32_t(16777619*((res.val()<<16) ^ faceid)) ) {}
699 return uint32_t(
_val);
Contains PtexHashMap, a lightweight multi-threaded hash table.
#define PTEX_NAMESPACE_END
Public API classes for reading, writing, caching, and filtering Ptex files.
Custom handler interface redirecting Ptex error messages.
Per-face texture data accessor.
virtual bool isConstant()
True if this data block is constant.
virtual Ptex::Res res()
Resolution of the texture held by this data block.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual bool isTiled()
True if this data block is tiled.
virtual void * getData()
Access the data from this data block.
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
ConstDataPtr(void *data, int pixelsize)
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
ConstantFace(int pixelsize)
virtual bool isConstant()
True if this data block is constant.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
ErrorFace(void *errorPixel, int pixelsize, bool deleteOnRelease)
virtual Ptex::Res res()
Resolution of the texture held by this data block.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)=0
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
std::vector< FilePos > offsets
std::vector< FaceDataHeader > fdh
std::vector< FaceData * > faces
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
PackedFace(Res resArg, int pixelsize, int size)
virtual bool isTiled()
True if this data block is tiled.
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual bool isConstant()
True if this data block is constant.
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
virtual void * getData()
Access the data from this data block.
bool isEmpty() const volatile
ReductionKey(uint32_t faceid, Res res)
void move(volatile ReductionKey &key) volatile
uint32_t hash() const volatile
void copy(volatile ReductionKey &key) volatile
bool matches(const ReductionKey &key) const volatile
TiledFaceBase(PtexReader *reader, Res resArg, Res tileresArg)
size_t baseExtraMemUsed()
std::vector< FaceData * > _tiles
virtual bool isTiled()
True if this data block is tiled.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual void * getData()
Access the data from this data block.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual bool isConstant()
True if this data block is constant.
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
std::vector< FaceDataHeader > _fdh
TiledFace(PtexReader *reader, Res resArg, Res tileresArg, int levelid)
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
void readTile(int tile, FaceData *&data)
std::vector< FilePos > _offsets
TiledFaceBase * _parentface
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
PtexUtils::ReduceFn * _reducefn
TiledReducedFace(PtexReader *reader, Res resArg, Res tileresArg, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
DataType datatype() const
void readMetaDataBlock(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
const ExtHeader & extheader() const
virtual void * getConstantData(int faceid) final
Access the constant (or average) data value for a given face.
virtual int numFaces()
Number of faces stored in file.
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
std::vector< FilePos > _levelpos
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)
Access a single texel from the highest resolution texture .
void setIOError(const char *error)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
void increaseMemUsed(size_t amount)
virtual const char * path()
Path that file was opened with.
void computeFaceTileOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
FaceData * getFace(int levelid, Level *level, int faceid, Res res)
Level * getLevel(int levelid)
FaceData * errorData(bool deleteOnRelease=false)
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
virtual PtexMetaData * getMetaData()
Access meta data.
virtual int alphaChannel()
Index of alpha channel (if any).
virtual void getData(int faceid, void *buffer, int stride)
Access texture data for a face at highest-resolution.
const Header & header() const
std::vector< LevelInfo > _levelinfo
bool readBlock(void *data, int size)
PtexHashMap< ReductionKey, FaceData * > ReductionMap
PtexReader(bool premultiply, PtexInputHandler *inputHandler, PtexErrorHandler *errorHandler)
virtual bool hasMipMaps()
True if the file has mipmaps.
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)
Access resolution and adjacency information about a face.
void readLargeMetaDataHeaders(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
bool pendingPurge() const
void setError(const char *error, bool ioError=false)
void readFace(int levelid, Level *level, int faceid, Res res)
virtual bool hasEdits()
Obsolete (returns false).
std::vector< uint32_t > _rfaceids
DefaultInputHandler _defaultIo
volatile size_t _blockReads
void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData *&face)
libdeflate_decompressor * _decompressor
std::vector< Level * > _levels
std::vector< FaceInfo > _faceinfo
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
virtual Ptex::EdgeFilterMode edgeFilterMode()
Mode for filtering textures across edges.
PtexInputHandler::Handle _fp
bool readZipBlock(void *data, int zipsize, int unzipsize)
void getCompressedData(int faceid, int level, FaceDataHeader &fdh, std::vector< std::byte > &data)
void readLevel(int levelid, Level *&level)
virtual Ptex::DataType dataType()
Type of data stored in file.
std::vector< char > _errorPixel
virtual int numChannels()
Number of channels stored in file.
bool open(const char *path, Ptex::String &error)
const LevelInfo & levelinfo(int level) const
Interface for reading data from a ptex file.
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
DataType
Type of data stored in texture file.
MeshType
Type of base mesh for which the textures are defined.
BorderMode
How to handle mesh border when filtering.
EdgeFilterMode
How to handle transformation across edges when filtering.
Get most commonly used info in a single call for convenience / efficiency.
EdgeFilterMode edgeFilterMode
Information about a face, as stored in the Ptex file header.
Pixel resolution of a given texture.