Commit 07068513 authored by Silvio Heinrich's avatar Silvio Heinrich

Adding a new composite(...) method to KoCompositeOp that takes a parameter structure...

...instead of single parameters.
parent 06275f19
......@@ -250,6 +250,28 @@ KoCompositeOp::KoCompositeOp(const KoColorSpace * cs, const QString& id, const
}
}
void KoCompositeOp::composite(quint8 *dstRowStart, qint32 dstRowStride,
const quint8 *srcRowStart, qint32 srcRowStride,
const quint8 *maskRowStart, qint32 maskRowStride,
qint32 rows, qint32 numColumns,
quint8 opacity, quint8 flow, const QBitArray& channelFlags) const
{
KoCompositeOp::ParameterInfo params;
params.dstRowStart = dstRowStart;
params.dstRowStride = dstRowStride;
params.srcRowStart = srcRowStart;
params.srcRowStride = srcRowStride;
params.maskRowStart = maskRowStart;
params.maskRowStride = maskRowStride;
params.rows = rows;
params.cols = numColumns;
params.opacity = opacity;
params.opacity2 = 255;
params.flow = flow;
params.channelFlags = channelFlags;
composite(params);
}
void KoCompositeOp::composite(quint8 *dstRowStart, qint32 dstRowStride,
const quint8 *srcRowStart, qint32 srcRowStride,
const quint8 *maskRowStart, qint32 maskRowStride,
......@@ -263,19 +285,16 @@ void KoCompositeOp::composite(quint8 *dstRowStart, qint32 dstRowStride,
opacity, 255, channelFlags);
}
void KoCompositeOp::composite(quint8 *dstRowStart, qint32 dstRowStride,
const quint8 *srcRowStart, qint32 srcRowStride,
const quint8 *maskRowStart, qint32 maskRowStride,
qint32 rows, qint32 numColumns,
quint8 opacity, quint8 flow, const QBitArray& channelFlags) const
void KoCompositeOp::composite(const KoCompositeOp::ParameterInfo& params) const
{
composite(dstRowStart, dstRowStride,
srcRowStart, srcRowStride,
maskRowStart, maskRowStride,
rows, numColumns,
opacity, channelFlags);
composite(params.dstRowStart , params.dstRowStride ,
params.srcRowStart , params.srcRowStride ,
params.maskRowStart, params.maskRowStride,
params.rows , params.cols ,
params.opacity , params.channelFlags );
}
QString KoCompositeOp::category() const
{
return d->category;
......
/*
* Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
* Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
* Copyright (c) 2011 Silvio Heinrich <plassy@web.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -181,6 +182,22 @@ public:
static QString categoryMix();
static QString categoryMisc();
struct PIGMENTCMS_EXPORT ParameterInfo
{
quint8* dstRowStart;
qint32 dstRowStride;
const quint8* srcRowStart;
qint32 srcRowStride;
const quint8* maskRowStart;
qint32 maskRowStride;
qint32 rows;
qint32 cols;
quint8 opacity;
quint8 opacity2;
quint8 flow;
QBitArray channelFlags;
};
public:
/**
......@@ -250,6 +267,11 @@ public:
qint32 rows, qint32 numColumns,
quint8 opacity,
const QBitArray& channelFlags=QBitArray()) const;
/**
* Same as previous, but uses a parameter structure
*/
virtual void composite(const ParameterInfo& params) const;
private:
KoCompositeOp();
......
......@@ -53,49 +53,46 @@ public:
using KoCompositeOp::composite;
virtual void composite(quint8* dstRowStart , qint32 dstRowStride ,
const quint8* srcRowStart , qint32 srcRowStride ,
const quint8* maskRowStart, qint32 maskRowStride,
qint32 rows, qint32 cols, quint8 U8_opacity, quint8 U8_flow, const QBitArray& channelFlags) const {
virtual void composite(const KoCompositeOp::ParameterInfo& params) const {
const QBitArray& flags = channelFlags.isEmpty() ? QBitArray(channels_nb,true) : channelFlags;
bool allChannelFlags = channelFlags.isEmpty() || channelFlags == QBitArray(channels_nb,true);
const QBitArray& flags = params.channelFlags.isEmpty() ? QBitArray(channels_nb,true) : params.channelFlags;
bool allChannelFlags = params.channelFlags.isEmpty() || params.channelFlags == QBitArray(channels_nb,true);
bool alphaLocked = (alpha_pos != -1) && !flags.testBit(alpha_pos);
if(alphaLocked) {
if(allChannelFlags)
genericComposite<true,true>(dstRowStart, dstRowStride, srcRowStart, srcRowStride, maskRowStart, maskRowStride, rows, cols, U8_opacity, U8_flow, flags);
genericComposite<true,true>(params, flags);
else
genericComposite<true,false>(dstRowStart, dstRowStride, srcRowStart, srcRowStride, maskRowStart, maskRowStride, rows, cols, U8_opacity, U8_flow, flags);
genericComposite<true,false>(params, flags);
}
else {
if(allChannelFlags)
genericComposite<false,true>(dstRowStart, dstRowStride, srcRowStart, srcRowStride, maskRowStart, maskRowStride, rows, cols, U8_opacity, U8_flow, flags);
genericComposite<false,true>(params, flags);
else
genericComposite<false,false>(dstRowStart, dstRowStride, srcRowStart, srcRowStride, maskRowStart, maskRowStride, rows, cols, U8_opacity, U8_flow, flags);
genericComposite<false,false>(params, flags);
}
}
private:
template<bool alphaLocked, bool allChannelFlags>
void genericComposite(quint8* dstRowStart , qint32 dstRowStride ,
const quint8* srcRowStart , qint32 srcRowStride ,
const quint8* maskRowStart, qint32 maskRowStride,
qint32 rows, qint32 cols, quint8 U8_opacity, quint8 U8_flow, const QBitArray& channelFlags) const {
void genericComposite(const KoCompositeOp::ParameterInfo& params, const QBitArray& channelFlags) const {
using namespace Arithmetic;
qint32 srcInc = (srcRowStride == 0) ? 0 : channels_nb;
bool useMask = maskRowStart != 0;
channels_type flow = scale<channels_type>(U8_flow);
channels_type opacity = mul(scale<channels_type>(U8_opacity), flow);
qint32 srcInc = (params.srcRowStride == 0) ? 0 : channels_nb;
bool useMask = params.maskRowStart != 0;
channels_type flow = scale<channels_type>(params.flow);
channels_type opacity = mul(scale<channels_type>(params.opacity), flow);
quint8* dstRowStart = params.dstRowStart;
const quint8* srcRowStart = params.srcRowStart;
const quint8* maskRowStart = params.maskRowStart;
for(; rows>0; --rows) {
for(qint32 r=0; r<params.rows; ++r) {
const channels_type* src = reinterpret_cast<const channels_type*>(srcRowStart);
channels_type* dst = reinterpret_cast<channels_type*>(dstRowStart);
const quint8* mask = maskRowStart;
for(qint32 c=cols; c>0; --c) {
for(qint32 c=0; c<params.cols; ++c) {
channels_type srcAlpha = (alpha_pos == -1) ? unitValue<channels_type>() : src[alpha_pos];
channels_type dstAlpha = (alpha_pos == -1) ? unitValue<channels_type>() : dst[alpha_pos];
channels_type blend = useMask ? mul(opacity, scale<channels_type>(*mask)) : opacity;
......@@ -112,9 +109,9 @@ private:
++mask;
}
srcRowStart += srcRowStride;
dstRowStart += dstRowStride;
maskRowStart += maskRowStride;
srcRowStart += params.srcRowStride;
dstRowStart += params.dstRowStride;
maskRowStart += params.maskRowStride;
}
}
};
......
......@@ -65,9 +65,7 @@ public:
virtual void composite(quint8* dstRowStart , qint32 dstRowStride ,
const quint8* srcRowStart , qint32 srcRowStride ,
const quint8* maskRowStart, qint32 maskRowStride,
qint32 rows, qint32 cols, quint8 U8_opacity, quint8 U8_flow, const QBitArray& channelFlags) const {
Q_UNUSED(U8_flow);
qint32 rows, qint32 cols, quint8 U8_opacity, const QBitArray& channelFlags) const {
const QBitArray& flags = channelFlags.isEmpty() ? QBitArray(channels_nb,true) : channelFlags;
bool alphaLocked = (alpha_pos != -1) && !flags.testBit(alpha_pos);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment