File indexing completed on 2024-05-12 15:59:33
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef _KO_COLOR_PROFILE_H_ 0008 #define _KO_COLOR_PROFILE_H_ 0009 0010 #include <boost/operators.hpp> 0011 #include <QString> 0012 #include <QVector> 0013 #include <QVariant> 0014 0015 #include "KoColorProfileConstants.h" 0016 #include "kritapigment_export.h" 0017 0018 /** 0019 * Contains information needed for color transformation. 0020 */ 0021 class KRITAPIGMENT_EXPORT KoColorProfile : public boost::equality_comparable<KoColorProfile> 0022 { 0023 0024 public: 0025 0026 /** 0027 * @param fileName file name to load or save that profile 0028 */ 0029 explicit KoColorProfile(const QString &fileName = QString()); 0030 KoColorProfile(const KoColorProfile& profile); 0031 virtual ~KoColorProfile(); 0032 0033 /** 0034 * @return the type of this profile (icc, ctlcs etc) 0035 */ 0036 virtual QString type() const { 0037 return QString(); 0038 } 0039 0040 /** 0041 * Create a copy of this profile. 0042 * Data that shall not change during the life time of the profile shouldn't be 0043 * duplicated but shared, like for instance ICC data. 0044 * 0045 * Data that shall be changed like a palette or hdr information such as exposure 0046 * must be duplicated while cloning. 0047 */ 0048 virtual KoColorProfile* clone() const = 0; 0049 0050 /** 0051 * Load the profile in memory. 0052 * @return true if the profile has been successfully loaded 0053 */ 0054 virtual bool load(); 0055 0056 /** 0057 * Override this function to save the profile. 0058 * @param fileName destination 0059 * @return true if the profile has been successfully saved 0060 */ 0061 virtual bool save(const QString &fileName); 0062 0063 /** 0064 * @return true if the profile is valid, false if it isn't been loaded in memory yet, or 0065 * if the loaded memory is a bad profile 0066 */ 0067 virtual bool valid() const = 0; 0068 0069 /** 0070 * @return the name of this profile 0071 */ 0072 QString name() const; 0073 /** 0074 * @return the info of this profile 0075 */ 0076 QString info() const; 0077 /** @return manufacturer of the profile 0078 */ 0079 QString manufacturer() const; 0080 /** 0081 * @return the copyright of the profile 0082 */ 0083 QString copyright() const; 0084 /** 0085 * @return the filename of the profile (it might be empty) 0086 */ 0087 QString fileName() const; 0088 /** 0089 * @param filename new filename 0090 */ 0091 void setFileName(const QString &filename); 0092 0093 /** 0094 * Return version 0095 */ 0096 virtual float version() const = 0; 0097 0098 /** 0099 * @return a string for a color model id. 0100 */ 0101 virtual QString colorModelID() const { 0102 return QString(); 0103 }; 0104 /** 0105 * @return true if you can use this profile can be used to convert color from a different 0106 * profile to this one 0107 */ 0108 virtual bool isSuitableForOutput() const = 0; 0109 /** 0110 * @return true if this profile is suitable to use for printing 0111 */ 0112 virtual bool isSuitableForPrinting() const = 0; 0113 /** 0114 * @return true if this profile is suitable to use for display 0115 */ 0116 virtual bool isSuitableForDisplay() const = 0; 0117 0118 /** 0119 * @return which rendering intents are supported 0120 */ 0121 virtual bool supportsPerceptual() const = 0; 0122 virtual bool supportsSaturation() const = 0; 0123 virtual bool supportsAbsolute() const = 0; 0124 virtual bool supportsRelative() const = 0; 0125 /** 0126 * @return if the profile has colorants. 0127 */ 0128 virtual bool hasColorants() const = 0; 0129 /** 0130 * @return a qvector <double>(9) with the RGB colorants in XYZ 0131 */ 0132 virtual QVector <qreal> getColorantsXYZ() const = 0; 0133 /** 0134 * @return a qvector <double>(9) with the RGB colorants in xyY 0135 */ 0136 virtual QVector <qreal> getColorantsxyY() const = 0; 0137 /** 0138 * @return a qvector <double>(3) with the whitepoint in XYZ 0139 */ 0140 virtual QVector <qreal> getWhitePointXYZ() const = 0; 0141 /** 0142 * @return a qvector <double>(3) with the whitepoint in xyY 0143 */ 0144 virtual QVector <qreal> getWhitePointxyY() const = 0; 0145 0146 /** 0147 * @return estimated gamma for RGB and Grayscale profiles 0148 */ 0149 virtual QVector <qreal> getEstimatedTRC() const = 0; 0150 0151 /** 0152 * @return if the profile has a TRC(required for linearisation). 0153 */ 0154 virtual bool hasTRC() const = 0; 0155 /** 0156 * @return if the profile's TRCs are linear. 0157 */ 0158 virtual bool isLinear() const = 0; 0159 /** 0160 * Linearizes first 3 values of QVector, leaving other values unchanged. 0161 * Returns the same QVector if it is not possible to linearize. 0162 */ 0163 virtual void linearizeFloatValue(QVector <qreal> & Value) const = 0; 0164 /** 0165 * Delinearizes first 3 values of QVector, leaving other values unchanged. 0166 * Returns the same QVector if it is not possible to delinearize. 0167 * Effectively undoes LinearizeFloatValue. 0168 */ 0169 virtual void delinearizeFloatValue(QVector <qreal> & Value) const = 0; 0170 /** 0171 * More imprecise versions of the above(limited to 16bit, and can't 0172 * delinearize above 1.0.) Use this for filters and images. 0173 */ 0174 virtual void linearizeFloatValueFast(QVector <qreal> & Value) const = 0; 0175 virtual void delinearizeFloatValueFast(QVector <qreal> & Value) const = 0; 0176 0177 /** 0178 * Comparing profile's TRC against the other with defined error threshold, 0179 * returns true if profile TRC is matched. 0180 */ 0181 virtual bool compareTRC(TransferCharacteristics characteristics, float error) const = 0; 0182 0183 virtual QByteArray uniqueId() const = 0; 0184 0185 virtual bool operator==(const KoColorProfile&) const = 0; 0186 0187 /** 0188 * @return an array with the raw data of the profile 0189 */ 0190 virtual QByteArray rawData() const { 0191 return QByteArray(); 0192 } 0193 0194 /** 0195 * @brief getColorPrimaries 0196 * @return colorprimaries, defaults to 'unspecified' if no match is possible. 0197 */ 0198 virtual ColorPrimaries getColorPrimaries() const; 0199 0200 /** 0201 * @brief getColorPrimariesName 0202 * @param primaries 0203 * @return human friendly name of the primary. 0204 */ 0205 static QString getColorPrimariesName(ColorPrimaries primaries); 0206 /** 0207 * @brief colorantsForPrimaries 0208 * fills a QVector<float> with the xy values of the whitepoint and red, green, blue colorants for 0209 * a given predefined value. Will not change the vector when the primaries are set to 'undefined'. 0210 * @param primaries predefined value. 0211 * @param colorants the vector to fill. 0212 */ 0213 static void colorantsForType(ColorPrimaries primaries, QVector<double> &colorants); 0214 0215 /** 0216 * @brief getTransferCharacteristics 0217 * This function should be subclassed at some point so we can get the value from the lcms profile. 0218 * @return transferfunction number. 0219 */ 0220 virtual TransferCharacteristics getTransferCharacteristics() const; 0221 0222 /** 0223 * @brief getTransferCharacteristicName 0224 * @param curve the number 0225 * @return name of the characteristic 0226 */ 0227 static QString getTransferCharacteristicName(TransferCharacteristics curve); 0228 0229 protected: 0230 /** 0231 * Allows to define the name of this profile. 0232 */ 0233 void setName(const QString &name); 0234 /** 0235 * Allows to set the information string of that profile. 0236 */ 0237 void setInfo(const QString &info); 0238 /** 0239 * Allows to set the manufacturer string of that profile. 0240 */ 0241 void setManufacturer(const QString &manufacturer); 0242 /** 0243 * Allows to set the copyright string of that profile. 0244 */ 0245 void setCopyright(const QString ©right); 0246 0247 /** 0248 * @brief setCharacteristics 0249 * ideally, we'd read this from the icc profile curve, but that can be tricky, instead 0250 * we'll set it on profile creation. 0251 * @param curve 0252 */ 0253 void setCharacteristics(ColorPrimaries primaries, TransferCharacteristics curve); 0254 0255 private: 0256 struct Private; 0257 Private* const d; 0258 }; 0259 0260 #endif