3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
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>
40 #include <kpPixmapFX.h>
43 static QImage
EmbossQImage (const QImage
&qimage_
, int strength
)
45 QImage qimage
= 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,
54 // I still have no idea what "radius" and "sigma" mean.
56 const double radius
= 0;
59 const double SigmaMin
= 1;
60 const double SigmaMax
= 1.2;
63 (kpEffectEmboss::MaxStrength
- strength
) *
64 (SigmaMax
- SigmaMin
) /
65 (kpEffectEmboss::MaxStrength
- 1);
67 const double sigma
= 1;
72 for (int i
= 0; i
< repeat
; i
++)
74 qimage
= Blitz::emboss (qimage
, radius
, sigma
);
83 kpImage
kpEffectEmboss::applyEffect (const kpImage
&image
, int strength
)
85 #if DEBUG_KP_EFFECT_EMBOSS
86 kDebug () << "kpEffectEmboss::applyEffect(strength=" << strength
<< ")"
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 ()