summaryrefslogtreecommitdiffstats
path: root/kjsembed/plugins/imagefx_plugin.h
blob: 7e1f10d0fc1d595ff3bca4ff57b27a87c07ce2e2 (plain)
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
128
129
130
// -*- c++ -*-

/*
 *  Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library 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 KJSEMBED_IMAGEFX_PLUGIN_H
#define KJSEMBED_IMAGEFX_PLUGIN_H

#include <kjsembed/jsbindingplugin.h>
#include <kjsembed/jsproxy_imp.h>
#include <kimageeffect.h>

#include <tqimage.h>

namespace KJSEmbed {
namespace Bindings {

class ImageFXLoader : public JSBindingPlugin
{
public:
    ImageFXLoader( TTQObject *parent, const char *name, const TTQStringList &args );
    KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const;
};
enum BumpmapType {
Linear,
Spherical,
Sinuosidal
};

class ImageFX : JSProxyImp
{
	
	/** Identifiers for the methods provided by this class. */
	enum MethodId {
	// Image effects 
	Methodgradient,
	MethodunbalancedGradient, MethodblendColor,MethodblendImage,
	MethodcomputeDestinationRect, MethodchannelIntensity, Methodfade,
	Methodflatten, Methodhash, Methodintensity, Methodmodulate, MethodtoGray,
	Methoddesaturate, Methoddither, MethodselectedImage, MethodcontrastHSV,
	Methodnormalize, Methodequalize, Methodthreshold, Methodsolarize,
	Methodemboss, Methoddespeckle, Methodcharcoal, Methodcharcoal2,
	Methodrotate, Methodsample, MethodaddNoise, Methodblur, Methodedge,
	Methodimplode, MethodoilPaintConvolve, MethodoilPaint, Methodsharpen,
	Methodsharpen2, Methodspread, Methodshade, Methodswirl, Methodwave,
	Methodcontrast, MethodbumpMap 
	};
	
	public:
		ImageFX( KJS::ExecState *exec, int id );
		virtual ~ImageFX();
		
		static void addBindings( KJS::ExecState *exec, KJS::Object &object );
		
		/** Returns true iff this object implements the call function. */
		virtual bool implementsCall() const { return true; }
		
		/** Invokes the call function. */
		virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args );
	
	private:
		// Image effects
		void gradient(const TTQSize &size, const TTQColor &ca, const TTQColor &cb, KImageEffect::GradientType type, int ncols);
		void unbalancedGradient(const TTQSize &size, const TTQColor &ca,const TTQColor &cb, KImageEffect::GradientType type, int xfactor,int yfactor, int ncols);
		void blendColor(const TTQColor& clr, float opacity);
		void blendImage(TTQImage& blendImage, float opacity);
		TTQRect computeDestinationRect(const TTQSize &lowerSize,KImageEffect::Disposition disposition);
		
		void channelIntensity(float percent,KImageEffect::RGBComponent channel);
		void fade(float val, const TTQColor &color);
		void flatten(const TTQColor &ca,const TTQColor &cb, int ncols);
		void hash(KImageEffect::Lighting lite,uint spacing);
		void intensity(float percent);
		void modulate(TTQImage &modImage, bool reverse,KImageEffect::ModulationType type, int factor, KImageEffect::RGBComponent channel);
		void toGray(bool fast);
		void desaturate(float desat);
		void contrast(int c);
		void dither(const TTQColor *palette, int size);
		void selectedImage(  const TTQColor &col );
		void contrastHSV( bool sharpen);
		void normalize();
		void equalize();
		void threshold( uint value);
		void solarize( double factor);
		void emboss(double radius, double sigma);
		//void emboss();
		void despeckle();
		void charcoal(double radius, double sigma);
		void charcoal(double factor);
		void rotate(KImageEffect::RotateDirection r);
		void sample(int w, int h);
		void addNoise(KImageEffect::NoiseType type);
		void blur(double radius, double sigma);
		void edge(double radius);
		void implode(double factor, uint background );
		void oilPaintConvolve(double radius);
		void oilPaint(int radius);
		void sharpen(double radius, double sigma);
		void sharpen(double factor);
		void spread(uint amount);
		void shade(bool color_shading, double azimuth,double elevation);
		void swirl(double degrees, uint background);
		void wave(double amplitude, double frequency,uint background);
		
		TTQImage bumpmap(TTQImage &img, TTQImage &map, double azimuth=135.0, double elevation=45.0, int depth=3, int xofs=0, int yofs=0, int waterlevel=0, int ambient=0, bool compensate=false, bool invert=false, BumpmapType type=Linear, bool tiled=false);
			
		int mid;
};


} // namespace
} // namespace

#endif // KJSEMBED_IMAGEFX_PLUGIN_H