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

List:       kde-commits
Subject:    [calligra] /: When converting between colorspaces make sure that a
From:       Silvio Heinrich <plassy () web ! de>
Date:       2011-11-11 13:30:07
Message-ID: 20111111133007.E4832A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit a201a7a59f9c8f94e469fbb198774b996c481aca by Silvio Heinrich.
Committed on 11/11/2011 at 14:22.
Pushed by heinrich into branch 'master'.

When converting between colorspaces make sure that a full conversion is only done \
when more than the bit depth canges.

When converting between two equal colorspaces where only the channel size is
different, the pixel values should only be scaled to the new channel size.
BUG:281761

M  +2    -1    krita/plugins/tools/tool_crop/kis_tool_crop.cc
M  +57   -7    libs/pigment/KoColorSpaceAbstract.h
M  +2    -1    libs/pigment/KoColorSpaceMaths.h

http://commits.kde.org/calligra/a201a7a59f9c8f94e469fbb198774b996c481aca

diff --git a/krita/plugins/tools/tool_crop/kis_tool_crop.cc \
b/krita/plugins/tools/tool_crop/kis_tool_crop.cc index e756225..b2df88e 100644
--- a/krita/plugins/tools/tool_crop/kis_tool_crop.cc
+++ b/krita/plugins/tools/tool_crop/kis_tool_crop.cc
@@ -452,7 +452,8 @@ void KisToolCrop::crop()
     } else {
         currentImage()->cropImage(cropRect);
     }
-
+    
+    currentImage()->requestProjectionUpdate(currentNode().data(), QRect(0, 0, \
cropRect.width(), cropRect.height()));  m_rectCrop = QRect(0, 0, 0, 0);
 
     updateWidgetValues();
diff --git a/libs/pigment/KoColorSpaceAbstract.h \
b/libs/pigment/KoColorSpaceAbstract.h index fb5d56b..d072d13 100644
--- a/libs/pigment/KoColorSpaceAbstract.h
+++ b/libs/pigment/KoColorSpaceAbstract.h
@@ -25,6 +25,7 @@
 #include <klocale.h>
 
 #include <KoColorSpace.h>
+#include <KoColorProfile.h>
 #include "KoColorSpaceConstants.h"
 #include <KoColorSpaceMaths.h>
 #include <KoColorSpaceRegistry.h>
@@ -51,13 +52,9 @@
 template<class _CSTrait>
 class KoColorSpaceAbstract : public KoColorSpace
 {
-
 public:
-
     KoColorSpaceAbstract(const QString &id, const QString &name) :
-            KoColorSpace(id, name, new KoMixColorsOpImpl< _CSTrait>(), new \
                KoConvolutionOpImpl< _CSTrait>()) {
-
-        
+        KoColorSpace(id, name, new KoMixColorsOpImpl< _CSTrait>(), new \
KoConvolutionOpImpl< _CSTrait>()) {  }
 
     virtual quint32 colorChannelCount() const {
@@ -100,6 +97,7 @@ public:
         typename _CSTrait::channels_type c = \
                _CSTrait::nativeArray(srcPixel)[channelIndex];
         return KoColorSpaceMaths<typename _CSTrait::channels_type, \
quint16>::scaleToA(c);  }
+
     virtual void singleChannelPixel(quint8 *dstPixel, const quint8 *srcPixel, \
quint32 channelIndex) const {  _CSTrait::singleChannelPixel(dstPixel, srcPixel, \
channelIndex);  }
@@ -149,7 +147,59 @@ public:
     virtual KoID mathToolboxId() const {
         return KoID("Basic");
     }
-};
 
+    virtual bool convertPixelsTo(const quint8 *src,
+                                 quint8 *dst, const KoColorSpace *dstColorSpace,
+                                 quint32 numPixels,
+                                 KoColorConversionTransformation::Intent \
renderingIntent = KoColorConversionTransformation::IntentPerceptual) const { +        \
 +        // check whether we have the same profile and color model, but only a \
different bit +        // depth; in that case we don't convert as such, but scale
+        bool scaleOnly = dstColorSpace->colorModelId().id() == colorModelId().id() \
&& +                         dstColorSpace->colorDepthId().id() != \
colorDepthId().id() && +                         dstColorSpace->profile()->name()   \
== profile()->name(); +        
+        if(scaleOnly && dynamic_cast<const KoColorSpaceAbstract*>(dstColorSpace)) {
+            typedef typename _CSTrait::channels_type channels_type;
+            
+            switch(dstColorSpace->channels()[0]->channelValueType())
+            {
+            case KoChannelInfo::UINT8:
+                scalePixels<_CSTrait::pixelSize, 1, channels_type, quint8>(src, dst, \
numPixels); +                return true;
+//             case KoChannelInfo::INT8:
+//                 scalePixels<_CSTrait::pixelSize, 1, channels_type, qint8>(src, \
dst, numPixels); +//                 return true;
+            case KoChannelInfo::UINT16:
+                scalePixels<_CSTrait::pixelSize, 2, channels_type, quint16>(src, \
dst, numPixels); +                return true;
+            case KoChannelInfo::INT16:
+                scalePixels<_CSTrait::pixelSize, 2, channels_type, qint16>(src, dst, \
numPixels); +                return true;
+            case KoChannelInfo::UINT32:
+                scalePixels<_CSTrait::pixelSize, 4, channels_type, quint32>(src, \
dst, numPixels); +                return true;
+            default:
+                break;
+            }
+        }
+        
+        return KoColorSpace::convertPixelsTo(src, dst, dstColorSpace, numPixels, \
renderingIntent); +    }
+    
+private:
+    template<int srcPixelSize, int dstChannelSize, class TSrcChannel, class \
TDstChannel> +    void scalePixels(const quint8* src, quint8* dst, quint32 numPixels) \
const { +        qint32 dstPixelSize = dstChannelSize * _CSTrait::channels_nb;
+        
+        for(quint32 i=0; i<numPixels; ++i) {
+            const TSrcChannel* srcPixel = reinterpret_cast<const TSrcChannel*>(src + \
i * srcPixelSize); +            TDstChannel*       dstPixel = \
reinterpret_cast<TDstChannel*>(dst + i * dstPixelSize); +            
+            for(quint32 c=0; c<_CSTrait::channels_nb; ++c)
+                dstPixel[c] = Arithmetic::scale<TDstChannel>(srcPixel[c]);
+        }
+    }
+};
 
-#endif
+#endif // KOCOLORSPACEABSTRACT_H
diff --git a/libs/pigment/KoColorSpaceMaths.h b/libs/pigment/KoColorSpaceMaths.h
index 68eb3d1..b8df329 100644
--- a/libs/pigment/KoColorSpaceMaths.h
+++ b/libs/pigment/KoColorSpaceMaths.h
@@ -275,7 +275,8 @@ public:
      * This function will scale a value of type _T to fit into a _Tdst.
      */
     inline static _Tdst scaleToA(_T a) {
-        return src_compositetype(a) >> (traits::bits - \
KoColorSpaceMathsTraits<_Tdst>::bits); +//         return src_compositetype(a) >> \
(traits::bits - KoColorSpaceMathsTraits<_Tdst>::bits); +        return \
_Tdst(dst_compositetype(a) * KoColorSpaceMathsTraits<_Tdst>::unitValue / \
KoColorSpaceMathsTraits<_T>::unitValue);  }
 
     inline static dst_compositetype clamp(dst_compositetype val) {


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

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