From 5af2cb8ddabeaba7d00c996dc32e9cb1976340ad Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Wed, 4 Jul 2007 10:01:04 +0000 Subject: [PATCH] Add sharpen effect which does some basic sharpening. Also requires shaders and shortcut is Ctrl+F7 for now. svn path=/trunk/KDE/kdebase/workspace/; revision=683165 --- effects/CMakeLists.txt | 4 ++++ effects/data/sharpen.frag | 24 ++++++++++++++++++++++ effects/data/sharpen.vert | 6 ++++++ effects/sharpen.cpp | 42 +++++++++++++++++++++++++++++++++++++++ effects/sharpen.desktop | 15 ++++++++++++++ effects/sharpen.h | 34 +++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 effects/data/sharpen.frag create mode 100644 effects/data/sharpen.vert create mode 100644 effects/sharpen.cpp create mode 100644 effects/sharpen.desktop create mode 100644 effects/sharpen.h diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 31e67a6a25..1ab5e210ba 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -64,6 +64,7 @@ if(OPENGL_FOUND) magnifier.cpp mousemark.cpp shadow.cpp + sharpen.cpp trackmouse.cpp ) install( FILES @@ -73,6 +74,7 @@ if(OPENGL_FOUND) magnifier.desktop mousemark.desktop shadow.desktop + sharpen.desktop trackmouse.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) install( FILES @@ -87,6 +89,8 @@ if(OPENGL_FOUND) data/blur-render.vert data/invert.frag data/invert.vert + data/sharpen.frag + data/sharpen.vert DESTINATION ${DATA_INSTALL_DIR}/kwin ) # config modules diff --git a/effects/data/sharpen.frag b/effects/data/sharpen.frag new file mode 100644 index 0000000000..d76c25f31a --- /dev/null +++ b/effects/data/sharpen.frag @@ -0,0 +1,24 @@ +uniform sampler2D sceneTex; +uniform float textureWidth; +uniform float textureHeight; + + +// Converts pixel coordinates to texture coordinates +vec2 pix2tex(vec2 pix) +{ + return vec2(pix.x / textureWidth, 1.0 - pix.y / textureHeight); +} + +void main() +{ + float amount = 0.4; + vec3 tex = texture2D(sceneTex, pix2tex(gl_TexCoord[0].xy)).rgb * (1.0 + 4.0 * amount); + + tex -= texture2D(sceneTex, pix2tex(gl_TexCoord[0].xy + vec2(0.0, 1.0))).rgb * amount; + tex -= texture2D(sceneTex, pix2tex(gl_TexCoord[0].xy + vec2(0.0, -1.0))).rgb * amount; + tex -= texture2D(sceneTex, pix2tex(gl_TexCoord[0].xy + vec2(1.0, 0.0))).rgb * amount; + tex -= texture2D(sceneTex, pix2tex(gl_TexCoord[0].xy + vec2(-1.0, 0.0))).rgb * amount; + + gl_FragColor = vec4(tex, 1.0); +} + diff --git a/effects/data/sharpen.vert b/effects/data/sharpen.vert new file mode 100644 index 0000000000..066ac6c2aa --- /dev/null +++ b/effects/data/sharpen.vert @@ -0,0 +1,6 @@ +void main() +{ + gl_TexCoord[0].xy = gl_Vertex.xy; + gl_Position = ftransform(); +} + diff --git a/effects/sharpen.cpp b/effects/sharpen.cpp new file mode 100644 index 0000000000..b9e667be83 --- /dev/null +++ b/effects/sharpen.cpp @@ -0,0 +1,42 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + + +#include "sharpen.h" + +#include +#include +#include + + +namespace KWin +{ + +KWIN_EFFECT( sharpen, SharpenEffect ) +KWIN_EFFECT_SUPPORTED( sharpen, ShaderEffect::supported() ) + + +SharpenEffect::SharpenEffect() : QObject(), ShaderEffect("sharpen") + { + KActionCollection* actionCollection = new KActionCollection( this ); + KAction* a = (KAction*)actionCollection->addAction( "Sharpen" ); + a->setText( i18n("Toggle Sharpen effect" )); + a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::Key_F7)); + connect(a, SIGNAL(triggered(bool)), this, SLOT(toggle())); + } + +void SharpenEffect::toggle() + { + setEnabled( !isEnabled()); + } + +} // namespace + +#include "sharpen.moc" diff --git a/effects/sharpen.desktop b/effects/sharpen.desktop new file mode 100644 index 0000000000..943d09826a --- /dev/null +++ b/effects/sharpen.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Sharpen + +Type=Service +ServiceTypes=KWin/Effect +X-KDE-PluginInfo-Author=Rivo Laks +X-KDE-PluginInfo-Email=rivolaks@hot.ee +X-KDE-PluginInfo-Name=kwin4_effect_sharpen +X-KDE-PluginInfo-Version=0.1.0 +X-KDE-PluginInfo-Category=Appearance +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/sharpen.h b/effects/sharpen.h new file mode 100644 index 0000000000..7f66967967 --- /dev/null +++ b/effects/sharpen.h @@ -0,0 +1,34 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_SHARPEN_H +#define KWIN_SHARPEN_H + +#include + +namespace KWin +{ + +/** + * Sharpens the whole desktop + **/ +class SharpenEffect : public QObject, public ShaderEffect + { + Q_OBJECT + public: + SharpenEffect(); + + public slots: + void toggle(); + }; + +} // namespace + +#endif