From 71cfda6b25552b57f7081d72c1e3bd74dc3d951c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Niemel=C3=A4?= Date: Wed, 13 Jun 2012 13:00:33 +0300 Subject: Renamed 'internal' folder to 'private'. Private is more widely used term for files that do not belong to public API. Change-Id: Ib4219a4026bc04f79f0803272f8af6a13b517ca8 Reviewed-by: Kim Gronholm --- src/effects/Blend.qml | 2 +- src/effects/BrightnessContrast.qml | 2 +- src/effects/ColorOverlay.qml | 2 +- src/effects/Colorize.qml | 2 +- src/effects/ConicalGradient.qml | 2 +- src/effects/Desaturate.qml | 2 +- src/effects/DirectionalBlur.qml | 2 +- src/effects/Displace.qml | 2 +- src/effects/DropShadow.qml | 2 +- src/effects/FastBlur.qml | 2 +- src/effects/GammaAdjust.qml | 2 +- src/effects/GaussianBlur.qml | 2 +- src/effects/Glow.qml | 2 +- src/effects/HueSaturation.qml | 2 +- src/effects/InnerShadow.qml | 2 +- src/effects/LevelAdjust.qml | 2 +- src/effects/LinearGradient.qml | 2 +- src/effects/MaskedBlur.qml | 2 +- src/effects/OpacityMask.qml | 2 +- src/effects/RadialBlur.qml | 2 +- src/effects/RadialGradient.qml | 2 +- src/effects/RectangularGlow.qml | 2 +- src/effects/RecursiveBlur.qml | 2 +- src/effects/ThresholdMask.qml | 2 +- src/effects/ZoomBlur.qml | 2 +- src/effects/effects.pro | 2 +- src/effects/internal/FastGlow.qml | 393 --------------------- src/effects/internal/FastInnerShadow.qml | 413 ----------------------- src/effects/internal/FastMaskedBlur.qml | 332 ------------------ src/effects/internal/GaussianDirectionalBlur.qml | 287 ---------------- src/effects/internal/GaussianGlow.qml | 98 ------ src/effects/internal/GaussianInnerShadow.qml | 155 --------- src/effects/internal/GaussianMaskedBlur.qml | 104 ------ src/effects/internal/SourceProxy.qml | 136 -------- src/effects/private/FastGlow.qml | 393 +++++++++++++++++++++ src/effects/private/FastInnerShadow.qml | 413 +++++++++++++++++++++++ src/effects/private/FastMaskedBlur.qml | 332 ++++++++++++++++++ src/effects/private/GaussianDirectionalBlur.qml | 287 ++++++++++++++++ src/effects/private/GaussianGlow.qml | 98 ++++++ src/effects/private/GaussianInnerShadow.qml | 155 +++++++++ src/effects/private/GaussianMaskedBlur.qml | 104 ++++++ src/effects/private/SourceProxy.qml | 136 ++++++++ 42 files changed, 1944 insertions(+), 1944 deletions(-) delete mode 100644 src/effects/internal/FastGlow.qml delete mode 100644 src/effects/internal/FastInnerShadow.qml delete mode 100644 src/effects/internal/FastMaskedBlur.qml delete mode 100644 src/effects/internal/GaussianDirectionalBlur.qml delete mode 100644 src/effects/internal/GaussianGlow.qml delete mode 100644 src/effects/internal/GaussianInnerShadow.qml delete mode 100644 src/effects/internal/GaussianMaskedBlur.qml delete mode 100644 src/effects/internal/SourceProxy.qml create mode 100644 src/effects/private/FastGlow.qml create mode 100644 src/effects/private/FastInnerShadow.qml create mode 100644 src/effects/private/FastMaskedBlur.qml create mode 100644 src/effects/private/GaussianDirectionalBlur.qml create mode 100644 src/effects/private/GaussianGlow.qml create mode 100644 src/effects/private/GaussianInnerShadow.qml create mode 100644 src/effects/private/GaussianMaskedBlur.qml create mode 100644 src/effects/private/SourceProxy.qml diff --git a/src/effects/Blend.qml b/src/effects/Blend.qml index 4d44651..ccea3c2 100644 --- a/src/effects/Blend.qml +++ b/src/effects/Blend.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/BrightnessContrast.qml b/src/effects/BrightnessContrast.qml index 545be08..d441607 100644 --- a/src/effects/BrightnessContrast.qml +++ b/src/effects/BrightnessContrast.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/ColorOverlay.qml b/src/effects/ColorOverlay.qml index 387334c..19dc19e 100644 --- a/src/effects/ColorOverlay.qml +++ b/src/effects/ColorOverlay.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/Colorize.qml b/src/effects/Colorize.qml index 02078eb..681449a 100644 --- a/src/effects/Colorize.qml +++ b/src/effects/Colorize.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/ConicalGradient.qml b/src/effects/ConicalGradient.qml index d1cfa6b..f3c2e76 100644 --- a/src/effects/ConicalGradient.qml +++ b/src/effects/ConicalGradient.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/Desaturate.qml b/src/effects/Desaturate.qml index 87c7dac..6eca86e 100644 --- a/src/effects/Desaturate.qml +++ b/src/effects/Desaturate.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/DirectionalBlur.qml b/src/effects/DirectionalBlur.qml index a9a924c..148bceb 100644 --- a/src/effects/DirectionalBlur.qml +++ b/src/effects/DirectionalBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/Displace.qml b/src/effects/Displace.qml index 6d04129..3082a05 100644 --- a/src/effects/Displace.qml +++ b/src/effects/Displace.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/DropShadow.qml b/src/effects/DropShadow.qml index c7a9ed5..e07d4d2 100644 --- a/src/effects/DropShadow.qml +++ b/src/effects/DropShadow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/FastBlur.qml b/src/effects/FastBlur.qml index 7dc95e5..8fed702 100644 --- a/src/effects/FastBlur.qml +++ b/src/effects/FastBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/GammaAdjust.qml b/src/effects/GammaAdjust.qml index ef017ab..093db51 100644 --- a/src/effects/GammaAdjust.qml +++ b/src/effects/GammaAdjust.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/GaussianBlur.qml b/src/effects/GaussianBlur.qml index 0755c2c..52c6c34 100644 --- a/src/effects/GaussianBlur.qml +++ b/src/effects/GaussianBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/Glow.qml b/src/effects/Glow.qml index 7d36571..20182f2 100644 --- a/src/effects/Glow.qml +++ b/src/effects/Glow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/HueSaturation.qml b/src/effects/HueSaturation.qml index b8e7761..0bcd3a2 100644 --- a/src/effects/HueSaturation.qml +++ b/src/effects/HueSaturation.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/InnerShadow.qml b/src/effects/InnerShadow.qml index 32efeef..8a51ada 100644 --- a/src/effects/InnerShadow.qml +++ b/src/effects/InnerShadow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/LevelAdjust.qml b/src/effects/LevelAdjust.qml index 434b15d..560c4e6 100644 --- a/src/effects/LevelAdjust.qml +++ b/src/effects/LevelAdjust.qml @@ -39,7 +39,7 @@ *****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/LinearGradient.qml b/src/effects/LinearGradient.qml index 6bd1066..3179407 100644 --- a/src/effects/LinearGradient.qml +++ b/src/effects/LinearGradient.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/MaskedBlur.qml b/src/effects/MaskedBlur.qml index 4a83a35..55cd5a3 100644 --- a/src/effects/MaskedBlur.qml +++ b/src/effects/MaskedBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/OpacityMask.qml b/src/effects/OpacityMask.qml index 4ea63e8..840277c 100644 --- a/src/effects/OpacityMask.qml +++ b/src/effects/OpacityMask.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/RadialBlur.qml b/src/effects/RadialBlur.qml index 830ebec..0a3c11f 100644 --- a/src/effects/RadialBlur.qml +++ b/src/effects/RadialBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/RadialGradient.qml b/src/effects/RadialGradient.qml index 13d68a3..fb90bc6 100644 --- a/src/effects/RadialGradient.qml +++ b/src/effects/RadialGradient.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/RectangularGlow.qml b/src/effects/RectangularGlow.qml index c7f590f..021940e 100644 --- a/src/effects/RectangularGlow.qml +++ b/src/effects/RectangularGlow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/RecursiveBlur.qml b/src/effects/RecursiveBlur.qml index 52a01b2..82a7688 100644 --- a/src/effects/RecursiveBlur.qml +++ b/src/effects/RecursiveBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/ThresholdMask.qml b/src/effects/ThresholdMask.qml index 5f995d7..bf157ed 100644 --- a/src/effects/ThresholdMask.qml +++ b/src/effects/ThresholdMask.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/ZoomBlur.qml b/src/effects/ZoomBlur.qml index c784014..ac2ff9d 100644 --- a/src/effects/ZoomBlur.qml +++ b/src/effects/ZoomBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "internal" +import "private" Item { id: rootItem diff --git a/src/effects/effects.pro b/src/effects/effects.pro index 8ff7daf..c192fbc 100644 --- a/src/effects/effects.pro +++ b/src/effects/effects.pro @@ -4,7 +4,7 @@ TARGETPATH = "QtGraphicalEffects" plugin.files += $$PWD/qmldir plugin.files += $$PWD/*.qml -plugin.files += $$PWD/internal +plugin.files += $$PWD/private plugin.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH !isEmpty(DESTDIR): plugin.path = $$DESTDIR diff --git a/src/effects/internal/FastGlow.qml b/src/effects/internal/FastGlow.qml deleted file mode 100644 index 081350b..0000000 --- a/src/effects/internal/FastGlow.qml +++ /dev/null @@ -1,393 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property real spread: 0.0 - property real blur: 0.0 - property color color: "white" - property bool transparentBorder: false - property bool cached: false - - SourceProxy { - id: sourceProxy - input: rootItem.source - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: shaderItem - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - property string __internalBlurVertexShader: " - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - uniform highp mat4 qt_Matrix; - uniform highp float yStep; - uniform highp float xStep; - varying highp vec2 qt_TexCoord0; - varying highp vec2 qt_TexCoord1; - varying highp vec2 qt_TexCoord2; - varying highp vec2 qt_TexCoord3; - - void main() { - qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); - qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); - qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); - qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); - gl_Position = qt_Matrix * qt_Vertex; - } - " - - property string __internalBlurFragmentShader: " - uniform lowp sampler2D source; - uniform lowp float qt_Opacity; - varying highp vec2 qt_TexCoord0; - varying highp vec2 qt_TexCoord1; - varying highp vec2 qt_TexCoord2; - varying highp vec2 qt_TexCoord3; - - void main() { - highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + - texture2D(source, qt_TexCoord1) + - texture2D(source, qt_TexCoord2) + - texture2D(source, qt_TexCoord3)) * 0.25; - gl_FragColor = sourceColor * qt_Opacity; - } - " - - ShaderEffect { - id: level0 - property variant source: sourceProxy.output - anchors.fill: parent - visible: false - smooth: true - } - - ShaderEffectSource { - id: level1 - width: Math.ceil(shaderItem.width / 32) * 32 - height: Math.ceil(shaderItem.height / 32) * 32 - sourceItem: level0 - hideSource: rootItem.visible - sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0,0,0,0) - smooth: true - visible: false - } - - ShaderEffect { - id: effect1 - property variant source: level1 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level2 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level2 - width: level1.width / 2 - height: level1.height / 2 - sourceItem: effect1 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect2 - property variant source: level2 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level3 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level3 - width: level2.width / 2 - height: level2.height / 2 - sourceItem: effect2 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect3 - property variant source: level3 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level4 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level4 - width: level3.width / 2 - height: level3.height / 2 - sourceItem: effect3 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect4 - property variant source: level4 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level5 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level5 - width: level4.width / 2 - height: level4.height / 2 - sourceItem: effect4 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect5 - property variant source: level5 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level6 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level6 - width: level5.width / 2 - height: level5.height / 2 - sourceItem: effect5 - hideSource: rootItem.visible - visible: false - smooth: true - } - - Item { - id: dummysource - width: 1 - height: 1 - visible: false - } - - ShaderEffectSource { - id: dummy - width: 1 - height: 1 - sourceItem: dummysource - visible: false - smooth: false - live: false - } - - ShaderEffect { - id: shaderItem - x: transparentBorder ? -64 : 0 - y: transparentBorder ? -64 : 0 - width: transparentBorder ? parent.width + 128 : parent.width - height: transparentBorder ? parent.height + 128 : parent.height - - property variant source1: level1 - property variant source2: level2 - property variant source3: level3 - property variant source4: level4 - property variant source5: level5 - property variant source6: level6 - property real lod: rootItem.blur - - property real weight1; - property real weight2; - property real weight3; - property real weight4; - property real weight5; - property real weight6; - - property real spread: 1.0 - (rootItem.spread * 0.98) - property alias color: rootItem.color - - function weight(v) { - if (v <= 0.0) - return 1 - if (v >= 0.5) - return 0 - - return 1.0 - v / 0.5 - } - - function calculateWeights() { - - var w1 = weight(Math.abs(lod - 0.100)) - var w2 = weight(Math.abs(lod - 0.300)) - var w3 = weight(Math.abs(lod - 0.500)) - var w4 = weight(Math.abs(lod - 0.700)) - var w5 = weight(Math.abs(lod - 0.900)) - var w6 = weight(Math.abs(lod - 1.100)) - - var sum = w1 + w2 + w3 + w4 + w5 + w6; - weight1 = w1 / sum; - weight2 = w2 / sum; - weight3 = w3 / sum; - weight4 = w4 / sum; - weight5 = w5 / sum; - weight6 = w6 / sum; - - upateSources() - } - - function upateSources() { - var sources = new Array(); - var weights = new Array(); - - if (weight1 > 0) { - sources.push(level1) - weights.push(weight1) - } - - if (weight2 > 0) { - sources.push(level2) - weights.push(weight2) - } - - if (weight3 > 0) { - sources.push(level3) - weights.push(weight3) - } - - if (weight4 > 0) { - sources.push(level4) - weights.push(weight4) - } - - if (weight5 > 0) { - sources.push(level5) - weights.push(weight5) - } - - if (weight6 > 0) { - sources.push(level6) - weights.push(weight6) - } - - for (var j = sources.length; j < 6; j++) { - sources.push(dummy) - weights.push(0.0) - } - - source1 = sources[0] - source2 = sources[1] - source3 = sources[2] - source4 = sources[3] - source5 = sources[4] - source6 = sources[5] - - weight1 = weights[0] - weight2 = weights[1] - weight3 = weights[2] - weight4 = weights[3] - weight5 = weights[4] - weight6 = weights[5] - } - - Component.onCompleted: calculateWeights() - - onLodChanged: calculateWeights() - - fragmentShader: " - uniform lowp sampler2D source1; - uniform lowp sampler2D source2; - uniform lowp sampler2D source3; - uniform lowp sampler2D source4; - uniform lowp sampler2D source5; - uniform mediump float weight1; - uniform mediump float weight2; - uniform mediump float weight3; - uniform mediump float weight4; - uniform mediump float weight5; - uniform highp vec4 color; - uniform highp float spread; - uniform lowp float qt_Opacity; - varying mediump vec2 qt_TexCoord0; - - highp float linearstep(highp float e0, highp float e1, highp float x) { - return clamp((x - e0) / (e1 - e0), 0.0, 1.0); - } - - void main() { - lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1; - sourceColor += texture2D(source2, qt_TexCoord0) * weight2; - sourceColor += texture2D(source3, qt_TexCoord0) * weight3; - sourceColor += texture2D(source4, qt_TexCoord0) * weight4; - sourceColor += texture2D(source5, qt_TexCoord0) * weight5; - sourceColor = mix(vec4(0), color, linearstep(0.0, spread, sourceColor.a)); - gl_FragColor = sourceColor * qt_Opacity; - } - " - } -} diff --git a/src/effects/internal/FastInnerShadow.qml b/src/effects/internal/FastInnerShadow.qml deleted file mode 100644 index 04a45ce..0000000 --- a/src/effects/internal/FastInnerShadow.qml +++ /dev/null @@ -1,413 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property real blur: 0.0 - property real horizontalOffset: 0 - property real verticalOffset: 0 - property real spread: 0.0 - property color color: "black" - property bool cached: false - - SourceProxy { - id: sourceProxy - input: rootItem.source - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: shaderItem - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - property string __internalBlurVertexShader: " - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - uniform highp mat4 qt_Matrix; - uniform highp float yStep; - uniform highp float xStep; - varying highp vec2 qt_TexCoord0; - varying highp vec2 qt_TexCoord1; - varying highp vec2 qt_TexCoord2; - varying highp vec2 qt_TexCoord3; - - void main() { - qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); - qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); - qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); - qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); - gl_Position = qt_Matrix * qt_Vertex; - } - " - - property string __internalBlurFragmentShader: " - uniform lowp sampler2D source; - uniform lowp float qt_Opacity; - varying highp vec2 qt_TexCoord0; - varying highp vec2 qt_TexCoord1; - varying highp vec2 qt_TexCoord2; - varying highp vec2 qt_TexCoord3; - - void main() { - highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + - texture2D(source, qt_TexCoord1) + - texture2D(source, qt_TexCoord2) + - texture2D(source, qt_TexCoord3)) * 0.25; - gl_FragColor = sourceColor * qt_Opacity; - } - " - - ShaderEffect { - id: level0 - property variant source: sourceProxy.output - property real horizontalOffset: rootItem.horizontalOffset / rootItem.width - property real verticalOffset: rootItem.verticalOffset / rootItem.width - property color color: rootItem.color - - anchors.fill: parent - visible: false - smooth: true - fragmentShader: " - varying highp vec2 qt_TexCoord0; - uniform lowp float qt_Opacity; - uniform highp sampler2D source; - uniform lowp vec4 color; - uniform highp float horizontalOffset; - uniform highp float verticalOffset; - - void main(void) { - highp vec2 pos = qt_TexCoord0 - vec2(horizontalOffset, verticalOffset); - lowp float ea = step(0.0, pos.x) * step(0.0, pos.y) * step(pos.x, 1.0) * step(pos.y, 1.0); - lowp float eb = 1.0 - ea; - gl_FragColor = (eb * color + ea * color * (1.0 - texture2D(source, pos).a)) * qt_Opacity; - } - " - } - - ShaderEffectSource { - id: level1 - width: Math.ceil(shaderItem.width / 32) * 32 - height: Math.ceil(shaderItem.height / 32) * 32 - sourceItem: level0 - hideSource: rootItem.visible - smooth: true - visible: false - } - - ShaderEffect { - id: effect1 - property variant source: level1 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level2 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level2 - width: level1.width / 2 - height: level1.height / 2 - sourceItem: effect1 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect2 - property variant source: level2 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level3 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level3 - width: level2.width / 2 - height: level2.height / 2 - sourceItem: effect2 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect3 - property variant source: level3 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level4 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level4 - width: level3.width / 2 - height: level3.height / 2 - sourceItem: effect3 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect4 - property variant source: level4 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level5 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level5 - width: level4.width / 2 - height: level4.height / 2 - sourceItem: effect4 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect5 - property variant source: level5 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level6 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level6 - width: level5.width / 2 - height: level5.height / 2 - sourceItem: effect5 - hideSource: rootItem.visible - visible: false - smooth: true - } - - Item { - id: dummysource - width: 1 - height: 1 - visible: false - } - - ShaderEffectSource { - id: dummy - width: 1 - height: 1 - sourceItem: dummysource - visible: false - smooth: false - live: false - } - - ShaderEffect { - id: shaderItem - width: parent.width - height: parent.height - - property variant original: sourceProxy.output - property variant source1: level1 - property variant source2: level2 - property variant source3: level3 - property variant source4: level4 - property variant source5: level5 - property variant source6: level6 - property real lod: rootItem.blur - - property real weight1; - property real weight2; - property real weight3; - property real weight4; - property real weight5; - property real weight6; - - property real spread: 1.0 - (rootItem.spread * 0.98) - property color color: rootItem.color - - function weight(v) { - if (v <= 0.0) - return 1 - if (v >= 0.5) - return 0 - - return 1.0 - v / 0.5 - } - - function calculateWeights() { - - var w1 = weight(Math.abs(lod - 0.100)) - var w2 = weight(Math.abs(lod - 0.300)) - var w3 = weight(Math.abs(lod - 0.500)) - var w4 = weight(Math.abs(lod - 0.700)) - var w5 = weight(Math.abs(lod - 0.900)) - var w6 = weight(Math.abs(lod - 1.100)) - - var sum = w1 + w2 + w3 + w4 + w5 + w6; - weight1 = w1 / sum; - weight2 = w2 / sum; - weight3 = w3 / sum; - weight4 = w4 / sum; - weight5 = w5 / sum; - weight6 = w6 / sum; - - upateSources() - } - - function upateSources() { - var sources = new Array(); - var weights = new Array(); - - if (weight1 > 0) { - sources.push(level1) - weights.push(weight1) - } - - if (weight2 > 0) { - sources.push(level2) - weights.push(weight2) - } - - if (weight3 > 0) { - sources.push(level3) - weights.push(weight3) - } - - if (weight4 > 0) { - sources.push(level4) - weights.push(weight4) - } - - if (weight5 > 0) { - sources.push(level5) - weights.push(weight5) - } - - if (weight6 > 0) { - sources.push(level6) - weights.push(weight6) - } - - for (var j = sources.length; j < 6; j++) { - sources.push(dummy) - weights.push(0.0) - } - - source1 = sources[0] - source2 = sources[1] - source3 = sources[2] - source4 = sources[3] - source5 = sources[4] - source6 = sources[5] - - weight1 = weights[0] - weight2 = weights[1] - weight3 = weights[2] - weight4 = weights[3] - weight5 = weights[4] - weight6 = weights[5] - } - - Component.onCompleted: calculateWeights() - - onLodChanged: calculateWeights() - - fragmentShader: " - uniform lowp sampler2D original; - uniform lowp sampler2D source1; - uniform lowp sampler2D source2; - uniform lowp sampler2D source3; - uniform lowp sampler2D source4; - uniform lowp sampler2D source5; - uniform mediump float weight1; - uniform mediump float weight2; - uniform mediump float weight3; - uniform mediump float weight4; - uniform mediump float weight5; - uniform highp vec4 color; - uniform highp float spread; - uniform lowp float qt_Opacity; - varying mediump vec2 qt_TexCoord0; - - highp float linearstep(highp float e0, highp float e1, highp float x) { - return clamp((x - e0) / (e1 - e0), 0.0, 1.0); - } - - void main() { - lowp vec4 shadowColor = texture2D(source1, qt_TexCoord0) * weight1; - shadowColor += texture2D(source2, qt_TexCoord0) * weight2; - shadowColor += texture2D(source3, qt_TexCoord0) * weight3; - shadowColor += texture2D(source4, qt_TexCoord0) * weight4; - shadowColor += texture2D(source5, qt_TexCoord0) * weight5; - lowp vec4 originalColor = texture2D(original, qt_TexCoord0); - shadowColor.rgb = mix(originalColor.rgb, color.rgb * originalColor.a, linearstep(0.0, spread, shadowColor.a)); - gl_FragColor = vec4(shadowColor.rgb, originalColor.a) * originalColor.a * qt_Opacity; - } - " - } -} diff --git a/src/effects/internal/FastMaskedBlur.qml b/src/effects/internal/FastMaskedBlur.qml deleted file mode 100644 index d40e295..0000000 --- a/src/effects/internal/FastMaskedBlur.qml +++ /dev/null @@ -1,332 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property variant maskSource - property real blur: 0.0 - property bool transparentBorder: false - property bool cached: false - - SourceProxy { - id: sourceProxy - input: rootItem.source - } - - SourceProxy { - id: maskSourceProxy - input: rootItem.maskSource - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: shaderItem - visible: rootItem.cached - sourceItem: shaderItem - live: true - hideSource: visible - smooth: rootItem.blur > 0 - } - - property string __internalBlurVertexShader: " - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - uniform highp mat4 qt_Matrix; - uniform highp float yStep; - uniform highp float xStep; - varying highp vec2 qt_TexCoord0; - varying highp vec2 qt_TexCoord1; - varying highp vec2 qt_TexCoord2; - varying highp vec2 qt_TexCoord3; - - void main() { - qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); - qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); - qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); - qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); - gl_Position = qt_Matrix * qt_Vertex; - } - " - - property string __internalBlurFragmentShader: " - uniform lowp sampler2D source; - uniform lowp float qt_Opacity; - varying highp vec2 qt_TexCoord0; - varying highp vec2 qt_TexCoord1; - varying highp vec2 qt_TexCoord2; - varying highp vec2 qt_TexCoord3; - - void main() { - highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + - texture2D(source, qt_TexCoord1) + - texture2D(source, qt_TexCoord2) + - texture2D(source, qt_TexCoord3)) * 0.25; - gl_FragColor = sourceColor * qt_Opacity; - } - " - - ShaderEffect { - id: mask0 - property variant source: maskSourceProxy.output - anchors.fill: parent - visible: false - smooth: true - } - - ShaderEffectSource { - id: masklevel1 - width: Math.ceil(shaderItem.width / 32) * 32 - height: Math.ceil(shaderItem.height / 32) * 32 - sourceItem: mask0 - hideSource: rootItem.visible - sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0) - visible: false - smooth: rootItem.blur > 0 - } - - ShaderEffect { - id: level0 - property variant source: sourceProxy.output - anchors.fill: parent - visible: false - smooth: true - } - - ShaderEffectSource { - id: level1 - width: Math.ceil(shaderItem.width / 32) * 32 - height: Math.ceil(shaderItem.height / 32) * 32 - sourceItem: level0 - hideSource: rootItem.visible - sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0) - visible: false - smooth: rootItem.blur > 0 - } - - ShaderEffect { - id: effect1 - property variant source: level1 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level2 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level2 - width: level1.width / 2 - height: level1.height / 2 - sourceItem: effect1 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect2 - property variant source: level2 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level3 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level3 - width: level2.width / 2 - height: level2.height / 2 - sourceItem: effect2 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect3 - property variant source: level3 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level4 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level4 - width: level3.width / 2 - height: level3.height / 2 - sourceItem: effect3 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect4 - property variant source: level4 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level5 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level5 - width: level4.width / 2 - height: level4.height / 2 - sourceItem: effect4 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: effect5 - property variant source: level5 - property real yStep: 1/height - property real xStep: 1/width - anchors.fill: level6 - visible: false - smooth: true - vertexShader: __internalBlurVertexShader - fragmentShader: __internalBlurFragmentShader - } - - ShaderEffectSource { - id: level6 - width: level5.width / 2 - height: level5.height / 2 - sourceItem: effect5 - hideSource: rootItem.visible - visible: false - smooth: true - } - - ShaderEffect { - id: shaderItem - property variant mask: masklevel1 - property variant source1: level1 - property variant source2: level2 - property variant source3: level3 - property variant source4: level4 - property variant source5: level5 - property variant source6: level6 - property real lod: Math.sqrt(rootItem.blur) * 1.2 - 0.2 - property real weight1 - property real weight2 - property real weight3 - property real weight4 - property real weight5 - property real weight6 - - x: transparentBorder ? -64 : 0 - y: transparentBorder ? -64 : 0 - width: transparentBorder ? parent.width + 128 : parent.width - height: transparentBorder ? parent.height + 128 : parent.height - - fragmentShader: " - uniform lowp sampler2D mask; - uniform lowp sampler2D source1; - uniform lowp sampler2D source2; - uniform lowp sampler2D source3; - uniform lowp sampler2D source4; - uniform lowp sampler2D source5; - uniform lowp sampler2D source6; - uniform lowp float lod; - uniform lowp float qt_Opacity; - varying mediump vec2 qt_TexCoord0; - - mediump float weight(mediump float v) { - if (v <= 0.0) - return 1.0; - - if (v >= 0.5) - return 0.0; - - return 1.0 - v * 2.0; - } - - void main() { - - lowp vec4 maskColor = texture2D(mask, qt_TexCoord0); - mediump float l = lod * maskColor.a; - - mediump float w1 = weight(abs(l - 0.100)); - mediump float w2 = weight(abs(l - 0.300)); - mediump float w3 = weight(abs(l - 0.500)); - mediump float w4 = weight(abs(l - 0.700)); - mediump float w5 = weight(abs(l - 0.900)); - mediump float w6 = weight(abs(l - 1.100)); - - mediump float sum = w1 + w2 + w3 + w4 + w5 + w6; - mediump float weight1 = w1 / sum; - mediump float weight2 = w2 / sum; - mediump float weight3 = w3 / sum; - mediump float weight4 = w4 / sum; - mediump float weight5 = w5 / sum; - mediump float weight6 = w6 / sum; - - lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1; - sourceColor += texture2D(source2, qt_TexCoord0) * weight2; - sourceColor += texture2D(source3, qt_TexCoord0) * weight3; - sourceColor += texture2D(source4, qt_TexCoord0) * weight4; - sourceColor += texture2D(source5, qt_TexCoord0) * weight5; - sourceColor += texture2D(source6, qt_TexCoord0) * weight6; - - gl_FragColor = sourceColor * qt_Opacity; - - } - " - } -} diff --git a/src/effects/internal/GaussianDirectionalBlur.qml b/src/effects/internal/GaussianDirectionalBlur.qml deleted file mode 100644 index 5515a96..0000000 --- a/src/effects/internal/GaussianDirectionalBlur.qml +++ /dev/null @@ -1,287 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property real deviation: (radius + 1) / 3.3333 - property real radius: 0.0 - property int maximumRadius: 0 - property real horizontalStep: 0.0 - property real verticalStep: 0.0 - property bool transparentBorder: false - property bool cached: false - - property bool enableColor: false - property color color: "white" - property real spread: 0.0 - - property bool enableMask: false - property variant maskSource - - SourceProxy { - id: sourceProxy - input: rootItem.source - } - - SourceProxy { - id: maskSourceProxy - input: rootItem.maskSource - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: rootItem - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - ShaderEffect { - id: shaderItem - property variant source: sourceProxy.output - property real deviation: Math.max(0.1, rootItem.deviation) - property real radius: rootItem.radius - property int maxRadius: rootItem.maximumRadius - property bool transparentBorder: rootItem.transparentBorder - property real gaussianSum: 0.0 - property real startIndex: 0.0 - property real deltaFactor: (2 * radius - 1) / (maxRadius * 2 - 1) - property real expandX: transparentBorder && rootItem.horizontalStep > 0 ? maxRadius / width : 0.0 - property real expandY: transparentBorder && rootItem.verticalStep > 0 ? maxRadius / height : 0.0 - property variant gwts: [] - property variant delta: Qt.vector3d(rootItem.horizontalStep * deltaFactor, rootItem.verticalStep * deltaFactor, startIndex); - property variant factor_0_2: Qt.vector3d(gwts[0], gwts[1], gwts[2]); - property variant factor_3_5: Qt.vector3d(gwts[3], gwts[4], gwts[5]); - property variant factor_6_8: Qt.vector3d(gwts[6], gwts[7], gwts[8]); - property variant factor_9_11: Qt.vector3d(gwts[9], gwts[10], gwts[11]); - property variant factor_12_14: Qt.vector3d(gwts[12], gwts[13], gwts[14]); - property variant factor_15_17: Qt.vector3d(gwts[15], gwts[16], gwts[17]); - property variant factor_18_20: Qt.vector3d(gwts[18], gwts[19], gwts[20]); - property variant factor_21_23: Qt.vector3d(gwts[21], gwts[22], gwts[23]); - property variant factor_24_26: Qt.vector3d(gwts[24], gwts[25], gwts[26]); - property variant factor_27_29: Qt.vector3d(gwts[27], gwts[28], gwts[29]); - property variant factor_30_32: Qt.vector3d(gwts[30], gwts[31], gwts[32]); - - property color color: rootItem.color - property real spread: 1.0 - (rootItem.spread * 0.98) - property variant maskSource: maskSourceProxy.output - - anchors.fill: rootItem - - function gausFunc(x){ - //Gaussian function = h(x):=(1/sqrt(2*3.14159*(D^2))) * %e^(-(x^2)/(2*(D^2))); - return (1.0 / Math.sqrt(2 * Math.PI * (Math.pow(shaderItem.deviation, 2)))) * Math.pow(Math.E, -((Math.pow(x, 2)) / (2 * (Math.pow(shaderItem.deviation, 2))))); - } - - function updateGaussianWeights() { - gaussianSum = 0.0; - startIndex = -maxRadius + 0.5 - - var n = new Array(32); - for (var j = 0; j < 32; j++) - n[j] = 0; - - var max = maxRadius * 2 - var delta = (2 * radius - 1) / (max - 1); - for (var i = 0; i < max; i++) { - n[i] = gausFunc(-radius + 0.5 + i * delta); - gaussianSum += n[i]; - } - - gwts = n; - } - - function buildFragmentShader() { - - var shaderSteps = [ - "gl_FragColor += texture2D(source, texCoord) * factor_0_2.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_0_2.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_0_2.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_3_5.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_3_5.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_3_5.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_6_8.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_6_8.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_6_8.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_9_11.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_9_11.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_9_11.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_12_14.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_12_14.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_12_14.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_15_17.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_15_17.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_15_17.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_18_20.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_18_20.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_18_20.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_21_23.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_21_23.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_21_23.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_24_26.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_24_26.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_24_26.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_27_29.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_27_29.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_27_29.z; texCoord += shift;", - - "gl_FragColor += texture2D(source, texCoord) * factor_30_32.x; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_30_32.y; texCoord += shift;", - "gl_FragColor += texture2D(source, texCoord) * factor_30_32.z; texCoord += shift;" - ] - - var shader = fragmentShaderBegin - var samples = maxRadius * 2 - if (samples > 32) { - console.log("DirectionalGaussianBlur.qml WARNING: Maximum of blur radius (16) exceeded!") - samples = 32 - } - - for (var i = 0; i < samples; i++) { - shader += shaderSteps[i] - } - - shader += fragmentShaderEnd - - var colorizeSteps = "" - var colorizeUniforms = "" - - var maskSteps = "" - var maskUniforms = "" - - if (enableColor) { - colorizeSteps += "gl_FragColor = mix(vec4(0), color, clamp((gl_FragColor.a - 0.0) / (spread - 0.0), 0.0, 1.0));\n" - colorizeUniforms += "uniform highp vec4 color;\n" - colorizeUniforms += "uniform highp float spread;\n" - } - - if (enableMask) { - maskSteps += "shift *= texture2D(maskSource, qt_TexCoord0).a;\n" - maskUniforms += "uniform sampler2D maskSource;\n" - } - - shader = shader.replace("PLACEHOLDER_COLORIZE_STEPS", colorizeSteps) - shader = shader.replace("PLACEHOLDER_COLORIZE_UNIFORMS", colorizeUniforms) - shader = shader.replace("PLACEHOLDER_MASK_STEPS", maskSteps) - shader = shader.replace("PLACEHOLDER_MASK_UNIFORMS", maskUniforms) - - fragmentShader = shader - } - - onDeviationChanged: updateGaussianWeights() - - onRadiusChanged: updateGaussianWeights() - - onTransparentBorderChanged: { - buildFragmentShader() - updateGaussianWeights() - } - - onMaxRadiusChanged: { - buildFragmentShader() - updateGaussianWeights() - } - - Component.onCompleted: { - buildFragmentShader() - updateGaussianWeights() - } - - property string fragmentShaderBegin: " - varying mediump vec2 qt_TexCoord0; - uniform highp float qt_Opacity; - uniform lowp sampler2D source; - uniform highp vec3 delta; - uniform highp vec3 factor_0_2; - uniform highp vec3 factor_3_5; - uniform highp vec3 factor_6_8; - uniform highp vec3 factor_9_11; - uniform highp vec3 factor_12_14; - uniform highp vec3 factor_15_17; - uniform highp vec3 factor_18_20; - uniform highp vec3 factor_21_23; - uniform highp vec3 factor_24_26; - uniform highp vec3 factor_27_29; - uniform highp vec3 factor_30_32; - uniform highp float gaussianSum; - uniform highp float expandX; - uniform highp float expandY; - PLACEHOLDER_MASK_UNIFORMS - PLACEHOLDER_COLORIZE_UNIFORMS - - void main() { - highp vec2 shift = vec2(delta.x, delta.y); - - PLACEHOLDER_MASK_STEPS - - highp float index = delta.z; - mediump vec2 texCoord = qt_TexCoord0; - texCoord.s = (texCoord.s - expandX) / (1.0 - 2.0 * expandX); - texCoord.t = (texCoord.t - expandY) / (1.0 - 2.0 * expandY); - texCoord += (shift * index); - - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); - " - - property string fragmentShaderEnd: " - - gl_FragColor /= gaussianSum; - - PLACEHOLDER_COLORIZE_STEPS - - gl_FragColor *= qt_Opacity; - } - " - } -} diff --git a/src/effects/internal/GaussianGlow.qml b/src/effects/internal/GaussianGlow.qml deleted file mode 100644 index 467c4f3..0000000 --- a/src/effects/internal/GaussianGlow.qml +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property real radius: 0.0 - property int maximumRadius: 0 - property real spread: 0.0 - property color color: "white" - property bool cached: false - property bool transparentBorder: false - - SourceProxy { - id: sourceProxy - input: rootItem.source - sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: shaderItem - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - GaussianDirectionalBlur { - id: shaderItem - x: transparentBorder ? -maximumRadius - 1 : 0 - y: transparentBorder ? -maximumRadius - 1 : 0 - width: horizontalBlur.width - height: horizontalBlur.height - horizontalStep: 0.0 - verticalStep: 1.0 / parent.height - source: horizontalBlur - radius: rootItem.radius - maximumRadius: rootItem.maximumRadius - transparentBorder: rootItem.transparentBorder - enableColor: true - color: rootItem.color - spread: rootItem.spread - } - - GaussianDirectionalBlur { - id: horizontalBlur - width: transparentBorder ? parent.width + 2 * maximumRadius + 2 : parent.width - height: transparentBorder ? parent.height + 2 * maximumRadius + 2 : parent.height - horizontalStep: 1.0 / parent.width - verticalStep: 0.0 - source: sourceProxy.output - radius: rootItem.radius - maximumRadius: rootItem.maximumRadius - transparentBorder: rootItem.transparentBorder - visible: false - } -} diff --git a/src/effects/internal/GaussianInnerShadow.qml b/src/effects/internal/GaussianInnerShadow.qml deleted file mode 100644 index 0d185bd..0000000 --- a/src/effects/internal/GaussianInnerShadow.qml +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property real radius: 0.0 - property int maximumRadius: 0 - property real horizontalOffset: 0 - property real verticalOffset: 0 - property real spread: 0 - property color color: "black" - property bool cached: false - - SourceProxy { - id: sourceProxy - input: rootItem.source - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: shaderItem - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - ShaderEffect{ - id: shadowItem - anchors.fill: parent - - property variant original: sourceProxy.output - property color color: rootItem.color - property real horizontalOffset: rootItem.horizontalOffset / rootItem.width - property real verticalOffset: rootItem.verticalOffset / rootItem.height - - visible: false - fragmentShader: " - uniform highp sampler2D original; - uniform lowp float qt_Opacity; - uniform lowp vec4 color; - uniform highp float horizontalOffset; - uniform highp float verticalOffset; - varying highp vec2 qt_TexCoord0; - - void main(void) { - highp vec2 pos = qt_TexCoord0 - vec2(horizontalOffset, verticalOffset); - lowp float ea = step(0.0, pos.x) * step(0.0, pos.y) * step(pos.x, 1.0) * step(pos.y, 1.0); - lowp float eb = 1.0 - ea; - gl_FragColor = eb * color + ea * color * (1.0 - texture2D(original, pos).a) * qt_Opacity; - } - " - } - - GaussianDirectionalBlur { - id: blurItem - anchors.fill: parent - horizontalStep: 0.0 - verticalStep: 1.0 / parent.height - source: horizontalBlur - radius: rootItem.radius - maximumRadius: rootItem.maximumRadius - visible: false - } - - GaussianDirectionalBlur { - id: horizontalBlur - width: transparentBorder ? parent.width + 2 * maximumRadius : parent.width - height: parent.height - horizontalStep: 1.0 / parent.width - verticalStep: 0.0 - source: shadowItem - radius: rootItem.radius - maximumRadius: rootItem.maximumRadius - visible: false - } - - ShaderEffectSource { - id: blurredSource - sourceItem: blurItem - live: true - smooth: true - } - - ShaderEffect { - id: shaderItem - anchors.fill: parent - - property variant original: sourceProxy.output - property variant shadow: blurredSource - property real spread: 1.0 - (rootItem.spread * 0.98) - property color color: rootItem.color - - fragmentShader: " - uniform highp sampler2D original; - uniform highp sampler2D shadow; - uniform lowp float qt_Opacity; - uniform highp float spread; - uniform lowp vec4 color; - varying highp vec2 qt_TexCoord0; - - highp float linearstep(highp float e0, highp float e1, highp float x) { - return clamp((x - e0) / (e1 - e0), 0.0, 1.0); - } - - void main(void) { - lowp vec4 originalColor = texture2D(original, qt_TexCoord0); - lowp vec4 shadowColor = texture2D(shadow, qt_TexCoord0); - shadowColor.rgb = mix(originalColor.rgb, color.rgb * originalColor.a, linearstep(0.0, spread, shadowColor.a)); - gl_FragColor = vec4(shadowColor.rgb, originalColor.a) * originalColor.a * qt_Opacity; - } - " - } -} diff --git a/src/effects/internal/GaussianMaskedBlur.qml b/src/effects/internal/GaussianMaskedBlur.qml deleted file mode 100644 index a761668..0000000 --- a/src/effects/internal/GaussianMaskedBlur.qml +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant source - property variant maskSource - property real radius: 0.0 - property int maximumRadius: 0 - property bool cached: false - property bool transparentBorder: false - - SourceProxy { - id: sourceProxy - input: rootItem.source - sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) - } - - SourceProxy { - id: maskSourceProxy - input: rootItem.maskSource - sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) - } - - ShaderEffectSource { - id: cacheItem - anchors.fill: blur - visible: rootItem.cached - smooth: true - sourceItem: blur - live: true - hideSource: visible - } - - GaussianDirectionalBlur { - id: blur - x: transparentBorder ? -maximumRadius - 1: 0 - y: transparentBorder ? -maximumRadius - 1: 0 - width: horizontalBlur.width - height: horizontalBlur.height - horizontalStep: 0.0 - verticalStep: 1.0 / parent.height - source: horizontalBlur - enableMask: true - maskSource: maskSourceProxy.output - radius: rootItem.radius - maximumRadius: rootItem.maximumRadius - transparentBorder: rootItem.transparentBorder - } - - GaussianDirectionalBlur { - id: horizontalBlur - width: transparentBorder ? parent.width + 2 * maximumRadius + 2 : parent.width - height: transparentBorder ? parent.height + 2 * maximumRadius + 2 : parent.height - horizontalStep: 1.0 / parent.width - verticalStep: 0.0 - source: sourceProxy.output - enableMask: true - maskSource: maskSourceProxy.output - radius: rootItem.radius - maximumRadius: rootItem.maximumRadius - transparentBorder: rootItem.transparentBorder - visible: false - } -} diff --git a/src/effects/internal/SourceProxy.qml b/src/effects/internal/SourceProxy.qml deleted file mode 100644 index 6b9f8ed..0000000 --- a/src/effects/internal/SourceProxy.qml +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant input - property variant output: input - property variant sourceRect - visible: false - - Component.onCompleted: evaluateInput() - - onInputChanged: evaluateInput() - - onSourceRectChanged: evaluateInput() - - function evaluateInput() { - if (input == undefined) { - output = input - } - else if (sourceRect != undefined && sourceRect != Qt.rect(0, 0, 0, 0) && !isQQuickShaderEffectSource(input)) { - proxySource.sourceItem = input - output = proxySource - proxySource.sourceRect = sourceRect - } - else if (isQQuickItemLayerEnabled(input)) { - output = input - } - else if ((isQQuickImage(input) && !hasTileMode(input) && !hasChildren(input))) { - output = input - } - else if (isQQuickShaderEffectSource(input)) { - output = input - } - else { - proxySource.sourceItem = input - output = proxySource - proxySource.sourceRect = Qt.rect(0, 0, 0, 0) - } - } - - function isQQuickItemLayerEnabled(item) { - if (item.hasOwnProperty("layer")) { - var l = item["layer"] - if (l.hasOwnProperty("enabled") && l["enabled"].toString() == "true") - return true - } - return false - } - - function isQQuickImage(item) { - var imageProperties = [ "fillMode", "progress", "asynchronous", "sourceSize", "status", "smooth" ] - return hasProperties(item, imageProperties) - } - - function isQQuickShaderEffectSource(item) { - var shaderEffectSourceProperties = [ "hideSource", "format", "sourceItem", "mipmap", "wrapMode", "live", "recursive", "sourceRect" ] - return hasProperties(item, shaderEffectSourceProperties) - } - - function hasProperties(item, properties) { - var counter = 0 - for (var j = 0; j < properties.length; j++) { - if (item.hasOwnProperty(properties [j])) - counter++ - } - return properties.length == counter - } - - function hasChildren(item) { - if (item.hasOwnProperty("childrenRect")) { - if (item["childrenRect"].toString() != "QRectF(0, 0, 0, 0)") - return true - else - return false - } - return false - } - - function hasTileMode(item) { - if (item.hasOwnProperty("fillMode")) { - if (item["fillMode"].toString() != "0") - return true - else - return false - } - return false - } - - ShaderEffectSource { - id: proxySource - live: rootItem.input != rootItem.output - hideSource: false - smooth: true - visible: false - } -} diff --git a/src/effects/private/FastGlow.qml b/src/effects/private/FastGlow.qml new file mode 100644 index 0000000..081350b --- /dev/null +++ b/src/effects/private/FastGlow.qml @@ -0,0 +1,393 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property real spread: 0.0 + property real blur: 0.0 + property color color: "white" + property bool transparentBorder: false + property bool cached: false + + SourceProxy { + id: sourceProxy + input: rootItem.source + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: shaderItem + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + property string __internalBlurVertexShader: " + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + uniform highp mat4 qt_Matrix; + uniform highp float yStep; + uniform highp float xStep; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord3; + + void main() { + qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); + qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); + qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); + qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); + gl_Position = qt_Matrix * qt_Vertex; + } + " + + property string __internalBlurFragmentShader: " + uniform lowp sampler2D source; + uniform lowp float qt_Opacity; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord3; + + void main() { + highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + + texture2D(source, qt_TexCoord1) + + texture2D(source, qt_TexCoord2) + + texture2D(source, qt_TexCoord3)) * 0.25; + gl_FragColor = sourceColor * qt_Opacity; + } + " + + ShaderEffect { + id: level0 + property variant source: sourceProxy.output + anchors.fill: parent + visible: false + smooth: true + } + + ShaderEffectSource { + id: level1 + width: Math.ceil(shaderItem.width / 32) * 32 + height: Math.ceil(shaderItem.height / 32) * 32 + sourceItem: level0 + hideSource: rootItem.visible + sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0,0,0,0) + smooth: true + visible: false + } + + ShaderEffect { + id: effect1 + property variant source: level1 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level2 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level2 + width: level1.width / 2 + height: level1.height / 2 + sourceItem: effect1 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect2 + property variant source: level2 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level3 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level3 + width: level2.width / 2 + height: level2.height / 2 + sourceItem: effect2 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect3 + property variant source: level3 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level4 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level4 + width: level3.width / 2 + height: level3.height / 2 + sourceItem: effect3 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect4 + property variant source: level4 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level5 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level5 + width: level4.width / 2 + height: level4.height / 2 + sourceItem: effect4 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect5 + property variant source: level5 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level6 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level6 + width: level5.width / 2 + height: level5.height / 2 + sourceItem: effect5 + hideSource: rootItem.visible + visible: false + smooth: true + } + + Item { + id: dummysource + width: 1 + height: 1 + visible: false + } + + ShaderEffectSource { + id: dummy + width: 1 + height: 1 + sourceItem: dummysource + visible: false + smooth: false + live: false + } + + ShaderEffect { + id: shaderItem + x: transparentBorder ? -64 : 0 + y: transparentBorder ? -64 : 0 + width: transparentBorder ? parent.width + 128 : parent.width + height: transparentBorder ? parent.height + 128 : parent.height + + property variant source1: level1 + property variant source2: level2 + property variant source3: level3 + property variant source4: level4 + property variant source5: level5 + property variant source6: level6 + property real lod: rootItem.blur + + property real weight1; + property real weight2; + property real weight3; + property real weight4; + property real weight5; + property real weight6; + + property real spread: 1.0 - (rootItem.spread * 0.98) + property alias color: rootItem.color + + function weight(v) { + if (v <= 0.0) + return 1 + if (v >= 0.5) + return 0 + + return 1.0 - v / 0.5 + } + + function calculateWeights() { + + var w1 = weight(Math.abs(lod - 0.100)) + var w2 = weight(Math.abs(lod - 0.300)) + var w3 = weight(Math.abs(lod - 0.500)) + var w4 = weight(Math.abs(lod - 0.700)) + var w5 = weight(Math.abs(lod - 0.900)) + var w6 = weight(Math.abs(lod - 1.100)) + + var sum = w1 + w2 + w3 + w4 + w5 + w6; + weight1 = w1 / sum; + weight2 = w2 / sum; + weight3 = w3 / sum; + weight4 = w4 / sum; + weight5 = w5 / sum; + weight6 = w6 / sum; + + upateSources() + } + + function upateSources() { + var sources = new Array(); + var weights = new Array(); + + if (weight1 > 0) { + sources.push(level1) + weights.push(weight1) + } + + if (weight2 > 0) { + sources.push(level2) + weights.push(weight2) + } + + if (weight3 > 0) { + sources.push(level3) + weights.push(weight3) + } + + if (weight4 > 0) { + sources.push(level4) + weights.push(weight4) + } + + if (weight5 > 0) { + sources.push(level5) + weights.push(weight5) + } + + if (weight6 > 0) { + sources.push(level6) + weights.push(weight6) + } + + for (var j = sources.length; j < 6; j++) { + sources.push(dummy) + weights.push(0.0) + } + + source1 = sources[0] + source2 = sources[1] + source3 = sources[2] + source4 = sources[3] + source5 = sources[4] + source6 = sources[5] + + weight1 = weights[0] + weight2 = weights[1] + weight3 = weights[2] + weight4 = weights[3] + weight5 = weights[4] + weight6 = weights[5] + } + + Component.onCompleted: calculateWeights() + + onLodChanged: calculateWeights() + + fragmentShader: " + uniform lowp sampler2D source1; + uniform lowp sampler2D source2; + uniform lowp sampler2D source3; + uniform lowp sampler2D source4; + uniform lowp sampler2D source5; + uniform mediump float weight1; + uniform mediump float weight2; + uniform mediump float weight3; + uniform mediump float weight4; + uniform mediump float weight5; + uniform highp vec4 color; + uniform highp float spread; + uniform lowp float qt_Opacity; + varying mediump vec2 qt_TexCoord0; + + highp float linearstep(highp float e0, highp float e1, highp float x) { + return clamp((x - e0) / (e1 - e0), 0.0, 1.0); + } + + void main() { + lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1; + sourceColor += texture2D(source2, qt_TexCoord0) * weight2; + sourceColor += texture2D(source3, qt_TexCoord0) * weight3; + sourceColor += texture2D(source4, qt_TexCoord0) * weight4; + sourceColor += texture2D(source5, qt_TexCoord0) * weight5; + sourceColor = mix(vec4(0), color, linearstep(0.0, spread, sourceColor.a)); + gl_FragColor = sourceColor * qt_Opacity; + } + " + } +} diff --git a/src/effects/private/FastInnerShadow.qml b/src/effects/private/FastInnerShadow.qml new file mode 100644 index 0000000..04a45ce --- /dev/null +++ b/src/effects/private/FastInnerShadow.qml @@ -0,0 +1,413 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property real blur: 0.0 + property real horizontalOffset: 0 + property real verticalOffset: 0 + property real spread: 0.0 + property color color: "black" + property bool cached: false + + SourceProxy { + id: sourceProxy + input: rootItem.source + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: shaderItem + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + property string __internalBlurVertexShader: " + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + uniform highp mat4 qt_Matrix; + uniform highp float yStep; + uniform highp float xStep; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord3; + + void main() { + qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); + qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); + qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); + qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); + gl_Position = qt_Matrix * qt_Vertex; + } + " + + property string __internalBlurFragmentShader: " + uniform lowp sampler2D source; + uniform lowp float qt_Opacity; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord3; + + void main() { + highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + + texture2D(source, qt_TexCoord1) + + texture2D(source, qt_TexCoord2) + + texture2D(source, qt_TexCoord3)) * 0.25; + gl_FragColor = sourceColor * qt_Opacity; + } + " + + ShaderEffect { + id: level0 + property variant source: sourceProxy.output + property real horizontalOffset: rootItem.horizontalOffset / rootItem.width + property real verticalOffset: rootItem.verticalOffset / rootItem.width + property color color: rootItem.color + + anchors.fill: parent + visible: false + smooth: true + fragmentShader: " + varying highp vec2 qt_TexCoord0; + uniform lowp float qt_Opacity; + uniform highp sampler2D source; + uniform lowp vec4 color; + uniform highp float horizontalOffset; + uniform highp float verticalOffset; + + void main(void) { + highp vec2 pos = qt_TexCoord0 - vec2(horizontalOffset, verticalOffset); + lowp float ea = step(0.0, pos.x) * step(0.0, pos.y) * step(pos.x, 1.0) * step(pos.y, 1.0); + lowp float eb = 1.0 - ea; + gl_FragColor = (eb * color + ea * color * (1.0 - texture2D(source, pos).a)) * qt_Opacity; + } + " + } + + ShaderEffectSource { + id: level1 + width: Math.ceil(shaderItem.width / 32) * 32 + height: Math.ceil(shaderItem.height / 32) * 32 + sourceItem: level0 + hideSource: rootItem.visible + smooth: true + visible: false + } + + ShaderEffect { + id: effect1 + property variant source: level1 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level2 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level2 + width: level1.width / 2 + height: level1.height / 2 + sourceItem: effect1 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect2 + property variant source: level2 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level3 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level3 + width: level2.width / 2 + height: level2.height / 2 + sourceItem: effect2 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect3 + property variant source: level3 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level4 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level4 + width: level3.width / 2 + height: level3.height / 2 + sourceItem: effect3 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect4 + property variant source: level4 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level5 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level5 + width: level4.width / 2 + height: level4.height / 2 + sourceItem: effect4 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect5 + property variant source: level5 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level6 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level6 + width: level5.width / 2 + height: level5.height / 2 + sourceItem: effect5 + hideSource: rootItem.visible + visible: false + smooth: true + } + + Item { + id: dummysource + width: 1 + height: 1 + visible: false + } + + ShaderEffectSource { + id: dummy + width: 1 + height: 1 + sourceItem: dummysource + visible: false + smooth: false + live: false + } + + ShaderEffect { + id: shaderItem + width: parent.width + height: parent.height + + property variant original: sourceProxy.output + property variant source1: level1 + property variant source2: level2 + property variant source3: level3 + property variant source4: level4 + property variant source5: level5 + property variant source6: level6 + property real lod: rootItem.blur + + property real weight1; + property real weight2; + property real weight3; + property real weight4; + property real weight5; + property real weight6; + + property real spread: 1.0 - (rootItem.spread * 0.98) + property color color: rootItem.color + + function weight(v) { + if (v <= 0.0) + return 1 + if (v >= 0.5) + return 0 + + return 1.0 - v / 0.5 + } + + function calculateWeights() { + + var w1 = weight(Math.abs(lod - 0.100)) + var w2 = weight(Math.abs(lod - 0.300)) + var w3 = weight(Math.abs(lod - 0.500)) + var w4 = weight(Math.abs(lod - 0.700)) + var w5 = weight(Math.abs(lod - 0.900)) + var w6 = weight(Math.abs(lod - 1.100)) + + var sum = w1 + w2 + w3 + w4 + w5 + w6; + weight1 = w1 / sum; + weight2 = w2 / sum; + weight3 = w3 / sum; + weight4 = w4 / sum; + weight5 = w5 / sum; + weight6 = w6 / sum; + + upateSources() + } + + function upateSources() { + var sources = new Array(); + var weights = new Array(); + + if (weight1 > 0) { + sources.push(level1) + weights.push(weight1) + } + + if (weight2 > 0) { + sources.push(level2) + weights.push(weight2) + } + + if (weight3 > 0) { + sources.push(level3) + weights.push(weight3) + } + + if (weight4 > 0) { + sources.push(level4) + weights.push(weight4) + } + + if (weight5 > 0) { + sources.push(level5) + weights.push(weight5) + } + + if (weight6 > 0) { + sources.push(level6) + weights.push(weight6) + } + + for (var j = sources.length; j < 6; j++) { + sources.push(dummy) + weights.push(0.0) + } + + source1 = sources[0] + source2 = sources[1] + source3 = sources[2] + source4 = sources[3] + source5 = sources[4] + source6 = sources[5] + + weight1 = weights[0] + weight2 = weights[1] + weight3 = weights[2] + weight4 = weights[3] + weight5 = weights[4] + weight6 = weights[5] + } + + Component.onCompleted: calculateWeights() + + onLodChanged: calculateWeights() + + fragmentShader: " + uniform lowp sampler2D original; + uniform lowp sampler2D source1; + uniform lowp sampler2D source2; + uniform lowp sampler2D source3; + uniform lowp sampler2D source4; + uniform lowp sampler2D source5; + uniform mediump float weight1; + uniform mediump float weight2; + uniform mediump float weight3; + uniform mediump float weight4; + uniform mediump float weight5; + uniform highp vec4 color; + uniform highp float spread; + uniform lowp float qt_Opacity; + varying mediump vec2 qt_TexCoord0; + + highp float linearstep(highp float e0, highp float e1, highp float x) { + return clamp((x - e0) / (e1 - e0), 0.0, 1.0); + } + + void main() { + lowp vec4 shadowColor = texture2D(source1, qt_TexCoord0) * weight1; + shadowColor += texture2D(source2, qt_TexCoord0) * weight2; + shadowColor += texture2D(source3, qt_TexCoord0) * weight3; + shadowColor += texture2D(source4, qt_TexCoord0) * weight4; + shadowColor += texture2D(source5, qt_TexCoord0) * weight5; + lowp vec4 originalColor = texture2D(original, qt_TexCoord0); + shadowColor.rgb = mix(originalColor.rgb, color.rgb * originalColor.a, linearstep(0.0, spread, shadowColor.a)); + gl_FragColor = vec4(shadowColor.rgb, originalColor.a) * originalColor.a * qt_Opacity; + } + " + } +} diff --git a/src/effects/private/FastMaskedBlur.qml b/src/effects/private/FastMaskedBlur.qml new file mode 100644 index 0000000..d40e295 --- /dev/null +++ b/src/effects/private/FastMaskedBlur.qml @@ -0,0 +1,332 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property variant maskSource + property real blur: 0.0 + property bool transparentBorder: false + property bool cached: false + + SourceProxy { + id: sourceProxy + input: rootItem.source + } + + SourceProxy { + id: maskSourceProxy + input: rootItem.maskSource + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: shaderItem + visible: rootItem.cached + sourceItem: shaderItem + live: true + hideSource: visible + smooth: rootItem.blur > 0 + } + + property string __internalBlurVertexShader: " + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + uniform highp mat4 qt_Matrix; + uniform highp float yStep; + uniform highp float xStep; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord3; + + void main() { + qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); + qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); + qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); + qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); + gl_Position = qt_Matrix * qt_Vertex; + } + " + + property string __internalBlurFragmentShader: " + uniform lowp sampler2D source; + uniform lowp float qt_Opacity; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord3; + + void main() { + highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + + texture2D(source, qt_TexCoord1) + + texture2D(source, qt_TexCoord2) + + texture2D(source, qt_TexCoord3)) * 0.25; + gl_FragColor = sourceColor * qt_Opacity; + } + " + + ShaderEffect { + id: mask0 + property variant source: maskSourceProxy.output + anchors.fill: parent + visible: false + smooth: true + } + + ShaderEffectSource { + id: masklevel1 + width: Math.ceil(shaderItem.width / 32) * 32 + height: Math.ceil(shaderItem.height / 32) * 32 + sourceItem: mask0 + hideSource: rootItem.visible + sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0) + visible: false + smooth: rootItem.blur > 0 + } + + ShaderEffect { + id: level0 + property variant source: sourceProxy.output + anchors.fill: parent + visible: false + smooth: true + } + + ShaderEffectSource { + id: level1 + width: Math.ceil(shaderItem.width / 32) * 32 + height: Math.ceil(shaderItem.height / 32) * 32 + sourceItem: level0 + hideSource: rootItem.visible + sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0) + visible: false + smooth: rootItem.blur > 0 + } + + ShaderEffect { + id: effect1 + property variant source: level1 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level2 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level2 + width: level1.width / 2 + height: level1.height / 2 + sourceItem: effect1 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect2 + property variant source: level2 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level3 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level3 + width: level2.width / 2 + height: level2.height / 2 + sourceItem: effect2 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect3 + property variant source: level3 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level4 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level4 + width: level3.width / 2 + height: level3.height / 2 + sourceItem: effect3 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect4 + property variant source: level4 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level5 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level5 + width: level4.width / 2 + height: level4.height / 2 + sourceItem: effect4 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: effect5 + property variant source: level5 + property real yStep: 1/height + property real xStep: 1/width + anchors.fill: level6 + visible: false + smooth: true + vertexShader: __internalBlurVertexShader + fragmentShader: __internalBlurFragmentShader + } + + ShaderEffectSource { + id: level6 + width: level5.width / 2 + height: level5.height / 2 + sourceItem: effect5 + hideSource: rootItem.visible + visible: false + smooth: true + } + + ShaderEffect { + id: shaderItem + property variant mask: masklevel1 + property variant source1: level1 + property variant source2: level2 + property variant source3: level3 + property variant source4: level4 + property variant source5: level5 + property variant source6: level6 + property real lod: Math.sqrt(rootItem.blur) * 1.2 - 0.2 + property real weight1 + property real weight2 + property real weight3 + property real weight4 + property real weight5 + property real weight6 + + x: transparentBorder ? -64 : 0 + y: transparentBorder ? -64 : 0 + width: transparentBorder ? parent.width + 128 : parent.width + height: transparentBorder ? parent.height + 128 : parent.height + + fragmentShader: " + uniform lowp sampler2D mask; + uniform lowp sampler2D source1; + uniform lowp sampler2D source2; + uniform lowp sampler2D source3; + uniform lowp sampler2D source4; + uniform lowp sampler2D source5; + uniform lowp sampler2D source6; + uniform lowp float lod; + uniform lowp float qt_Opacity; + varying mediump vec2 qt_TexCoord0; + + mediump float weight(mediump float v) { + if (v <= 0.0) + return 1.0; + + if (v >= 0.5) + return 0.0; + + return 1.0 - v * 2.0; + } + + void main() { + + lowp vec4 maskColor = texture2D(mask, qt_TexCoord0); + mediump float l = lod * maskColor.a; + + mediump float w1 = weight(abs(l - 0.100)); + mediump float w2 = weight(abs(l - 0.300)); + mediump float w3 = weight(abs(l - 0.500)); + mediump float w4 = weight(abs(l - 0.700)); + mediump float w5 = weight(abs(l - 0.900)); + mediump float w6 = weight(abs(l - 1.100)); + + mediump float sum = w1 + w2 + w3 + w4 + w5 + w6; + mediump float weight1 = w1 / sum; + mediump float weight2 = w2 / sum; + mediump float weight3 = w3 / sum; + mediump float weight4 = w4 / sum; + mediump float weight5 = w5 / sum; + mediump float weight6 = w6 / sum; + + lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1; + sourceColor += texture2D(source2, qt_TexCoord0) * weight2; + sourceColor += texture2D(source3, qt_TexCoord0) * weight3; + sourceColor += texture2D(source4, qt_TexCoord0) * weight4; + sourceColor += texture2D(source5, qt_TexCoord0) * weight5; + sourceColor += texture2D(source6, qt_TexCoord0) * weight6; + + gl_FragColor = sourceColor * qt_Opacity; + + } + " + } +} diff --git a/src/effects/private/GaussianDirectionalBlur.qml b/src/effects/private/GaussianDirectionalBlur.qml new file mode 100644 index 0000000..5515a96 --- /dev/null +++ b/src/effects/private/GaussianDirectionalBlur.qml @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property real deviation: (radius + 1) / 3.3333 + property real radius: 0.0 + property int maximumRadius: 0 + property real horizontalStep: 0.0 + property real verticalStep: 0.0 + property bool transparentBorder: false + property bool cached: false + + property bool enableColor: false + property color color: "white" + property real spread: 0.0 + + property bool enableMask: false + property variant maskSource + + SourceProxy { + id: sourceProxy + input: rootItem.source + } + + SourceProxy { + id: maskSourceProxy + input: rootItem.maskSource + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: rootItem + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + ShaderEffect { + id: shaderItem + property variant source: sourceProxy.output + property real deviation: Math.max(0.1, rootItem.deviation) + property real radius: rootItem.radius + property int maxRadius: rootItem.maximumRadius + property bool transparentBorder: rootItem.transparentBorder + property real gaussianSum: 0.0 + property real startIndex: 0.0 + property real deltaFactor: (2 * radius - 1) / (maxRadius * 2 - 1) + property real expandX: transparentBorder && rootItem.horizontalStep > 0 ? maxRadius / width : 0.0 + property real expandY: transparentBorder && rootItem.verticalStep > 0 ? maxRadius / height : 0.0 + property variant gwts: [] + property variant delta: Qt.vector3d(rootItem.horizontalStep * deltaFactor, rootItem.verticalStep * deltaFactor, startIndex); + property variant factor_0_2: Qt.vector3d(gwts[0], gwts[1], gwts[2]); + property variant factor_3_5: Qt.vector3d(gwts[3], gwts[4], gwts[5]); + property variant factor_6_8: Qt.vector3d(gwts[6], gwts[7], gwts[8]); + property variant factor_9_11: Qt.vector3d(gwts[9], gwts[10], gwts[11]); + property variant factor_12_14: Qt.vector3d(gwts[12], gwts[13], gwts[14]); + property variant factor_15_17: Qt.vector3d(gwts[15], gwts[16], gwts[17]); + property variant factor_18_20: Qt.vector3d(gwts[18], gwts[19], gwts[20]); + property variant factor_21_23: Qt.vector3d(gwts[21], gwts[22], gwts[23]); + property variant factor_24_26: Qt.vector3d(gwts[24], gwts[25], gwts[26]); + property variant factor_27_29: Qt.vector3d(gwts[27], gwts[28], gwts[29]); + property variant factor_30_32: Qt.vector3d(gwts[30], gwts[31], gwts[32]); + + property color color: rootItem.color + property real spread: 1.0 - (rootItem.spread * 0.98) + property variant maskSource: maskSourceProxy.output + + anchors.fill: rootItem + + function gausFunc(x){ + //Gaussian function = h(x):=(1/sqrt(2*3.14159*(D^2))) * %e^(-(x^2)/(2*(D^2))); + return (1.0 / Math.sqrt(2 * Math.PI * (Math.pow(shaderItem.deviation, 2)))) * Math.pow(Math.E, -((Math.pow(x, 2)) / (2 * (Math.pow(shaderItem.deviation, 2))))); + } + + function updateGaussianWeights() { + gaussianSum = 0.0; + startIndex = -maxRadius + 0.5 + + var n = new Array(32); + for (var j = 0; j < 32; j++) + n[j] = 0; + + var max = maxRadius * 2 + var delta = (2 * radius - 1) / (max - 1); + for (var i = 0; i < max; i++) { + n[i] = gausFunc(-radius + 0.5 + i * delta); + gaussianSum += n[i]; + } + + gwts = n; + } + + function buildFragmentShader() { + + var shaderSteps = [ + "gl_FragColor += texture2D(source, texCoord) * factor_0_2.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_0_2.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_0_2.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_3_5.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_3_5.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_3_5.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_6_8.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_6_8.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_6_8.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_9_11.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_9_11.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_9_11.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_12_14.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_12_14.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_12_14.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_15_17.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_15_17.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_15_17.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_18_20.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_18_20.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_18_20.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_21_23.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_21_23.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_21_23.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_24_26.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_24_26.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_24_26.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_27_29.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_27_29.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_27_29.z; texCoord += shift;", + + "gl_FragColor += texture2D(source, texCoord) * factor_30_32.x; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_30_32.y; texCoord += shift;", + "gl_FragColor += texture2D(source, texCoord) * factor_30_32.z; texCoord += shift;" + ] + + var shader = fragmentShaderBegin + var samples = maxRadius * 2 + if (samples > 32) { + console.log("DirectionalGaussianBlur.qml WARNING: Maximum of blur radius (16) exceeded!") + samples = 32 + } + + for (var i = 0; i < samples; i++) { + shader += shaderSteps[i] + } + + shader += fragmentShaderEnd + + var colorizeSteps = "" + var colorizeUniforms = "" + + var maskSteps = "" + var maskUniforms = "" + + if (enableColor) { + colorizeSteps += "gl_FragColor = mix(vec4(0), color, clamp((gl_FragColor.a - 0.0) / (spread - 0.0), 0.0, 1.0));\n" + colorizeUniforms += "uniform highp vec4 color;\n" + colorizeUniforms += "uniform highp float spread;\n" + } + + if (enableMask) { + maskSteps += "shift *= texture2D(maskSource, qt_TexCoord0).a;\n" + maskUniforms += "uniform sampler2D maskSource;\n" + } + + shader = shader.replace("PLACEHOLDER_COLORIZE_STEPS", colorizeSteps) + shader = shader.replace("PLACEHOLDER_COLORIZE_UNIFORMS", colorizeUniforms) + shader = shader.replace("PLACEHOLDER_MASK_STEPS", maskSteps) + shader = shader.replace("PLACEHOLDER_MASK_UNIFORMS", maskUniforms) + + fragmentShader = shader + } + + onDeviationChanged: updateGaussianWeights() + + onRadiusChanged: updateGaussianWeights() + + onTransparentBorderChanged: { + buildFragmentShader() + updateGaussianWeights() + } + + onMaxRadiusChanged: { + buildFragmentShader() + updateGaussianWeights() + } + + Component.onCompleted: { + buildFragmentShader() + updateGaussianWeights() + } + + property string fragmentShaderBegin: " + varying mediump vec2 qt_TexCoord0; + uniform highp float qt_Opacity; + uniform lowp sampler2D source; + uniform highp vec3 delta; + uniform highp vec3 factor_0_2; + uniform highp vec3 factor_3_5; + uniform highp vec3 factor_6_8; + uniform highp vec3 factor_9_11; + uniform highp vec3 factor_12_14; + uniform highp vec3 factor_15_17; + uniform highp vec3 factor_18_20; + uniform highp vec3 factor_21_23; + uniform highp vec3 factor_24_26; + uniform highp vec3 factor_27_29; + uniform highp vec3 factor_30_32; + uniform highp float gaussianSum; + uniform highp float expandX; + uniform highp float expandY; + PLACEHOLDER_MASK_UNIFORMS + PLACEHOLDER_COLORIZE_UNIFORMS + + void main() { + highp vec2 shift = vec2(delta.x, delta.y); + + PLACEHOLDER_MASK_STEPS + + highp float index = delta.z; + mediump vec2 texCoord = qt_TexCoord0; + texCoord.s = (texCoord.s - expandX) / (1.0 - 2.0 * expandX); + texCoord.t = (texCoord.t - expandY) / (1.0 - 2.0 * expandY); + texCoord += (shift * index); + + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + " + + property string fragmentShaderEnd: " + + gl_FragColor /= gaussianSum; + + PLACEHOLDER_COLORIZE_STEPS + + gl_FragColor *= qt_Opacity; + } + " + } +} diff --git a/src/effects/private/GaussianGlow.qml b/src/effects/private/GaussianGlow.qml new file mode 100644 index 0000000..467c4f3 --- /dev/null +++ b/src/effects/private/GaussianGlow.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property real radius: 0.0 + property int maximumRadius: 0 + property real spread: 0.0 + property color color: "white" + property bool cached: false + property bool transparentBorder: false + + SourceProxy { + id: sourceProxy + input: rootItem.source + sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: shaderItem + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + GaussianDirectionalBlur { + id: shaderItem + x: transparentBorder ? -maximumRadius - 1 : 0 + y: transparentBorder ? -maximumRadius - 1 : 0 + width: horizontalBlur.width + height: horizontalBlur.height + horizontalStep: 0.0 + verticalStep: 1.0 / parent.height + source: horizontalBlur + radius: rootItem.radius + maximumRadius: rootItem.maximumRadius + transparentBorder: rootItem.transparentBorder + enableColor: true + color: rootItem.color + spread: rootItem.spread + } + + GaussianDirectionalBlur { + id: horizontalBlur + width: transparentBorder ? parent.width + 2 * maximumRadius + 2 : parent.width + height: transparentBorder ? parent.height + 2 * maximumRadius + 2 : parent.height + horizontalStep: 1.0 / parent.width + verticalStep: 0.0 + source: sourceProxy.output + radius: rootItem.radius + maximumRadius: rootItem.maximumRadius + transparentBorder: rootItem.transparentBorder + visible: false + } +} diff --git a/src/effects/private/GaussianInnerShadow.qml b/src/effects/private/GaussianInnerShadow.qml new file mode 100644 index 0000000..0d185bd --- /dev/null +++ b/src/effects/private/GaussianInnerShadow.qml @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property real radius: 0.0 + property int maximumRadius: 0 + property real horizontalOffset: 0 + property real verticalOffset: 0 + property real spread: 0 + property color color: "black" + property bool cached: false + + SourceProxy { + id: sourceProxy + input: rootItem.source + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: shaderItem + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + ShaderEffect{ + id: shadowItem + anchors.fill: parent + + property variant original: sourceProxy.output + property color color: rootItem.color + property real horizontalOffset: rootItem.horizontalOffset / rootItem.width + property real verticalOffset: rootItem.verticalOffset / rootItem.height + + visible: false + fragmentShader: " + uniform highp sampler2D original; + uniform lowp float qt_Opacity; + uniform lowp vec4 color; + uniform highp float horizontalOffset; + uniform highp float verticalOffset; + varying highp vec2 qt_TexCoord0; + + void main(void) { + highp vec2 pos = qt_TexCoord0 - vec2(horizontalOffset, verticalOffset); + lowp float ea = step(0.0, pos.x) * step(0.0, pos.y) * step(pos.x, 1.0) * step(pos.y, 1.0); + lowp float eb = 1.0 - ea; + gl_FragColor = eb * color + ea * color * (1.0 - texture2D(original, pos).a) * qt_Opacity; + } + " + } + + GaussianDirectionalBlur { + id: blurItem + anchors.fill: parent + horizontalStep: 0.0 + verticalStep: 1.0 / parent.height + source: horizontalBlur + radius: rootItem.radius + maximumRadius: rootItem.maximumRadius + visible: false + } + + GaussianDirectionalBlur { + id: horizontalBlur + width: transparentBorder ? parent.width + 2 * maximumRadius : parent.width + height: parent.height + horizontalStep: 1.0 / parent.width + verticalStep: 0.0 + source: shadowItem + radius: rootItem.radius + maximumRadius: rootItem.maximumRadius + visible: false + } + + ShaderEffectSource { + id: blurredSource + sourceItem: blurItem + live: true + smooth: true + } + + ShaderEffect { + id: shaderItem + anchors.fill: parent + + property variant original: sourceProxy.output + property variant shadow: blurredSource + property real spread: 1.0 - (rootItem.spread * 0.98) + property color color: rootItem.color + + fragmentShader: " + uniform highp sampler2D original; + uniform highp sampler2D shadow; + uniform lowp float qt_Opacity; + uniform highp float spread; + uniform lowp vec4 color; + varying highp vec2 qt_TexCoord0; + + highp float linearstep(highp float e0, highp float e1, highp float x) { + return clamp((x - e0) / (e1 - e0), 0.0, 1.0); + } + + void main(void) { + lowp vec4 originalColor = texture2D(original, qt_TexCoord0); + lowp vec4 shadowColor = texture2D(shadow, qt_TexCoord0); + shadowColor.rgb = mix(originalColor.rgb, color.rgb * originalColor.a, linearstep(0.0, spread, shadowColor.a)); + gl_FragColor = vec4(shadowColor.rgb, originalColor.a) * originalColor.a * qt_Opacity; + } + " + } +} diff --git a/src/effects/private/GaussianMaskedBlur.qml b/src/effects/private/GaussianMaskedBlur.qml new file mode 100644 index 0000000..a761668 --- /dev/null +++ b/src/effects/private/GaussianMaskedBlur.qml @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant source + property variant maskSource + property real radius: 0.0 + property int maximumRadius: 0 + property bool cached: false + property bool transparentBorder: false + + SourceProxy { + id: sourceProxy + input: rootItem.source + sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) + } + + SourceProxy { + id: maskSourceProxy + input: rootItem.maskSource + sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) + } + + ShaderEffectSource { + id: cacheItem + anchors.fill: blur + visible: rootItem.cached + smooth: true + sourceItem: blur + live: true + hideSource: visible + } + + GaussianDirectionalBlur { + id: blur + x: transparentBorder ? -maximumRadius - 1: 0 + y: transparentBorder ? -maximumRadius - 1: 0 + width: horizontalBlur.width + height: horizontalBlur.height + horizontalStep: 0.0 + verticalStep: 1.0 / parent.height + source: horizontalBlur + enableMask: true + maskSource: maskSourceProxy.output + radius: rootItem.radius + maximumRadius: rootItem.maximumRadius + transparentBorder: rootItem.transparentBorder + } + + GaussianDirectionalBlur { + id: horizontalBlur + width: transparentBorder ? parent.width + 2 * maximumRadius + 2 : parent.width + height: transparentBorder ? parent.height + 2 * maximumRadius + 2 : parent.height + horizontalStep: 1.0 / parent.width + verticalStep: 0.0 + source: sourceProxy.output + enableMask: true + maskSource: maskSourceProxy.output + radius: rootItem.radius + maximumRadius: rootItem.maximumRadius + transparentBorder: rootItem.transparentBorder + visible: false + } +} diff --git a/src/effects/private/SourceProxy.qml b/src/effects/private/SourceProxy.qml new file mode 100644 index 0000000..6b9f8ed --- /dev/null +++ b/src/effects/private/SourceProxy.qml @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: rootItem + property variant input + property variant output: input + property variant sourceRect + visible: false + + Component.onCompleted: evaluateInput() + + onInputChanged: evaluateInput() + + onSourceRectChanged: evaluateInput() + + function evaluateInput() { + if (input == undefined) { + output = input + } + else if (sourceRect != undefined && sourceRect != Qt.rect(0, 0, 0, 0) && !isQQuickShaderEffectSource(input)) { + proxySource.sourceItem = input + output = proxySource + proxySource.sourceRect = sourceRect + } + else if (isQQuickItemLayerEnabled(input)) { + output = input + } + else if ((isQQuickImage(input) && !hasTileMode(input) && !hasChildren(input))) { + output = input + } + else if (isQQuickShaderEffectSource(input)) { + output = input + } + else { + proxySource.sourceItem = input + output = proxySource + proxySource.sourceRect = Qt.rect(0, 0, 0, 0) + } + } + + function isQQuickItemLayerEnabled(item) { + if (item.hasOwnProperty("layer")) { + var l = item["layer"] + if (l.hasOwnProperty("enabled") && l["enabled"].toString() == "true") + return true + } + return false + } + + function isQQuickImage(item) { + var imageProperties = [ "fillMode", "progress", "asynchronous", "sourceSize", "status", "smooth" ] + return hasProperties(item, imageProperties) + } + + function isQQuickShaderEffectSource(item) { + var shaderEffectSourceProperties = [ "hideSource", "format", "sourceItem", "mipmap", "wrapMode", "live", "recursive", "sourceRect" ] + return hasProperties(item, shaderEffectSourceProperties) + } + + function hasProperties(item, properties) { + var counter = 0 + for (var j = 0; j < properties.length; j++) { + if (item.hasOwnProperty(properties [j])) + counter++ + } + return properties.length == counter + } + + function hasChildren(item) { + if (item.hasOwnProperty("childrenRect")) { + if (item["childrenRect"].toString() != "QRectF(0, 0, 0, 0)") + return true + else + return false + } + return false + } + + function hasTileMode(item) { + if (item.hasOwnProperty("fillMode")) { + if (item["fillMode"].toString() != "0") + return true + else + return false + } + return false + } + + ShaderEffectSource { + id: proxySource + live: rootItem.input != rootItem.output + hideSource: false + smooth: true + visible: false + } +} -- cgit v1.2.1