[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/krita/plugins/colorspaces/ctlcs
From:       Cyrille Berger <cyb () lepi ! org>
Date:       2010-01-28 12:59:52
Message-ID: 1264683592.473728.28114.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1081481 by berger:

allow to load and save profile


 M  +65 -22    KoCtlColorProfile.cpp  
 M  +5 -1      KoCtlColorProfile.h  
 M  +2 -2      KoCtlColorSpace.cpp  
 M  +2 -2      KoCtlColorSpaceFactory.cpp  
 M  +1 -1      KoCtlConvolutionOp.cpp  
 M  +1 -1      ctl_cs_plugin.cpp  


--- trunk/koffice/krita/plugins/colorspaces/ctlcs/KoCtlColorProfile.cpp \
#1081480:1081481 @@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2008 Cyrille Berger <cberger@cberger.net>
+ *  Copyright (c) 2008,2010 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
@@ -73,15 +73,36 @@
     quint32 colorDepthIDNumber;
     qreal exposure;
     qreal middleGrayScaleFactor;
+    QString profileSource;
+    bool loadFromSource(KoCtlColorProfile* self);
 };
 
-KoCtlColorProfile::KoCtlColorProfile(QString filename) : KoColorProfile(filename), \
d(new Private) +KoCtlColorProfile::KoCtlColorProfile() : KoColorProfile(), d(new \
Private)  {
     d->module = 0;
     d->middleGrayScaleFactor = 0.0883883;
     d->exposure = pow(2, 2.47393) * d->middleGrayScaleFactor;
 }
 
+KoCtlColorProfile* KoCtlColorProfile::fromFile(QString fileName)
+{
+    KoCtlColorProfile* profile = new KoCtlColorProfile;
+    profile->setFileName(fileName);
+    return profile;
+}
+
+KoCtlColorProfile* KoCtlColorProfile::fromString(QString string)
+{
+    KoCtlColorProfile* profile = new KoCtlColorProfile;
+    profile->d->profileSource = string;
+    if (profile->d->loadFromSource(profile)) {
+        return profile;
+    } else {
+        delete profile;
+        return 0;
+    }
+}
+
 KoCtlColorProfile::KoCtlColorProfile(const KoCtlColorProfile& rhs) : \
KoColorProfile(rhs), d(new Private(*rhs.d))  {
 
@@ -127,11 +148,11 @@
     QString dstDepthId = _dstCs->colorDepthId().id();
     foreach(ConversionInfo info, d->conversionInfos) {
         if (info.sourceColorModelID == srcModelId
-                && (info.sourceColorDepthID == srcDepthId ||(info.sourceColorDepthID \
                == "F"
-                        &&(srcDepthId == Float16BitsColorDepthID.id() || srcDepthId \
== Float32BitsColorDepthID.id()))) +                && (info.sourceColorDepthID == \
srcDepthId || (info.sourceColorDepthID == "F" +                        && (srcDepthId \
== Float16BitsColorDepthID.id() || srcDepthId == Float32BitsColorDepthID.id())))  && \
                info.destinationColorModelID == dstModelId
-                &&(info.destinationColorDepthID == dstDepthId \
                ||(info.destinationColorDepthID == "F"
-                        &&(dstDepthId == Float16BitsColorDepthID.id() || dstDepthId \
== Float32BitsColorDepthID.id())))) { +                && \
(info.destinationColorDepthID == dstDepthId || (info.destinationColorDepthID == "F" + \
&& (dstDepthId == Float16BitsColorDepthID.id() || dstDepthId == \
                Float32BitsColorDepthID.id())))) {
             GTLCore::PixelDescription srcPixelDescription = \
                createPixelDescription(_srcCs);
             GTLCore::PixelDescription dstPixelDescription = \
                createPixelDescription(_dstCs);
             return new OpenCTL::Program(info.function.toAscii().data(), d->module, \
srcPixelDescription, dstPixelDescription); @@ -262,20 +283,25 @@
 
 bool KoCtlColorProfile::load()
 {
-    QDomDocument doc;
     QFile file(fileName());
     if (!file.open(QIODevice::ReadOnly)) {
         dbgPigment << "Can't open file : " << fileName();
         return false;
     }
+    d->profileSource = file.readAll();
+    file.close();
+    return d->loadFromSource(this);
+}
+
+bool KoCtlColorProfile::Private::loadFromSource(KoCtlColorProfile* self)
+{
+    QDomDocument doc;
     QString errorMsg;
     int errorLine;
-    if (!doc.setContent(&file, &errorMsg, &errorLine)) {
-        dbgPigment << "Can't parse file : " << fileName() << " Error at line " << \
                errorLine << " " << errorMsg;
-        file.close();
+    if (!doc.setContent(profileSource, &errorMsg, &errorLine)) {
+        dbgPigment << "Can't parse profile : " << self->fileName() << " Error at \
line " << errorLine << " " << errorMsg;  return false;
     }
-    file.close();
     QDomElement docElem = doc.documentElement();
     if (docElem.tagName() != "ctlprofile") {
         dbgPigment << "Not a ctlprofile, root tag was : " << docElem.tagName();
@@ -287,11 +313,11 @@
         if (!e.isNull()) {
             dbgPigment << e.tagName();
             if (e.tagName() == "info") {
-                setName(e.attribute("name"));
-                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); +                \
self->setName(e.attribute("name")); +                colorDepthID = \
KoCtlParser::generateDepthID(e.attribute("depth"), e.attribute("type")).id(); +       \
colorDepthIDNumber = \
KoUniqueNumberForIdServer::instance()->numberForId(colorDepthID); +                \
colorModelID = e.attribute("colorModel"); +                colorModelIDNumber = \
                KoUniqueNumberForIdServer::instance()->numberForId(colorModelID);
                 dbgPigment << "colorModel = " << e.attribute("colorModel");;
             } else if (e.tagName() == "program") {
                 QDomNode nCDATA = e.firstChild();
@@ -299,17 +325,17 @@
                     QMutexLocker lock(ctlMutex);
                     QDomCDATASection CDATA = nCDATA.toCDATASection();
                     dbgPigment << CDATA.data();
-                    d->module = new OpenCTL::Module();
-                    d->module->setSource(name().toAscii().data(), \
                CDATA.data().toAscii().data());
-                    d->module->compile();
+                    module = new OpenCTL::Module();
+                    module->setSource(self->name().toAscii().data(), \
CDATA.data().toAscii().data()); +                    module->compile();
 #if GTL_CORE_VERSION_MAJOR == 0 && GTL_CORE_VERSION_MINOR == 9 && \
                GTL_CORE_VERSION_REVISION > 12
-                    if (!d->module->isCompiled()) {
-                        dbgKrita << \
d->module->compilationMessages().toString().c_str(); +                    if \
(!module->isCompiled()) { +                        dbgKrita << \
module->compilationMessages().toString().c_str();  }
 #endif
                 }
             } else if (e.tagName() == "transformations") {
-                decodeTransformations(e);
+                self->decodeTransformations(e);
             }
         }
         n = n.nextSibling();
@@ -317,6 +343,23 @@
     return true;
 }
 
+bool KoCtlColorProfile::save(const QString &fileName)
+{
+    QFile file(fileName);
+    if (!file.open(QIODevice::WriteOnly)) {
+        dbgPigment << "Can't open file : " << fileName;
+        return false;
+    }
+    file.write(d->profileSource.toUtf8());
+    file.close();
+    return true;
+}
+
+QByteArray KoCtlColorProfile::rawData() const
+{
+    return d->profileSource.toUtf8();
+}
+
 QVariant KoCtlColorProfile::property(const QString& _name) const
 {
     if (_name == "exposure") {
--- trunk/koffice/krita/plugins/colorspaces/ctlcs/KoCtlColorProfile.h \
#1081480:1081481 @@ -42,8 +42,10 @@
  */
 class PIGMENTCMS_EXPORT KoCtlColorProfile : public KoColorProfile
 {
+    KoCtlColorProfile();
 public:
-    KoCtlColorProfile(QString fileName);
+    static KoCtlColorProfile* fromFile(QString fileName);
+    static KoCtlColorProfile* fromString(QString string);
     KoCtlColorProfile(const KoCtlColorProfile&);
     virtual ~KoCtlColorProfile();
     virtual KoColorProfile* clone() const;
@@ -53,6 +55,8 @@
     virtual bool isSuitableForDisplay() const;
     virtual bool operator==(const KoColorProfile&) const;
     virtual bool load();
+    virtual bool save(const QString &fileName);
+    virtual QByteArray rawData() const;
     /**
      * @return the color model that can be used by this profile
      */
--- trunk/koffice/krita/plugins/colorspaces/ctlcs/KoCtlColorSpace.cpp \
#1081480:1081481 @@ -180,8 +180,8 @@
     if (!ctlp) return false;
     dbgPlugins << ctlp->colorModel() << ctlp->colorDepth() << info->colorModelId() \
<< info->colorDepthId();  if (ctlp && ctlp->colorModel() == info->colorModelId().id()
-            &&(ctlp->colorDepth() == info->colorDepthId().id()
-                ||(ctlp->colorDepth() == "F" &&(info->colorDepthId().id() == "F16" \
|| info->colorDepthId().id() == "F32")))) { +            && (ctlp->colorDepth() == \
info->colorDepthId().id() +                || (ctlp->colorDepth() == "F" && \
(info->colorDepthId().id() == "F16" || info->colorDepthId().id() == "F32")))) {  \
return true;  }
     return false;
--- trunk/koffice/krita/plugins/colorspaces/ctlcs/KoCtlColorSpaceFactory.cpp \
#1081480:1081481 @@ -107,7 +107,7 @@
     return m_info->defaultProfile();
 }
 
-KoColorProfile* KoCtlColorSpaceFactory::createColorProfile(const QByteArray& \
/*rawData*/) const +KoColorProfile* KoCtlColorSpaceFactory::createColorProfile(const \
QByteArray& rawData) const  {
-    return 0;
+    return KoCtlColorProfile::fromString(rawData);
 }
--- trunk/koffice/krita/plugins/colorspaces/ctlcs/KoCtlConvolutionOp.cpp \
#1081480:1081481 @@ -62,7 +62,7 @@
     if (totalWeightTransparent == 0) {
         for (int i = 0; i < channelsNb; i++) {
             if ((allChannels && i != (uint)alphaPos)
-                    ||(!allChannels && channelFlags.testBit(i))) {
+                    || (!allChannels && channelFlags.testBit(i))) {
                 m_accumulators[i]->affect(dst, factor, offset);
             }
         }
--- trunk/koffice/krita/plugins/colorspaces/ctlcs/ctl_cs_plugin.cpp #1081480:1081481
@@ -100,7 +100,7 @@
             KoColorProfile* profile = 0;
             for (QStringList::Iterator it = ctlprofileFilenames.begin(); it != \
ctlprofileFilenames.end(); ++it) {  dbgPlugins << "Load profile : " << *it;
-                profile = new KoCtlColorProfile(*it);
+                profile = KoCtlColorProfile::fromFile(*it);
                 profile->load();
                 if (profile->valid()) {
                     dbgPlugins << "Valid profile : " << profile->name();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic