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

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  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_PREVIEW_LOAD_THREAD_H
0016 #define DIGIKAM_PREVIEW_LOAD_THREAD_H
0017 
0018 // Local includes
0019 
0020 #include "managedloadsavethread.h"
0021 #include "previewsettings.h"
0022 
0023 namespace Digikam
0024 {
0025 
0026 class DIGIKAM_EXPORT PreviewLoadThread : public ManagedLoadSaveThread
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031 
0032     /**
0033      * Creates a preview load thread.
0034      * Provides three flavors of preview loading.
0035      * The default loading policy, for the typical usage in a preview widget,
0036      * always stops any previous tasks and loads the new task as soon as possible.
0037      */
0038     explicit PreviewLoadThread(QObject* const parent = nullptr);
0039     ~PreviewLoadThread() override;
0040 
0041     /**
0042      * Load a preview that is optimized for fast loading.
0043      * Raw decoding and color management settings will be adjusted.
0044      */
0045     void loadFast(const QString& filePath, int size);
0046 
0047     /**
0048      * Load a preview that is as large as possible without sacrificing speed
0049      * for performance. Especially, raw previews are taken if larger than the given size.
0050      * Raw decoding and color management settings will be adjusted.
0051      */
0052     void loadFastButLarge(const QString& filePath, int minimumSize);
0053 
0054     /**
0055      * Load a preview with higher resolution, trading more quality
0056      * for less speed.
0057      * Raw decoding and color management settings will be adjusted.
0058      */
0059     void loadHighQuality(const QString& filePath,
0060                          PreviewSettings::RawLoading rawLoadingMode = PreviewSettings::RawPreviewAutomatic);
0061 
0062     /**
0063      * Load a preview.
0064      * Settings determine the loading mode.
0065      * For fast loading, size is preview area size.
0066      * For fast-but-large loading, it serves as a minimum size.
0067      * For high quality loading, it is ignored
0068      */
0069     void load(const QString& filePath, const PreviewSettings& settings, int size = 0);
0070 
0071     /**
0072      * Load a preview. Loading description will not be touched.
0073      */
0074     void load(const LoadingDescription& description);
0075 
0076     /**
0077      * Optionally, set the displaying widget for color management
0078      */
0079     void setDisplayingWidget(QWidget* const widget);
0080 
0081     /**
0082      * Synchronous versions of the above methods.
0083      * These are safe to call from the non-UI thread, as the IccProfile either passed or deduced independent from a displaying widget
0084      */
0085     static DImg loadFastSynchronously(const QString& filePath,
0086                                       int size,
0087                                       const IccProfile& profile = IccProfile());
0088     static DImg loadFastButLargeSynchronously(const QString& filePath,
0089                                               int minimumSize,
0090                                               const IccProfile& profile = IccProfile());
0091     static DImg loadHighQualitySynchronously(const QString& filePath,
0092                                              PreviewSettings::RawLoading rawLoadingMode = PreviewSettings::RawPreviewAutomatic,
0093                                              const IccProfile& profile = IccProfile());
0094     static DImg loadSynchronously(const QString& filePath,
0095                                   const PreviewSettings& previewSettings,
0096                                   int size,
0097                                   const IccProfile& profile = IccProfile());
0098     static DImg loadSynchronously(const LoadingDescription& description);
0099 
0100 protected:
0101 
0102     static LoadingDescription createLoadingDescription(const QString& filePath,
0103                                                        const PreviewSettings& settings,
0104                                                        int size,
0105                                                        const IccProfile& profile);
0106     LoadingDescription createLoadingDescription(const QString& filePath,
0107                                                 const PreviewSettings& settings,
0108                                                 int size);
0109 
0110 protected:
0111 
0112     QWidget* m_displayingWidget;
0113 
0114 private:
0115 
0116     // Disable
0117     PreviewLoadThread(const PreviewLoadThread&)            = delete;
0118     PreviewLoadThread& operator=(const PreviewLoadThread&) = delete;
0119 };
0120 
0121 } // namespace Digikam
0122 
0123 #endif // DIGIKAM_PREVIEW_LOAD_THREAD_H