File indexing completed on 2024-04-28 15:50:40

0001 /*
0002     SPDX-FileCopyrightText: 2006-2015 Gilles Caulier <caulier dot gilles at gmail dot com>
0003     SPDX-FileCopyrightText: 2006-2013 Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0004     SPDX-FileCopyrightText: 2007-2008 Guillaume Castagnino <casta at xwing dot info>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KDCRAW_H
0010 #define KDCRAW_H
0011 
0012 // C++ includes
0013 
0014 #include <cmath>
0015 #include <memory>
0016 
0017 // Qt includes
0018 
0019 #include <QBuffer>
0020 #include <QString>
0021 #include <QObject>
0022 #include <QImage>
0023 
0024 // Local includes
0025 
0026 #include "libkdcraw_export.h"
0027 #include "rawdecodingsettings.h"
0028 #include "dcrawinfocontainer.h"
0029 
0030 /** @brief Main namespace of libKDcraw
0031  */
0032 namespace KDcrawIface
0033 {
0034 
0035 /** The wrapper class.
0036  */
0037 class LIBKDCRAW_EXPORT KDcraw : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042 
0043     /** Standard constructor.
0044      */
0045     KDcraw();
0046 
0047     /** Standard destructor.
0048      */
0049     virtual ~KDcraw();
0050 
0051 public:
0052 
0053     /** Return a string version of libkdcraw release
0054      */
0055     static QString version();
0056 
0057     /** Get the preview of RAW picture as a QImage.
0058         It tries loadEmbeddedPreview() first and if it fails, calls loadHalfPreview().
0059      */
0060     static bool loadRawPreview(QImage& image, const QString& path);
0061 
0062     /** Get the preview of RAW picture as a QByteArray holding JPEG data.
0063         It tries loadEmbeddedPreview() first and if it fails, calls loadHalfPreview().
0064      */
0065     static bool loadRawPreview(QByteArray& imgData, const QString& path);
0066 
0067     /** Get the preview of RAW picture passed in QBuffer as a QByteArray holding JPEG data.
0068         It tries loadEmbeddedPreview() first and if it fails, calls loadHalfPreview().
0069      */
0070     static bool loadRawPreview(QByteArray& imgData, const QBuffer& inBuffer);
0071 
0072     /** Get the embedded JPEG preview image from RAW picture as a QByteArray which will include Exif Data.
0073         This is fast and non cancelable. This method does not require a class instance to run.
0074      */
0075     static bool loadEmbeddedPreview(QByteArray& imgData, const QString& path);
0076 
0077     /** Get the embedded JPEG preview image from RAW picture as a QImage. This is fast and non cancelable
0078         This method does not require a class instance to run.
0079      */
0080     static bool loadEmbeddedPreview(QImage& image, const QString& path);
0081 
0082     /** Get the embedded JPEG preview image from RAW image passed in QBuffer as a QByteArray which will include Exif Data.
0083         This is fast and non cancelable. This method does not require a class instance to run.
0084      */
0085     static bool loadEmbeddedPreview(QByteArray& imgData, const QBuffer& inBuffer);
0086 
0087     /** Get the half decoded RAW picture. This is slower than loadEmbeddedPreview() method
0088         and non cancelable. This method does not require a class instance to run.
0089      */
0090     static bool loadHalfPreview(QImage& image, const QString& path);
0091 
0092     /** Get the half decoded RAW picture as JPEG data in QByteArray. This is slower than loadEmbeddedPreview()
0093         method and non cancelable. This method does not require a class instance to run.
0094      */
0095     static bool loadHalfPreview(QByteArray& imgData, const QString& path);
0096 
0097     /** Get the half decoded RAW picture passed in QBuffer as JPEG data in QByteArray. This is slower than loadEmbeddedPreview()
0098         method and non cancelable. This method does not require a class instance to run.
0099      */
0100     static bool loadHalfPreview(QByteArray& imgData, const QBuffer& inBuffer);
0101 
0102     /** Get the full decoded RAW picture. This is a more slower than loadHalfPreview() method
0103         and non cancelable. This method does not require a class instance to run.
0104      */
0105     static bool loadFullImage(QImage& image, const QString& path, const RawDecodingSettings& settings = RawDecodingSettings());
0106 
0107     /** Get the camera settings witch have taken RAW file. Look into dcrawinfocontainer.h
0108         for more details. This is a fast and non cancelable method witch do not require
0109         a class instance to run.
0110      */
0111     static bool rawFileIdentify(DcrawInfoContainer& identify, const QString& path);
0112 
0113     /** Return the string of all RAW file type mime supported.
0114      */
0115     static const char* rawFiles();
0116 
0117     /** Return the list of all RAW file type mime supported,
0118         as a QStringList, without wildcard and suffix dot.
0119      */
0120     static QStringList rawFilesList();
0121 
0122     /** Returns a version number for the list of supported RAW file types.
0123         This version is incremented if the list of supported formats has changed
0124         between library releases.
0125      */
0126     static int rawFilesVersion();
0127 
0128     /** Provide a list of supported RAW Camera name.
0129      */
0130     static QStringList supportedCamera();
0131 
0132     /** Return LibRaw version string.
0133      */
0134     static QString librawVersion();
0135 
0136     /** Return true or false if LibRaw use parallel demosaicing or not (libgomp support).
0137      *  Return -1 if undefined.
0138      */
0139     static int librawUseGomp();
0140 
0141     /** Return true or false if LibRaw use RawSpeed codec or not.
0142      *  Return -1 if undefined.
0143      */
0144     static int librawUseRawSpeed();
0145 
0146     /** Return true or false if LibRaw use Demosaic Pack GPL2 or not.
0147      *  Return -1 if undefined.
0148      */
0149     static int librawUseGPL2DemosaicPack();
0150 
0151     /** Return true or false if LibRaw use Demosaic Pack GPL3 or not.
0152      *  Return -1 if undefined.
0153      */
0154     static int librawUseGPL3DemosaicPack();
0155 
0156 public:
0157 
0158     /** Extract Raw image data undemosaiced and without post processing from 'filePath' picture file.
0159         This is a cancelable method which require a class instance to run because RAW pictures loading
0160         can take a while.
0161 
0162         This method return:
0163 
0164             - A byte array container 'rawData' with raw data.
0165             - All info about Raw image into 'identify' container.
0166             - 'false' is returned if loadding failed, else 'true'.
0167      */
0168     bool extractRAWData(const QString& filePath, QByteArray& rawData, DcrawInfoContainer& identify, unsigned int shotSelect=0);
0169 
0170     /** Extract a small size of decode RAW data from 'filePath' picture file using
0171         'rawDecodingSettings' settings. This is a cancelable method which require
0172         a class instance to run because RAW pictures decoding can take a while.
0173 
0174         This method return:
0175 
0176             - A byte array container 'imageData' with picture data. Pixels order is RGB.
0177               Color depth can be 8 or 16. In 8 bits you can access to color component
0178               using (uchar*), in 16 bits using (ushort*).
0179 
0180             - Size size of image in number of pixels ('width' and 'height').
0181             - The max average of RGB components from decoded picture.
0182             - 'false' is returned if decoding failed, else 'true'.
0183      */
0184     bool decodeHalfRAWImage(const QString& filePath, const RawDecodingSettings& rawDecodingSettings,
0185                             QByteArray& imageData, int& width, int& height, int& rgbmax);
0186 
0187     /** Extract a full size of RAW data from 'filePath' picture file using
0188         'rawDecodingSettings' settings. This is a cancelable method which require
0189         a class instance to run because RAW pictures decoding can take a while.
0190 
0191         This method return:
0192 
0193             - A byte array container 'imageData' with picture data. Pixels order is RGB.
0194               Color depth can be 8 or 16. In 8 bits you can access to color component
0195               using (uchar*), in 16 bits using (ushort*).
0196 
0197             - Size size of image in number of pixels ('width' and 'height').
0198             - The max average of RGB components from decoded picture.
0199             - 'false' is returned if decoding failed, else 'true'.
0200      */
0201     bool decodeRAWImage(const QString& filePath, const RawDecodingSettings& rawDecodingSettings,
0202                         QByteArray& imageData, int& width, int& height, int& rgbmax);
0203 
0204     /** To cancel 'decodeHalfRAWImage' and 'decodeRAWImage' methods running
0205         in a separate thread.
0206      */
0207     void cancel();
0208 
0209 protected:
0210 
0211     /** Used internally to cancel RAW decoding operation. Normally, you don't need to use it
0212         directly, excepted if you derivated this class. Usual way is to use cancel() method
0213      */
0214     bool                m_cancel;
0215 
0216     /** The settings container used to perform RAW pictures decoding. See 'rawdecodingsetting.h'
0217         for details.
0218      */
0219     RawDecodingSettings m_rawDecodingSettings;
0220 
0221 protected:
0222 
0223     /** Re-implement this method to control the cancelisation of loop witch wait data
0224         from RAW decoding process with your proper environment.
0225         By default, this method check if m_cancel is true.
0226      */
0227     virtual bool checkToCancelWaitingData();
0228 
0229     /** Re-implement this method to control the pseudo progress value during RAW decoding (when dcraw run with an
0230         internal loop without feedback) with your proper environment. By default, this method does nothing.
0231         Progress value average for this stage is 0%-n%, with 'n' == 40% max (see setWaitingDataProgress() method).
0232      */
0233     virtual void setWaitingDataProgress(double value);
0234 
0235 private:
0236     std::unique_ptr<class KDcrawPrivate> const d;
0237 
0238     friend class KDcrawPrivate;
0239 };
0240 
0241 }  // namespace KDcrawIface
0242 
0243 #endif /* KDCRAW_H */