File indexing completed on 2024-04-21 15:22:26

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