"Fossies" - the Fresh Open Source Software Archive

Member "exiv2-0.27.5-Source/include/exiv2/bmffimage.hpp" (21 Oct 2021, 7136 Bytes) of package /linux/misc/exiv2-0.27.5-Source.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bmffimage.hpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.27.4_vs_0.27.5.

    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;  //!< BMFF (bmff) image type (see class BMFF)
   59     }
   60 
   61     /*!
   62       @brief Class to access BMFF images.
   63      */
   64     class EXIV2API BmffImage : public Image
   65     {
   66     public:
   67         //! @name Creators
   68         //@{
   69         /*!
   70           @brief Constructor to open a BMFF image. Since the
   71               constructor can not return a result, callers should check the
   72               good() method after object construction to determine success
   73               or failure.
   74           @param io An auto-pointer that owns a BasicIo instance used for
   75               reading and writing image metadata. \b Important: The constructor
   76               takes ownership of the passed in BasicIo instance through the
   77               auto-pointer. Callers should not continue to use the BasicIo
   78               instance after it is passed to this method.  Use the Image::io()
   79               method to get a temporary reference.
   80           @param create Specifies if an existing image should be read (false)
   81               or if a new file should be created (true).
   82          */
   83         BmffImage(BasicIo::AutoPtr io, bool create);
   84         //@}
   85 
   86         //@{
   87         /*!
   88           @brief parse embedded tiff file (Exif metadata)
   89           @param root_tag root of parse tree Tag::root, Tag::cmt2 etc.
   90           @param length tiff block length
   91           @param start offset in file (default, io_->tell())
   92          @
   93          */
   94         void parseTiff(uint32_t root_tag, uint64_t length);
   95         void parseTiff(uint32_t root_tag, uint64_t length,uint64_t start);
   96         //@}
   97 
   98         //@{
   99         /*!
  100           @brief parse embedded xmp/xml
  101           @param length xmp block length
  102           @param start offset in file
  103          @
  104          */
  105         void parseXmp(uint64_t length,uint64_t start);
  106         //@}
  107 
  108         //@{
  109         /*!
  110         @brief Parse a Canon PRVW or THMB box and add an entry to the set
  111             of native previews.
  112         @param data Buffer containing the box
  113         @param out Logging stream
  114         @param bTrace Controls logging
  115         @param width_offset Index of image width field in data
  116         @param height_offset Index of image height field in data
  117         @param size_offset Index of image size field in data
  118         @param relative_position Location of the start of image data in the file,
  119             relative to the current file position indicator.
  120         */
  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);
  129         //@}
  130 
  131         //! @name Manipulators
  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);
  137         //@}
  138 
  139         //! @name Accessors
  140         //@{
  141         std::string mimeType() const /* override */;
  142         int pixelWidth() const;
  143         int pixelHeight() const;
  144         //@}
  145         
  146         Exiv2::ByteOrder endian_ ;
  147 
  148     private:
  149         void openOrThrow();
  150         /*!
  151           @brief recursiveBoxHandler
  152           @throw Error if we visit a box more than once
  153           @param pbox_end The end location of the parent box. Boxes are
  154               nested, so we must not read beyond this.
  155           @return address of next box
  156           @warning This function should only be called by readMetadata()
  157          */
  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_;
  173         //@}
  174 
  175         /*!
  176           @brief box utilities
  177          */
  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.
  191     /*!
  192       @brief Create a new BMFF instance and return an auto-pointer to it.
  193              Caller owns the returned object and the auto-pointer ensures that
  194              it will be deleted.
  195      */
  196     EXIV2API Image::AutoPtr newBmffInstance(BasicIo::AutoPtr io, bool create);
  197 
  198     //! Check if the file iIo is a BMFF image.
  199     EXIV2API bool isBmffType(BasicIo& iIo, bool advance);
  200 }  // namespace Exiv2
  201 #endif // EXV_ENABLE_BMFF