[PATCH 14/15] Added "Additive-Substractive" composition function and imporved "Divide" composition.

Silvio Heinrich plassy at web.de
Mon Jan 10 23:02:59 CET 2011


Also made the KoCompositeOpGenericHSL class aware of channel flags.
---
 libs/pigment/KoCompositeOp.h                       |    3 ++-
 .../compositeops/KoCompositeOpCopyChannel.h        |    3 ++-
 libs/pigment/compositeops/KoCompositeOpFunctions.h |   11 ++++++++++-
 libs/pigment/compositeops/KoCompositeOpGeneric.h   |   11 ++++++++---
 libs/pigment/compositeops/KoCompositeOps.h         |   11 ++++++-----
 5 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/libs/pigment/KoCompositeOp.h b/libs/pigment/KoCompositeOp.h
index aa32c4e..d0fb207 100644
--- a/libs/pigment/KoCompositeOp.h
+++ b/libs/pigment/KoCompositeOp.h
@@ -45,6 +45,7 @@ const QString COMPOSITE_DIVIDE = "divide";
 const QString COMPOSITE_ARC_TANGENT = "arc_tangent";
 const QString COMPOSITE_EQUIVALENCE = "equivalence";
 const QString COMPOSITE_GEOMETRIC_MEAN = "geometric_mean";
+const QString COMPOSITE_ADDITIVE_SUBSTRACTIVE = "additive_substractive";
 const QString COMPOSITE_DODGE = "dodge";
 const QString COMPOSITE_LINEAR_DODGE = "linear_dodge";
 const QString COMPOSITE_BURN = "burn";
@@ -81,7 +82,7 @@ const QString COMPOSITE_INVERTED_DIVIDE = "inverted_divide"; // XXX: not impleme
 const QString COMPOSITE_VIVID_LIGHT = "vivid_light";
 const QString COMPOSITE_LINEAR_LIGHT = "linear light";
 const QString COMPOSITE_PIN_LIGHT = "pin_light";
-const QString COMPOSITE_HARD_MIX = "hard mix"; // XXX: not implemented anywhere yet
+const QString COMPOSITE_HARD_MIX = "hard mix";
 const QString COMPOSITE_PASS_THROUGH = "pass through"; // XXX: not implemented anywhere yet
 
 const QString COMPOSITE_UNDEF = "underfined";
diff --git a/libs/pigment/compositeops/KoCompositeOpCopyChannel.h b/libs/pigment/compositeops/KoCompositeOpCopyChannel.h
index 1747334..c17dc52 100644
--- a/libs/pigment/compositeops/KoCompositeOpCopyChannel.h
+++ b/libs/pigment/compositeops/KoCompositeOpCopyChannel.h
@@ -52,7 +52,8 @@ public:
             if(channel_pos == alpha_pos)
                 return lerp(dstAlpha, srcAlpha, opacity);
             
-            dst[channel_pos] = lerp(dst[channel_pos], src[channel_pos], opacity);
+            srcAlpha = mul(srcAlpha, opacity);
+            dst[channel_pos] = lerp(dst[channel_pos], src[channel_pos], srcAlpha);
         }
         
         return dstAlpha;
diff --git a/libs/pigment/compositeops/KoCompositeOpFunctions.h b/libs/pigment/compositeops/KoCompositeOpFunctions.h
index 9b75faf..c70d27e 100644
--- a/libs/pigment/compositeops/KoCompositeOpFunctions.h
+++ b/libs/pigment/compositeops/KoCompositeOpFunctions.h
@@ -267,7 +267,9 @@ template<class T>
 inline T cfDivide(T src, T dst) {
     typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
     if(src == KoColorSpaceMathsTraits<T>::zeroValue)
-        return dst;
+        return (dst == KoColorSpaceMathsTraits<T>::zeroValue) ?
+            KoColorSpaceMathsTraits<T>::zeroValue : KoColorSpaceMathsTraits<T>::unitValue;
+    
     return clamp<T>(div(dst, src));
 }
 
@@ -402,6 +404,13 @@ inline T cfHardMix(T src, T dst) {
 }
 
 template<class T>
+inline T cfAdditiveSubstractive(T src, T dst) {
+    // min(1,max(0,abs(sqr(CB)-sqr(CT))))
+    qreal x = sqrt(scale<qreal>(dst)) - sqrt(scale<qreal>(src));
+    return scale<T>((x < 0.0) ? -x : x);
+}
+
+template<class T>
 inline T cfGammaDark(T src, T dst) {
     if(src == KoColorSpaceMathsTraits<T>::zeroValue)
         return KoColorSpaceMathsTraits<T>::zeroValue;
diff --git a/libs/pigment/compositeops/KoCompositeOpGeneric.h b/libs/pigment/compositeops/KoCompositeOpGeneric.h
index 308cc0a..a400b95 100644
--- a/libs/pigment/compositeops/KoCompositeOpGeneric.h
+++ b/libs/pigment/compositeops/KoCompositeOpGeneric.h
@@ -111,9 +111,14 @@ public:
             
             compositeFunc(srcR, srcG, srcB, dstR, dstG, dstB);
             
-            dst[red_pos]   = div(blend(src[red_pos]  , srcAlpha, dst[red_pos]  , dstAlpha, scale<channels_type>(dstR)), newDstAlpha);
-            dst[green_pos] = div(blend(src[green_pos], srcAlpha, dst[green_pos], dstAlpha, scale<channels_type>(dstG)), newDstAlpha);
-            dst[blue_pos]  = div(blend(src[blue_pos] , srcAlpha, dst[blue_pos] , dstAlpha, scale<channels_type>(dstB)), newDstAlpha);
+            if(allChannelFlags || channelFlags.testBit(red_pos))
+                dst[red_pos] = div(blend(src[red_pos], srcAlpha, dst[red_pos], dstAlpha, scale<channels_type>(dstR)), newDstAlpha);
+            
+            if(allChannelFlags || channelFlags.testBit(green_pos))
+                dst[green_pos] = div(blend(src[green_pos], srcAlpha, dst[green_pos], dstAlpha, scale<channels_type>(dstG)), newDstAlpha);
+            
+            if(allChannelFlags || channelFlags.testBit(blue_pos))
+                dst[blue_pos] = div(blend(src[blue_pos], srcAlpha, dst[blue_pos], dstAlpha, scale<channels_type>(dstB)), newDstAlpha);
         }
         
         return newDstAlpha;
diff --git a/libs/pigment/compositeops/KoCompositeOps.h b/libs/pigment/compositeops/KoCompositeOps.h
index e514e35..1258a4b 100644
--- a/libs/pigment/compositeops/KoCompositeOps.h
+++ b/libs/pigment/compositeops/KoCompositeOps.h
@@ -97,11 +97,12 @@ struct AddGeneralOps<Traits, true>
         add<&cfScreen> (cs, COMPOSITE_SCREEN , i18n("Screen") , KoCompositeOp::categoryColor());
         add<&cfOverlay>(cs, COMPOSITE_OVERLAY, i18n("Overlay"), KoCompositeOp::categoryColor());
         
-        add<&cfArcTangent>   (cs, COMPOSITE_ARC_TANGENT   , i18n("Arcus Tangent") , KoCompositeOp::categoryMisc());
-        add<&cfGeometricMean>(cs, COMPOSITE_GEOMETRIC_MEAN, i18n("Geometric Mean"), KoCompositeOp::categoryMisc());
-        add<&cfAllanon>      (cs, COMPOSITE_ALLANON       , i18n("Allanon")       , KoCompositeOp::categoryMisc());
-        add<&cfParallel>     (cs, COMPOSITE_PARALLEL      , i18n("Parallel")      , KoCompositeOp::categoryMisc());
-        add<&cfEquivalence>  (cs, COMPOSITE_EQUIVALENCE   , i18n("Equivalence")   , KoCompositeOp::categoryMisc());
+        add<&cfArcTangent>          (cs, COMPOSITE_ARC_TANGENT          , i18n("Arcus Tangent")        , KoCompositeOp::categoryMisc());
+        add<&cfGeometricMean>       (cs, COMPOSITE_GEOMETRIC_MEAN       , i18n("Geometric Mean")       , KoCompositeOp::categoryMisc());
+        add<&cfAllanon>             (cs, COMPOSITE_ALLANON              , i18n("Allanon")              , KoCompositeOp::categoryMisc());
+        add<&cfParallel>            (cs, COMPOSITE_PARALLEL             , i18n("Parallel")             , KoCompositeOp::categoryMisc());
+        add<&cfEquivalence>         (cs, COMPOSITE_EQUIVALENCE          , i18n("Equivalence")          , KoCompositeOp::categoryMisc());
+        add<&cfAdditiveSubstractive>(cs, COMPOSITE_ADDITIVE_SUBSTRACTIVE, i18n("Additive-Substractive"), KoCompositeOp::categoryMisc());
     }
 };
 
-- 
1.7.1




More information about the kimageshop mailing list