Blame include/exiv2/preview.hpp

Packit Service 21b5d1
// ***************************************************************** -*- C++ -*-
Packit Service 21b5d1
/*
Packit Service 21b5d1
 * Copyright (C) 2004-2018 Exiv2 authors
Packit Service 21b5d1
 * This program is part of the Exiv2 distribution.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * This program is free software; you can redistribute it and/or
Packit Service 21b5d1
 * modify it under the terms of the GNU General Public License
Packit Service 21b5d1
 * as published by the Free Software Foundation; either version 2
Packit Service 21b5d1
 * of the License, or (at your option) any later version.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * This program is distributed in the hope that it will be useful,
Packit Service 21b5d1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 21b5d1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 21b5d1
 * GNU General Public License for more details.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * You should have received a copy of the GNU General Public License
Packit Service 21b5d1
 * along with this program; if not, write to the Free Software
Packit Service 21b5d1
 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
Packit Service 21b5d1
 */
Packit Service 21b5d1
/*!
Packit Service 21b5d1
  @file    preview.hpp
Packit Service 21b5d1
  @brief   Classes to access all preview images embedded in an image.
Packit Service 21b5d1
  @author  Vladimir Nadvornik (vn)
Packit Service 21b5d1
           nadvornik@suse.cz
Packit Service 21b5d1
  @date    18-Sep-08, vn: created
Packit Service 21b5d1
 */
Packit Service 21b5d1
#ifndef PREVIEW_HPP_
Packit Service 21b5d1
#define PREVIEW_HPP_
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
#include "exiv2lib_export.h"
Packit Service 21b5d1
Packit Service 21b5d1
#include "image.hpp"
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
// namespace extensions
Packit Service 21b5d1
namespace Exiv2 {
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
// class definitions
Packit Service 21b5d1
Packit Service 21b5d1
    //! Type of preview image.
Packit Service 21b5d1
    typedef int PreviewId;
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Preview image properties.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    struct EXIV2API PreviewProperties {
Packit Service 21b5d1
        //! Preview image mime type.
Packit Service 21b5d1
        std::string mimeType_;
Packit Service 21b5d1
        //! Preview image extension.
Packit Service 21b5d1
        std::string extension_;
Packit Service 21b5d1
#ifdef EXV_UNICODE_PATH
Packit Service 21b5d1
        //! Unicode preview image extension in an std::wstring
Packit Service 21b5d1
        std::wstring wextension_;
Packit Service 21b5d1
#endif
Packit Service 21b5d1
        //! Preview image size in bytes.
Packit Service 21b5d1
        uint32_t size_;
Packit Service 21b5d1
        //! Preview image width in pixels or 0 for unknown width.
Packit Service 21b5d1
        uint32_t width_;
Packit Service 21b5d1
        //! Preview image height in pixels or 0 for unknown height.
Packit Service 21b5d1
        uint32_t height_;
Packit Service 21b5d1
        //! Identifies type of preview image.
Packit Service 21b5d1
        PreviewId id_;
Packit Service 21b5d1
    };
Packit Service 21b5d1
Packit Service 21b5d1
    //! Container type to hold all preview images metadata.
Packit Service 21b5d1
    typedef std::vector<PreviewProperties> PreviewPropertiesList;
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Class that holds preview image properties and data buffer.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    class EXIV2API PreviewImage {
Packit Service 21b5d1
        friend class PreviewManager;
Packit Service 21b5d1
    public:
Packit Service 21b5d1
        //! @name Constructors
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        //! Copy constructor
Packit Service 21b5d1
        PreviewImage(const PreviewImage& rhs);
Packit Service 21b5d1
        //! Destructor.
Packit Service 21b5d1
        ~PreviewImage();
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Manipulators
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        //! Assignment operator
Packit Service 21b5d1
        PreviewImage& operator=(const PreviewImage& rhs);
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Accessors
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return a copy of the preview image data. The caller owns
Packit Service 21b5d1
                 this copy and %DataBuf ensures that it will be deleted.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        DataBuf copy() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return a pointer to the image data for read-only access.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        const byte* pData() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the size of the preview image in bytes.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        uint32_t size() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Write the thumbnail image to a file.
Packit Service 21b5d1
Packit Service 21b5d1
          A filename extension is appended to \em path according to the image
Packit Service 21b5d1
          type of the preview image, so \em path should not include an extension.
Packit Service 21b5d1
          The function will overwrite an existing file of the same name.
Packit Service 21b5d1
Packit Service 21b5d1
          @param path File name of the preview image without extension.
Packit Service 21b5d1
          @return The number of bytes written.
Packit Service 21b5d1
        */
Packit Service 21b5d1
        long writeFile(const std::string& path) const;
Packit Service 21b5d1
#ifdef EXV_UNICODE_PATH
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Like writeFile() but accepts a unicode path in an std::wstring.
Packit Service 21b5d1
          @note This function is only available on Windows.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        long writeFile(const std::wstring& wpath) const;
Packit Service 21b5d1
#endif
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the MIME type of the preview image, usually either
Packit Service 21b5d1
                 \c "image/tiff" or \c "image/jpeg".
Packit Service 21b5d1
         */
Packit Service 21b5d1
        std::string mimeType() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the file extension for the format of the preview image
Packit Service 21b5d1
                 (".tif" or ".jpg").
Packit Service 21b5d1
         */
Packit Service 21b5d1
        std::string extension() const;
Packit Service 21b5d1
#ifdef EXV_UNICODE_PATH
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Like extension() but returns the unicode encoded extension in
Packit Service 21b5d1
                 an std::wstring.
Packit Service 21b5d1
          @note This function is only available on Windows.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        std::wstring wextension() const;
Packit Service 21b5d1
#endif
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the width of the preview image in pixels.
Packit Service 21b5d1
        */
Packit Service 21b5d1
        uint32_t width() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the height of the preview image in pixels.
Packit Service 21b5d1
        */
Packit Service 21b5d1
        uint32_t height() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the preview image type identifier.
Packit Service 21b5d1
        */
Packit Service 21b5d1
        PreviewId id() const;
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
    private:
Packit Service 21b5d1
        //! Private constructor
Packit Service 21b5d1
        PreviewImage(const PreviewProperties& properties, DataBuf data);
Packit Service 21b5d1
Packit Service 21b5d1
        PreviewProperties properties_;          //!< Preview image properties
Packit Service 21b5d1
        byte* pData_;                           //!< Pointer to the preview image data
Packit Service 21b5d1
        uint32_t size_;                         //!< Size of the preview image data
Packit Service 21b5d1
Packit Service 21b5d1
    }; // class PreviewImage
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Class for extracting preview images from image metadata.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    class EXIV2API PreviewManager {
Packit Service 21b5d1
    public:
Packit Service 21b5d1
        //! @name Constructors
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        //! Constructor.
Packit Service 21b5d1
        explicit PreviewManager(const Image& image);
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Accessors
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the properties of all preview images in a list
Packit Service 21b5d1
                 sorted by preview width * height, starting with the smallest
Packit Service 21b5d1
                 preview image.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        PreviewPropertiesList getPreviewProperties() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the preview image for the given preview properties.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        PreviewImage getPreviewImage(const PreviewProperties& properties) const;
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
    private:
Packit Service 21b5d1
    const Image& image_;
Packit Service 21b5d1
Packit Service 21b5d1
    }; // class PreviewManager
Packit Service 21b5d1
}                                       // namespace Exiv2
Packit Service 21b5d1
Packit Service 21b5d1
#endif                                  // #ifndef PREVIEW_HPP_