Warning, file /office/calligra/libs/pigment/KoCompositeOp.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoCompositeOp.h" 0021 0022 #include <klocalizedstring.h> 0023 #include <KoID.h> 0024 #include <QList> 0025 0026 #include "KoColorSpace.h" 0027 #include "KoColorSpaceMaths.h" 0028 0029 QString KoCompositeOp::categoryColor() 0030 { 0031 return i18n("Color"); 0032 } 0033 0034 QString KoCompositeOp::categoryArithmetic() { return i18n("Arithmetic"); } 0035 QString KoCompositeOp::categoryNegative() { return i18n("Negative"); } 0036 QString KoCompositeOp::categoryLight() { return i18n("Lighten"); } 0037 QString KoCompositeOp::categoryDark() { return i18n("Darken"); } 0038 QString KoCompositeOp::categoryHSY() { return i18n("HSY"); } 0039 QString KoCompositeOp::categoryHSI() { return i18n("HSI"); } 0040 QString KoCompositeOp::categoryHSL() { return i18n("HSL"); } 0041 QString KoCompositeOp::categoryHSV() { return i18n("HSV"); } 0042 QString KoCompositeOp::categoryMix() { return i18n("Mix"); } 0043 QString KoCompositeOp::categoryMisc() { return i18n("Misc"); } 0044 0045 KoCompositeOp::ParameterInfo::ParameterInfo() 0046 : opacity(1.0f), 0047 flow(1.0f), 0048 lastOpacity(&opacity) 0049 { 0050 } 0051 0052 KoCompositeOp::ParameterInfo::ParameterInfo(const ParameterInfo &rhs) 0053 { 0054 copy(rhs); 0055 } 0056 0057 KoCompositeOp::ParameterInfo& KoCompositeOp::ParameterInfo::operator=(const ParameterInfo &rhs) 0058 { 0059 copy(rhs); 0060 return *this; 0061 } 0062 0063 void KoCompositeOp::ParameterInfo::copy(const ParameterInfo &rhs) 0064 { 0065 dstRowStart = rhs.dstRowStart; 0066 dstRowStride = rhs.dstRowStride; 0067 srcRowStart = rhs.srcRowStart; 0068 srcRowStride = rhs.srcRowStride; 0069 maskRowStart = rhs.maskRowStart; 0070 maskRowStride = rhs.maskRowStride; 0071 rows = rhs.rows; 0072 cols = rhs.cols; 0073 opacity = rhs.opacity; 0074 flow = rhs.flow; 0075 _lastOpacityData = rhs._lastOpacityData; 0076 channelFlags = rhs.channelFlags; 0077 0078 lastOpacity = rhs.lastOpacity == &rhs.opacity ? 0079 &opacity : &_lastOpacityData; 0080 } 0081 0082 void KoCompositeOp::ParameterInfo::updateOpacityAndAverage(float value) { 0083 const float exponent = 0.1; 0084 0085 opacity = value; 0086 0087 if (*lastOpacity < opacity) { 0088 lastOpacity = &opacity; 0089 } else { 0090 _lastOpacityData = exponent * opacity + (1.0 - exponent) * (*lastOpacity); 0091 lastOpacity = &_lastOpacityData; 0092 } 0093 } 0094 0095 struct Q_DECL_HIDDEN KoCompositeOp::Private { 0096 const KoColorSpace * colorSpace; 0097 QString id; 0098 QString description; 0099 QString category; 0100 QBitArray defaultChannelFlags; 0101 }; 0102 0103 KoCompositeOp::KoCompositeOp() : d(new Private) 0104 { 0105 0106 } 0107 0108 KoCompositeOp::~KoCompositeOp() 0109 { 0110 delete d; 0111 } 0112 0113 KoCompositeOp::KoCompositeOp(const KoColorSpace * cs, const QString& id, const QString& description, const QString & category) 0114 : d(new Private) 0115 { 0116 d->colorSpace = cs; 0117 d->id = id; 0118 d->description = description; 0119 d->category = category; 0120 if (d->category.isEmpty()) { 0121 d->category = categoryMisc(); 0122 } 0123 } 0124 0125 void KoCompositeOp::composite(quint8 *dstRowStart, qint32 dstRowStride, 0126 const quint8 *srcRowStart, qint32 srcRowStride, 0127 const quint8 *maskRowStart, qint32 maskRowStride, 0128 qint32 rows, qint32 numColumns, 0129 quint8 opacity, const QBitArray& channelFlags) const 0130 { 0131 KoCompositeOp::ParameterInfo params; 0132 params.dstRowStart = dstRowStart; 0133 params.dstRowStride = dstRowStride; 0134 params.srcRowStart = srcRowStart; 0135 params.srcRowStride = srcRowStride; 0136 params.maskRowStart = maskRowStart; 0137 params.maskRowStride = maskRowStride; 0138 params.rows = rows; 0139 params.cols = numColumns; 0140 params.opacity = float(opacity) / 255.0f; 0141 params.flow = 1.0f; 0142 params.channelFlags = channelFlags; 0143 composite(params); 0144 } 0145 0146 void KoCompositeOp::composite(const KoCompositeOp::ParameterInfo& params) const 0147 { 0148 using namespace Arithmetic; 0149 0150 composite(params.dstRowStart , params.dstRowStride , 0151 params.srcRowStart , params.srcRowStride , 0152 params.maskRowStart , params.maskRowStride, 0153 params.rows , params.cols , 0154 scale<quint8>(params.opacity), params.channelFlags ); 0155 } 0156 0157 0158 QString KoCompositeOp::category() const 0159 { 0160 return d->category; 0161 } 0162 0163 QString KoCompositeOp::id() const 0164 { 0165 return d->id; 0166 } 0167 0168 QString KoCompositeOp::description() const 0169 { 0170 return d->description; 0171 } 0172 0173 const KoColorSpace * KoCompositeOp::colorSpace() const 0174 { 0175 return d->colorSpace; 0176 }