Changeset View
Changeset View
Standalone View
Standalone View
imagelib/effects/kpEffectBlurSharpen.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
50 | // are weighted depending on how far the are from the center one. This is | 50 | // are weighted depending on how far the are from the center one. This is | ||
51 | // closer to strength, but not exactly >:) | 51 | // closer to strength, but not exactly >:) | ||
52 | // </quote> | 52 | // </quote> | ||
53 | // | 53 | // | ||
54 | 54 | | |||
55 | 55 | | |||
56 | static QImage BlurQImage(const QImage &qimage, int strength) | 56 | static QImage BlurQImage(const QImage &qimage, int strength) | ||
57 | { | 57 | { | ||
58 | if (strength == 0) | 58 | if (strength == 0) { | ||
59 | return qimage; | 59 | return qimage; | ||
60 | } | ||||
60 | 61 | | |||
61 | // The numbers that follow were picked by experimentation to try to get | 62 | // The numbers that follow were picked by experimentation to try to get | ||
62 | // an effect linearly proportional to <strength> and at the same time, | 63 | // an effect linearly proportional to <strength> and at the same time, | ||
63 | // be fast enough. | 64 | // be fast enough. | ||
64 | // | 65 | // | ||
65 | // I still have no idea what "radius" means. | 66 | // I still have no idea what "radius" means. | ||
66 | 67 | | |||
67 | const double RadiusMin = 1; | 68 | const double RadiusMin = 1; | ||
68 | const double RadiusMax = 10; | 69 | const double RadiusMax = 10; | ||
69 | const double radius = RadiusMin + | 70 | const double radius = RadiusMin + | ||
70 | (strength - 1) * | 71 | (strength - 1) * | ||
71 | (RadiusMax - RadiusMin) / | 72 | (RadiusMax - RadiusMin) / | ||
72 | (kpEffectBlurSharpen::MaxStrength - 1); | 73 | (kpEffectBlurSharpen::MaxStrength - 1); | ||
73 | 74 | | |||
74 | qCDebug(kpLogImagelib) << "kpEffectBlurSharpen.cpp:BlurQImage(strength=" << strength << ")" | 75 | qCDebug(kpLogImagelib) << "kpEffectBlurSharpen.cpp:BlurQImage(strength=" << strength << ")" | ||
75 | << " radius=" << radius | 76 | << " radius=" << radius; | ||
76 | << endl; | | |||
77 | 77 | | |||
78 | QImage img(qimage); | 78 | QImage img(qimage); | ||
79 | return Blitz::blur(img, qRound(radius)); | 79 | return Blitz::blur(img, qRound(radius)); | ||
80 | } | 80 | } | ||
81 | 81 | | |||
82 | //--------------------------------------------------------------------- | 82 | //--------------------------------------------------------------------- | ||
83 | 83 | | |||
84 | static QImage SharpenQImage (const QImage &qimage_, int strength) | 84 | static QImage SharpenQImage (const QImage &qimage_, int strength) | ||
85 | { | 85 | { | ||
86 | QImage qimage = qimage_; | 86 | QImage qimage = qimage_; | ||
87 | if (strength == 0) | 87 | if (strength == 0) { | ||
88 | return qimage; | 88 | return qimage; | ||
89 | } | ||||
89 | 90 | | |||
90 | 91 | | |||
91 | // The numbers that follow were picked by experimentation to try to get | 92 | // The numbers that follow were picked by experimentation to try to get | ||
92 | // an effect linearly proportional to <strength> and at the same time, | 93 | // an effect linearly proportional to <strength> and at the same time, | ||
93 | // be fast enough. | 94 | // be fast enough. | ||
94 | // | 95 | // | ||
95 | // I still have no idea what "radius" and "sigma" mean. | 96 | // I still have no idea what "radius" and "sigma" mean. | ||
96 | 97 | | |||
Show All 17 Lines | 114 | const double repeat = qRound (RepeatMin + | |||
114 | (strength - 1) * | 115 | (strength - 1) * | ||
115 | (RepeatMax - RepeatMin) / | 116 | (RepeatMax - RepeatMin) / | ||
116 | (kpEffectBlurSharpen::MaxStrength - 1)); | 117 | (kpEffectBlurSharpen::MaxStrength - 1)); | ||
117 | 118 | | |||
118 | 119 | | |||
119 | qCDebug(kpLogImagelib) << "kpEffectBlurSharpen.cpp:SharpenQImage(strength=" << strength << ")" | 120 | qCDebug(kpLogImagelib) << "kpEffectBlurSharpen.cpp:SharpenQImage(strength=" << strength << ")" | ||
120 | << " radius=" << radius | 121 | << " radius=" << radius | ||
121 | << " sigma=" << sigma | 122 | << " sigma=" << sigma | ||
122 | << " repeat=" << repeat | 123 | << " repeat=" << repeat; | ||
123 | << endl; | | |||
124 | 124 | | |||
125 | 125 | | |||
126 | for (int i = 0; i < repeat; i++) | 126 | for (int i = 0; i < repeat; i++) | ||
127 | { | 127 | { | ||
128 | QTime timer; timer.start (); | 128 | QTime timer; timer.start (); | ||
129 | qimage = Blitz::gaussianSharpen (qimage, static_cast<float> (radius), | 129 | qimage = Blitz::gaussianSharpen (qimage, static_cast<float> (radius), | ||
130 | static_cast<float> (sigma)); | 130 | static_cast<float> (sigma)); | ||
131 | qCDebug(kpLogImagelib) << "\titeration #" + QString::number (i) | 131 | qCDebug(kpLogImagelib) << "\titeration #" + QString::number (i) | ||
132 | << ": " + QString::number (timer.elapsed ()) << "ms" << endl; | 132 | << ": " + QString::number (timer.elapsed ()) << "ms"; | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | 135 | | |||
136 | return qimage; | 136 | return qimage; | ||
137 | } | 137 | } | ||
138 | 138 | | |||
139 | //--------------------------------------------------------------------- | 139 | //--------------------------------------------------------------------- | ||
140 | 140 | | |||
141 | // public static | 141 | // public static | ||
142 | kpImage kpEffectBlurSharpen::applyEffect (const kpImage &image, | 142 | kpImage kpEffectBlurSharpen::applyEffect (const kpImage &image, | ||
143 | Type type, int strength) | 143 | Type type, int strength) | ||
144 | { | 144 | { | ||
145 | qCDebug(kpLogImagelib) << "kpEffectBlurSharpen::applyEffect(image.rect=" << image.rect () | 145 | qCDebug(kpLogImagelib) << "kpEffectBlurSharpen::applyEffect(image.rect=" << image.rect () | ||
146 | << ",type=" << int (type) | 146 | << ",type=" << int (type) | ||
147 | << ",strength=" << strength | 147 | << ",strength=" << strength | ||
148 | << ")" << endl; | 148 | << ")"; | ||
149 | 149 | | |||
150 | Q_ASSERT (strength >= MinStrength && strength <= MaxStrength); | 150 | Q_ASSERT (strength >= MinStrength && strength <= MaxStrength); | ||
151 | 151 | | |||
152 | if (type == Blur) | 152 | if (type == Blur) { | ||
153 | return ::BlurQImage (image, strength); | 153 | return ::BlurQImage (image, strength); | ||
154 | else if (type == Sharpen) | 154 | } | ||
155 | | ||||
156 | if (type == Sharpen) { | ||||
155 | return ::SharpenQImage (image, strength); | 157 | return ::SharpenQImage (image, strength); | ||
156 | else if (type == MakeConfidential) | 158 | } | ||
157 | { | 159 | | ||
160 | if (type == MakeConfidential) { | ||||
158 | QImage img(image); | 161 | QImage img(image); | ||
159 | return Blitz::blur(img, qMin(20, img.width() / 2)); | 162 | return Blitz::blur(img, qMin(20, img.width() / 2)); | ||
160 | } | 163 | } | ||
161 | else | 164 | | ||
162 | return kpImage(); | 165 | return kpImage(); | ||
163 | } | 166 | } |