Fix KImageEffect blur convolution

Add blur ability to krootpixmap


git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1249535 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 14 years ago
parent eab043fd0d
commit 2944cdf050

@ -4316,6 +4316,7 @@ TQImage KImageEffect::blur(TQImage &src, double radius, double sigma)
dest.create(src.width(), src.height(), 32); dest.create(src.width(), src.height(), 32);
// Horizontal convolution
scanline = (unsigned int *)malloc(sizeof(unsigned int)*src.height()); scanline = (unsigned int *)malloc(sizeof(unsigned int)*src.height());
temp = (unsigned int *)malloc(sizeof(unsigned int)*src.height()); temp = (unsigned int *)malloc(sizeof(unsigned int)*src.height());
for(y=0; y < src.height(); ++y){ for(y=0; y < src.height(); ++y){
@ -4324,14 +4325,17 @@ TQImage KImageEffect::blur(TQImage &src, double radius, double sigma)
blurScanLine(kernel, width, p, q, src.width()); blurScanLine(kernel, width, p, q, src.width());
} }
unsigned int **srcTable = (unsigned int **)src.jumpTable(); TQImage partial = dest;
// Vertical convolution
unsigned int **srcTable = (unsigned int **)partial.jumpTable();
unsigned int **destTable = (unsigned int **)dest.jumpTable(); unsigned int **destTable = (unsigned int **)dest.jumpTable();
for(x=0; x < src.width(); ++x){ for(x=0; x < partial.width(); ++x){
for(y=0; y < src.height(); ++y){ for(y=0; y < partial.height(); ++y){
scanline[y] = srcTable[y][x]; scanline[y] = srcTable[y][x];
} }
blurScanLine(kernel, width, scanline, temp, src.height()); blurScanLine(kernel, width, scanline, temp, partial.height());
for(y=0; y < src.height(); ++y){ for(y=0; y < partial.height(); ++y){
destTable[y][x] = temp[y]; destTable[y][x] = temp[y];
} }
} }

@ -59,6 +59,8 @@ void KRootPixmap::init()
{ {
d = new KRootPixmapData; d = new KRootPixmapData;
m_Fade = 0; m_Fade = 0;
m_BlurRadius = 0;
m_BlurSigma = 0;
m_pPixmap = new KSharedPixmap; //ordinary KPixmap on win32 m_pPixmap = new KSharedPixmap; //ordinary KPixmap on win32
m_pTimer = new TQTimer( this ); m_pTimer = new TQTimer( this );
m_bInit = false; m_bInit = false;
@ -137,6 +139,11 @@ void KRootPixmap::setFadeEffect(double fade, const TQColor &color)
if ( m_bActive && m_bInit ) tqrepaint(true); if ( m_bActive && m_bInit ) tqrepaint(true);
} }
void KRootPixmap::setBlurEffect(double radius, double sigma)
{
m_BlurRadius = radius;
m_BlurSigma = sigma;
}
bool KRootPixmap::eventFilter(TQObject *, TQEvent *event) bool KRootPixmap::eventFilter(TQObject *, TQEvent *event)
{ {
@ -312,6 +319,14 @@ void KRootPixmap::updateBackground( KSharedPixmap *spm )
pm = io.convertToPixmap(img); pm = io.convertToPixmap(img);
} }
if ((m_BlurRadius > 1e-6) || (m_BlurSigma > 1e-6))
{
KPixmapIO io;
TQImage img = io.convertToImage(pm);
img = KImageEffect::blur(img, m_BlurRadius, m_BlurSigma);
pm = io.convertToPixmap(img);
}
if ( !m_bCustomPaint ) if ( !m_bCustomPaint )
m_pWidget->setBackgroundPixmap( pm ); m_pWidget->setBackgroundPixmap( pm );
else { else {

@ -105,6 +105,16 @@ public:
*/ */
const TQColor &color() const { return m_FadeColor; } const TQColor &color() const { return m_FadeColor; }
/** @since 3.5
* @return the blur radius.
*/
const double &blurRadius() const { return m_BlurRadius; }
/** @since 3.5
* @return the blur sigma.
*/
const double &blurSigma() const { return m_BlurSigma; }
/** @since 3.2 /** @since 3.2
* @return the color opacity. * @return the color opacity.
*/ */
@ -133,6 +143,18 @@ public slots:
*/ */
void setFadeEffect(double opacity, const TQColor &color); void setFadeEffect(double opacity, const TQColor &color);
/**
* Sets the blue effect.
*
* This effect will blur the background with the specified values.
* If both values are set to zero no blur is applied (this is the default).
* @param radius The radius of the gaussian not counting the
* center pixel. Use 0 and a suitable radius will be automatically used.
* @param sigma The standard deviation of the gaussian. Use 1 if you're not
* sure.
*/
void setBlurEffect(double radius, double sigma);
/** /**
* Repaints the widget background. Normally, you shouldn't need this * Repaints the widget background. Normally, you shouldn't need this
* as it is handled automatically. * as it is handled automatically.
@ -201,6 +223,8 @@ private:
double m_Fade; double m_Fade;
TQColor m_FadeColor; TQColor m_FadeColor;
double m_BlurRadius;
double m_BlurSigma;
TQRect m_Rect; TQRect m_Rect;
TQWidget *m_pWidget; TQWidget *m_pWidget;

Loading…
Cancel
Save