File: linear-sharpen-effect.diff

package info (click to toggle)
kolourpaint 4%3A18.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,544 kB
  • sloc: cpp: 37,589; xml: 327; sh: 10; makefile: 6
file content (150 lines) | stat: -rw-r--r-- 4,552 bytes parent folder | download | duplicates (7)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Changes the "Sharpen" effect to Blitz::sharpen() instead of
Blitz::gaussianSharpen(), in order to avoid parameters that are currently
set in a dangerously adhoc fashion (radius, sigma, repeat).

Unfortunately, the results do not look good.

2007-08-14 20:35


Index: imagelib/effects/kpEffectBlurSharpen.cpp
===================================================================
--- imagelib/effects/kpEffectBlurSharpen.cpp	(revision 699849)
+++ imagelib/effects/kpEffectBlurSharpen.cpp	(working copy)
@@ -26,7 +26,7 @@
 */
 
 
-#define DEBUG_KP_EFFECT_BLUR_SHARPEN 0
+#define DEBUG_KP_EFFECT_BLUR_SHARPEN 1
 
 
 #include <kpEffectBlurSharpen.h>
@@ -46,18 +46,10 @@
 #endif
 
 
-static QImage BlurQImage (const QImage qimage_, int strength)
+static int RadiusForStrength (int strength)
 {
-    QImage qimage = qimage_;
-    if (strength == 0)
-        return qimage;
-
-
-    // The numbers that follow were picked by experimentation to try to get
-    // an effect linearly proportional to <strength> and at the same time,
-    // be fast enough.
-    //
-    // I still have no idea what "radius" means.
+    // (must be in range and not 0)
+    Q_ASSERT (strength > 0 && strength <= kpEffectBlurSharpen::MaxStrength);
 
     const double RadiusMin = 1;
     const double RadiusMax = 10;
@@ -67,92 +59,36 @@ static QImage BlurQImage (const QImage q
         (kpEffectBlurSharpen::MaxStrength - 1);
 
 #if DEBUG_KP_EFFECT_BLUR_SHARPEN
-    kDebug () << "kpEffectBlurSharpen.cpp:BlurQImage(strength=" << strength << ")"
+    kDebug () << "kpEffectBlurSharpen.cpp:RadiusForStrength(strength=" << strength << ")"
                << " radius=" << radius
                << endl;
 #endif
 
-
-    qimage = Blitz::blur (qimage, qRound (radius));
-
-
-    return qimage;
+    return qRound (radius);
 }
 
-static QImage SharpenQImage (const QImage &qimage_, int strength)
+
+static QImage BlurQImage (const QImage qimage_, int strength)
 {
     QImage qimage = qimage_;
     if (strength == 0)
         return qimage;
 
 
-    // The numbers that follow were picked by experimentation to try to get
-    // an effect linearly proportional to <strength> and at the same time,
-    // be fast enough.
-    //
-    // I still have no idea what "radius" and "sigma" mean.
-
-    const double RadiusMin = .1;
-    const double RadiusMax = 2.5;
-    const double radius = RadiusMin +
-       (strength - 1) *
-       (RadiusMax - RadiusMin) /
-       (kpEffectBlurSharpen::MaxStrength - 1);
-
-    const double SigmaMin = .5;
-    const double SigmaMax = 3.0;
-    const double sigma = SigmaMin +
-        (strength - 1) *
-        (SigmaMax - SigmaMin) /
-        (kpEffectBlurSharpen::MaxStrength - 1);
-
-    const double RepeatMin = 1;
-    const double RepeatMax = 2;
-    const double repeat = qRound (RepeatMin +
-        (strength - 1) *
-        (RepeatMax - RepeatMin) /
-        (kpEffectBlurSharpen::MaxStrength - 1));
+    qimage = Blitz::blur (qimage, ::RadiusForStrength (strength));
 
-// I guess these values are more proper as they use an auto-calculated
-// radius but they cause sharpen() to be too slow.
-#if 0
-    const double radius = 0/*auto-calculate*/;
-
-    const double SigmaMin = .6;
-    const double SigmaMax = 1.0;
-    const double sigma = SigmaMin +
-        (strength - 1) *
-        (SigmaMax - SigmaMin) /
-        (kpEffectBlurSharpen::MaxStrength - 1);
 
-    const double RepeatMin = 1;
-    const double RepeatMax = 3;
-    const double repeat = qRound (RepeatMin +
-        (strength - 1) *
-        (RepeatMax - RepeatMin) /
-        (kpEffectBlurSharpen::MaxStrength - 1));
-#endif
+    return qimage;
+}
 
-#if DEBUG_KP_EFFECT_BLUR_SHARPEN
-    kDebug () << "kpEffectBlurSharpen.cpp:SharpenQImage(strength=" << strength << ")"
-               << " radius=" << radius
-               << " sigma=" << sigma
-               << " repeat=" << repeat
-               << endl;
-#endif
+static QImage SharpenQImage (const QImage &qimage_, int strength)
+{
+    QImage qimage = qimage_;
+    if (strength == 0)
+        return qimage;
 
 
-    for (int i = 0; i < repeat; i++)
-    {
-    #if DEBUG_KP_EFFECT_BLUR_SHARPEN
-	QTime timer; timer.start ();
-    #endif
-        qimage = Blitz::gaussianSharpen (qimage, radius, sigma);
-    #if DEBUG_KP_EFFECT_BLUR_SHARPEN
-        kDebug () << "\titeration #" + QString::number (i)
-                  << ": " + QString::number (timer.elapsed ()) << "ms" << endl;
-    #endif
-    }
+    qimage = Blitz::sharpen (qimage, ::RadiusForStrength (strength) * 10);
 
 
     return qimage;