diff --git a/src/crwimage.cpp b/src/crwimage.cpp index 035f2832..f066be23 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -150,19 +150,12 @@ namespace Exiv2 { clearMetadata(); // Read the image into a memory buffer - long imageSize = io_->size(); - DataBuf image(imageSize); - io_->read(image.pData_, imageSize); + long len = io_->size(); + DataBuf buf(len); + io_->read(buf.pData_, len); if (io_->error() || io_->eof()) throw Error(14); - // Parse the image - RawMetadata::AutoPtr parseTree(new CiffHeader); - parseTree->read(image.pData_, image.size_, 0, invalidByteOrder); -#ifdef DEBUG - parseTree->print(std::cerr, invalidByteOrder); -#endif - parseTree->extract(*this, invalidByteOrder); - + CrwParser::decode(this, buf.pData_, buf.size_); } // CrwImage::readMetadata void CrwImage::writeMetadata() @@ -175,6 +168,21 @@ namespace Exiv2 { return isCrwType(iIo, advance); } + void CrwParser::decode(CrwImage* crwImage, const byte* buf, uint32_t len) + { + assert(crwImage != 0); + assert(buf != 0); + + // Parse the image + RawMetadata::AutoPtr parseTree(new CiffHeader); + parseTree->read(buf, len, 0, invalidByteOrder); +#ifdef DEBUG + parseTree->print(std::cerr, invalidByteOrder); +#endif + parseTree->extract(*crwImage, invalidByteOrder); + + } // CrwParser::decode + void CiffComponent::read(const byte* buf, uint32_t len, uint32_t start, diff --git a/src/crwimage.hpp b/src/crwimage.hpp index 4807873a..2e26b88d 100644 --- a/src/crwimage.hpp +++ b/src/crwimage.hpp @@ -257,6 +257,28 @@ namespace Exiv2 { }; // class RawMetadata + /*! + Stateless parser class for Canon Crw images (Ciff format). + */ + class CrwParser { + public: + /*! + @brief Decode metadata from a Canon Crw image in data buffer \em buf of length + \em len into \em crwImage. + + This is the entry point to access image data in Ciff format. The parser uses + classes CiffHeader, CiffEntry, CiffDirectory. + + @param crwImage %Exiv2 Crw image to hold the metadata read from the buffer. + @param buf Pointer to the data buffer. Must point to the data of a Crw + image; no checks are performed. + @param len Length of the data buffer. + */ + static void decode(CrwImage* crwImage, const byte* buf, uint32_t len); + //! Todo: implement me! + static void encode(); + }; + /*! @brief Interface class for components of the CIFF directory hierarchy of a Crw (Canon Raw data) image. Both CIFF directories as well as @@ -276,9 +298,6 @@ namespace Exiv2 { //@{ // Default assignment operator is fine - // See base class comment - virtual void add(RawMetadata::AutoPtr component) =0; - // See base class comment virtual void read(const byte* buf, uint32_t len,