Warning, /graphics/kolourpaint/patches/linear-sharpen-effect.diff is written in an unsupported language. File is not indexed.

0001 Changes the "Sharpen" effect to Blitz::sharpen() instead of
0002 Blitz::gaussianSharpen(), in order to avoid parameters that are currently
0003 set in a dangerously adhoc fashion (radius, sigma, repeat).
0004 
0005 Unfortunately, the results do not look good.
0006 
0007 2007-08-14 20:35
0008 
0009 
0010 Index: imagelib/effects/kpEffectBlurSharpen.cpp
0011 ===================================================================
0012 --- imagelib/effects/kpEffectBlurSharpen.cpp    (revision 699849)
0013 +++ imagelib/effects/kpEffectBlurSharpen.cpp    (working copy)
0014 @@ -26,7 +26,7 @@
0015  */
0016  
0017  
0018 -#define DEBUG_KP_EFFECT_BLUR_SHARPEN 0
0019 +#define DEBUG_KP_EFFECT_BLUR_SHARPEN 1
0020  
0021  
0022  #include <kpEffectBlurSharpen.h>
0023 @@ -46,18 +46,10 @@
0024  #endif
0025  
0026  
0027 -static QImage BlurQImage (const QImage qimage_, int strength)
0028 +static int RadiusForStrength (int strength)
0029  {
0030 -    QImage qimage = qimage_;
0031 -    if (strength == 0)
0032 -        return qimage;
0033 -
0034 -
0035 -    // The numbers that follow were picked by experimentation to try to get
0036 -    // an effect linearly proportional to <strength> and at the same time,
0037 -    // be fast enough.
0038 -    //
0039 -    // I still have no idea what "radius" means.
0040 +    // (must be in range and not 0)
0041 +    Q_ASSERT (strength > 0 && strength <= kpEffectBlurSharpen::MaxStrength);
0042  
0043      const double RadiusMin = 1;
0044      const double RadiusMax = 10;
0045 @@ -67,92 +59,36 @@ static QImage BlurQImage (const QImage q
0046          (kpEffectBlurSharpen::MaxStrength - 1);
0047  
0048  #if DEBUG_KP_EFFECT_BLUR_SHARPEN
0049 -    kDebug () << "kpEffectBlurSharpen.cpp:BlurQImage(strength=" << strength << ")"
0050 +    kDebug () << "kpEffectBlurSharpen.cpp:RadiusForStrength(strength=" << strength << ")"
0051                 << " radius=" << radius
0052                 << endl;
0053  #endif
0054  
0055 -
0056 -    qimage = Blitz::blur (qimage, qRound (radius));
0057 -
0058 -
0059 -    return qimage;
0060 +    return qRound (radius);
0061  }
0062  
0063 -static QImage SharpenQImage (const QImage &qimage_, int strength)
0064 +
0065 +static QImage BlurQImage (const QImage qimage_, int strength)
0066  {
0067      QImage qimage = qimage_;
0068      if (strength == 0)
0069          return qimage;
0070  
0071  
0072 -    // The numbers that follow were picked by experimentation to try to get
0073 -    // an effect linearly proportional to <strength> and at the same time,
0074 -    // be fast enough.
0075 -    //
0076 -    // I still have no idea what "radius" and "sigma" mean.
0077 -
0078 -    const double RadiusMin = .1;
0079 -    const double RadiusMax = 2.5;
0080 -    const double radius = RadiusMin +
0081 -       (strength - 1) *
0082 -       (RadiusMax - RadiusMin) /
0083 -       (kpEffectBlurSharpen::MaxStrength - 1);
0084 -
0085 -    const double SigmaMin = .5;
0086 -    const double SigmaMax = 3.0;
0087 -    const double sigma = SigmaMin +
0088 -        (strength - 1) *
0089 -        (SigmaMax - SigmaMin) /
0090 -        (kpEffectBlurSharpen::MaxStrength - 1);
0091 -
0092 -    const double RepeatMin = 1;
0093 -    const double RepeatMax = 2;
0094 -    const double repeat = qRound (RepeatMin +
0095 -        (strength - 1) *
0096 -        (RepeatMax - RepeatMin) /
0097 -        (kpEffectBlurSharpen::MaxStrength - 1));
0098 +    qimage = Blitz::blur (qimage, ::RadiusForStrength (strength));
0099  
0100 -// I guess these values are more proper as they use an auto-calculated
0101 -// radius but they cause sharpen() to be too slow.
0102 -#if 0
0103 -    const double radius = 0/*auto-calculate*/;
0104 -
0105 -    const double SigmaMin = .6;
0106 -    const double SigmaMax = 1.0;
0107 -    const double sigma = SigmaMin +
0108 -        (strength - 1) *
0109 -        (SigmaMax - SigmaMin) /
0110 -        (kpEffectBlurSharpen::MaxStrength - 1);
0111  
0112 -    const double RepeatMin = 1;
0113 -    const double RepeatMax = 3;
0114 -    const double repeat = qRound (RepeatMin +
0115 -        (strength - 1) *
0116 -        (RepeatMax - RepeatMin) /
0117 -        (kpEffectBlurSharpen::MaxStrength - 1));
0118 -#endif
0119 +    return qimage;
0120 +}
0121  
0122 -#if DEBUG_KP_EFFECT_BLUR_SHARPEN
0123 -    kDebug () << "kpEffectBlurSharpen.cpp:SharpenQImage(strength=" << strength << ")"
0124 -               << " radius=" << radius
0125 -               << " sigma=" << sigma
0126 -               << " repeat=" << repeat
0127 -               << endl;
0128 -#endif
0129 +static QImage SharpenQImage (const QImage &qimage_, int strength)
0130 +{
0131 +    QImage qimage = qimage_;
0132 +    if (strength == 0)
0133 +        return qimage;
0134  
0135  
0136 -    for (int i = 0; i < repeat; i++)
0137 -    {
0138 -    #if DEBUG_KP_EFFECT_BLUR_SHARPEN
0139 -       QTime timer; timer.start ();
0140 -    #endif
0141 -        qimage = Blitz::gaussianSharpen (qimage, radius, sigma);
0142 -    #if DEBUG_KP_EFFECT_BLUR_SHARPEN
0143 -        kDebug () << "\titeration #" + QString::number (i)
0144 -                  << ": " + QString::number (timer.elapsed ()) << "ms" << endl;
0145 -    #endif
0146 -    }
0147 +    qimage = Blitz::sharpen (qimage, ::RadiusForStrength (strength) * 10);
0148  
0149  
0150      return qimage;