1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/* This file is part of the KDE project
* Copyright (c) 2009 Jan Hambrecht <jaham@gmx.net>
*
* 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.1 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
* Library 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 COMPONENTTRANSFEREFFECT_H
#define COMPONENTTRANSFEREFFECT_H
#include "KoFilterEffect.h"
#define ComponentTransferEffectId "feComponentTransfer"
/// A component transfer effect
class ComponentTransferEffect : public KoFilterEffect
{
public:
/// the different transfer functions
enum Function {
Identity,
Table,
Discrete,
Linear,
Gamma
};
/// the different color channels
enum Channel {
ChannelR,
ChannelG,
ChannelB,
ChannelA
};
ComponentTransferEffect();
/// Returns the component transfer function of the specified channel
Function function(Channel channel) const;
/// Sets the component transfer function to use for the specified channel
void setFunction(Channel channel, Function function);
/// Returns the lookup table for the specified channel
QList<qreal> tableValues(Channel channel) const;
/// Sets the lookup table for the specified channel
void setTableValues(Channel channel, QList<qreal> tableValues);
/// Sets the slope for the specified channel
void setSlope(Channel channel, qreal slope);
/// Returns the slope for the specified channel
qreal slope(Channel channel) const;
/// Sets the intercept for the specified channel
void setIntercept(Channel channel, qreal intercept);
/// Returns the intercept for the specified channel
qreal intercept(Channel channel) const;
/// Sets the amplitude for the specified channel
void setAmplitude(Channel channel, qreal amplitude);
/// Returns the amplitude for the specified channel
qreal amplitude(Channel channel) const;
/// Sets the exponent for the specified channel
void setExponent(Channel channel, qreal exponent);
/// Returns the exponent for the specified channel
qreal exponent(Channel channel) const;
/// Sets the offset for the specified channel
void setOffset(Channel channel, qreal offset);
/// Returns the offset for the specified channel
qreal offset(Channel channel) const;
/// reimplemented from KoFilterEffect
QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override;
/// reimplemented from KoFilterEffect
bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override;
/// reimplemented from KoFilterEffect
void save(KoXmlWriter &writer) override;
private:
/// loads channel transfer function from given xml element
void loadChannel(Channel channel, const KoXmlElement &element);
/// saves channel transfer function to given xml writer
void saveChannel(Channel channel, KoXmlWriter &writer);
/// transfers color channel
qreal transferChannel(Channel channel, qreal value) const;
struct Data {
Data()
: function(Identity), slope(1.0), intercept(0.0)
, amplitude(1.0), exponent(1.0), offset(0.0) {
}
Function function; ///< the component transfer function
QList<qreal> tableValues; ///< lookup table for table or discrete function
qreal slope; ///< slope for linear function
qreal intercept; ///< intercept for linear function
qreal amplitude; ///< amplitude for gamma function
qreal exponent; ///< exponent for gamma function
qreal offset; ///< offset for gamma function
};
Data m_data[4];
};
#endif // COMPONENTTRANSFEREFFECT_H
|