File indexing completed on 2024-05-12 16:34:28
0001 /* This file is part of the KDE project 0002 * Copyright (c) 2009 Jan Hambrecht <jaham@gmx.net> 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 * Library 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 #ifndef COMPONENTTRANSFEREFFECT_H 0021 #define COMPONENTTRANSFEREFFECT_H 0022 0023 #include "KoFilterEffect.h" 0024 0025 #define ComponentTransferEffectId "feComponentTransfer" 0026 0027 /// A component transfer effect 0028 class ComponentTransferEffect : public KoFilterEffect 0029 { 0030 public: 0031 /// the different transfer functions 0032 enum Function { 0033 Identity, 0034 Table, 0035 Discrete, 0036 Linear, 0037 Gamma 0038 }; 0039 0040 /// the different color channels 0041 enum Channel { 0042 ChannelR, 0043 ChannelG, 0044 ChannelB, 0045 ChannelA 0046 }; 0047 0048 ComponentTransferEffect(); 0049 0050 /// Returns the component transfer function of the specified channel 0051 Function function(Channel channel) const; 0052 0053 /// Sets the component transfer function to use for the specified channel 0054 void setFunction(Channel channel, Function function); 0055 0056 /// Returns the lookup table for the specified channel 0057 QList<qreal> tableValues(Channel channel) const; 0058 0059 /// Sets the lookup table for the specified channel 0060 void setTableValues(Channel channel, QList<qreal> tableValues); 0061 0062 /// Sets the slope for the specified channel 0063 void setSlope(Channel channel, qreal slope); 0064 0065 /// Returns the slope for the specified channel 0066 qreal slope(Channel channel) const; 0067 0068 /// Sets the intercept for the specified channel 0069 void setIntercept(Channel channel, qreal intercept); 0070 0071 /// Returns the intercept for the specified channel 0072 qreal intercept(Channel channel) const; 0073 0074 /// Sets the amplitude for the specified channel 0075 void setAmplitude(Channel channel, qreal amplitude); 0076 0077 /// Returns the amplitude for the specified channel 0078 qreal amplitude(Channel channel) const; 0079 0080 /// Sets the exponent for the specified channel 0081 void setExponent(Channel channel, qreal exponent); 0082 0083 /// Returns the exponent for the specified channel 0084 qreal exponent(Channel channel) const; 0085 0086 /// Sets the offset for the specified channel 0087 void setOffset(Channel channel, qreal offset); 0088 0089 /// Returns the offset for the specified channel 0090 qreal offset(Channel channel) const; 0091 0092 /// reimplemented from KoFilterEffect 0093 QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; 0094 /// reimplemented from KoFilterEffect 0095 bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; 0096 /// reimplemented from KoFilterEffect 0097 void save(KoXmlWriter &writer) override; 0098 0099 private: 0100 /// loads channel transfer function from given xml element 0101 void loadChannel(Channel channel, const KoXmlElement &element); 0102 0103 /// saves channel transfer function to given xml writer 0104 void saveChannel(Channel channel, KoXmlWriter &writer); 0105 0106 /// transfers color channel 0107 qreal transferChannel(Channel channel, qreal value) const; 0108 0109 struct Data { 0110 Data() 0111 : function(Identity), slope(1.0), intercept(0.0) 0112 , amplitude(1.0), exponent(1.0), offset(0.0) { 0113 } 0114 0115 Function function; ///< the component transfer function 0116 QList<qreal> tableValues; ///< lookup table for table or discrete function 0117 qreal slope; ///< slope for linear function 0118 qreal intercept; ///< intercept for linear function 0119 qreal amplitude; ///< amplitude for gamma function 0120 qreal exponent; ///< exponent for gamma function 0121 qreal offset; ///< offset for gamma function 0122 }; 0123 0124 Data m_data[4]; 0125 }; 0126 0127 #endif // COMPONENTTRANSFEREFFECT_H