49 struct 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,
133 if (index < 0 || index >=
int(
_entries.size())) {
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)) {
166 virtual void getValue(
int index,
const char*& value)
168 if (index < 0 || index >=
int(
_entries.size())) { value = 0;
return; }
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; }
196 getValue<T>(index, requestedType, value, count);
199 virtual void getValue(
const char* key,
const int8_t*& value,
int& count)
201 getValue<int8_t>(key,
mdt_int8, value, count);
204 virtual void getValue(
int index,
const int8_t*& value,
int& count)
206 getValue<int8_t>(index,
mdt_int8, value, count);
209 virtual void getValue(
const char* key,
const int16_t*& value,
int& count)
211 getValue<int16_t>(key,
mdt_int16, value, count);
214 virtual void getValue(
int index,
const int16_t*& value,
int& count)
216 getValue<int16_t>(index,
mdt_int16, value, count);
219 virtual void getValue(
const char* key,
const int32_t*& value,
int& count)
221 getValue<int32_t>(key,
mdt_int32, value, count);
224 virtual void getValue(
int index,
const int32_t*& value,
int& count)
226 getValue<int32_t>(index,
mdt_int32, value, count);
229 virtual void getValue(
const char* key,
const float*& value,
int& count)
231 getValue<float>(key,
mdt_float, value, count);
234 virtual void getValue(
int index,
const float*& value,
int& count)
236 getValue<float>(index,
mdt_float, value, count);
239 virtual void getValue(
const char* key,
const double*& value,
int& count)
241 getValue<double>(key,
mdt_double, value, count);
244 virtual void getValue(
int index,
const double*& value,
int& count)
246 getValue<double>(index,
mdt_double, value, count);
250 uint32_t datasize,
const void* data,
size_t& metaDataMemUsed)
252 Entry* e =
newEntry(keysize, key, datatype, datasize, 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)
262 Entry* e =
newEntry(keysize, key, datatype, datasize, metaDataMemUsed);
279 :
_data(new char [size]) {}
300 isLmd(0), lmdData(0), lmdPos(0), lmdZipSize(0) {}
305 if (lmdData) {
delete lmdData; lmdData = 0; }
310 if (data) {
delete []
data; }
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);
417 :
ConstantFace(pixelsize), _deleteOnRelease(deleteOnRelease)
419 memcpy(
_data, errorPixel, pixelsize);
421 virtual void release() {
if (_deleteOnRelease)
delete this; }
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: ";
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);
639 if (buffer) {
delete []
buffer; buffer = 0; }
642 virtual const char*
lastError() {
return strerror(errno); }
680 : _val( int64_t(faceid)<<32 | uint32_t(16777619*((res.val()<<16) ^ faceid)) ) {}
694 return _val == key.
_val;
696 bool isEmpty()
const volatile {
return _val==-1; }
699 return uint32_t(_val);
DefaultInputHandler _defaultIo
EdgeFilterMode edgeFilterMode
virtual int numFaces()
Number of faces stored in file.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
std::vector< char > _errorPixel
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
uint32_t hash() const volatile
virtual bool hasMipMaps()
True if the file has mipmaps.
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
const ExtHeader & extheader() const
ConstantFace(int pixelsize)
void setIOError(const char *error)
virtual void * getData()
Access the data from this data block.
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual bool hasEdits()
Obsolete (returns false).
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
void computeFaceTileOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)
Access resolution and adjacency information about a face.
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
PackedFace(Res resArg, int pixelsize, int size)
bool readBlock(void *data, int size)
virtual int alphaChannel()
Index of alpha channel (if any).
PtexReader(bool premultiply, PtexInputHandler *inputHandler, PtexErrorHandler *errorHandler)
virtual bool isConstant()
True if this data block is constant.
bool isEmpty() const volatile
std::vector< FilePos > offsets
virtual const char * path()
Path that file was opened with.
virtual int numChannels()
Number of channels stored in file.
void readLevel(int levelid, Level *&level)
std::vector< FilePos > _levelpos
bool matches(const ReductionKey &key) const volatile
virtual PtexMetaData * getMetaData()
Access meta data.
void readMetaDataBlock(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
EdgeFilterMode
How to handle transformation across edges when filtering.
Get most commonly used info in a single call for convenience / efficiency.
virtual Ptex::Res res()
Resolution of the texture held by this data block.
std::vector< uint32_t > _rfaceids
virtual Ptex::EdgeFilterMode edgeFilterMode()
Mode for filtering textures across edges.
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Double-precision (32-bit) floating point.
virtual Ptex::DataType dataType()
Type of data stored in file.
virtual void reportError(const char *error)=0
FaceData * errorData(bool deleteOnRelease=false)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
void readFace(int levelid, Level *level, int faceid, Res res)
ErrorFace(void *errorPixel, int pixelsize, bool deleteOnRelease)
Per-face texture data accessor.
void increaseMemUsed(size_t amount)
Custom handler interface redirecting Ptex error messages.
TiledFace(PtexReader *reader, Res resArg, Res tileresArg, int levelid)
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
void getCompressedData(int faceid, int level, FaceDataHeader &fdh, std::vector< std::byte > &data)
const LevelInfo & levelinfo(int level) const
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
std::vector< FaceData * > _tiles
virtual bool isTiled()
True if this data block is tiled.
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
virtual bool isConstant()
True if this data block is constant.
MeshType
Type of base mesh for which the textures are defined.
virtual void * getData()
Access the data from this data block.
virtual bool isConstant()
True if this data block is constant.
void readTile(int tile, FaceData *&data)
void readLargeMetaDataHeaders(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
BorderMode
How to handle mesh border when filtering.
virtual void * getConstantData(int faceid) final
Access the constant (or average) data value for a given face.
PtexHashMap< ReductionKey, FaceData * > ReductionMap
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
TiledReducedFace(PtexReader *reader, Res resArg, Res tileresArg, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
virtual Ptex::Res res()
Resolution of the texture held by this data block.
bool readZipBlock(void *data, int zipsize, int unzipsize)
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
DataType datatype() const
virtual bool isConstant()
True if this data block is constant.
virtual void getData(int faceid, void *buffer, int stride)
Access texture data for a face at highest-resolution.
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
virtual bool isTiled()
True if this data block is tiled.
std::vector< Level * > _levels
std::vector< FaceDataHeader > fdh
Level * getLevel(int levelid)
virtual bool isTiled()
True if this data block is tiled.
PtexInputHandler::Handle _fp
std::vector< FaceInfo > _faceinfo
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)
Access a single texel from the highest resolution texture .
std::vector< FaceDataHeader > _fdh
const Header & header() const
FaceData * getFace(int levelid, Level *level, int faceid, Res res)
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
PtexUtils::ReduceFn * _reducefn
void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData *&face)
ReductionKey(uint32_t faceid, Res res)
virtual void * getData()
Access the data from this data block.
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
TiledFaceBase(PtexReader *reader, Res resArg, Res tileresArg)
Interface for reading data from a ptex file.
std::vector< FilePos > _offsets
Pixel resolution of a given texture.
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
bool pendingPurge() const
Contains PtexHashMap, a lightweight multi-threaded hash table.
ConstDataPtr(void *data, int pixelsize)
void copy(volatile ReductionKey &key) volatile
bool open(const char *path, Ptex::String &error)
Single-precision (32-bit) floating point.
int DataSize(DataType dt)
Look up size of given data type (in bytes).
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
void setError(const char *error, bool ioError=false)
MetaDataType
Type of meta data entry.
std::vector< LevelInfo > _levelinfo
std::vector< FaceData * > faces
libdeflate_decompressor * _decompressor
void move(volatile ReductionKey &key) volatile
Information about a face, as stored in the Ptex file header.
size_t baseExtraMemUsed()
DataType
Type of data stored in texture file.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)=0
#define PTEX_NAMESPACE_END
volatile size_t _blockReads
Public API classes for reading, writing, caching, and filtering Ptex files.
TiledFaceBase * _parentface