File indexing completed on 2025-01-19 03:56:02

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-09-15
0007  * Description : Exiv2 library interface.
0008  *               Embedded preview loading.
0009  *
0010  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2006-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef META_ENGINE_PREVIEWS_H
0018 #define META_ENGINE_PREVIEWS_H
0019 
0020 // Qt includes
0021 
0022 #include <QByteArray>
0023 #include <QSize>
0024 #include <QString>
0025 #include <QImage>
0026 
0027 // Local includes
0028 
0029 #include "digikam_export.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 class DIGIKAM_EXPORT MetaEnginePreviews
0035 {
0036 public:
0037 
0038     /**
0039      * Open the given file and scan for embedded preview images
0040      */
0041     explicit MetaEnginePreviews(const QString& filePath);
0042 
0043     /**
0044      * Open the given image data and scan the image for embedded preview images.
0045      */
0046     explicit MetaEnginePreviews(const QByteArray& imgData);
0047     ~MetaEnginePreviews();
0048 
0049     /// Returns the pixel size of the original image, as read from the file (not the metadata).
0050     QSize originalSize()        const;
0051 
0052     /// Returns the mimeType of the original image, detected from the file's content.
0053     QString originalMimeType()  const;
0054 
0055     /// Returns if there are any preview images available
0056     bool       isEmpty();
0057 
0058     /// Returns how many embedded previews are available
0059     int        count()          const;
0060     int        size()           const;
0061 
0062     /**
0063      * For each contained preview image, return the size
0064      * of the image data in bytes, width and height of the preview,
0065      * the mimeType and the file extension.
0066      * Ensure that index < count().
0067      * Previews are sorted by width*height, largest first.
0068      */
0069     int        dataSize(int index = 0);
0070     int        width(int index = 0);
0071     int        height(int index = 0);
0072     QString    mimeType(int index = 0);
0073     QString    fileExtension(int index = 0);
0074 
0075     /**
0076      * Retrieve the image data for the specified embedded preview image
0077      */
0078     QByteArray data(int index = 0);
0079 
0080     /**
0081      * Loads the data of the specified preview and creates a QImage
0082      * from this data. Returns a null QImage if the loading failed.
0083      */
0084     QImage image(int index = 0);
0085 
0086 private:
0087 
0088     // Disable
0089     MetaEnginePreviews(const MetaEnginePreviews&)            = delete;
0090     MetaEnginePreviews& operator=(const MetaEnginePreviews&) = delete;
0091 
0092 private:
0093 
0094     class Private;
0095     Private* const d;
0096 };
0097 
0098 } // namespace Digikam
0099 
0100 #endif // META_ENGINE_PREVIEWS_H