add url
[kdegraphics.git] / kolourpaint / patches / linear-sharpen-effect.diff
blob605852f057c6fc5e8ddb5bc08c7be4d7a35068e1
1 Changes the "Sharpen" effect to Blitz::sharpen() instead of
2 Blitz::gaussianSharpen(), in order to avoid parameters that are currently
3 set in a dangerously adhoc fashion (radius, sigma, repeat).
5 Unfortunately, the results do not look good.
7 2007-08-14 20:35
10 Index: imagelib/effects/kpEffectBlurSharpen.cpp
11 ===================================================================
12 --- imagelib/effects/kpEffectBlurSharpen.cpp (revision 699849)
13 +++ imagelib/effects/kpEffectBlurSharpen.cpp (working copy)
14 @@ -26,7 +26,7 @@
18 -#define DEBUG_KP_EFFECT_BLUR_SHARPEN 0
19 +#define DEBUG_KP_EFFECT_BLUR_SHARPEN 1
22 #include <kpEffectBlurSharpen.h>
23 @@ -46,18 +46,10 @@
24 #endif
27 -static QImage BlurQImage (const QImage qimage_, int strength)
28 +static int RadiusForStrength (int strength)
30 - QImage qimage = qimage_;
31 - if (strength == 0)
32 - return qimage;
35 - // The numbers that follow were picked by experimentation to try to get
36 - // an effect linearly proportional to <strength> and at the same time,
37 - // be fast enough.
38 - //
39 - // I still have no idea what "radius" means.
40 + // (must be in range and not 0)
41 + Q_ASSERT (strength > 0 && strength <= kpEffectBlurSharpen::MaxStrength);
43 const double RadiusMin = 1;
44 const double RadiusMax = 10;
45 @@ -67,92 +59,36 @@ static QImage BlurQImage (const QImage q
46 (kpEffectBlurSharpen::MaxStrength - 1);
48 #if DEBUG_KP_EFFECT_BLUR_SHARPEN
49 - kDebug () << "kpEffectBlurSharpen.cpp:BlurQImage(strength=" << strength << ")"
50 + kDebug () << "kpEffectBlurSharpen.cpp:RadiusForStrength(strength=" << strength << ")"
51 << " radius=" << radius
52 << endl;
53 #endif
56 - qimage = Blitz::blur (qimage, qRound (radius));
59 - return qimage;
60 + return qRound (radius);
63 -static QImage SharpenQImage (const QImage &qimage_, int strength)
65 +static QImage BlurQImage (const QImage qimage_, int strength)
67 QImage qimage = qimage_;
68 if (strength == 0)
69 return qimage;
72 - // The numbers that follow were picked by experimentation to try to get
73 - // an effect linearly proportional to <strength> and at the same time,
74 - // be fast enough.
75 - //
76 - // I still have no idea what "radius" and "sigma" mean.
78 - const double RadiusMin = .1;
79 - const double RadiusMax = 2.5;
80 - const double radius = RadiusMin +
81 - (strength - 1) *
82 - (RadiusMax - RadiusMin) /
83 - (kpEffectBlurSharpen::MaxStrength - 1);
85 - const double SigmaMin = .5;
86 - const double SigmaMax = 3.0;
87 - const double sigma = SigmaMin +
88 - (strength - 1) *
89 - (SigmaMax - SigmaMin) /
90 - (kpEffectBlurSharpen::MaxStrength - 1);
92 - const double RepeatMin = 1;
93 - const double RepeatMax = 2;
94 - const double repeat = qRound (RepeatMin +
95 - (strength - 1) *
96 - (RepeatMax - RepeatMin) /
97 - (kpEffectBlurSharpen::MaxStrength - 1));
98 + qimage = Blitz::blur (qimage, ::RadiusForStrength (strength));
100 -// I guess these values are more proper as they use an auto-calculated
101 -// radius but they cause sharpen() to be too slow.
102 -#if 0
103 - const double radius = 0/*auto-calculate*/;
105 - const double SigmaMin = .6;
106 - const double SigmaMax = 1.0;
107 - const double sigma = SigmaMin +
108 - (strength - 1) *
109 - (SigmaMax - SigmaMin) /
110 - (kpEffectBlurSharpen::MaxStrength - 1);
112 - const double RepeatMin = 1;
113 - const double RepeatMax = 3;
114 - const double repeat = qRound (RepeatMin +
115 - (strength - 1) *
116 - (RepeatMax - RepeatMin) /
117 - (kpEffectBlurSharpen::MaxStrength - 1));
118 -#endif
119 + return qimage;
122 -#if DEBUG_KP_EFFECT_BLUR_SHARPEN
123 - kDebug () << "kpEffectBlurSharpen.cpp:SharpenQImage(strength=" << strength << ")"
124 - << " radius=" << radius
125 - << " sigma=" << sigma
126 - << " repeat=" << repeat
127 - << endl;
128 -#endif
129 +static QImage SharpenQImage (const QImage &qimage_, int strength)
131 + QImage qimage = qimage_;
132 + if (strength == 0)
133 + return qimage;
136 - for (int i = 0; i < repeat; i++)
138 - #if DEBUG_KP_EFFECT_BLUR_SHARPEN
139 - QTime timer; timer.start ();
140 - #endif
141 - qimage = Blitz::gaussianSharpen (qimage, radius, sigma);
142 - #if DEBUG_KP_EFFECT_BLUR_SHARPEN
143 - kDebug () << "\titeration #" + QString::number (i)
144 - << ": " + QString::number (timer.elapsed ()) << "ms" << endl;
145 - #endif
147 + qimage = Blitz::sharpen (qimage, ::RadiusForStrength (strength) * 10);
150 return qimage;