Commit 8ff085eb authored by Cyrille Berger's avatar Cyrille Berger

implement a factory for the new style of CTL color space

svn path=/trunk/koffice/; revision=952054
parent a2cd9888
......@@ -10,6 +10,7 @@ set( CTLCS_SRCS
KoCtlColorProfile.cpp
KoCtlColorConversionTransformation.cpp
KoCtlColorSpace.cpp
KoCtlColorSpaceFactory.cpp
KoCtlColorSpaceInfo.cpp
KoCtlParser.cpp
ctl_cs_plugin.cpp
......
......@@ -237,10 +237,10 @@ void KoCtlColorProfile::decodeConversions(QDomElement& elt)
ConversionInfo ci;
ci.function = e.attribute("function");
ci.sourceColorModelID = eIn.attribute("colorModel");
ci.sourceColorDepthID = KoCtlParser::generateDepthID(eIn.attribute("depth"), eIn.attribute("type"));
ci.sourceColorDepthID = KoCtlParser::generateDepthID(eIn.attribute("depth"), eIn.attribute("type")).id();
ci.sourceProfile = eIn.attribute("profile");
ci.destinationColorModelID = eOut.attribute("colorModel");
ci.destinationColorDepthID = KoCtlParser::generateDepthID(eOut.attribute("depth"), eOut.attribute("type") );
ci.destinationColorDepthID = KoCtlParser::generateDepthID(eOut.attribute("depth"), eOut.attribute("type") ).id();
ci.destinationProfile = eOut.attribute("profile");
if( ci.sourceColorModelID == colorModel() and ci.sourceColorDepthID == colorDepth() and ci.sourceProfile.isEmpty())
{
......@@ -294,7 +294,7 @@ bool KoCtlColorProfile::load()
if( e.tagName() == "info")
{
setName(e.attribute("name"));
d->colorDepthID = KoCtlParser::generateDepthID(e.attribute("depth"), e.attribute("type"));
d->colorDepthID = KoCtlParser::generateDepthID(e.attribute("depth"), e.attribute("type")).id();
d->colorDepthIDNumber = KoUniqueNumberForIdServer::instance()->numberForId( d->colorDepthID );
d->colorModelID = e.attribute("colorModel");
d->colorModelIDNumber = KoUniqueNumberForIdServer::instance()->numberForId( d->colorModelID );
......
......@@ -132,29 +132,3 @@ void KoCtlColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
}
bool KoCtlColorSpaceFactory::profileIsCompatible(const KoColorProfile* profile) const
{
const KoCtlColorProfile* ctlp = dynamic_cast<const KoCtlColorProfile*>(profile);
if(ctlp and ctlp->colorModel() == colorModelId().id() and ctlp->colorDepth() == colorDepthId().id() )
{
return true;
}
return false;
}
QList<KoColorConversionTransformationFactory*> KoCtlColorSpaceFactory::colorConversionLinks() const
{
QList<const KoColorProfile*> profiles = KoColorSpaceRegistry::instance()->profilesFor( this );
QList<KoColorConversionTransformationFactory*> list;
foreach(const KoColorProfile* profile, profiles)
{
const KoCtlColorProfile* ctlprofile = dynamic_cast<const KoCtlColorProfile*>( profile );
if(ctlprofile)
{
list += ctlprofile->createColorConversionTransformationFactories();
}
}
return list;
}
......@@ -21,11 +21,10 @@
#define _KO_CTL_COLOR_SPACE_H_
#include <KoColorSpace.h>
#include "pigment_export.h"
class KoCtlColorProfile;
class PIGMENTCMS_EXPORT KoCtlColorSpace : public KoColorSpace {
class KoCtlColorSpace : public KoColorSpace {
public:
/**
* This class is use when creating color space that are defined using the Color Transformation Language.
......@@ -53,11 +52,4 @@ class PIGMENTCMS_EXPORT KoCtlColorSpace : public KoColorSpace {
Private* const d;
};
class PIGMENTCMS_EXPORT KoCtlColorSpaceFactory : public KoColorSpaceFactory {
public:
virtual ~KoCtlColorSpaceFactory() {}
virtual bool profileIsCompatible(const KoColorProfile* profile) const;
QList<KoColorConversionTransformationFactory*> colorConversionLinks() const;
};
#endif
/*
* Copyright (c) 2008-2009 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoCtlColorSpaceFactory.h"
#include "KoCtlColorProfile.h"
#include <KoColorSpaceRegistry.h>
#include "KoCtlColorSpaceInfo.h"
KoCtlColorSpaceFactory::KoCtlColorSpaceFactory( KoCtlColorSpaceInfo* info) : m_info(info)
{
}
KoCtlColorSpaceFactory::~KoCtlColorSpaceFactory()
{
}
bool KoCtlColorSpaceFactory::profileIsCompatible(const KoColorProfile* profile) const
{
const KoCtlColorProfile* ctlp = dynamic_cast<const KoCtlColorProfile*>(profile);
if(ctlp and ctlp->colorModel() == colorModelId().id() and ctlp->colorDepth() == colorDepthId().id() )
{
return true;
}
return false;
}
QList<KoColorConversionTransformationFactory*> KoCtlColorSpaceFactory::colorConversionLinks() const
{
QList<const KoColorProfile*> profiles = KoColorSpaceRegistry::instance()->profilesFor( this );
QList<KoColorConversionTransformationFactory*> list;
foreach(const KoColorProfile* profile, profiles)
{
const KoCtlColorProfile* ctlprofile = dynamic_cast<const KoCtlColorProfile*>( profile );
if(ctlprofile)
{
list += ctlprofile->createColorConversionTransformationFactories();
}
}
return list;
}
QString KoCtlColorSpaceFactory::id() const
{
return m_info->colorSpaceId();
}
QString KoCtlColorSpaceFactory::name() const
{
return m_info->name();
}
bool KoCtlColorSpaceFactory::userVisible() const
{
return true;
}
KoID KoCtlColorSpaceFactory::colorModelId() const
{
return m_info->colorModelId();
}
KoID KoCtlColorSpaceFactory::colorDepthId() const
{
return m_info->colorDepthId();
}
KoColorSpace *KoCtlColorSpaceFactory::createColorSpace(const KoColorProfile *) const
{
return 0;
}
QString KoCtlColorSpaceFactory::colorSpaceEngine() const
{
return "";
}
bool KoCtlColorSpaceFactory::isHdr() const
{
return m_info->isHdr();
}
int KoCtlColorSpaceFactory::referenceDepth() const
{
return m_info->referenceDepth();
}
QString KoCtlColorSpaceFactory::defaultProfile() const
{
return m_info->defaultProfile();
}
/*
* Copyright (c) 2008-2009 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KOCTLCOLORSPACEFACTORY_H_
#define _KOCTLCOLORSPACEFACTORY_H_
#include <KoColorSpace.h>
class KoCtlColorSpaceInfo;
class KoCtlColorSpaceFactory : public KoColorSpaceFactory {
public:
KoCtlColorSpaceFactory( KoCtlColorSpaceInfo* );
virtual ~KoCtlColorSpaceFactory();
virtual QString id() const ;
virtual QString name() const;
virtual bool userVisible() const;
virtual KoID colorModelId() const;
virtual KoID colorDepthId() const;
virtual KoColorSpace *createColorSpace(const KoColorProfile *) const;
virtual QString colorSpaceEngine() const;
virtual bool isHdr() const;
virtual int referenceDepth() const;
virtual QString defaultProfile() const;
virtual bool profileIsCompatible(const KoColorProfile* profile) const;
QList<KoColorConversionTransformationFactory*> colorConversionLinks() const;
private:
KoCtlColorSpaceInfo* m_info;
};
#endif
......@@ -22,6 +22,7 @@
#include <QDomDocument>
#include <kis_debug.h>
#include "KoCtlParser.h"
#include <KoID.h>
struct KoCtlColorSpaceInfo::ChannelInfo::Private {
Private() : color(0,0,0) {}
......@@ -76,12 +77,13 @@ const QColor& KoCtlColorSpaceInfo::ChannelInfo::color() const {
struct KoCtlColorSpaceInfo::Private {
QString fileName;
QString colorDepthID;
QString colorModelId;
KoID colorDepthID;
KoID colorModelId;
QString id;
QString name;
QString defaultProfile;
bool isHdr;
qint32 referenceDepth;
QList<const KoCtlColorSpaceInfo::ChannelInfo*> channels;
};
......@@ -149,7 +151,10 @@ bool KoCtlColorSpaceInfo::load()
CHECK_AVAILABILITY("type");
CHECK_AVAILABILITY("depth");
d->colorDepthID = KoCtlParser::generateDepthID(e.attribute("depth"), e.attribute("type"));
FILL_MEMBER("colorModel", colorModelId);
d->referenceDepth = e.attribute("depth").toInt();
CHECK_AVAILABILITY("colorModelId");
CHECK_AVAILABILITY("colorModelName");
d->colorModelId = KoID(e.attribute("colorModelId"), e.attribute("colorModelName"));
FILL_MEMBER("name", name);
FILL_MEMBER("id", id);
} else if( e.tagName() == "defaultProfile" ) {
......@@ -244,12 +249,12 @@ bool KoCtlColorSpaceInfo::load()
return true;
}
const QString& KoCtlColorSpaceInfo::colorDepthId() const
const KoID& KoCtlColorSpaceInfo::colorDepthId() const
{
return d->colorDepthID;
}
const QString& KoCtlColorSpaceInfo::colorModelId() const
const KoID& KoCtlColorSpaceInfo::colorModelId() const
{
return d->colorModelId;
}
......@@ -277,3 +282,8 @@ bool KoCtlColorSpaceInfo::isHdr() const
const QList<const KoCtlColorSpaceInfo::ChannelInfo*>& KoCtlColorSpaceInfo::channels() const {
return d->channels;
}
qint32 KoCtlColorSpaceInfo::referenceDepth() const
{
return d->referenceDepth;
}
......@@ -22,6 +22,8 @@
#include <KoChannelInfo.h>
class KoID;
class KoCtlColorSpaceInfo {
public:
class ChannelInfo {
......@@ -47,8 +49,9 @@ class KoCtlColorSpaceInfo {
const QString& fileName() const;
bool load();
~KoCtlColorSpaceInfo();
const QString& colorDepthId() const;
const QString& colorModelId() const;
qint32 referenceDepth() const;
const KoID& colorDepthId() const;
const KoID& colorModelId() const;
const QString& colorSpaceId() const;
const QString& name() const;
const QString& defaultProfile() const;
......
......@@ -22,13 +22,23 @@
#include<QString>
#include <kis_debug.h>
#include <KoColorModelStandardIds.h>
QString KoCtlParser::generateDepthID(const QString& depth, const QString& type)
KoID KoCtlParser::generateDepthID(const QString& depth, const QString& type)
{
QString prefix;
if(type == "integer") prefix = "U";
else if(type == "float") prefix = "F";
else dbgPlugins << "Invalid type";
return prefix + depth;
if(type == "integer") {
if( depth == "8" )
return Integer8BitsColorDepthID;
else if(depth == "16" )
return Integer16BitsColorDepthID;
}
else if(type == "float") {
if( depth == "16" )
return Float16BitsColorDepthID;
else if(depth == "32" )
return Float32BitsColorDepthID;
}
dbgPlugins << "Invalid type";
return KoID("","");
}
......@@ -18,8 +18,9 @@
*/
class QString;
class KoID;
namespace KoCtlParser {
QString generateDepthID(const QString& depth, const QString& type);
KoID generateDepthID(const QString& depth, const QString& type);
}
<ctlcolorspace>
<info colorModel="RGBA" type="float" depth="32" name="RGB (32-bit float/channel) for High Dynamic Range imaging" id="RgbAF32" />
<info colorModelId="RGBA" colorModelName="Red Green Blue" type="float" depth="32" name="RGB (32-bit float/channel) for High Dynamic Range imaging" id="RgbAF32" />
<channels>
<channel name="Red" shortName="r" index="2" channelType="Color" valueType="float32" size="4" color="255,0,0" />
<channel name="Green" shortName="g" index="1" channelType="Color" valueType="float32" size="4" color="0,255,0" />
......
......@@ -7,5 +7,5 @@ set(ko_ctl_color_space_info_test_SRCS KoCtlColorSpaceInfoTest.cpp ../KoCtlColorS
kde4_add_unit_test(ko_ctl_color_space_info_test TESTNAME krita-cs-ko_ctl_color_space_info_test ${ko_ctl_color_space_info_test_SRCS})
target_link_libraries(ko_ctl_color_space_info_test ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY})
target_link_libraries(ko_ctl_color_space_info_test ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY} pigmentcms)
......@@ -21,13 +21,15 @@
#include <qtest_kde.h>
#include "../KoCtlColorSpaceInfo.h"
#include <KoID.h>
void KoCtlColorSpaceInfoTest::testCreation()
{
KoCtlColorSpaceInfo info(FILES_DATA_DIR + QString("rgba32f.ctlcs"));
QVERIFY(info.load());
QCOMPARE(info.colorDepthId(), QString( "F32"));
QCOMPARE(info.colorModelId(), QString( "RGBA"));
QCOMPARE(info.colorDepthId().id(), QString( "F32"));
QCOMPARE(info.colorModelId().id(), QString( "RGBA"));
QCOMPARE(info.colorModelId().name(), QString( "Red Green Blue"));
QCOMPARE(info.colorSpaceId(), QString( "RgbAF32"));
QCOMPARE(info.name(), QString( "RGB (32-bit float/channel) for High Dynamic Range imaging"));
QCOMPARE(info.defaultProfile(), QString( "Standard Linear RGB (scRGB/sRGB64)"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment