Ptex
|
#include <PtexWriter.h>
Classes | |
struct | LevelRec |
Public Member Functions | |
PtexMainWriter (const char *path, PtexTexture *tex, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, bool genmipmaps) | |
virtual bool | close (Ptex::String &error) |
Close the file. More... | |
virtual bool | writeFace (int faceid, const FaceInfo &f, const void *data, int stride) |
Write texture data for a face. More... | |
virtual bool | writeConstantFace (int faceid, const FaceInfo &f, const void *data) |
Write constant texture data for a face. More... | |
![]() | |
virtual void | setBorderModes (Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode) |
Set border modes. More... | |
virtual void | writeMeta (const char *key, const char *value) |
Write a string as meta data. More... | |
virtual void | writeMeta (const char *key, const int8_t *value, int count) |
Write an array of signed 8-bit integers as meta data. More... | |
virtual void | writeMeta (const char *key, const int16_t *value, int count) |
Write an array of signed 16-bit integers as meta data. More... | |
virtual void | writeMeta (const char *key, const int32_t *value, int count) |
Write an array of signed 32-bit integers as meta data. More... | |
virtual void | writeMeta (const char *key, const float *value, int count) |
Write an array of signed 32-bit floats as meta data. More... | |
virtual void | writeMeta (const char *key, const double *value, int count) |
Write an array of signed 32-bit doubles as meta data. More... | |
virtual void | writeMeta (PtexMetaData *data) |
Copy meta data from an existing meta data block. More... | |
virtual void | release () |
Release resources held by this pointer (pointer becomes invalid). More... | |
bool | ok (Ptex::String &error) |
void | getError (Ptex::String &error) |
Protected Member Functions | |
virtual | ~PtexMainWriter () |
virtual void | addMetaData (const char *key, MetaDataType t, const void *value, int size) |
![]() | |
PtexWriterBase (const char *path, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, bool compress) | |
virtual | ~PtexWriterBase () |
int | writeBlank (FILE *fp, int size) |
int | writeBlock (FILE *fp, const void *data, int size) |
int | writeZipBlock (FILE *fp, const void *data, int size, bool finish=true) |
int | readBlock (FILE *fp, void *data, int size) |
int | copyBlock (FILE *dst, FILE *src, FilePos pos, int size) |
Res | calcTileRes (Res faceres) |
void | writeConstFaceBlock (FILE *fp, const void *data, FaceDataHeader &fdh) |
void | writeFaceBlock (FILE *fp, const void *data, int stride, Res res, FaceDataHeader &fdh) |
void | writeFaceData (FILE *fp, const void *data, int stride, Res res, FaceDataHeader &fdh) |
void | writeReduction (FILE *fp, const void *data, int stride, Res res) |
int | writeMetaDataBlock (FILE *fp, MetaEntry &val) |
void | setError (const std::string &error) |
bool | storeFaceInfo (int faceid, FaceInfo &dest, const FaceInfo &src, int flags=0) |
![]() | |
virtual | ~PtexWriter () |
Destructor not for public use. Use release() instead. More... | |
Private Member Functions | |
virtual void | finish () |
void | generateReductions () |
void | flagConstantNeighorhoods () |
void | storeConstValue (int faceid, const void *data, int stride, Res res) |
void | writeMetaData (FILE *fp) |
Private Attributes | |
std::string | _newpath |
std::string | _tmppath |
FILE * | _tmpfp |
bool | _hasNewData |
bool | _genmipmaps |
std::vector< FaceInfo > | _faceinfo |
std::vector< uint8_t > | _constdata |
std::vector< uint32_t > | _rfaceids |
std::vector< uint32_t > | _faceids_r |
std::vector< LevelRec > | _levels |
std::vector< FilePos > | _rpos |
PtexReader * | _reader |
Static Private Attributes | |
static const int | MinReductionLog2 =2 |
Additional Inherited Members | |
![]() | |
enum | Encoding { enc_constant, enc_zipped, enc_diffzipped, enc_tiled } |
enum | EditType { et_editfacedata, et_editmetadata } |
![]() | |
enum | MeshType { mt_triangle, mt_quad } |
Type of base mesh for which the textures are defined. More... | |
enum | DataType { dt_uint8, dt_uint16, dt_half, dt_float } |
Type of data stored in texture file. More... | |
enum | BorderMode { m_clamp, m_black, m_periodic } |
How to handle mesh border when filtering. More... | |
enum | EdgeId { e_bottom, e_right, e_top, e_left } |
Edge IDs used in adjacency data in the Ptex::FaceInfo struct. More... | |
enum | MetaDataType { mdt_string, mdt_int8, mdt_int16, mdt_int32, mdt_float, mdt_double } |
Type of meta data entry. More... | |
![]() | |
static PtexWriter * | open (const char *path, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, Ptex::String &error, bool genmipmaps=true) |
Open a new texture file for writing. More... | |
static PtexWriter * | edit (const char *path, bool incremental, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, Ptex::String &error, bool genmipmaps=true) |
Open an existing texture file for writing. More... | |
static bool | applyEdits (const char *path, Ptex::String &error) |
Apply edits to a file. More... | |
![]() | |
static bool | LittleEndian () |
![]() | |
static const char * | MeshTypeName (MeshType mt) |
Look up name of given mesh type. More... | |
static const char * | DataTypeName (DataType dt) |
Look up name of given data type. More... | |
static const char * | BorderModeName (BorderMode m) |
Look up name of given border mode. More... | |
static const char * | EdgeIdName (EdgeId eid) |
Look up name of given edge ID. More... | |
static const char * | MetaDataTypeName (MetaDataType mdt) |
Look up name of given meta data type. More... | |
static int | DataSize (DataType dt) |
Look up size of given data type (in bytes). More... | |
static float | OneValue (DataType dt) |
Look up value of given data type that corresponds to the normalized value of 1.0. More... | |
static float | OneValueInv (DataType dt) |
Lookup up inverse value of given data type that corresponds to the normalized value of 1.0. More... | |
static void | ConvertToFloat (float *dst, const void *src, Ptex::DataType dt, int numChannels) |
Convert a number of data values from the given data type to float. More... | |
static void | ConvertFromFloat (void *dst, const float *src, Ptex::DataType dt, int numChannels) |
Convert a number of data values from float to the given data type. More... | |
![]() | |
static const uint32_t | Magic = 'P' | ('t'<<8) | ('e'<<16) | ('x'<<24) |
static const int | HeaderSize = sizeof(Header) |
static const int | ExtHeaderSize = sizeof(ExtHeader) |
static const int | LevelInfoSize = sizeof(LevelInfo) |
static const int | FaceDataHeaderSize = sizeof(FaceDataHeader) |
static const int | EditFaceDataHeaderSize = sizeof(EditFaceDataHeader) |
static const int | EditMetaDataHeaderSize = sizeof(EditMetaDataHeader) |
static const int | IBuffSize = 8192 |
static const int | BlockSize = 16384 |
static const int | TileSize = 65536 |
static const int | AllocaMax = 16384 |
static const int | MetaDataThreshold = 1024 |
![]() | |
bool | _ok |
std::string | _error |
std::string | _path |
std::string | _tilepath |
FILE * | _tilefp |
Header | _header |
ExtHeader | _extheader |
int | _pixelSize |
std::vector< MetaEntry > | _metadata |
std::map< std::string, int > | _metamap |
z_stream_s | _zstream |
PtexUtils::ReduceFn * | _reduceFn |
Definition at line 122 of file PtexWriter.h.
PtexMainWriter::PtexMainWriter | ( | const char * | path, |
PtexTexture * | tex, | ||
Ptex::MeshType | mt, | ||
Ptex::DataType | dt, | ||
int | nchannels, | ||
int | alphachan, | ||
int | nfaces, | ||
bool | genmipmaps | ||
) |
Definition at line 725 of file PtexWriter.cpp.
References _constdata, _faceinfo, _hasNewData, _levels, _newpath, PtexWriterBase::_pixelSize, _reader, _rpos, _tmpfp, _tmppath, PtexReader::getMetaData(), PtexReader::hasEdits(), PtexWriterBase::setBorderModes(), PtexWriterBase::setError(), PtexTexture::uBorderMode(), PtexTexture::vBorderMode(), and PtexWriterBase::writeMeta().
|
protectedvirtual |
Definition at line 773 of file PtexWriter.cpp.
References _reader, and PtexReader::release().
|
inlineprotectedvirtual |
Reimplemented from PtexWriterBase.
Definition at line 134 of file PtexWriter.h.
References _hasNewData, and PtexWriterBase::addMetaData().
|
virtual |
Close the file.
This operation can take some time if mipmaps are being generated or if there are many edit blocks. If an error occurs while writing, false is returned and an error string is written into the error parameter.
Reimplemented from PtexWriterBase.
Definition at line 779 of file PtexWriter.cpp.
References _hasNewData, _newpath, PtexWriterBase::_path, _reader, _tmpfp, _tmppath, PtexWriterBase::close(), and PtexReader::release().
|
privatevirtual |
Implements PtexWriterBase.
Definition at line 889 of file PtexWriter.cpp.
References _constdata, PtexWriterBase::_extheader, _faceinfo, _genmipmaps, _hasNewData, PtexWriterBase::_header, _levels, PtexWriterBase::_metadata, _newpath, PtexWriterBase::_pixelSize, _reader, _tmpfp, PtexIO::Header::constdatasize, PtexWriterBase::copyBlock(), PtexIO::ExtHeader::editdatapos, PtexIO::ExtHeaderSize, PtexIO::Header::faceinfosize, PtexMainWriter::LevelRec::fdh, Ptex::FaceInfo::flag_constant, flagConstantNeighorhoods(), generateReductions(), PtexReader::getData(), PtexReader::getFaceInfo(), PtexIO::HeaderSize, Ptex::FaceInfo::isConstant(), PtexIO::Header::leveldatasize, PtexIO::LevelInfo::leveldatasize, PtexIO::LevelInfo::levelheadersize, PtexIO::Header::levelinfosize, PtexIO::LevelInfoSize, PtexIO::Header::nfaces, PtexIO::LevelInfo::nfaces, PtexIO::Header::nlevels, PtexMainWriter::LevelRec::pos, Ptex::FaceInfo::res, PtexWriterBase::setError(), Ptex::Res::size(), PtexWriterBase::writeBlank(), PtexWriterBase::writeBlock(), writeConstantFace(), writeFace(), writeMetaData(), and PtexWriterBase::writeZipBlock().
|
private |
Definition at line 995 of file PtexWriter.cpp.
References _constdata, _faceinfo, PtexWriterBase::_header, PtexWriterBase::_pixelSize, Ptex::FaceInfo::adjedge(), Ptex::FaceInfo::adjface(), Ptex::FaceInfo::flag_nbconstant, Ptex::FaceInfo::flags, Ptex::FaceInfo::isConstant(), Ptex::FaceInfo::isSubface(), PtexIO::Header::meshtype, and Ptex::mt_triangle.
Referenced by finish().
|
private |
Definition at line 1059 of file PtexWriter.cpp.
References _faceids_r, _faceinfo, PtexWriterBase::_header, _levels, PtexWriterBase::_ok, PtexWriterBase::_pixelSize, _rfaceids, _rpos, _tmpfp, PtexMainWriter::LevelRec::fdh, PtexUtils::genRfaceids(), Ptex::FaceInfo::isConstant(), PtexUtils::max(), PtexUtils::min(), MinReductionLog2, PtexIO::Header::nfaces, PtexMainWriter::LevelRec::pos, PtexWriterBase::readBlock(), Ptex::FaceInfo::res, Ptex::Res::size(), storeConstValue(), Ptex::Res::u(), Ptex::Res::ulog2, Ptex::Res::vlog2, PtexWriterBase::writeFaceData(), and PtexWriterBase::writeReduction().
Referenced by finish().
|
private |
Definition at line 877 of file PtexWriter.cpp.
References _constdata, PtexWriterBase::_header, PtexWriterBase::_pixelSize, PtexIO::Header::alphachan, PtexUtils::average(), PtexIO::Header::datatype, PtexUtils::divalpha(), PtexIO::Header::hasAlpha(), PtexIO::Header::nchannels, Ptex::Res::u(), and Ptex::Res::v().
Referenced by generateReductions(), and writeFace().
|
virtual |
Write constant texture data for a face.
The data is written as a single constant texel value. Note: the resolution specified in the info param may indicate a resolution greater than 1x1 and the value will be preserved when reading. This is useful to indicate a texture's logical resolution even when the data is constant.
Implements PtexWriter.
Definition at line 862 of file PtexWriter.cpp.
References _constdata, _faceinfo, _hasNewData, PtexWriterBase::_ok, PtexWriterBase::_pixelSize, Ptex::FaceInfo::flag_constant, and PtexWriterBase::storeFaceInfo().
Referenced by finish(), and writeFace().
|
virtual |
Write texture data for a face.
The data is assumed to be channel-interleaved per texel and stored in v-major order.
faceid | Face index [0..nfaces-1]. |
info | Face resolution and adjacency information. |
data | Texel data. |
stride | Distance between rows, in bytes (if zero, data is assumed packed). |
If an error is encountered while writing, false is returned and an error message can be when close is called.
Implements PtexWriter.
Definition at line 805 of file PtexWriter.cpp.
References _faceinfo, _genmipmaps, _hasNewData, PtexWriterBase::_header, _levels, PtexWriterBase::_ok, PtexWriterBase::_pixelSize, _rpos, _tmpfp, PtexIO::Header::alphachan, PtexUtils::copy(), PtexIO::Header::datatype, PtexIO::Header::hasAlpha(), PtexUtils::isConstant(), MinReductionLog2, PtexUtils::multalpha(), PtexIO::Header::nchannels, Ptex::FaceInfo::res, Ptex::Res::size(), storeConstValue(), PtexWriterBase::storeFaceInfo(), Ptex::Res::u(), Ptex::Res::ulog2, Ptex::Res::v(), Ptex::Res::vlog2, writeConstantFace(), PtexWriterBase::writeFaceData(), and PtexWriterBase::writeReduction().
Referenced by finish().
|
private |
Definition at line 1130 of file PtexWriter.cpp.
References PtexWriterBase::_extheader, PtexWriterBase::_header, PtexWriterBase::_metadata, _tmpfp, PtexWriterBase::copyBlock(), PtexWriterBase::MetaEntry::data, PtexWriterBase::MetaEntry::datatype, PtexWriterBase::MetaEntry::key, PtexIO::ExtHeader::lmddatasize, PtexIO::ExtHeader::lmdheadermemsize, PtexIO::ExtHeader::lmdheaderzipsize, PtexIO::Header::metadatamemsize, PtexIO::MetaDataThreshold, PtexIO::Header::metadatazipsize, PtexWriterBase::writeBlank(), PtexWriterBase::writeMetaDataBlock(), and PtexWriterBase::writeZipBlock().
Referenced by finish().
|
private |
Definition at line 153 of file PtexWriter.h.
Referenced by finish(), flagConstantNeighorhoods(), PtexMainWriter(), storeConstValue(), and writeConstantFace().
|
private |
Definition at line 155 of file PtexWriter.h.
Referenced by generateReductions().
|
private |
Definition at line 152 of file PtexWriter.h.
Referenced by finish(), flagConstantNeighorhoods(), generateReductions(), PtexMainWriter(), writeConstantFace(), and writeFace().
|
private |
Definition at line 151 of file PtexWriter.h.
Referenced by finish(), and writeFace().
|
private |
Definition at line 150 of file PtexWriter.h.
Referenced by addMetaData(), close(), finish(), PtexMainWriter(), writeConstantFace(), and writeFace().
|
private |
Definition at line 167 of file PtexWriter.h.
Referenced by finish(), generateReductions(), PtexMainWriter(), and writeFace().
|
private |
Definition at line 147 of file PtexWriter.h.
Referenced by close(), finish(), and PtexMainWriter().
|
private |
Definition at line 170 of file PtexWriter.h.
Referenced by close(), finish(), PtexMainWriter(), and ~PtexMainWriter().
|
private |
Definition at line 154 of file PtexWriter.h.
Referenced by generateReductions().
|
private |
Definition at line 168 of file PtexWriter.h.
Referenced by generateReductions(), PtexMainWriter(), and writeFace().
|
private |
Definition at line 149 of file PtexWriter.h.
Referenced by close(), finish(), generateReductions(), PtexMainWriter(), writeFace(), and writeMetaData().
|
private |
Definition at line 148 of file PtexWriter.h.
Referenced by close(), and PtexMainWriter().
|
staticprivate |
Definition at line 157 of file PtexWriter.h.
Referenced by generateReductions(), and writeFace().