make sure to attach to the document also when a resize event is received prior of...
[kdegraphics.git] / kolourpaint / imagelib / effects / kpEffectEmboss.cpp
blob6572f3763015ae5e31a3a8a2a311c9937cb82d4f
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #define DEBUG_KP_EFFECT_EMBOSS 0
32 #include <kpEffectEmboss.h>
34 #include <qimageblitz.h>
36 #include <qimage.h>
38 #include <kdebug.h>
40 #include <kpPixmapFX.h>
43 static QImage EmbossQImage (const QImage &qimage_, int strength)
45 QImage qimage = qimage_;
46 if (strength == 0)
47 return qimage;
50 // The numbers that follow were picked by experimentation to try to get
51 // an effect linearly proportional to <strength> and at the same time,
52 // be fast enough.
54 // I still have no idea what "radius" and "sigma" mean.
56 const double radius = 0;
58 #if 0
59 const double SigmaMin = 1;
60 const double SigmaMax = 1.2;
62 return SigmaMin +
63 (kpEffectEmboss::MaxStrength - strength) *
64 (SigmaMax - SigmaMin) /
65 (kpEffectEmboss::MaxStrength - 1);
66 #endif
67 const double sigma = 1;
69 const int repeat = 1;
72 for (int i = 0; i < repeat; i++)
74 qimage = Blitz::emboss (qimage, radius, sigma);
78 return qimage;
82 // public static
83 kpImage kpEffectEmboss::applyEffect (const kpImage &image, int strength)
85 #if DEBUG_KP_EFFECT_EMBOSS
86 kDebug () << "kpEffectEmboss::applyEffect(strength=" << strength << ")"
87 << endl;
88 #endif
90 Q_ASSERT (strength >= MinStrength && strength <= MaxStrength);
93 QImage qimage = kpPixmapFX::convertToQImage (image);
95 qimage = ::EmbossQImage (qimage, strength);
97 kpImage retImage = kpPixmapFX::convertToPixmap (qimage);
100 #if DEBUG_KP_EFFECT_EMBOSS
101 kDebug () << "\thave masks: input=" << image.hasAlpha ()
102 << " output=" << retImage.hasAlpha ()
103 << endl;
104 #endif
106 return retImage;