[PATCH 01/15] Fixed the Burn composite option.

Silvio Heinrich plassy at web.de
Wed Jan 5 00:43:52 CET 2011


Should now work exactly like the Color burn mode in Photoshop
but only for fully opaque colors. Transparency is not considered jet.
---
 libs/pigment/compositeops/KoCompositeOpBurn.h |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/libs/pigment/compositeops/KoCompositeOpBurn.h b/libs/pigment/compositeops/KoCompositeOpBurn.h
index 97feaa4..2a56e2f 100644
--- a/libs/pigment/compositeops/KoCompositeOpBurn.h
+++ b/libs/pigment/compositeops/KoCompositeOpBurn.h
@@ -29,7 +29,8 @@ template<class _CSTraits>
 class KoCompositeOpBurn : public KoCompositeOpAlphaBase<_CSTraits, KoCompositeOpBurn<_CSTraits>, true >
 {
     typedef typename _CSTraits::channels_type channels_type;
-    typedef typename KoColorSpaceMathsTraits<typename _CSTraits::channels_type>::compositetype compositetype;
+    typedef typename KoColorSpaceMathsTraits<channels_type>::compositetype composite_type;
+    
 public:
 
     KoCompositeOpBurn(const KoColorSpace * cs)
@@ -48,20 +49,22 @@ public:
                                             const QBitArray & channelFlags) {
         for (uint i = 0; i < _CSTraits::channels_nb; i++) {
             if ((int)i != _CSTraits::alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {
-                compositetype srcColor = src[i];
-                compositetype dstColor = dst[i];
-
-                srcColor = qMin(((NATIVE_MAX_VALUE - dstColor) * (NATIVE_MAX_VALUE + 1)) / (srcColor + 1), (compositetype)NATIVE_MAX_VALUE);
-                if (NATIVE_MAX_VALUE - srcColor > NATIVE_MAX_VALUE) srcColor = NATIVE_MAX_VALUE;
-
-                channels_type newColor = NATIVE_MAX_VALUE - KoColorSpaceMaths<channels_type>::blend(srcColor, dstColor, srcBlend);
-
-                dst[i] = newColor;
+                composite_type unitValue = KoColorSpaceMathsTraits<channels_type>::unitValue;
+                composite_type invDst    = unitValue - dst[i];
+                
+                if(src[i] != KoColorSpaceMathsTraits<channels_type>::zeroValue) {
+                    composite_type result = unitValue - qMin<composite_type>(invDst * unitValue / src[i], unitValue);
+                    dst[i] = KoColorSpaceMaths<channels_type>::blend(result, dst[i], srcBlend);
+                }
+                else {
+                    //composite_type result = KoColorSpaceMathsTraits<channels_type>::zeroValue;
+                    composite_type result = unitValue - qMin<composite_type>(invDst * unitValue, unitValue);
+                    dst[i] = KoColorSpaceMaths<channels_type>::blend(result, dst[i], srcBlend);
+                }
             }
         }
     }
 
-
 };
 
 #endif
-- 
1.7.1




More information about the kimageshop mailing list