📄 tiff_support.hpp
字号:
virtual void ParseMemoryStream ( const void* data, XMP_Uns32 length, bool copyData = true ) = 0; virtual void ParseFileStream ( LFA_FileRef fileRef ) = 0; virtual void IntegrateFromPShop6 ( const void * buriedPtr, size_t buriedLen ) = 0; virtual XMP_Uns32 UpdateMemoryStream ( void** dataPtr, bool condenseStream = false ) = 0; virtual void UpdateFileStream ( LFA_FileRef fileRef ) = 0; // --------------------------------------------------------------------------------------------- GetUns16_Proc GetUns16; // Get values from the TIFF stream. GetUns32_Proc GetUns32; // Always native endian on the outside, stream endian in the stream. GetFloat_Proc GetFloat; GetDouble_Proc GetDouble; PutUns16_Proc PutUns16; // Put values into the TIFF stream. PutUns32_Proc PutUns32; // Always native endian on the outside, stream endian in the stream. PutFloat_Proc PutFloat; PutDouble_Proc PutDouble; virtual ~TIFF_Manager() {}; // ! Hacks to help the reconciliation code accomodate Photoshop behavior: bool xmpHadUserComment, xmpHadRelatedSoundFile;protected: bool bigEndian, nativeEndian; XMP_Uns8 * jpegTNailPtr; XMP_Uns32 CheckTIFFHeader ( const XMP_Uns8* tiffPtr, XMP_Uns32 length ); TIFF_Manager(); // Force clients to use the reader or writer derived classes. struct RawIFDEntry { XMP_Uns16 id; XMP_Uns16 type; XMP_Uns32 count; XMP_Uns32 dataOrOffset; };}; // TIFF_Manager// =================================================================================================// =================================================================================================// =================================================================================================// TIFF_MemoryReader// =================class TIFF_MemoryReader : public TIFF_Manager { // The derived class for memory-based read-only access.public: bool HasThumbnailIFD() const { return (containedIFDs[kTIFF_TNailIFD].count != 0); }; bool HasExifIFD() const { return (containedIFDs[kTIFF_ExifIFD].count != 0); }; bool HasGPSInfoIFD() const { return (containedIFDs[kTIFF_GPSInfoIFD].count != 0); }; bool GetIFD ( XMP_Uns8 ifd, TagInfoMap* ifdMap ) const; bool GetTag ( XMP_Uns8 ifd, XMP_Uns16 id, TagInfo* info ) const; void SetTag ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns16 type, XMP_Uns32 count, const void* dataPtr ) { NotAppropriate(); }; void DeleteTag ( XMP_Uns8 ifd, XMP_Uns16 id ) { NotAppropriate(); }; XMP_Uns32 GetValueOffset ( XMP_Uns8 ifd, XMP_Uns16 id ) const; bool GetTag_Integer ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns32* data ) const; bool GetTag_Byte ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns8* data ) const; bool GetTag_SByte ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Int8* data ) const; bool GetTag_Short ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns16* data ) const; bool GetTag_SShort ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Int16* data ) const; bool GetTag_Long ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns32* data ) const; bool GetTag_SLong ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Int32* data ) const; bool GetTag_Rational ( XMP_Uns8 ifd, XMP_Uns16 id, Rational* data ) const; bool GetTag_SRational ( XMP_Uns8 ifd, XMP_Uns16 id, SRational* data ) const; bool GetTag_Float ( XMP_Uns8 ifd, XMP_Uns16 id, float* data ) const; bool GetTag_Double ( XMP_Uns8 ifd, XMP_Uns16 id, double* data ) const; bool GetTag_ASCII ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_StringPtr* dataPtr, XMP_StringLen* dataLen ) const; bool GetTag_EncodedString ( XMP_Uns8 ifd, XMP_Uns16 id, std::string* utf8Str ) const; void SetTag_EncodedString ( XMP_Uns8 ifd, XMP_Uns16 id, const std::string& utf8Str, XMP_Uns8 encoding ) { NotAppropriate(); }; bool IsChanged() { return false; }; bool IsLegacyChanged() { return false; }; void ParseMemoryStream ( const void* data, XMP_Uns32 length, bool copyData = true ); void ParseFileStream ( LFA_FileRef fileRef ) { NotAppropriate(); }; void IntegrateFromPShop6 ( const void * buriedPtr, size_t buriedLen ) { NotAppropriate(); }; XMP_Uns32 UpdateMemoryStream ( void** dataPtr, bool condenseStream = false ) { if ( dataPtr != 0 ) *dataPtr = tiffStream; return tiffLength; }; void UpdateFileStream ( LFA_FileRef fileRef ) { NotAppropriate(); }; TIFF_MemoryReader() : ownedStream(false), tiffStream(0), tiffLength(0) {}; virtual ~TIFF_MemoryReader() { if ( this->ownedStream ) free ( this->tiffStream ); };private: bool ownedStream; XMP_Uns8* tiffStream; XMP_Uns32 tiffLength; struct TweakedIFDEntry { XMP_Uns16 id; XMP_Uns16 type; XMP_Uns32 bytes; XMP_Uns32 dataOrPtr; TweakedIFDEntry() : id(0), type(0), bytes(0), dataOrPtr(0) {}; }; struct TweakedIFDInfo { XMP_Uns16 count; TweakedIFDEntry* entries; TweakedIFDInfo() : count(0), entries(0) {}; }; TweakedIFDInfo containedIFDs[kTIFF_KnownIFDCount]; static void SortIFD ( TweakedIFDInfo* thisIFD ); XMP_Uns32 ProcessOneIFD ( XMP_Uns32 ifdOffset, XMP_Uns8 ifd ); const TweakedIFDEntry* FindTagInIFD ( XMP_Uns8 ifd, XMP_Uns16 id ) const; static inline void NotAppropriate() { XMP_Throw ( "Not appropriate for TIFF_Reader", kXMPErr_InternalFailure ); }; }; // TIFF_MemoryReader// =================================================================================================// =================================================================================================// =================================================================================================// TIFF_FileWriter// ===============class TIFF_FileWriter : public TIFF_Manager { // The derived class for file-based or read-write access.public: bool HasThumbnailIFD() const { return this->containedIFDs[kTIFF_TNailIFD].tagMap.size() != 0; }; bool HasExifIFD() const { return this->containedIFDs[kTIFF_ExifIFD].tagMap.size() != 0; }; bool HasGPSInfoIFD() const { return this->containedIFDs[kTIFF_GPSInfoIFD].tagMap.size() != 0; }; bool GetIFD ( XMP_Uns8 ifd, TagInfoMap* ifdMap ) const; bool GetTag ( XMP_Uns8 ifd, XMP_Uns16 id, TagInfo* info ) const; void SetTag ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns16 type, XMP_Uns32 count, const void* dataPtr ); void DeleteTag ( XMP_Uns8 ifd, XMP_Uns16 id ); XMP_Uns32 GetValueOffset ( XMP_Uns8 ifd, XMP_Uns16 id ) const; bool GetTag_Integer ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns32* data ) const; bool GetTag_Byte ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns8* data ) const; bool GetTag_SByte ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Int8* data ) const; bool GetTag_Short ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns16* data ) const; bool GetTag_SShort ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Int16* data ) const; bool GetTag_Long ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Uns32* data ) const; bool GetTag_SLong ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_Int32* data ) const; bool GetTag_Rational ( XMP_Uns8 ifd, XMP_Uns16 id, Rational* data ) const; bool GetTag_SRational ( XMP_Uns8 ifd, XMP_Uns16 id, SRational* data ) const; bool GetTag_Float ( XMP_Uns8 ifd, XMP_Uns16 id, float* data ) const; bool GetTag_Double ( XMP_Uns8 ifd, XMP_Uns16 id, double* data ) const; bool GetTag_ASCII ( XMP_Uns8 ifd, XMP_Uns16 id, XMP_StringPtr* dataPtr, XMP_StringLen* dataLen ) const; bool GetTag_EncodedString ( XMP_Uns8 ifd, XMP_Uns16 id, std::string* utf8Str ) const; void SetTag_EncodedString ( XMP_Uns8 ifd, XMP_Uns16 id, const std::string& utf8Str, XMP_Uns8 encoding ); bool IsChanged() { return this->changed; }; bool IsLegacyChanged(); enum { kDoNotCopyData = false }; void ParseMemoryStream ( const void* data, XMP_Uns32 length, bool copyData = true ); void ParseFileStream ( LFA_FileRef fileRef ); void IntegrateFromPShop6 ( const void * buriedPtr, size_t buriedLen ); XMP_Uns32 UpdateMemoryStream ( void** dataPtr, bool condenseStream = false ); void UpdateFileStream ( LFA_FileRef fileRef ); TIFF_FileWriter(); virtual ~TIFF_FileWriter();private: bool changed; bool memParsed, fileParsed; bool ownedStream; XMP_Uns8* memStream; XMP_Uns32 tiffLength; struct InternalTagInfo { XMP_Uns16 id; XMP_Uns16 type; XMP_Uns32 count; XMP_Uns32 dataLen; XMP_Uns32 dataOrOffset; // Small value or large offset in stream endianness. XMP_Uns8* dataPtr; // Always set, even for small values. XMP_Uns32 origLen; // The original data length in bytes. XMP_Uns32 origOffset; // The original data offset, regardless of length. bool changed; InternalTagInfo() : id(0), type(0), count(0), dataLen(0), dataOrOffset(0), dataPtr(0), origLen(0), origOffset(0), changed(false) {}; InternalTagInfo ( XMP_Uns16 _id, XMP_Uns16 _type, XMP_Uns32 _count ) : id(_id), type(_type), count(_count), dataLen(0), dataOrOffset(0), dataPtr(0), origLen(0), origOffset(0), changed(false) {}; ~InternalTagInfo() { if ( this->changed && (this->dataLen > 4) && (this->dataPtr != 0) ) free ( this->dataPtr ); }; void operator= ( const InternalTagInfo & in ) { // ! Gag! Transfer ownership of the dataPtr! if ( this->changed && (this->dataLen > 4) && (this->dataPtr != 0) ) free ( this->dataPtr ); memcpy ( this, &in, sizeof ( InternalTagInfo ) ); // AUDIT: Use of sizeof(InternalTagInfo) is safe. if ( this->dataLen <= 4 ) { this->dataPtr = (XMP_Uns8*) &this->dataOrOffset; } else { *((XMP_Uns8**)&in.dataPtr) = 0; // ! Avoid double calls to free from the destructor! } }; }; typedef std::map<XMP_Uns16,InternalTagInfo> InternalTagMap; struct InternalIFDInfo { bool changed; XMP_Uns16 origCount; // Original number of IFD entries. XMP_Uns32 origOffset; // Original stream offset of the IFD. XMP_Uns32 origNextIFD; // Original stream offset of the following IFD. InternalTagMap tagMap; InternalIFDInfo() : changed(false), origCount(0), origOffset(0), origNextIFD(0) {}; void clear() { this->changed = false; this->origCount = 0; this->origOffset = this->origNextIFD = 0; this->tagMap.clear(); }; }; InternalIFDInfo containedIFDs[kTIFF_KnownIFDCount]; static XMP_Uns8 PickIFD ( XMP_Uns8 ifd, XMP_Uns16 id ); const InternalTagInfo* FindTagInIFD ( XMP_Uns8 ifd, XMP_Uns16 id ) const; void DeleteExistingInfo(); XMP_Uns32 ProcessMemoryIFD ( XMP_Uns32 ifdOffset, XMP_Uns8 ifd ); XMP_Uns32 ProcessFileIFD ( XMP_Uns8 ifd, XMP_Uns32 ifdOffset, LFA_FileRef fileRef, IOBuffer* ioBuf ); void ProcessPShop6IFD ( const TIFF_MemoryReader& buriedExif, XMP_Uns8 ifd ); static void* CopyTagToMasterIFD ( const TagInfo& ps6Tag, InternalIFDInfo* masterIFD ); void UpdateMemByAppend ( XMP_Uns8** newStream_out, XMP_Uns32* newLength_out, bool appendAll = false, XMP_Uns32 extraSpace = 0 ); void UpdateMemByRewrite ( XMP_Uns8** newStream_out, XMP_Uns32* newLength_out ); XMP_Uns32 DetermineVisibleLength(); XMP_Uns32 DetermineAppendInfo ( XMP_Uns32 appendedOrigin, bool appendedIFDs[kTIFF_KnownIFDCount], XMP_Uns32 newIFDOffsets[kTIFF_KnownIFDCount], bool appendAll = false ); void WriteFileIFD ( LFA_FileRef fileRef, InternalIFDInfo & thisIFD ); }; // TIFF_FileWriter// =================================================================================================#endif // __TIFF_Support_hpp__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -