File indexing completed on 2024-05-19 04:22:56

0001 /*
0002    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0003    All rights reserved.
0004 
0005    Redistribution and use in source and binary forms, with or without
0006    modification, are permitted provided that the following conditions
0007    are met:
0008 
0009    1. Redistributions of source code must retain the above copyright
0010       notice, this list of conditions and the following disclaimer.
0011    2. Redistributions in binary form must reproduce the above copyright
0012       notice, this list of conditions and the following disclaimer in the
0013       documentation and/or other materials provided with the distribution.
0014 
0015    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0016    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0017    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0018    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0019    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0020    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0021    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0022    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0023    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0024    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0025 */
0026 
0027 
0028 #define DEBUG_KP_EFFECT_EMBOSS 0
0029 
0030 
0031 #include "kpEffectEmboss.h"
0032 #include "blitz.h"
0033 
0034 #include "kpLogCategories.h"
0035 
0036 #include "pixmapfx/kpPixmapFX.h"
0037 
0038 
0039 static QImage EmbossQImage (const QImage &qimage_, int strength)
0040 {
0041     QImage qimage = qimage_;
0042     if (strength == 0) {
0043         return qimage;
0044     }
0045 
0046 
0047     // The numbers that follow were picked by experimentation to try to get
0048     // an effect linearly proportional to <strength> and at the same time,
0049     // be fast enough.
0050     //
0051     // I still have no idea what "radius" and "sigma" mean.
0052 
0053     const auto radius = 0.0;
0054 
0055     const auto sigma = 1.0;
0056 
0057     const auto repeat = 1;
0058 
0059 
0060     for (int i = 0; i < repeat; i++)
0061     {
0062         qimage = Blitz::emboss (qimage, radius, sigma);
0063     }
0064 
0065 
0066     return qimage;
0067 }
0068 
0069 
0070 // public static
0071 kpImage kpEffectEmboss::applyEffect (const kpImage &image, int strength)
0072 {
0073 #if DEBUG_KP_EFFECT_EMBOSS
0074     qCDebug(kpLogImagelib) << "kpEffectEmboss::applyEffect(strength=" << strength << ")"
0075                << endl;
0076 #endif
0077 
0078     Q_ASSERT (strength >= MinStrength && strength <= MaxStrength);
0079 
0080     return ::EmbossQImage (image, strength);
0081 }