[PATCH 07/15] Added more blending functions.
Silvio Heinrich
plassy at web.de
Sat Jan 8 22:28:43 CET 2011
Arcus Tangent, Gamma Light, Gamma Dark, Geometric Mean, Vivid Light and Pin Light
---
libs/pigment/KoCompositeOp.h | 10 ++-
libs/pigment/compositeops/KoCompositeOpFunctions.h | 60 ++++++++++++++++++++
libs/pigment/compositeops/KoCompositeOps.h | 22 +++++---
3 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/libs/pigment/KoCompositeOp.h b/libs/pigment/KoCompositeOp.h
index 73c923e..6f84313 100644
--- a/libs/pigment/KoCompositeOp.h
+++ b/libs/pigment/KoCompositeOp.h
@@ -42,6 +42,8 @@ const QString COMPOSITE_INVERSED_SUBTRACT = "inversed_subtract";
const QString COMPOSITE_DIFF = "diff";
const QString COMPOSITE_MULT = "multiply";
const QString COMPOSITE_DIVIDE = "divide";
+const QString COMPOSITE_ARC_TANGENT = "arc_tangent";
+const QString COMPOSITE_GEOMETRIC_MEAN = "geometric_mean";
const QString COMPOSITE_DODGE = "dodge";
const QString COMPOSITE_LINEAR_DODGE = "linear_dodge";
const QString COMPOSITE_BURN = "burn";
@@ -67,11 +69,13 @@ const QString COMPOSITE_COPY_BLUE = "copy_blue";
const QString COMPOSITE_COPY_OPACITY = "copy_opacity";
const QString COMPOSITE_HARD_LIGHT = "hard_light";
const QString COMPOSITE_SOFT_LIGHT = "soft_light";
-const QString COMPOSITE_EXCLUSION = "exclusion"; // XXX: not implemented anywhere yet
+const QString COMPOSITE_GAMMA_LIGHT = "gamma_light";
+const QString COMPOSITE_GAMMA_DARK = "gamma_dark";
+const QString COMPOSITE_EXCLUSION = "exclusion";
const QString COMPOSITE_INVERTED_DIVIDE = "inverted_divide"; // XXX: not implemented anywhere yet
-const QString COMPOSITE_VIVID_LIGHT = "vivid light"; // XXX: not implemented anywhere yet
+const QString COMPOSITE_VIVID_LIGHT = "vivid_light";
const QString COMPOSITE_LINEAR_LIGHT = "linear light"; // XXX: not implemented anywhere yet
-const QString COMPOSITE_PIN_LIGHT = "pin light"; // XXX: not implemented anywhere yet
+const QString COMPOSITE_PIN_LIGHT = "pin_light";
const QString COMPOSITE_HARD_MIX = "hard mix"; // XXX: not implemented anywhere yet
const QString COMPOSITE_PASS_THROUGH = "pass through"; // XXX: not implemented anywhere yet
diff --git a/libs/pigment/compositeops/KoCompositeOpFunctions.h b/libs/pigment/compositeops/KoCompositeOpFunctions.h
index de41921..ae45877 100644
--- a/libs/pigment/compositeops/KoCompositeOpFunctions.h
+++ b/libs/pigment/compositeops/KoCompositeOpFunctions.h
@@ -169,6 +169,66 @@ inline T cfSoftLight(T src, T dst) {
}
template<class T>
+inline T cfVividLight(T src, T dst) {
+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
+
+ if(src < KoColorSpaceMathsTraits<T>::halfValue) {
+ if(src == KoColorSpaceMathsTraits<T>::zeroValue)
+ return KoColorSpaceMathsTraits<T>::zeroValue; //TODO: maybe better to return unitValue, must be verified
+
+ // min(1,max(0,1-(1-dst) / (2*src)))
+ composite_type src2 = composite_type(src) + src;
+ composite_type dsti = inv(dst);
+ return clamp<T>(KoColorSpaceMathsTraits<T>::unitValue - (dsti * KoColorSpaceMathsTraits<T>::unitValue / src2));
+ }
+
+ if(src == KoColorSpaceMathsTraits<T>::unitValue)
+ return KoColorSpaceMathsTraits<T>::unitValue; //TODO: maybe better to return zeroValue, must be verified
+
+ // min(1,max(0, dst / (2*(1-src)))
+ composite_type srci2 = inv(src);
+ srci2 += srci2;
+ return clamp<T>(composite_type(dst) * KoColorSpaceMathsTraits<T>::unitValue / srci2);
+}
+
+template<class T>
+inline T cfPinLight(T src, T dst) {
+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
+ // TODO: verify that the formular is correct (the first max would be useless here)
+ // max(0, max(2*src-1, min(dst, 2*src)))
+ composite_type src2 = composite_type(src) + src;
+ composite_type a = qMin<composite_type>(dst, src2);
+ composite_type b = qMax<composite_type>(src2-KoColorSpaceMathsTraits<T>::unitValue, a);
+ return T(b);
+}
+
+template<class T>
+inline T cfArcTangent(T src, T dst) {
+ const static qreal pi = 3.14159265358979323846;
+
+ if(dst == KoColorSpaceMathsTraits<T>::zeroValue)
+ return (src == KoColorSpaceMathsTraits<T>::zeroValue) ?
+ KoColorSpaceMathsTraits<T>::zeroValue : KoColorSpaceMathsTraits<T>::unitValue;
+
+ return scale<T>(2.0 * atan(scale<qreal>(src) / scale<qreal>(dst)) / pi);
+}
+
+template<class T>
+inline T cfGammaDark(T src, T dst) {
+ if(src == KoColorSpaceMathsTraits<T>::zeroValue)
+ return KoColorSpaceMathsTraits<T>::zeroValue;
+
+ // power(dst, 1/src)
+ return scale<T>(pow(scale<qreal>(dst), 1.0/scale<qreal>(src)));
+}
+
+template<class T>
+inline T cfGammaLight(T src, T dst) { return scale<T>(pow(scale<qreal>(dst), scale<qreal>(src))); }
+
+template<class T>
+inline T cfGeometricMean(T src, T dst) { return scale<T>(sqrt(scale<qreal>(dst) * scale<qreal>(src))); }
+
+template<class T>
inline T cfOver(T src, T dst) { Q_UNUSED(dst); return src; }
template<class T>
diff --git a/libs/pigment/compositeops/KoCompositeOps.h b/libs/pigment/compositeops/KoCompositeOps.h
index b563261..000d2f8 100644
--- a/libs/pigment/compositeops/KoCompositeOps.h
+++ b/libs/pigment/compositeops/KoCompositeOps.h
@@ -73,15 +73,21 @@ void addStandardCompositeOps(KoColorSpace* cs)
cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfLightenOnly<T> >(cs, COMPOSITE_LIGHTEN , i18n("Lighten"), KoCompositeOp::categoryLight()));
cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfHardLight<T> >(cs, COMPOSITE_HARD_LIGHT , i18n("Hard Light"), KoCompositeOp::categoryLight()));
cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfSoftLight<T> >(cs, COMPOSITE_SOFT_LIGHT , i18n("Soft Light"), KoCompositeOp::categoryLight()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfGammaLight<T> >(cs, COMPOSITE_GAMMA_LIGHT , i18n("Gamma Light"), KoCompositeOp::categoryLight()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfGammaDark<T> >(cs, COMPOSITE_GAMMA_DARK , i18n("Gamma Dark"), KoCompositeOp::categoryLight()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfVividLight<T> >(cs, COMPOSITE_VIVID_LIGHT , i18n("Vivid Light"), KoCompositeOp::categoryLight()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfPinLight<T> >(cs, COMPOSITE_PIN_LIGHT , i18n("Pin Light"), KoCompositeOp::categoryLight()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfScreen<T> >(cs, COMPOSITE_SCREEN , i18n("Screen"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfOverlay<T> >(cs, COMPOSITE_OVERLAY , i18n("Overlay"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfAddition<T> >(cs, COMPOSITE_ADD , i18n("Addition"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfSubtract<T> >(cs, COMPOSITE_SUBTRACT , i18n("Subtract"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfDifference<T> >(cs, COMPOSITE_DIFF , i18n("Difference"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfMultiply<T> >(cs, COMPOSITE_MULT , i18n("Multiply"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfDivide<T> >(cs, COMPOSITE_DIVIDE , i18n("Divide"), KoCompositeOp::categoryArithmetic()));
- cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfExclusion<T> >(cs, COMPOSITE_EXCLUSION, i18n("Exclusion"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfScreen<T> >(cs, COMPOSITE_SCREEN , i18n("Screen"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfOverlay<T> >(cs, COMPOSITE_OVERLAY , i18n("Overlay"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfAddition<T> >(cs, COMPOSITE_ADD , i18n("Addition"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfSubtract<T> >(cs, COMPOSITE_SUBTRACT , i18n("Subtract"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfDifference<T> >(cs, COMPOSITE_DIFF , i18n("Difference"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfMultiply<T> >(cs, COMPOSITE_MULT , i18n("Multiply"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfDivide<T> >(cs, COMPOSITE_DIVIDE , i18n("Divide"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfExclusion<T> >(cs, COMPOSITE_EXCLUSION , i18n("Exclusion"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfArcTangent<T> >(cs, COMPOSITE_ARC_TANGENT , i18n("Arcus Tangent"), KoCompositeOp::categoryArithmetic()));
+ cs->addCompositeOp(new KoCompositeOpGeneric< _Traits_, &cfGeometricMean<T> >(cs, COMPOSITE_GEOMETRIC_MEAN, i18n("Geometric Mean"), KoCompositeOp::categoryArithmetic()));
}
#endif
--
1.7.1
More information about the kimageshop
mailing list