[PATCH 12/15] Added composite modes "Grain Merge", "Grain Extract", "Hard Mix" and "Copy Red/Green/Blue/Opacy".
Silvio Heinrich
plassy at web.de
Mon Jan 10 00:14:01 CET 2011
---
libs/pigment/KoCompositeOp.h | 2 +
.../compositeops/KoCompositeOpCopyChannel.h | 59 ++++++++++++++++++++
libs/pigment/compositeops/KoCompositeOpFunctions.h | 20 +++++++
libs/pigment/compositeops/KoCompositeOps.h | 24 +++++++-
4 files changed, 101 insertions(+), 4 deletions(-)
create mode 100644 libs/pigment/compositeops/KoCompositeOpCopyChannel.h
diff --git a/libs/pigment/KoCompositeOp.h b/libs/pigment/KoCompositeOp.h
index 920fe3e..aa32c4e 100644
--- a/libs/pigment/KoCompositeOp.h
+++ b/libs/pigment/KoCompositeOp.h
@@ -55,6 +55,8 @@ const QString COMPOSITE_BUMPMAP = "bumpmap";
const QString COMPOSITE_CLEAR = "clear";
const QString COMPOSITE_DISSOLVE = "dissolve";
const QString COMPOSITE_DISPLACE = "displace";
+const QString COMPOSITE_GRAIN_MERGE = "grain_merge";
+const QString COMPOSITE_GRAIN_EXTRACT = "grain_extract";
const QString COMPOSITE_NO = "nocomposition";
const QString COMPOSITE_DARKEN = "darken";
const QString COMPOSITE_LIGHTEN = "lighten";
diff --git a/libs/pigment/compositeops/KoCompositeOpCopyChannel.h b/libs/pigment/compositeops/KoCompositeOpCopyChannel.h
new file mode 100644
index 0000000..7bb6b40
--- /dev/null
+++ b/libs/pigment/compositeops/KoCompositeOpCopyChannel.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 Silvio Heinrich <plassy at web.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KOCOMPOSITEO_COPY_CHANNEL_H_
+#define _KOCOMPOSITEO_COPY_CHANNEL_H_
+
+#include "KoCompositeOpBase.h"
+
+/**
+ * KoCompositeOpCopyChannel class
+ *
+ * This class creates a CompositeOp that will just copy/blend
+ * a source channel to a destination channel
+ *
+ * @param channel_pos the channel to copy/blend
+ */
+template<class Traits, qint32 channel_pos>
+class KoCompositeOpCopyChannel: public KoCompositeOpBase< Traits, KoCompositeOpCopyChannel<Traits,channel_pos> >
+{
+ typedef KoCompositeOpBase< Traits, KoCompositeOpCopyChannel<Traits,channel_pos> > base_class;
+ typedef typename Traits::channels_type channels_type;
+ typedef typename KoColorSpaceMathsTraits<channels_type>::compositetype composite_type;
+
+ static const qint32 alpha_pos = Traits::alpha_pos;
+
+public:
+ KoCompositeOpCopyChannel(const KoColorSpace* cs, const QString& id, const QString& description, const QString& category, bool userVisible=true)
+ : base_class(cs, id, description, category, userVisible) { }
+
+public:
+ template<bool alphaLocked, bool allChannelFlags>
+ inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,
+ channels_type* dst, channels_type dstAlpha,
+ channels_type opacity, const QBitArray& channelFlags) {
+ if(channel_pos == alpha_pos)
+ return lerp(dstAlpha, srcAlpha, opacity);
+
+ dst[channel_pos] = lerp(dst[channel_pos], src[channel_pos], opacity);
+ return dstAlpha;
+ }
+};
+
+#endif // _KOCOMPOSITEO_COPY_CHANNEL_H_
diff --git a/libs/pigment/compositeops/KoCompositeOpFunctions.h b/libs/pigment/compositeops/KoCompositeOpFunctions.h
index 7f1fa7a..a6ec380 100644
--- a/libs/pigment/compositeops/KoCompositeOpFunctions.h
+++ b/libs/pigment/compositeops/KoCompositeOpFunctions.h
@@ -370,6 +370,26 @@ inline T cfEquivalence(T src, T dst) {
}
template<class T>
+inline T cfGrainMerge(T src, T dst) {
+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
+ return clamp<T>(composite_type(dst) + src - KoColorSpaceMathsTraits<T>::halfValue);
+}
+
+template<class T>
+inline T cfGrainExtract(T src, T dst) {
+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
+ return clamp<T>(composite_type(dst) - src + KoColorSpaceMathsTraits<T>::halfValue);
+}
+
+template<class T>
+inline T cfHardMix(T src, T dst) {
+ if(dst > KoColorSpaceMathsTraits<T>::halfValue)
+ return cfColorDodge(src, dst);
+
+ return cfColorBurn(src, dst);
+}
+
+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/KoCompositeOps.h b/libs/pigment/compositeops/KoCompositeOps.h
index d00f2d1..e514e35 100644
--- a/libs/pigment/compositeops/KoCompositeOps.h
+++ b/libs/pigment/compositeops/KoCompositeOps.h
@@ -27,6 +27,7 @@
#include "KoColorSpaceTraits.h"
#include "compositeops/KoCompositeOpGeneric.h"
+#include "compositeops/KoCompositeOpCopyChannel.h"
#include "compositeops/KoCompositeOpAlphaDarken.h"
#include "compositeops/KoCompositeOpErase.h"
#include "compositeops/KoCompositeOpCopy2.h"
@@ -63,11 +64,14 @@ struct AddGeneralOps<Traits, true>
}
static void add(KoColorSpace* cs) {
+ cs->addCompositeOp(new KoCompositeOpOver<Traits>(cs));
cs->addCompositeOp(new KoCompositeOpAlphaDarken<Traits>(cs));
cs->addCompositeOp(new KoCompositeOpCopy2<Traits>(cs));
cs->addCompositeOp(new KoCompositeOpErase<Traits>(cs));
- add<&cfOver>(cs, COMPOSITE_OVER, i18n("Normal"), KoCompositeOp::categoryMix());
+ add<&cfGrainMerge> (cs, COMPOSITE_GRAIN_MERGE , i18n("Grain Merge") , KoCompositeOp::categoryMix());
+ add<&cfGrainExtract>(cs, COMPOSITE_GRAIN_EXTRACT, i18n("Grain Extract"), KoCompositeOp::categoryMix());
+ add<&cfHardMix> (cs, COMPOSITE_HARD_MIX , i18n("Hard Mix") , KoCompositeOp::categoryMix());
add<&cfColorBurn> (cs, COMPOSITE_BURN , i18n("Color Burn") , KoCompositeOp::categoryLight());
add<&cfColorDodge> (cs, COMPOSITE_DODGE , i18n("Color Dodge") , KoCompositeOp::categoryLight());
@@ -102,22 +106,34 @@ struct AddGeneralOps<Traits, true>
};
template<class Traits, bool flag>
-struct AddHSLOps
+struct AddRGBOps
{
static void add(KoColorSpace* cs) { Q_UNUSED(cs); }
};
template<class Traits>
-struct AddHSLOps<Traits, true>
+struct AddRGBOps<Traits, true>
{
typedef float Arg;
+ static const qint32 red_pos = Traits::red_pos;
+ static const qint32 green_pos = Traits::green_pos;
+ static const qint32 blue_pos = Traits::blue_pos;
+ static const qint32 alpha_pos = Traits::alpha_pos;
+
template<void compositeFunc(Arg, Arg, Arg, Arg&, Arg&, Arg&)>
static void add(KoColorSpace* cs, const QString& id, const QString& description, const QString& category, bool userVisible=true) {
cs->addCompositeOp(new KoCompositeOpGenericHSL<Traits, compositeFunc>(cs, id, description, category, userVisible));
}
static void add(KoColorSpace* cs) {
+ cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,red_pos >(cs, COMPOSITE_COPY_RED , i18n("Copy Red") , KoCompositeOp::categoryMisc()));
+ cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,green_pos>(cs, COMPOSITE_COPY_GREEN, i18n("Copy Green"), KoCompositeOp::categoryMisc()));
+ cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,blue_pos >(cs, COMPOSITE_COPY_BLUE , i18n("Copy Blue") , KoCompositeOp::categoryMisc()));
+
+ if(alpha_pos != -1)
+ cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,alpha_pos>(cs, COMPOSITE_COPY_OPACITY, i18n("Copy Alpha") , KoCompositeOp::categoryMisc()));
+
add<&cfColor>(cs, COMPOSITE_COLOR, i18n("Color"), KoCompositeOp::categoryColor());
add<&cfHue> (cs, COMPOSITE_HUE , i18n("Hue") , KoCompositeOp::categoryColor());
@@ -159,7 +175,7 @@ void addStandardCompositeOps(KoColorSpace* cs)
static const bool useHSLOps = boost::is_base_of<KoRgbTraits<channels_type>, _Traits_>::value;
Private::AddGeneralOps<_Traits_, useGeneralOps>::add(cs);
- Private::AddHSLOps <_Traits_, useHSLOps >::add(cs);
+ Private::AddRGBOps <_Traits_, useHSLOps >::add(cs);
}
#endif
--
1.7.1
More information about the kimageshop
mailing list