File indexing completed on 2025-04-27 03:58:07

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-01-16
0007  * Description : image file IO threaded interface.
0008  *
0009  * SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_LOADING_DESCRIPTION_H
0017 #define DIGIKAM_LOADING_DESCRIPTION_H
0018 
0019 // Qt includes
0020 
0021 #include <QFlags>
0022 
0023 // Local includes
0024 
0025 #include "dimg.h"
0026 #include "digikam_export.h"
0027 #include "previewsettings.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class IccTransform;
0033 class ThumbnailIdentifier;
0034 
0035 class DIGIKAM_EXPORT LoadingDescription
0036 {
0037 public:
0038 
0039     enum ColorManagementSettings
0040     {
0041         NoColorConversion,
0042         ApplyTransform,    ///< IccData is an IccTransform
0043         ConvertForEditor,
0044         ConvertToSRGB,
0045         ConvertForDisplay, ///< IccData can be the output profile
0046         ConvertForOutput   ///< IccData is the output profile
0047     };
0048 
0049     enum RawDecodingHint
0050     {
0051         /**
0052          * The raw decoding options passed are taken from default, hardcoded settings
0053          */
0054         RawDecodingDefaultSettings,
0055         /**
0056          * The raw decoding options passed are taken from global settings
0057          */
0058         RawDecodingGlobalSettings,
0059         /**
0060          * The raw decoding options may be customly edited by the user
0061          */
0062         RawDecodingCustomSettings,
0063         /**
0064          * The raw decoding options are hardcoded settings optimized for loading time
0065          * The halfSizeColorImage and 16bit settings can be adjusted separately
0066          */
0067         RawDecodingTimeOptimized
0068     };
0069 
0070 public:
0071 
0072     class PreviewParameters
0073     {
0074     public:
0075 
0076         enum PreviewType
0077         {
0078             NoPreview,
0079             PreviewImage,
0080             Thumbnail,
0081             DetailThumbnail
0082         };
0083 
0084         enum PreviewFlag
0085         {
0086             NoFlags         = 0,
0087             OnlyPregenerate = 1 << 0,
0088             OnlyFromStorage = 1 << 1
0089         };
0090         Q_DECLARE_FLAGS(PreviewFlags, PreviewFlag)
0091 
0092     public:
0093 
0094         explicit PreviewParameters();
0095 
0096         bool onlyPregenerate()                          const;
0097         bool onlyFromStorage()                          const;
0098 
0099         bool operator==(const PreviewParameters& other) const;
0100 
0101     public:
0102 
0103         PreviewType     type;
0104         int             size;
0105         PreviewFlags    flags;
0106         PreviewSettings previewSettings;
0107         QVariant        extraParameter;
0108         QVariant        storageReference;
0109     };
0110 
0111     // ---------------------------------------------------------------------
0112 
0113     class PostProcessingParameters
0114     {
0115     public:
0116 
0117         explicit PostProcessingParameters()
0118         {
0119             colorManagement = NoColorConversion;
0120         }
0121 
0122     public:
0123 
0124         bool needsProcessing()                                 const;
0125 
0126         void         setTransform(const IccTransform& transform);
0127         bool         hasTransform()                            const;
0128         IccTransform transform()                               const;
0129 
0130         void         setProfile(const IccProfile& profile);
0131         bool         hasProfile()                              const;
0132         IccProfile   profile()                                 const;
0133 
0134         bool operator==(const PostProcessingParameters& other) const;
0135 
0136     public:
0137 
0138         ColorManagementSettings colorManagement;
0139         QVariant                iccData;
0140     };
0141 
0142 public:
0143 
0144     /**
0145      * An invalid LoadingDescription
0146      */
0147     LoadingDescription();
0148 
0149     /**
0150      * Use this for full loading of non-raw files
0151      */
0152     explicit LoadingDescription(const QString& filePath,
0153                                 ColorManagementSettings = NoColorConversion);
0154 
0155     /**
0156      * Use this for full loading of raw files
0157      */
0158     LoadingDescription(const QString& filePath,
0159                        const DRawDecoding& settings,
0160                        RawDecodingHint rawDecodingHint = RawDecodingCustomSettings,
0161                        ColorManagementSettings = NoColorConversion);
0162 
0163     /**
0164      * For preview and thumbnail jobs:
0165      * Stores preview max size and Exif rotation.
0166      * Raw files / preview jobs:
0167      *    If size is not 0, the embedded preview will be loaded if available.
0168      *    If size is 0, DImg based loading will be used with default raw decoding settings.
0169      *    You can also adjust raw decoding settings and hint in this case.
0170      */
0171     LoadingDescription(const QString& filePath,
0172                        const PreviewSettings& settings,
0173                        int size,
0174                        ColorManagementSettings = NoColorConversion,
0175                        PreviewParameters::PreviewType = PreviewParameters::PreviewImage);
0176 
0177     /**
0178      * Return the cache key for this description
0179      */
0180     QString             cacheKey()                                      const;
0181 
0182     /**
0183      * For some RAW images, the same cache key is not enough to say it is the correct result.
0184      * You must check the raw decoding settings in this case.
0185      */
0186     bool                needCheckRawDecoding()                          const;
0187 
0188     /**
0189      * Return all possible cache keys, starting with the best choice,
0190      * for which a result may be found in the cache for this description.
0191      * Included in the list are better quality versions, if this description is reduced.
0192      */
0193     QStringList         lookupCacheKeys()                               const;
0194 
0195     /**
0196      * Returns whether this description describes a loading operation which
0197      * loads the image in a reduced version (quality, size etc.)
0198      */
0199     bool                isReducedVersion()                              const;
0200 
0201     /**
0202      * Returns if this description will load a thumbnail
0203      */
0204     bool                isThumbnail()                                   const;
0205 
0206     /**
0207      * Returns if this description will load a preview
0208      */
0209     bool                isPreviewImage()                                const;
0210 
0211     /**
0212      * If this referenced a thumbnail, recreate the identifier
0213      */
0214     ThumbnailIdentifier thumbnailIdentifier()                           const;
0215 
0216     /**
0217      * Returns whether the other loading task equals this one
0218      */
0219     bool operator==(const LoadingDescription& other)                    const;
0220     bool operator!=(const LoadingDescription& other)                    const;
0221 
0222     /**
0223      * Returns whether the other loading task equals this one
0224      * ignoring parameters used to specify a reduced version.
0225      */
0226     bool equalsIgnoreReducedVersion(const LoadingDescription& other)    const;
0227 
0228     /**
0229      * Returns whether this loading task equals the other one
0230      * or is superior to it, if the other one is a reduced version
0231      */
0232     bool equalsOrBetterThan(const LoadingDescription& other)            const;
0233 
0234 public:
0235 
0236     /**
0237      * Returns all possible cacheKeys for the given file path
0238      * (all cache keys under which the given file could be stored in the cache).
0239      */
0240     static QStringList possibleCacheKeys(const QString& filePath);
0241     static QStringList possibleThumbnailCacheKeys(const QString& filePath);
0242 
0243 public:
0244 
0245     QString                  filePath;
0246     DRawDecoding             rawDecodingSettings;
0247     RawDecodingHint          rawDecodingHint;
0248     PreviewParameters        previewParameters;
0249     PostProcessingParameters postProcessingParameters;
0250 };
0251 
0252 } // namespace Digikam
0253 
0254 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::LoadingDescription::PreviewParameters::PreviewFlags)
0255 
0256 #endif // DIGIKAM_LOADING_DESCRIPTION_H