File indexing completed on 2025-01-05 03:59:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-02-14
0007  * Description : image data interface for image tools
0008  *
0009  * SPDX-FileCopyrightText: 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2004-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_IMAGE_IFACE_H
0017 #define DIGIKAM_IMAGE_IFACE_H
0018 
0019 // Qt includes
0020 
0021 #include <QString>
0022 #include <QPixmap>
0023 
0024 // Local includes
0025 
0026 #include "dimg.h"
0027 #include "dcolor.h"
0028 #include "filteraction.h"
0029 #include "photoinfocontainer.h"
0030 #include "digikam_export.h"
0031 
0032 class QPaintDevice;
0033 
0034 namespace Digikam
0035 {
0036 
0037 class DIGIKAM_EXPORT ImageIface
0038 {
0039 
0040 public:
0041 
0042     enum PreviewType
0043     {
0044         FullImage,      ///< Preview will be rendered using full image.
0045         ImageSelection  ///< Preview will be rendered using current selection from editor canvas.
0046     };
0047 
0048 public:
0049 
0050     /**
0051      * Standard constructor. Size is the constrain dimension of preview. This can be null size.
0052      */
0053     explicit ImageIface(const QSize& size = QSize(0, 0));
0054     ~ImageIface();
0055 
0056     /**
0057      * If useSelection is true, preview will be rendered using current selection in editor instead the full
0058      * image. Default preview is FullImage.
0059      */
0060     void setPreviewType(PreviewType type = FullImage);
0061 
0062     /**
0063      * Sets preview size and returns new preview as with getPreview.
0064      * The parameters are only hints, previewSize() may differ from size.
0065      */
0066     DImg  setPreviewSize(const QSize& size)                 const;
0067 
0068     /**
0069      * Methods to get/set preview image information.
0070      */
0071     QSize       previewSize()                               const;
0072     bool        previewHasAlpha()                           const;
0073     bool        previewSixteenBit()                         const;
0074     PreviewType previewType()                               const;
0075 
0076     /**
0077      * Return a pointer to the DImg object representing the preview image.
0078      *  This function is a backdoor for preview editing.
0079      */
0080     DImg* previewReference();
0081 
0082     /**
0083      * Return a DImg object representing the preview image.
0084      */
0085     DImg  preview()                                         const;
0086 
0087     /**
0088      * Return current image selection position and size into original image coordinates.
0089      */
0090     QRect selectionRect()                                   const;
0091 
0092     /**
0093      * Return a DImg object representing the current original image selection.
0094      */
0095     DImg  selection()                                       const;
0096 
0097     /**
0098      * Crop the original image currently hosted by editor to the region.
0099      */
0100     void crop(const QRect& region);
0101 
0102     /**
0103      * Get colors from original, (unchanged) preview
0104      * or target preview (set by setPreviewImage) image.
0105      */
0106     DColor colorInfoFromOriginal(const QPoint& point)       const;
0107     DColor colorInfoFromPreview(const QPoint& point)        const;
0108     DColor colorInfoFromTargetPreview(const QPoint& point)  const;
0109 
0110     /**
0111      * Methods to get/set original image information.
0112      */
0113     QSize originalSize()                                    const;
0114     bool  originalHasAlpha()                                const;
0115     bool  originalSixteenBit()                              const;
0116 
0117     /**
0118      * Original image meta-data management methods.
0119      */
0120     IccProfile         originalIccProfile()                 const;
0121     PhotoInfoContainer originalPhotoInfo()                  const;
0122     MetaEngineData     originalMetadata()                   const;
0123     void               setOriginalMetadata(const MetaEngineData& meta);
0124 
0125     /**
0126      * Return a pointer to the DImg object representing the original image.
0127      * This object may not be modified or stored. Make copies if you need.
0128      */
0129     DImg* original()                                        const;
0130 
0131     /**
0132      * Convert depth of original image.
0133      */
0134     void convertOriginalColorDepth(int depth);
0135 
0136     /**
0137      * Convert a DImg image to a pixmap for screen using color
0138      * managed view if necessary.
0139      */
0140     QPixmap convertToPixmap(const DImg& img)                const;
0141 
0142     /**
0143      * Paint the current target preview image (or the preview image,
0144      * if setPreview has not been called) on the given paint device.
0145      * at x|y, with given maximum width and height taken from rectangle rect.
0146      */
0147     void paint(QPaintDevice* const device, const QRect& rect, QPainter* const painter = nullptr);
0148 
0149     /**
0150      * Set the color profile of the original image.
0151      */
0152     void setOriginalIccProfile(const IccProfile& profile);
0153 
0154     /**
0155      * Set the color profile of the preview image.
0156      */
0157     void setPreviewIccProfile(const IccProfile& profile);
0158 
0159     /**
0160      * Replace the data of the current original image selection with the given data.
0161      * The characteristics of the data must match the characteristics of the current
0162      * selection as returned by the selectionWidth(), selectionHeight(),
0163      * originalSixteenBit() and originalHasAlpha() methods.
0164      * Caller is an i18n'ed string that will be shown as the undo/redo action name.
0165      */
0166     void setSelection(const QString& caller, const FilterAction& action, const DImg& img);
0167 
0168     /**
0169      * Replace the stored target preview with the given image.
0170      * The characteristics of the data must match the characteristics of the current
0171      * as returned by the preview...() methods.
0172      * The target preview image is used by the paint() and
0173      * colorInfoFromTargetPreview() methods.
0174      * The image returned by getPreview() is unaffected.
0175      */
0176     void setPreview(const DImg& img);
0177 
0178     /**
0179      * Replace the data of the original with the given image.
0180      * The characteristics of the data must match the characteristics of
0181      * the original image as returned by the original...() methods,
0182      * The size of image can be changed.
0183      * Caller is an i18n'ed string that will be shown as the undo/redo action name.
0184      */
0185     void setOriginal(const QString& caller, const FilterAction& action, const DImg& img);
0186 
0187 private:
0188 
0189     // Disable
0190     ImageIface(const ImageIface&)            = delete;
0191     ImageIface& operator=(const ImageIface&) = delete;
0192 
0193 private:
0194 
0195     class Private;
0196     Private* const d;
0197 };
0198 
0199 } // namespace Digikam
0200 
0201 #endif // DIGIKAM_IMAGE_IFACE_H