diff options
Diffstat (limited to 'XMPFiles/source/FileHandlers')
-rw-r--r-- | XMPFiles/source/FileHandlers/AIFF_Handler.cpp | 2 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/MP3_Handler.cpp | 4 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/Makefile.am | 73 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/P2_Handler.cpp | 2 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/PSD_Handler.cpp | 2 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/PSD_Handler.hpp | 2 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/UCF_Handler.hpp | 23 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/WAVE_Handler.cpp | 2 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/WEBP_Handler.cpp | 197 | ||||
-rw-r--r-- | XMPFiles/source/FileHandlers/WEBP_Handler.hpp | 48 |
10 files changed, 337 insertions, 18 deletions
diff --git a/XMPFiles/source/FileHandlers/AIFF_Handler.cpp b/XMPFiles/source/FileHandlers/AIFF_Handler.cpp index 8c9d604..6331a0b 100644 --- a/XMPFiles/source/FileHandlers/AIFF_Handler.cpp +++ b/XMPFiles/source/FileHandlers/AIFF_Handler.cpp @@ -132,7 +132,7 @@ const ChunkIdentifier AIFF_MetaHandler::kAIFCAnno[2] = { { kChunk_FORM, kType_AI // ================================ AIFF_MetaHandler::AIFF_MetaHandler ( XMPFiles * _parent ) - : mChunkBehavior(NULL), mChunkController(NULL), + : mChunkController(NULL), mChunkBehavior(NULL), mAiffMeta(), mXMPChunk(NULL), mNameChunk(NULL), mAuthChunk(NULL), mCprChunk(NULL), mAnnoChunk(NULL) diff --git a/XMPFiles/source/FileHandlers/MP3_Handler.cpp b/XMPFiles/source/FileHandlers/MP3_Handler.cpp index e9520f3..9295a2e 100644 --- a/XMPFiles/source/FileHandlers/MP3_Handler.cpp +++ b/XMPFiles/source/FileHandlers/MP3_Handler.cpp @@ -130,8 +130,8 @@ MP3_MetaHandler::MP3_MetaHandler ( XMPFiles * _parent ) this->newFramesSize = 0; this->tagIsDirty = false; this->mustShift = false; - this->majorVersion = 2.3; - this->minorVersion = 2.3; + this->majorVersion = 2; + this->minorVersion = 3; this->hasID3Tag = false; this->hasFooter = false; this->extHeaderSize = 0; diff --git a/XMPFiles/source/FileHandlers/Makefile.am b/XMPFiles/source/FileHandlers/Makefile.am new file mode 100644 index 0000000..1198856 --- /dev/null +++ b/XMPFiles/source/FileHandlers/Makefile.am @@ -0,0 +1,73 @@ +# +# exempi - Makefile.am +# +# Copyright (C) 2007-2013 Hubert Figuiere +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1 Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2 Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the +# distribution. +# +# 3 Neither the name of the Authors, nor the names of its +# contributors may be used to endorse or promote products derived +# from this software wit hout specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +# OF THE POSSIBILITY OF SUCH DAMAGE. +# + + + +noinst_LTLIBRARIES = libxmpfilehandlers.la + +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/public/include \ + -Wall @XMPCORE_CPPFLAGS@ + + +libxmpfilehandlers_la_SOURCES = \ +AIFF_Handler.cpp AIFF_Handler.hpp\ +ASF_Handler.cpp ASF_Handler.hpp\ +AVCHD_Handler.cpp AVCHD_Handler.hpp\ +Basic_Handler.cpp Basic_Handler.hpp\ +FLV_Handler.cpp FLV_Handler.hpp\ +InDesign_Handler.cpp InDesign_Handler.hpp\ +JPEG_Handler.cpp JPEG_Handler.hpp\ +MP3_Handler.cpp MP3_Handler.hpp\ +MPEG2_Handler.cpp MPEG2_Handler.hpp \ +MPEG4_Handler.cpp MPEG4_Handler.hpp \ +P2_Handler.cpp P2_Handler.hpp\ +PNG_Handler.cpp PNG_Handler.hpp\ +PostScript_Handler.cpp PostScript_Handler.hpp\ +PSD_Handler.cpp PSD_Handler.hpp\ +RIFF_Handler.cpp RIFF_Handler.hpp \ +Scanner_Handler.cpp Scanner_Handler.hpp\ +SonyHDV_Handler.cpp SonyHDV_Handler.hpp\ +SWF_Handler.cpp SWF_Handler.hpp\ +TIFF_Handler.cpp TIFF_Handler.hpp\ +Trivial_Handler.cpp Trivial_Handler.hpp\ +UCF_Handler.cpp UCF_Handler.hpp\ +XDCAMEX_Handler.cpp XDCAMEX_Handler.hpp\ +XDCAM_Handler.cpp XDCAM_Handler.hpp\ +WAVE_Handler.cpp WAVE_Handler.hpp \ +GIF_Handler.cpp GIF_Handler.hpp \ +WEBP_Handler.cpp WEB_Handler.hpp +$(NULL) + diff --git a/XMPFiles/source/FileHandlers/P2_Handler.cpp b/XMPFiles/source/FileHandlers/P2_Handler.cpp index 982744d..1b7ad09 100644 --- a/XMPFiles/source/FileHandlers/P2_Handler.cpp +++ b/XMPFiles/source/FileHandlers/P2_Handler.cpp @@ -720,7 +720,7 @@ void P2_MetaHandler::SetStartTimecodeFromLegacyXML ( XML_NodePtr legacyVideoCont dmTimeFormat = "50Timecode"; this->AdjustTimeCode( p2StartTimecode, false ); - } else if ( p2FrameRate == "59.94p" ) { + } else if ( ( p2FrameRate == "59.94p" ) && ( p2DropFrameFlag != 0 ) ) { if ( XMP_LitMatch ( p2DropFrameFlag, "true" ) ) { dmTimeFormat = "5994DropTimecode"; diff --git a/XMPFiles/source/FileHandlers/PSD_Handler.cpp b/XMPFiles/source/FileHandlers/PSD_Handler.cpp index cbcf4df..312e855 100644 --- a/XMPFiles/source/FileHandlers/PSD_Handler.cpp +++ b/XMPFiles/source/FileHandlers/PSD_Handler.cpp @@ -81,7 +81,7 @@ XMPFileHandler * PSD_MetaHandlerCTor ( XMPFiles * parent ) // PSD_MetaHandler::PSD_MetaHandler // ================================ -PSD_MetaHandler::PSD_MetaHandler ( XMPFiles * _parent ) : iptcMgr(0), exifMgr(0), skipReconcile(false),imageWidth(0),imageHeight(0) +PSD_MetaHandler::PSD_MetaHandler ( XMPFiles * _parent ) : skipReconcile(false), iptcMgr(0), exifMgr(0),imageWidth(0),imageHeight(0) { this->parent = _parent; this->handlerFlags = kPSD_HandlerFlags; diff --git a/XMPFiles/source/FileHandlers/PSD_Handler.hpp b/XMPFiles/source/FileHandlers/PSD_Handler.hpp index 51dd4b9..4caec1b 100644 --- a/XMPFiles/source/FileHandlers/PSD_Handler.hpp +++ b/XMPFiles/source/FileHandlers/PSD_Handler.hpp @@ -58,7 +58,7 @@ public: private: - PSD_MetaHandler() : iptcMgr(0), exifMgr(0), skipReconcile(false) {}; // Hidden on purpose. + PSD_MetaHandler() : skipReconcile(false), iptcMgr(0), exifMgr(0) {} // Hidden on purpose. PSIR_FileWriter psirMgr; // Don't need a pointer, the PSIR part is always file-based. IPTC_Manager * iptcMgr; // Need to use pointers so we can properly select between read-only diff --git a/XMPFiles/source/FileHandlers/UCF_Handler.hpp b/XMPFiles/source/FileHandlers/UCF_Handler.hpp index 3140c23..eee46ef 100644 --- a/XMPFiles/source/FileHandlers/UCF_Handler.hpp +++ b/XMPFiles/source/FileHandlers/UCF_Handler.hpp @@ -237,8 +237,8 @@ private: //TODO intergrate in clear() void release() // avoid terminus free() since subject to a #define (mem-leak-check) { - if (filename) delete filename; - if (extraField) delete extraField; + if (filename) delete [] filename; + if (extraField) delete [] extraField; filename=0; extraField=0; } @@ -277,10 +277,10 @@ private: PutUns16LE(0x14, &fields[FileHeader::o_extractVersion] ); } - FileHeader() : filename(0),filenameLen(0),extraField(0),extraFieldLen(0) + FileHeader() : filename(0),extraField(0),filenameLen(0),extraFieldLen(0) { clear(); - }; + } // reads entire *FileHeader* structure from file (starting at current position) void read(XMP_IO* file) @@ -379,9 +379,9 @@ private: private: void release() //*** needed or can go? { - if (filename) delete filename; - if (extraField) delete extraField; - if (comment) delete comment; + if (filename) delete [] filename; + if (extraField) delete [] extraField; + if (comment) delete [] comment; filename=0; filenameLen=0; extraField=0; extraFieldLen=0; comment=0; commentLen=0; @@ -547,7 +547,7 @@ private: { //// WRITE BACK REAL 64 BIT VALUES, CREATE EXTRA FIELD /////////////// //may only wipe extra field after obtaining all Info from it - if (extraField) delete extraField; + if (extraField) delete [] extraField; extraFieldLen=0; if ( ( sizeUncompressed > 0xffffffff ) || @@ -598,7 +598,7 @@ private: void setXMPFilename() { - if (filename) delete filename; + if (filename) delete [] filename; filenameLen = xmpFilenameLen; filename = new char[xmpFilenameLen]; PutUns16LE(filenameLen, &fields[CDFileHeader::o_fileNameLength] ); @@ -630,8 +630,9 @@ private: const static XMP_Uns32 SIG = 0x06054b50; void UCFECD_Free() { - if(commentLen) delete comment; + if(commentLen) delete [] comment; commentLen = 0; + comment = 0; } public: const static XMP_Int32 o_Sig = 0; @@ -678,7 +679,7 @@ private: ~EndOfCD() { - if (comment) delete comment; + if (comment) delete [] comment; }; }; //class EndOfCD diff --git a/XMPFiles/source/FileHandlers/WAVE_Handler.cpp b/XMPFiles/source/FileHandlers/WAVE_Handler.cpp index 1695013..6f7f287 100644 --- a/XMPFiles/source/FileHandlers/WAVE_Handler.cpp +++ b/XMPFiles/source/FileHandlers/WAVE_Handler.cpp @@ -140,7 +140,7 @@ const ChunkIdentifier WAVE_MetaHandler::kRF64iXML[2] = { { kChunk_RF64, kType_WA // ================================ WAVE_MetaHandler::WAVE_MetaHandler ( XMPFiles * _parent ) - : mChunkBehavior(NULL), mChunkController(NULL), + : mChunkController(NULL), mChunkBehavior(NULL), mINFOMeta(), mBEXTMeta(), mCartMeta(), mDISPMeta(), miXMLMeta(), mXMPChunk(NULL), mINFOChunk(NULL), mBEXTChunk(NULL), mCartChunk(NULL), mDISPChunk(NULL), miXMLChunk(NULL) diff --git a/XMPFiles/source/FileHandlers/WEBP_Handler.cpp b/XMPFiles/source/FileHandlers/WEBP_Handler.cpp new file mode 100644 index 0000000..c0b1f09 --- /dev/null +++ b/XMPFiles/source/FileHandlers/WEBP_Handler.cpp @@ -0,0 +1,197 @@ +#include "public/include/XMP_Const.h" +#include "public/include/XMP_Environment.h" // ! XMP_Environment.h must be the first included header. + +#include "XMPFiles/source/FileHandlers/WEBP_Handler.hpp" + +#include "XMPFiles/source/FormatSupport/IPTC_Support.hpp" +#include "XMPFiles/source/FormatSupport/PSIR_Support.hpp" +#include "XMPFiles/source/FormatSupport/ReconcileLegacy.hpp" +#include "XMPFiles/source/FormatSupport/Reconcile_Impl.hpp" +#include "XMPFiles/source/FormatSupport/TIFF_Support.hpp" +#include "XMPFiles/source/FormatSupport/WEBP_Support.hpp" +#include "source/XIO.hpp" + +using namespace std; + +/// File format handler for WEBP. + +XMPFileHandler* WEBP_MetaHandlerCTor(XMPFiles* parent) +{ + return new WEBP_MetaHandler(parent); +} + +// Check that the file begins with "RIFF", a 4 byte length, then the chunkType +// (WEBP). +bool WEBP_CheckFormat(XMP_FileFormat format, XMP_StringPtr filePath, + XMP_IO* file, XMPFiles* parent) +{ + IgnoreParam(format); + IgnoreParam(parent); + XMP_Assert(format == kXMP_WEBPFile); + + if (file->Length() < 12) + return false; + file->Rewind(); + + XMP_Uns8 chunkID[12]; + file->ReadAll(chunkID, 12); + if (!CheckBytes(&chunkID[0], "RIFF", 4)) { + return false; + } + if (CheckBytes(&chunkID[8], "WEBP", 4) && format == kXMP_WEBPFile) { + return true; + } + return false; +} + +WEBP_MetaHandler::WEBP_MetaHandler(XMPFiles* parent) + : exifMgr(0) +{ + this->parent = parent; + this->handlerFlags = kWEBP_HandlerFlags; + this->stdCharForm = kXMP_Char8Bit; + + this->initialFileSize = 0; + this->mainChunk = 0; +} + +WEBP_MetaHandler::~WEBP_MetaHandler() +{ + if (this->mainChunk) { + delete this->mainChunk; + } + if (this->exifMgr) { + delete this->exifMgr; + } + if (this->iptcMgr) { + delete this->iptcMgr; + } + if (this->psirMgr) { + delete this->psirMgr; + } +} + +void WEBP_MetaHandler::CacheFileData() +{ + this->containsXMP = false; // assume for now + + XMP_IO* file = this->parent->ioRef; + this->initialFileSize = file->Length(); + + file->Rewind(); + + XMP_Int64 filePos = 0; + while (filePos < this->initialFileSize) { + this->mainChunk = new WEBP::Container(this); + filePos = file->Offset(); + } + + // covered before => internal error if it occurs + XMP_Validate(file->Offset() == this->initialFileSize, + "WEBP_MetaHandler::CacheFileData: unknown data at end of file", + kXMPErr_InternalFailure); +} + +void WEBP_MetaHandler::ProcessXMP() +{ + SXMPUtils::RemoveProperties(&this->xmpObj, 0, 0, kXMPUtil_DoAllProperties); + + bool readOnly = false; + bool xmpOnly = false; + bool haveExif = false; + if (this->parent) { + readOnly = + !XMP_OptionIsSet(this->parent->openFlags, kXMPFiles_OpenForUpdate); + xmpOnly = + XMP_OptionIsSet(this->parent->openFlags, kXMPFiles_OpenOnlyXMP); + } + if (!xmpOnly) { + if (readOnly) { + this->exifMgr = new TIFF_MemoryReader(); + } + else { + this->exifMgr = new TIFF_FileWriter(); + } + this->psirMgr = new PSIR_MemoryReader(); + this->iptcMgr = new IPTC_Reader(); + if (this->parent) { + exifMgr->SetErrorCallback(&this->parent->errorCallback); + } + if (this->mainChunk) { + WEBP::Chunk* exifChunk = this->mainChunk->getExifChunk(); + if (exifChunk != NULL) { + haveExif = true; + this->exifMgr->ParseMemoryStream(exifChunk->data.data() + 6, + exifChunk->data.size() - 6); + } + } + } + + if (this->containsXMP) { + this->xmpObj.ParseFromBuffer(this->xmpPacket.c_str(), + (XMP_StringLen) this->xmpPacket.size()); + } + if (haveExif) { + XMP_OptionBits options = k2XMP_FileHadExif; + if (this->containsXMP) { + options |= k2XMP_FileHadXMP; + } + TIFF_Manager& exif = *this->exifMgr; + PSIR_Manager& psir = *this->psirMgr; + IPTC_Manager& iptc = *this->iptcMgr; + ImportPhotoData(exif, iptc, psir, kDigestMatches, &this->xmpObj, + options); + // Assume that, since the file had EXIF data, some of it was mapped to + // XMP + this->containsXMP = true; + } + this->processedXMP = true; +} + +void WEBP_MetaHandler::UpdateFile(bool doSafeUpdate) +{ + XMP_Validate(this->needsUpdate, "nothing to update", + kXMPErr_InternalFailure); + + bool xmpOnly = false; + if (this->parent) { + xmpOnly = + XMP_OptionIsSet(this->parent->openFlags, kXMPFiles_OpenOnlyXMP); + } + + if (!xmpOnly && this->exifMgr) { + WEBP::Chunk* exifChunk = this->mainChunk->getExifChunk(); + if (exifChunk != NULL) { + ExportPhotoData(kXMP_TIFFFile, &this->xmpObj, this->exifMgr, 0, 0); + if (this->exifMgr->IsLegacyChanged()) { + XMP_Uns8* exifPtr; + XMP_Uns32 exifLen = + this->exifMgr->UpdateMemoryStream((void**)&exifPtr); + RawDataBlock exifData(&exifChunk->data[0], &exifChunk->data[6]); + exifData.insert(exifData.begin() + 6, &exifPtr[0], + &exifPtr[exifLen]); + exifChunk->data = exifData; + exifChunk->size = exifLen + 6; + exifChunk->needsRewrite = true; + } + } + } + + this->packetInfo.charForm = stdCharForm; + this->packetInfo.writeable = true; + this->packetInfo.offset = kXMPFiles_UnknownOffset; + this->packetInfo.length = kXMPFiles_UnknownLength; + + this->xmpObj.SerializeToBuffer(&this->xmpPacket, kXMP_OmitPacketWrapper); + + this->mainChunk->write(this); + this->needsUpdate = false; // do last for safety +} + +void WEBP_MetaHandler::WriteTempFile(XMP_IO* tempRef) +{ + IgnoreParam(tempRef); + XMP_Throw("WEBP_MetaHandler::WriteTempFile: Not supported (must go through " + "UpdateFile)", + kXMPErr_Unavailable); +} diff --git a/XMPFiles/source/FileHandlers/WEBP_Handler.hpp b/XMPFiles/source/FileHandlers/WEBP_Handler.hpp new file mode 100644 index 0000000..c5041ea --- /dev/null +++ b/XMPFiles/source/FileHandlers/WEBP_Handler.hpp @@ -0,0 +1,48 @@ +#ifndef __WEBP_Handler_hpp__ +#define __WEBP_Handler_hpp__ 1 + +#include "public/include/XMP_Const.h" +#include "public/include/XMP_Environment.h" + +#include "XMPFiles/source/FormatSupport/WEBP_Support.hpp" +#include "XMPFiles/source/FormatSupport/TIFF_Support.hpp" +#include "XMPFiles/source/FormatSupport/IPTC_Support.hpp" +#include "XMPFiles/source/FormatSupport/PSIR_Support.hpp" + +#include "source/XIO.hpp" + +// File format handler for WEBP + +extern XMPFileHandler* WEBP_MetaHandlerCTor(XMPFiles* parent); + +extern bool WEBP_CheckFormat(XMP_FileFormat format, XMP_StringPtr filePath, + XMP_IO* fileRef, XMPFiles* parent); + +static const XMP_OptionBits kWEBP_HandlerFlags = + (kXMPFiles_CanInjectXMP | kXMPFiles_CanExpand | kXMPFiles_PrefersInPlace | + kXMPFiles_AllowsOnlyXMP | kXMPFiles_ReturnsRawPacket | + kXMPFiles_CanReconcile); + +class WEBP_MetaHandler + : public XMPFileHandler { +public: + WEBP_MetaHandler(XMPFiles* parent); + ~WEBP_MetaHandler(); + + void CacheFileData(); + void ProcessXMP(); + void UpdateFile(bool doSafeUpdate); + void WriteTempFile(XMP_IO* tempRef); + + WEBP::Container* mainChunk; + WEBP::XMPChunk* xmpChunk; + XMP_Int64 initialFileSize; + TIFF_Manager* exifMgr; + // The PSIR_Manager and IPTC_Manager aren't actually used, but they need + // to be instantiated and passed to the function that reconciles EXIF and + // XMP data. + PSIR_Manager* psirMgr; + IPTC_Manager* iptcMgr; +}; + +#endif /* __WEBP_Handler_hpp__ */ |