From 4cb74a42e5d5af5fa0781870ddbc3c6129e1bc91 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Mon, 24 May 2004 02:32:25 +0000 Subject: [PATCH] * Replaced too simple prefix with a more general concept of a makernote header. * Code and documentation cleanup. --- src/fujimn.cpp | 40 ++++++++++++++++++++++++++++++++++------ src/fujimn.hpp | 20 ++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/fujimn.cpp b/src/fujimn.cpp index 29e2ca0a..3d3519b1 100644 --- a/src/fujimn.cpp +++ b/src/fujimn.cpp @@ -20,7 +20,7 @@ */ /* File: fujimn.cpp - Version: $Name: $ $Revision: 1.5 $ + Version: $Name: $ $Revision: 1.6 $ Author(s): Andreas Huggel (ahu) History: 18-Feb-04, ahu: created 07-Mar-04, ahu: isolated as a separate component @@ -31,7 +31,7 @@ */ // ***************************************************************************** #include "rcsid.hpp" -EXIV2_RCSID("@(#) $Name: $ $Revision: 1.5 $ $RCSfile: fujimn.cpp,v $") +EXIV2_RCSID("@(#) $Name: $ $Revision: 1.6 $ $RCSfile: fujimn.cpp,v $") // ***************************************************************************** // included header files @@ -44,6 +44,7 @@ EXIV2_RCSID("@(#) $Name: $ $Revision: 1.5 $ $RCSfile: fujimn.cpp,v $") #include #include #include +#include // Define DEBUG_MAKERNOTE to output debug information to std::cerr #undef DEBUG_MAKERNOTE @@ -79,14 +80,41 @@ namespace Exiv2 { FujiMakerNote::FujiMakerNote(bool alloc) : IfdMakerNote(fujiMnTagInfo, alloc), sectionName_("Fujifilm") { - setByteOrder(littleEndian); - prefix_ = std::string("FUJIFILM\xc\0\0\0", 12); + byteOrder_ = littleEndian; absOffset_ = false; } - MakerNote* FujiMakerNote::clone(bool alloc) const + int FujiMakerNote::readHeader(const char* buf, + long len, + ByteOrder byteOrder) { - return createFujiMakerNote(alloc); + if (len < 12) return 1; + + header_.alloc(12); + memcpy(header_.pData_, buf, header_.size_); + // Read the offset relative to the start of the makernote from the header + // Note: we ignore the byteOrder paramter + adjOffset_ = getUShort(header_.pData_ + 8, byteOrder_); + return 0; + } + + int FujiMakerNote::checkHeader() const + { + int rc = 0; + // Check the FUJIFILM prefix + if ( header_.size_ < 12 + || std::string(header_.pData_, 8) != std::string("FUJIFILM", 8)) { + rc = 2; + } + return rc; + } + + FujiMakerNote* FujiMakerNote::clone(bool alloc) const + { + FujiMakerNote* pMakerNote = new FujiMakerNote(alloc); + assert(pMakerNote); + pMakerNote->readHeader(header_.pData_, header_.size_, byteOrder_); + return pMakerNote; } std::ostream& FujiMakerNote::printTag(std::ostream& os, diff --git a/src/fujimn.hpp b/src/fujimn.hpp index d5ecfc0e..389c8516 100644 --- a/src/fujimn.hpp +++ b/src/fujimn.hpp @@ -21,10 +21,10 @@ /*! @file fujimn.hpp @brief Fujifilm MakerNote implemented according to the specification - in "Appendix 4: Makernote of Fujifilm" of the document - "Exif file format" by TsuruZoh Tachibanaya - - @version $Name: $ $Revision: 1.3 $ + in Appendix 4: Makernote of Fujifilm of the document + + Exif file format by TsuruZoh Tachibanaya + @version $Name: $ $Revision: 1.4 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 11-Feb-04, ahu: created @@ -82,9 +82,17 @@ namespace Exiv2 { virtual ~FujiMakerNote() {} //@} - //! @name Accessors + //! @name Manipulators //@{ - MakerNote* clone(bool alloc =true) const; + int readHeader(const char* buf, + long len, + ByteOrder byteOrder); + //@} + + //! @name Accessors + //@{ + int checkHeader() const; + FujiMakerNote* clone(bool alloc =true) const; //! Return the name of the makernote section ("Fujifilm") std::string sectionName(uint16 tag) const { return sectionName_; } std::ostream& printTag(std::ostream& os,