File indexing completed on 2024-05-19 05:31:35

0001 /*
0002     SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include "core/colorspace.h"
0009 #include "kwin_export.h"
0010 
0011 #include <QMatrix4x4>
0012 #include <QString>
0013 #include <memory>
0014 #include <optional>
0015 
0016 typedef void *cmsHPROFILE;
0017 
0018 namespace KWin
0019 {
0020 
0021 class ColorTransformation;
0022 class ColorLUT3D;
0023 
0024 class KWIN_EXPORT IccProfile
0025 {
0026 public:
0027     struct BToATagData
0028     {
0029         std::unique_ptr<ColorTransformation> B;
0030         std::optional<QMatrix4x4> matrix;
0031         std::unique_ptr<ColorTransformation> M;
0032         std::unique_ptr<ColorLUT3D> CLut;
0033         std::unique_ptr<ColorTransformation> A;
0034     };
0035 
0036     explicit IccProfile(cmsHPROFILE handle, const Colorimetry &colorimetry, BToATagData &&bToATag, const std::shared_ptr<ColorTransformation> &vcgt);
0037     explicit IccProfile(cmsHPROFILE handle, const Colorimetry &colorimetry, const std::shared_ptr<ColorTransformation> &inverseEOTF, const std::shared_ptr<ColorTransformation> &vcgt);
0038     ~IccProfile();
0039 
0040     /**
0041      * the BToA tag describes a transformation from XYZ with D50 whitepoint
0042      * to the display color space. May be nullptr!
0043      */
0044     const BToATagData *BtToATag() const;
0045     /**
0046      * Contains the inverse of the TRC tags. May be nullptr!
0047      */
0048     std::shared_ptr<ColorTransformation> inverseEOTF() const;
0049     /**
0050      * The VCGT is a non-standard tag that needs to be applied before
0051      * pixels are sent to the display. May be nullptr!
0052      */
0053     std::shared_ptr<ColorTransformation> vcgt() const;
0054     const Colorimetry &colorimetry() const;
0055 
0056     static std::unique_ptr<IccProfile> load(const QString &path);
0057 
0058 private:
0059     cmsHPROFILE const m_handle;
0060     const Colorimetry m_colorimetry;
0061     const std::optional<BToATagData> m_bToATag;
0062     const std::shared_ptr<ColorTransformation> m_inverseEOTF;
0063     const std::shared_ptr<ColorTransformation> m_vcgt;
0064 };
0065 
0066 }