Browse Source

Introduce shader effects (taken from qmlvideofx) for experimentation

Change-Id: I34adddb39e6b6fd52f6d7147d0de6d72632bc2e5
Donald Carr 9 years ago
parent
commit
9fce6e5e9d

+ 1 - 0
qml/ArtDelegate.qml

@@ -6,6 +6,7 @@ ImageBoxBody {
     id: picture
 
     signal beyondThePale(var item)
+    property var effect
 
     onYChanged:
         if (y > globalFloor.y)

+ 18 - 7
qml/Gravity.qml

@@ -9,6 +9,7 @@ Item {
     signal next
 
     property var pictureDelegate: Qt.createComponent("HorizontalArtDelegate.qml")
+    property var effectDelegate: Qt.createComponent("VisualEffect.qml")
 
     anchors.fill: parent
 
@@ -21,6 +22,7 @@ Item {
         property int columnCount: settings.columnCount
         property bool running: primedColumns >= columnCount
         property bool globalWorld: settings.globalWorld
+        property bool embossEffect: settings.embossEffect
 
         function reset() {
             itemCount = 0
@@ -66,17 +68,26 @@ Item {
             }
 
             function addImage() {
-                var item = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
-                item.beyondThePale.connect(removeImage)
-                stackHeight += (item.height + d.itemTravel)
-                item.world = d.globalWorld ? commonWorld : columnWorld
-                item.x = xOffset
-                item.y = floor.y - stackHeight
+                var image = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
+
+                if (d.embossEffect) {
+                  image.effect = effectDelegate.createObject(column)
+                  image.effect.target = image
+                }
+                image.beyondThePale.connect(removeImage)
+                image.world = d.globalWorld ? commonWorld : columnWorld
+                image.x = xOffset
+                stackHeight += (image.height + d.itemTravel)
+                image.y = floor.y - stackHeight
+
+                pictureArray.push(image)
                 d.itemCount++
-                pictureArray.push(item)
             }
 
             function removeImage(image) {
+                if (image.effect) {
+                    image.effect.destroy()
+                }
                 stackHeight -= (image.height + d.itemTravel)
                 image.destroy()
                 d.itemCount--

+ 21 - 0
qml/VisualEffect.qml

@@ -0,0 +1,21 @@
+import QtQuick 2.5
+import "effects" as Effects
+
+Item {
+    property alias target: source.sourceItem
+
+    anchors.fill: target
+    ShaderEffectSource {
+        id: source
+        smooth: true
+        hideSource: true
+        sourceItem: target
+    }
+
+    Effects.Emboss {
+        source: source
+        anchors.fill: parent
+        targetWidth: parent.width
+        targetHeight: parent.height
+    }
+}

+ 60 - 0
qml/effects/Billboard.qml

@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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.5
+
+Effect {
+    property real grid: 30.0
+
+    property real step_x: 0.0015625
+    property real step_y: targetHeight ? (step_x * targetWidth / targetHeight) : 0.0
+
+    fragmentShaderFilename: "billboard.fsh"
+}

+ 81 - 0
qml/effects/Effect.qml

@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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.5
+
+ShaderEffect {
+    property variant source
+    property real targetWidth: 0
+    property real targetHeight: 0
+    property string fragmentShaderFilename
+    property string vertexShaderFilename
+
+    QtObject {
+        id: d
+        property string fragmentShaderCommon: "
+            #ifdef GL_ES
+                precision mediump float;
+            #else
+            #   define lowp
+            #   define mediump
+            #   define highp
+            #endif // GL_ES
+        "
+    }
+
+    // The following is a workaround for the fact that ShaderEffect
+    // doesn't provide a way for shader programs to be read from a file,
+    // rather than being inline in the QML file
+
+    onFragmentShaderFilenameChanged:
+        fragmentShader = d.fragmentShaderCommon + fileReader.readFile(":shaders/" + fragmentShaderFilename)
+    onVertexShaderFilenameChanged:
+        vertexShader = fileReader.readFile(":shaders/" + vertexShaderFilename)
+}

+ 55 - 0
qml/effects/Emboss.qml

@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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.5
+
+Effect {
+    fragmentShaderFilename: "emboss.fsh"
+}

+ 102 - 0
qml/effects/GaussianBlur.qml

@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+// Based on http://www.geeks3d.com/20100909/shader-library-gaussian-blur-post-processing-filter-in-glsl/
+
+import QtQuick 2.5
+
+Item {
+    id: root
+    property real radius: 0.5
+
+    function updateBlurSize()
+    {
+        if ((targetHeight > 0) && (targetWidth > 0))
+        {
+            verticalBlurSize = 4.0 * radius / targetHeight;
+            horizontalBlurSize = 4.0 * radius / targetWidth;
+        }
+    }
+
+    property alias targetWidth: verticalShader.targetWidth
+    property alias targetHeight: verticalShader.targetHeight
+    property alias source: verticalShader.source
+    property alias horizontalBlurSize: horizontalShader.blurSize
+    property alias verticalBlurSize: verticalShader.blurSize
+
+    Effect {
+        id: verticalShader
+        anchors.fill:  parent
+        property real blurSize: 0.0
+
+        onTargetHeightChanged: {
+            updateBlurSize()
+        }
+        onTargetWidthChanged: {
+            updateBlurSize()
+        }
+        fragmentShaderFilename: "gaussianblur_v.fsh"
+    }
+
+    Effect {
+        id: horizontalShader
+        anchors.fill: parent
+        property real blurSize: 0.0
+        fragmentShaderFilename: "gaussianblur_h.fsh"
+        source: horizontalShaderSource
+
+        ShaderEffectSource {
+            id: horizontalShaderSource
+            sourceItem: verticalShader
+            smooth: true
+            hideSource: true
+        }
+    }
+}

+ 2 - 0
qml/main.qml

@@ -20,6 +20,7 @@ Window {
         property bool globalWorld: false
         // Very computationally heavy: 40% vs 20% for 0.1 vs 0
         property double restitution: 0.1
+        property bool embossEffect: false
     }
 
     Rectangle {
@@ -27,6 +28,7 @@ Window {
         color: "black"
         anchors.fill: parent
         Keys.forwardTo: [punk, toplevelhandler]
+
         Gravity {
             // TODO: generalize all this
             id: punk

+ 5 - 0
qml/qml.qrc

@@ -7,5 +7,10 @@
         <file>HorizontalArtDelegate.qml</file>
         <file>Gravity.qml</file>
         <file>Ticker.qml</file>
+        <file>effects/Effect.qml</file>
+        <file>effects/Billboard.qml</file>
+        <file>effects/Emboss.qml</file>
+        <file>effects/GaussianBlur.qml</file>
+        <file>VisualEffect.qml</file>
     </qresource>
 </RCC>

+ 4 - 0
resources/resources.qrc

@@ -1,5 +1,9 @@
 <RCC>
     <qresource prefix="/">
         <file>qt_logo_green_rgb.png</file>
+        <file>shaders/billboard.fsh</file>
+        <file>shaders/emboss.fsh</file>
+        <file>shaders/gaussianblur_h.fsh</file>
+        <file>shaders/gaussianblur_v.fsh</file>
     </qresource>
 </RCC>

+ 79 - 0
resources/shaders/billboard.fsh

@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html
+
+uniform float grid;
+uniform float step_x;
+uniform float step_y;
+
+uniform sampler2D source;
+uniform lowp float qt_Opacity;
+varying vec2 qt_TexCoord0;
+
+void main()
+{
+    vec2 uv = qt_TexCoord0.xy;
+    float offx = floor(uv.x  / (grid * step_x));
+    float offy = floor(uv.y  / (grid * step_y));
+    vec3 res = texture2D(source, vec2(offx * grid * step_x , offy * grid * step_y)).rgb;
+    vec2 prc = fract(uv / vec2(grid * step_x, grid * step_y));
+    vec2 pw = pow(abs(prc - 0.5), vec2(2.0));
+    float  rs = pow(0.45, 2.0);
+    float gr = smoothstep(rs - 0.1, rs + 0.1, pw.x + pw.y);
+    float y = (res.r + res.g + res.b) / 3.0;
+    vec3 ra = res / y;
+    float ls = 0.3;
+    float lb = ceil(y / ls);
+    float lf = ls * lb + 0.3;
+    res = lf * res;
+    vec3 col = mix(res, vec3(0.1, 0.1, 0.1), gr);
+    gl_FragColor = qt_Opacity * vec4(col, 1.0);
+}

+ 76 - 0
resources/shaders/emboss.fsh

@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html
+
+const float step_w = 0.0015625;
+const float step_h = 0.0027778;
+
+uniform sampler2D source;
+uniform lowp float qt_Opacity;
+varying vec2 qt_TexCoord0;
+
+void main()
+{
+    vec2 uv = qt_TexCoord0.xy;
+    vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb;
+    vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb;
+    vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb;
+    vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb;
+    vec3 t5 = texture2D(source, uv).rgb;
+    vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb;
+    vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb;
+    vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb;
+    vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb;
+    vec3 rr = -4.0 * t1 - 4.0 * t2 - 4.0 * t4 + 12.0 * t5;
+    float y = (rr.r + rr.g + rr.b) / 3.0;
+    vec3 col = vec3(y, y, y) + 0.3;
+    gl_FragColor = qt_Opacity * vec4(col, 1.0);
+}

+ 71 - 0
resources/shaders/gaussianblur_h.fsh

@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+uniform float blurSize;
+
+uniform sampler2D source;
+uniform lowp float qt_Opacity;
+varying vec2 qt_TexCoord0;
+
+void main()
+{
+    vec2 uv = qt_TexCoord0.xy;
+    vec4 c = vec4(0.0);
+    c += texture2D(source, uv - vec2(4.0*blurSize, 0.0)) * 0.05;
+    c += texture2D(source, uv - vec2(3.0*blurSize, 0.0)) * 0.09;
+    c += texture2D(source, uv - vec2(2.0*blurSize, 0.0)) * 0.12;
+    c += texture2D(source, uv - vec2(1.0*blurSize, 0.0)) * 0.15;
+    c += texture2D(source, uv) * 0.18;
+    c += texture2D(source, uv + vec2(1.0*blurSize, 0.0)) * 0.15;
+    c += texture2D(source, uv + vec2(2.0*blurSize, 0.0)) * 0.12;
+    c += texture2D(source, uv + vec2(3.0*blurSize, 0.0)) * 0.09;
+    c += texture2D(source, uv + vec2(4.0*blurSize, 0.0)) * 0.05;
+    gl_FragColor = qt_Opacity * c;
+}

+ 72 - 0
resources/shaders/gaussianblur_v.fsh

@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+uniform float blurSize;
+
+uniform sampler2D source;
+uniform lowp float qt_Opacity;
+varying vec2 qt_TexCoord0;
+
+void main()
+{
+    vec2 uv = qt_TexCoord0.xy;
+    vec4 c = vec4(0.0);
+    c += texture2D(source, uv - vec2(0.0, 4.0*blurSize)) * 0.05;
+    c += texture2D(source, uv - vec2(0.0, 3.0*blurSize)) * 0.09;
+    c += texture2D(source, uv - vec2(0.0, 2.0*blurSize)) * 0.12;
+    c += texture2D(source, uv - vec2(0.0, 1.0*blurSize)) * 0.15;
+    c += texture2D(source, uv) * 0.18;
+    c += texture2D(source, uv + vec2(0.0, 1.0*blurSize)) * 0.15;
+    c += texture2D(source, uv + vec2(0.0, 2.0*blurSize)) * 0.12;
+    c += texture2D(source, uv + vec2(0.0, 3.0*blurSize)) * 0.09;
+    c += texture2D(source, uv + vec2(0.0, 4.0*blurSize)) * 0.05;
+    // First pass we don't apply opacity
+    gl_FragColor = c;
+}

+ 27 - 1
src/main.cpp

@@ -1,3 +1,5 @@
+#include "picturemodel.h"
+
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
 #include <QQmlContext>
@@ -6,7 +8,28 @@
 #include <QSurfaceFormat>
 #include <QTimer>
 
-#include "picturemodel.h"
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QTextStream>
+
+#include <QDebug>
+
+class FileReader : public QObject {
+    Q_OBJECT
+public:
+    FileReader(QObject *p) : QObject(p) { /**/ }
+    Q_INVOKABLE static QString readFile(const QString &fileName)
+    {
+        QString content;
+        QFile file(fileName);
+        if (file.open(QIODevice::ReadOnly)) {
+            QTextStream stream(&file);
+            content = stream.readAll();
+        }
+        return content;
+    }
+};
 
 int main(int argc, char *argv[])
 {
@@ -44,9 +67,12 @@ int main(int argc, char *argv[])
     settings.setValue("artPath", artPath);
 
     engine.rootContext()->setContextProperty("imageModel", model);
+    engine.rootContext()->setContextProperty("fileReader", new FileReader(&app));
     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
 
     QObject::connect(&app, &QGuiApplication::lastWindowClosed, &scanningThread, &QThread::quit);
 
     return app.exec();
 }
+
+#include "main.moc"

+ 0 - 1
src/picturemodel.h

@@ -8,7 +8,6 @@ class FSNode;
 class PictureModel : public QAbstractListModel
 {
     Q_OBJECT
-
 public:
     enum PictureRoles {
         PathRole = Qt::UserRole + 1