Warning, file /office/calligra/libs/pigment/KoColorSpaceRegistry.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (c) 2003 Patrick Julien  <freak@codepimps.org>
0003  *  Copyright (c) 2004,2010 Cyrille Berger <cberger@cberger.net>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef KOCOLORSPACEREGISTRY_H
0022 #define KOCOLORSPACEREGISTRY_H
0023 
0024 #include <QObject>
0025 #include <QList>
0026 #include <QString>
0027 #include "pigment_export.h"
0028 
0029 #include <KoGenericRegistry.h>
0030 #include <KoColorSpace.h>
0031 #include <KoColorSpaceFactory.h>
0032 
0033 class KoColorProfile;
0034 class KoColorConversionSystem;
0035 class KoColorConversionCache;
0036 
0037 /**
0038  * The registry for colorspaces and profiles.
0039  * This class contains:
0040  *      - a registry of colorspace instantiated with specific profiles.
0041  *      - a registry of singleton colorspace factories.
0042  *      - a registry of icc profiles
0043  */
0044 class PIGMENTCMS_EXPORT KoColorSpaceRegistry
0045 {
0046 public:
0047     KoColorSpaceRegistry();
0048 
0049     enum ColorSpaceListVisibility {
0050         OnlyUserVisible = 1, ///< Only user visible color space
0051         AllColorSpaces = 4 ///< All color space even those not visible to the user
0052     };
0053     enum ColorSpaceListProfilesSelection {
0054         OnlyDefaultProfile = 1, ///< Only add the default profile
0055         AllProfiles = 4 ///< Add all profiles
0056     };
0057 
0058     /**
0059      * Return an instance of the KoColorSpaceRegistry
0060      * Creates an instance if that has never happened before and returns the singleton instance.
0061      */
0062     static KoColorSpaceRegistry * instance();
0063 
0064     virtual ~KoColorSpaceRegistry();
0065 
0066 public:
0067     /**
0068       * add a color space to the registry
0069       * @param item the color space factory to add
0070       */
0071     void add(KoColorSpaceFactory* item);
0072 
0073     /**
0074      * Remove a color space factory from the registry. Note that it is the
0075      * responsibility of the caller to ensure that the colorspaces are not
0076      * used anymore.
0077      */
0078     void remove(KoColorSpaceFactory* item);
0079 
0080     /**
0081      * Add a profile to the profile map but do not add it to the
0082      * color conversion system yet.
0083      * @param profile the new profile to be registered.
0084      */
0085     void addProfileToMap(KoColorProfile *p);
0086 
0087     /**
0088      * register the profile with the color space registry
0089      * @param profile the new profile to be registered so it can be combined with
0090      *  colorspaces.
0091      */
0092     void addProfile(KoColorProfile* profile);
0093     void addProfile(const KoColorProfile* profile); // TODO why ?
0094     void removeProfile(KoColorProfile* profile);
0095     
0096     /**
0097      * Create an alias to a profile with a different name. Then @ref profileByName
0098      * will return the profile @p to when passed @p name as a parameter.
0099      */
0100     void addProfileAlias(const QString& name, const QString& to);
0101     
0102     /**
0103      * @return the profile alias, or name if not aliased
0104      */
0105     QString profileAlias(const QString& name) const;
0106 
0107     /**
0108      * create a profile of the specified type.
0109      */
0110     const KoColorProfile* createColorProfile(const QString & colorModelId, const QString & colorDepthId, const QByteArray& rawData);
0111 
0112     /**
0113      * Return a profile by its given name, or 0 if none registered.
0114      * @return a profile by its given name, or 0 if none registered.
0115      * @param name the product name as set on the profile.
0116      * @see addProfile()
0117      * @see KoColorProfile::productName()
0118      */
0119     const KoColorProfile *  profileByName(const QString & name) const ;
0120 
0121     /**
0122      * Return the list of profiles for the argument colorspacefactory.
0123      * Profiles will not work with any color space, you can query which profiles
0124      * that are registered with this registry can be used in combination with the
0125      * argument factory.
0126      * @param factory the factory with which all the returned profiles will work.
0127      * @return a list of profiles for the factory
0128      */
0129     QList<const KoColorProfile *>  profilesFor(const KoColorSpaceFactory * factory) const;
0130 
0131     /**
0132      * Return the list of profiles for a colorspace with the argument id.
0133      * Profiles will not work with any color space, you can query which profiles
0134      * that are registered with this registry can be used in combination with the
0135      * argument factory.
0136      * @param id the colorspace-id with which all the returned profiles will work.
0137      * @return a list of profiles for the factory
0138      */
0139     QList<const KoColorProfile *>  profilesFor(const KoID& id) const;
0140 
0141     /**
0142      * @return a list of color spaces compatible with this profile
0143      */
0144     QList<const KoColorSpaceFactory*> colorSpacesFor(const KoColorProfile* _profile) const;
0145 
0146     /**
0147      * Return the list of profiles for a colorspace with the argument id.
0148      * Profiles will not work with any color space, you can query which profiles
0149      * that are registered with this registry can be used in combination with the
0150      * argument factory.
0151      * @param colorSpaceId the colorspace-id with which all the returned profiles will work.
0152      * @return a list of profiles for the factory
0153      */
0154     QList<const KoColorProfile *>  profilesFor(const QString& id) const;
0155     const KoColorSpaceFactory* colorSpaceFactory(const QString &colorSpaceId) const;
0156 
0157 private:
0158     /**
0159      * Return a colorspace that works with the parameter profile.
0160      * @param csID the ID of the colorspace that you want to have returned
0161      * @param profileName the name of the KoColorProfile to be combined with the colorspace
0162      * @return the wanted colorspace, or 0 when the cs and profile can not be combined.
0163      */
0164     const KoColorSpace *  colorSpace(const KoID &csID, const QString & profileName);
0165 
0166     /**
0167      * Return a colorspace that works with the parameter profile.
0168      * @param colorSpaceId the ID string of the colorspace that you want to have returned
0169      * @param profile the profile be combined with the colorspace
0170      * @return the wanted colorspace, or 0 when the cs and profile can not be combined.
0171      */
0172     const KoColorSpace * colorSpace(const QString &colorSpaceId, const KoColorProfile *profile);
0173 
0174     /**
0175      * Return a colorspace that works with the parameter profile.
0176      * @param profileName the name of the KoColorProfile to be combined with the colorspace
0177      * @return the wanted colorspace, or 0 when the cs and profile can not be combined.
0178      */
0179     const KoColorSpace * colorSpace(const QString &colorSpaceId, const QString &profileName = QString());
0180 public:
0181     /**
0182      * Return a colorspace that works with the parameter profile.
0183      * @param colorSpaceId the ID string of the colorspace that you want to have returned
0184      * @param profile the profile be combined with the colorspace
0185      * @return the wanted colorspace, or 0 when the cs and profile can not be combined.
0186      */
0187     const KoColorSpace * colorSpace(const QString & colorModelId, const QString & colorDepthId, const KoColorProfile *profile);
0188 
0189     /**
0190      * Return a colorspace that works with the parameter profile.
0191      * @param profileName the name of the KoColorProfile to be combined with the colorspace
0192      * @return the wanted colorspace, or 0 when the cs and profile can not be combined.
0193      */
0194     const KoColorSpace * colorSpace(const QString & colorModelId, const QString & colorDepthId, const QString &profileName);
0195 
0196     /**
0197      * Return the id of the colorspace that have the defined colorModelId with colorDepthId.
0198      * @param colorModelId id of the color model
0199      * @param colorDepthId id of the color depth
0200      * @return the id of the wanted colorspace, or "" if no colorspace correspond to those ids
0201      */
0202     QString colorSpaceId(const QString & colorModelId, const QString & colorDepthId) const;
0203     /**
0204      * It's a convenient function that behave like the above.
0205      * Return the id of the colorspace that have the defined colorModelId with colorDepthId.
0206      * @param colorModelId id of the color model
0207      * @param colorDepthId id of the color depth
0208      * @return the id of the wanted colorspace, or "" if no colorspace correspond to those ids
0209      */
0210     QString colorSpaceId(const KoID& colorModelId, const KoID& colorDepthId) const;
0211 
0212     /**
0213      * @return a the identifier of the color model for the given color space id.
0214      *
0215      * This function is a compatibility function used to get the color space from
0216      * all kra files.
0217      */
0218     KoID colorSpaceColorModelId(const QString & _colorSpaceId) const;
0219 
0220     /**
0221      * @return a the identifier of the color depth for the given color space id.
0222      *
0223      * This function is a compatibility function used to get the color space from
0224      * all kra files.
0225      */
0226     KoID colorSpaceColorDepthId(const QString & _colorSpaceId) const;
0227 
0228     /**
0229      * Convenience method to get the often used alpha colorspace
0230      */
0231     const KoColorSpace * alpha8();
0232 
0233     /**
0234      * Convenience method to get an RGBA 8bit colorspace. If a profile is not specified,
0235      * an sRGB profile will be used.
0236      * @param profileName the name of an RGB color profile
0237      * @return the wanted colorspace, or 0 if the color space and profile can not be combined.
0238      */
0239     const KoColorSpace * rgb8(const QString &profileName = QString());
0240 
0241     /**
0242      * Convenience method to get an RGBA 8bit colorspace with the given profile.
0243      * @param profile an RGB profile
0244      * @return the wanted colorspace, or 0 if the color space and profile can not be combined.
0245      */
0246     const KoColorSpace * rgb8(const KoColorProfile * profile);
0247 
0248     /**
0249      * Convenience method to get an RGBA 16bit colorspace. If a profile is not specified,
0250      * an sRGB profile will be used.
0251      * @param profileName the name of an RGB color profile
0252      * @return the wanted colorspace, or 0 if the color space and profile can not be combined.
0253      */
0254     const KoColorSpace * rgb16(const QString &profileName = QString());
0255 
0256     /**
0257      * Convenience method to get an RGBA 16bit colorspace with the given profile.
0258      * @param profile an RGB profile
0259      * @return the wanted colorspace, or 0 if the color space and profile can not be combined.
0260      */
0261     const KoColorSpace * rgb16(const KoColorProfile * profile);
0262 
0263     /**
0264      * Convenience method to get an Lab 16bit colorspace. If a profile is not specified,
0265      * an Lab profile with a D50 whitepoint will be used.
0266      * @param profileName the name of an Lab color profile
0267      * @return the wanted colorspace, or 0 if the color space and profile can not be combined.
0268      */
0269     const KoColorSpace * lab16(const QString &profileName = QString());
0270 
0271     /**
0272      * Convenience method to get an Lab 16bit colorspace with the given profile.
0273      * @param profile an Lab profile
0274      * @return the wanted colorspace, or 0 if the color space and profile can not be combined.
0275      */
0276     const KoColorSpace * lab16(const KoColorProfile * profile);
0277 
0278     /**
0279      * @return the list of available color models
0280      */
0281     QList<KoID> colorModelsList(ColorSpaceListVisibility option) const;
0282 
0283     /**
0284      * @return the list of available color models for the given colorModelId
0285      */
0286     QList<KoID> colorDepthList(const KoID& colorModelId, ColorSpaceListVisibility option) const;
0287 
0288     /**
0289      * @return the list of available color models for the given colorModelId
0290      */
0291     QList<KoID> colorDepthList(const QString & colorModelId, ColorSpaceListVisibility option) const;
0292 
0293     /**
0294      * @return the color conversion system use by the registry and the color
0295      * spaces to create color conversion transformation
0296      */
0297     const KoColorConversionSystem* colorConversionSystem() const;
0298 
0299     /**
0300      * @return the cache of color conversion transformation to be use by KoColorSpace
0301      */
0302     KoColorConversionCache* colorConversionCache() const;
0303 
0304     /**
0305      * @return a permanent colorspace owned by the registry, of the same type and profile
0306      *         as the one given in argument
0307      */
0308     const KoColorSpace* permanentColorspace(const KoColorSpace* _colorSpace);
0309 
0310     /**
0311      * This function return a list of all the keys in KoID format by using the name() method
0312      * on the objects stored in the registry.
0313      */
0314     QList<KoID> listKeys() const;
0315 
0316 private:
0317 
0318     friend class KisCsConversionTest;
0319     friend class KisIteratorTest;
0320     friend class KisPainterTest;
0321     friend class KisCrashFilterTest;
0322     friend class KoColorSpacesBenchmark;
0323     friend class TestKoColorSpaceSanity;
0324     friend class KisActionRecorderTest;
0325     /**
0326      * @return a list with an instance of all color space with their default profile.
0327      */
0328     QList<const KoColorSpace*> allColorSpaces(ColorSpaceListVisibility visibility, ColorSpaceListProfilesSelection pSelection);
0329 
0330 private:
0331 
0332     /**
0333      * The function checks if a colorspace with a certain id and profile name can be found in the cache
0334      * NOTE: the function doesn't take any lock but it needs to be called inside a d->registryLock
0335      * locked either in read or write.
0336      * @param csId The colorspace id
0337      * @param profileName The colorspace profile name
0338      * @retval KoColorSpace The matching colorspace
0339      * @retval 0 Null pointer if not match
0340      */
0341     const KoColorSpace* getCachedColorSpace(const QString & csId, const QString & profileName) const;
0342 
0343     QString idsToCacheName(const QString & csId, const QString & profileName) const;
0344 
0345 private:
0346     KoColorSpaceRegistry(const KoColorSpaceRegistry&);
0347     KoColorSpaceRegistry operator=(const KoColorSpaceRegistry&);
0348     void init();
0349 
0350 private:
0351     struct Private;
0352     Private * const d;
0353 };
0354 
0355 #endif // KOCOLORSPACEREGISTRY_H