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

List:       kde-kimageshop
Subject:    Re: https://bugs.kde.org/show_bug.cgi?id=281761 -- scaling between
From:       Silvio Heinrich <plassy () web ! de>
Date:       2011-09-18 17:54:32
Message-ID: 4E763058.5010707 () web ! de
[Download RAW message or body]

On 09/18/2011 03:06 PM, Boudewijn Rempt wrote:
> hi,
> 
> I'm stuck with this bug... Could someone with adequate templating foo please check \
> my patch and help me out a bit? I get a crash now if I follow the instructions in \
> the bug report exactly.

Ok I got it. Now it seems to work.
Now just one part is missing.
We need to test if the destination colorspace uses floating point 
channels so that the second part of the "else" part is executed.


["convert.patch" (text/x-patch)]

diff --git a/libs/pigment/KoColorSpaceAbstract.h \
b/libs/pigment/KoColorSpaceAbstract.h index fb5d56b..2a94ead 100644
--- a/libs/pigment/KoColorSpaceAbstract.h
+++ b/libs/pigment/KoColorSpaceAbstract.h
@@ -24,7 +24,12 @@
 #include <QtCore/QBitArray>
 #include <klocale.h>
 
+#ifdef HAVE_OPENEXR
+#include <half.h>
+#endif
+
 #include <KoColorSpace.h>
+#include <KoColorProfile.h>
 #include "KoColorSpaceConstants.h"
 #include <KoColorSpaceMaths.h>
 #include <KoColorSpaceRegistry.h>
@@ -100,6 +105,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 +155,72 @@ 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) {
+            typedef typename _CSTrait::channels_type channels_type;
+            int colorDepth = dstColorSpace->pixelSize() / \
dstColorSpace->channelCount(); +            
+            std::cout << "color depth: " << colorDepth << "\n";
+            
+            //TODO: test if destination color space is a floating point color space
+            if(true) {
+                switch(colorDepth)
+                {
+                case 1:
+                    scalePixels<_CSTrait::pixelSize, 1, channels_type, quint8>(src, \
dst, numPixels); +                    std::cout << "convert to 8bit\n";
+                    return true;
+                case 2:
+                    scalePixels<_CSTrait::pixelSize, 2, channels_type, quint16>(src, \
dst, numPixels); +                    std::cout << "convert to 16bit\n";
+                    return true;
+                }
+            }
+            else {
+                switch(colorDepth)
+                {
+#ifdef HAVE_OPENEXR
+                case 2:
+                    scalePixels<_CSTrait::pixelSize, 2, channels_type, half>(src, \
dst, numPixels); +                    return true;
 #endif
+                case 4:
+                    scalePixels<_CSTrait::pixelSize, 4, channels_type, float>(src, \
dst, numPixels); +                    return true;
+                case 8:
+                    scalePixels<_CSTrait::pixelSize, 8, channels_type, double>(src, \
dst, numPixels); +                    return true;
+                }
+            }
+        }
+        
+        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 // KOCOLORSPACEABSTRACT_H



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


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

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