Exiv2
bmffimage.hpp
1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2021 Exiv2 authors
4  * This program is part of the Exiv2 distribution.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
23 // *****************************************************************************
24 #include "exiv2lib_export.h"
25 
26 // included header files
27 #include "image.hpp"
28 #include "iostream"
29 
30 // *****************************************************************************
31 // namespace extensions
32 namespace Exiv2
33 {
34  EXIV2API bool enableBMFF(bool enable = true);
35 }
36 
37 #ifdef EXV_ENABLE_BMFF
38 namespace Exiv2
39 {
40  struct Iloc
41  {
42  Iloc(uint32_t ID = 0, uint32_t start = 0, uint32_t length = 0) : ID_(ID), start_(start), length_(length){};
43  virtual ~Iloc(){};
44 
45  uint32_t ID_;
46  uint32_t start_;
47  uint32_t length_;
48 
49  std::string toString() const;
50  }; // class Iloc
51 
52  // *****************************************************************************
53  // class definitions
54 
55  // Add Base Media File Format to the supported image formats
56  namespace ImageType
57  {
58  const int bmff = 19;
59  }
60 
64  class EXIV2API BmffImage : public Image
65  {
66  public:
68 
69 
83  BmffImage(BasicIo::AutoPtr io, bool create);
85 
87 
94  void parseTiff(uint32_t root_tag, uint64_t length);
95  void parseTiff(uint32_t root_tag, uint64_t length,uint64_t start);
97 
99 
105  void parseXmp(uint64_t length,uint64_t start);
107 
109 
121  void parseCr3Preview(DataBuf &data,
122  std::ostream &out,
123  bool bTrace,
124  uint8_t version,
125  uint32_t width_offset,
126  uint32_t height_offset,
127  uint32_t size_offset,
128  uint32_t relative_position);
130 
132 
133  void readMetadata() /* override */;
134  void writeMetadata() /* override */;
135  void setComment(const std::string& comment) /* override */;
136  void printStructure(std::ostream& out, Exiv2::PrintStructureOption option,int depth);
138 
140 
141  std::string mimeType() const /* override */;
142  int pixelWidth() const;
143  int pixelHeight() const;
145 
146  Exiv2::ByteOrder endian_ ;
147 
148  private:
149  void openOrThrow();
158  long boxHandler(std::ostream& out, Exiv2::PrintStructureOption option,
159  const long pbox_end, int depth);
160  std::string indent(int i)
161  {
162  return std::string(2*i,' ');
163  }
164 
165  uint32_t fileType_;
166  std::set<uint64_t> visits_;
167  uint64_t visits_max_;
168  uint16_t unknownID_; // 0xffff
169  uint16_t exifID_;
170  uint16_t xmpID_;
171  std::map<uint32_t, Iloc> ilocs_;
172  bool bReadMetadata_;
174 
178  std::string toAscii(long n);
179  std::string boxName(uint32_t box);
180  bool superBox(uint32_t box);
181  bool fullBox(uint32_t box);
182  std::string uuidName(Exiv2::DataBuf& uuid);
183 
184  }; // class BmffImage
185 
186  // *****************************************************************************
187  // template, inline and free functions
188 
189  // These could be static private functions on Image subclasses but then
190  // ImageFactory needs to be made a friend.
196  EXIV2API Image::AutoPtr newBmffInstance(BasicIo::AutoPtr io, bool create);
197 
199  EXIV2API bool isBmffType(BasicIo& iIo, bool advance);
200 } // namespace Exiv2
201 #endif // EXV_ENABLE_BMFF
Exiv2::ImageType::xmp
const int xmp
XMP sidecar files (see class XmpSidecar)
Definition: xmpsidecar.hpp:38
Exiv2::DataBuf::pData_
byte * pData_
Pointer to the buffer, 0 if none has been allocated.
Definition: types.hpp:258
Exiv2::Internal::indent
std::string indent(int32_t d)
indent output for kpsRecursive in printStructure() .
Definition: image_int.cpp:106
Exiv2::Internal::Tag::cmt4
const uint32_t cmt4
Special tag: root IFD of CR3 images.
Definition: tiffcomposite_int.hpp:80
Exiv2::Internal::Tag::cmt3
const uint32_t cmt3
Special tag: root IFD of CR3 images.
Definition: tiffcomposite_int.hpp:79
Exiv2::ExifData::const_iterator
ExifMetadata::const_iterator const_iterator
ExifMetadata const iterator type.
Definition: exif.hpp:439
Exiv2::comment
@ comment
Exiv2 type for the Exif user comment.
Definition: types.hpp:139
Exiv2::strError
EXIV2API std::string strError()
Return a system error message and the error code (errno). See strerror(3).
Definition: futils.cpp:316
Exiv2::Internal::Tag::cmt2
const uint32_t cmt2
Special tag: root IFD of CR3 images.
Definition: tiffcomposite_int.hpp:78
Exiv2::Internal::TiffMapping::findDecoder
static DecoderFct findDecoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find the decoder function for a key.
Definition: tiffimage_int.cpp:1640
Exiv2::Internal::stringFormat
std::string stringFormat(const char *format,...)
format a string in the pattern of sprintf .
Definition: image_int.cpp:32
Exiv2::getShort
EXIV2API int16_t getShort(const byte *buf, ByteOrder byteOrder)
Read a 2 byte signed short value from the data buffer.
Definition: types.cpp:313
Exiv2::getULongLong
EXIV2API uint64_t getULongLong(const byte *buf, ByteOrder byteOrder)
Read a 8 byte unsigned long value from the data buffer.
Definition: types.cpp:290
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:193
Exiv2::ExifKey
Concrete keys for Exif metadata and access to Exif tag reference data.
Definition: tags.hpp:140
Exiv2::getLong
EXIV2API int32_t getLong(const byte *buf, ByteOrder byteOrder)
Read a 4 byte signed long value from the data buffer.
Definition: types.cpp:323
Exiv2::XmpParser::encode
static int encode(std::string &xmpPacket, const XmpData &xmpData, uint16_t formatFlags=useCompactFormat, uint32_t padding=0)
Encode (serialize) XMP metadata from xmpData into a string xmpPacket. The XMP packet returned in the ...
Definition: xmp.cpp:1000
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:102
Exiv2::Image::AutoPtr
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition: image.hpp:81
Exiv2::Internal::Tag::root
const uint32_t root
Special tag: root IFD.
Definition: tiffcomposite_int.hpp:73
Exiv2::BasicIo::AutoPtr
std::auto_ptr< BasicIo > AutoPtr
BasicIo auto_ptr type.
Definition: basicio.hpp:58
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:324
Exiv2::version
const EXIV2API char * version()
Return the version of Exiv2 as "C" string eg "0.27.0.2".
Definition: version.cpp:103
Exiv2::PrintStructureOption
PrintStructureOption
Options for printStructure.
Definition: image.hpp:64
Exiv2::toString
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:510
Exiv2::XmpParser::decode
static int decode(XmpData &xmpData, const std::string &xmpPacket)
Decode XMP metadata from an XMP packet xmpPacket into xmpData. The format of the XMP packet must foll...
Definition: xmp.cpp:887
Exiv2::Internal::TiffParserWorker::decode
static ByteOrder decode(ExifData &exifData, IptcData &iptcData, XmpData &xmpData, const byte *pData, uint32_t size, uint32_t root, FindDecoderFct findDecoderFct, TiffHeaderBase *pHeader=0)
Decode TIFF metadata from a data buffer pData of length size into the provided metadata containers.
Definition: tiffimage_int.cpp:1717
error.hpp
Error class for exceptions, log message class.