[vlc-commits] [Git][videolan/vlc][master] 7 commits: qml: optimize color effect on audio player background
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Tue Jul 12 12:07:14 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
b0623229 by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: optimize color effect on audio player background
This reduce the number of intermediary FBO and shader passes
- - - - -
88bf5949 by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: limit the size of intermediary blur texture in the audio player
this limits the video memory used by the texture, this also provides a look and
feel closer to designer's mockups
- - - - -
342072fd by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: only update PlayerBlurredBackground when cover content changes
Co-authored-by: Fatih Uzunoglu <fuzun54 at outlook.com>
- - - - -
dde38750 by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: add align functions to Helpers.js class
- - - - -
af296bf3 by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: limit the size of the central widget
- - - - -
f00af8f9 by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: don't generate blur from solid texture in Player view
- - - - -
255a6be4 by Pierre Lamot at 2022-07-12T11:47:35+00:00
qml: use FastBlur in player blurred background
result is good enough compared to GaussianBlur
- - - - -
6 changed files:
- modules/gui/qt/Makefile.am
- modules/gui/qt/player/qml/Player.qml
- + modules/gui/qt/player/qml/PlayerBlurredBackground.frag
- + modules/gui/qt/player/qml/PlayerBlurredBackground.qml
- modules/gui/qt/util/qml/Helpers.js
- modules/gui/qt/vlc.qrc
Changes:
=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -819,6 +819,8 @@ libqt_plugin_la_QML = \
gui/qt/player/qml/MiniPlayer.qml \
gui/qt/player/qml/PIPPlayer.qml \
gui/qt/player/qml/Player.qml \
+ gui/qt/player/qml/PlayerBlurredBackground.qml \
+ gui/qt/player/qml/PlayerBlurredBackground.frag \
gui/qt/player/qml/PlayerControlLayout.qml \
gui/qt/player/qml/PlayerMenu.qml \
gui/qt/player/qml/PlayerMenuItem.qml \
=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -27,6 +27,7 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
import "qrc:///playlist/" as PL
+import "qrc:///util/Helpers.js" as Helpers
FocusScope {
id: rootPlayer
@@ -173,57 +174,20 @@ FocusScope {
color: rootPlayer.colors.bg
anchors.fill: parent
- Item {
- //destination aspect ration
+ PlayerBlurredBackground {
+ id: backgroundImage
+
+ //destination aspect ratio
readonly property real dar: parent.width / parent.height
anchors.centerIn: parent
width: (cover.sar < dar) ? parent.width : parent.height * cover.sar
height: (cover.sar < dar) ? parent.width / cover.sar : parent.height
- GaussianBlur {
- id: blur
-
- anchors.fill: parent
- source: cover
- samples: 102
- radius: 50
- visible: false
- }
-
- Rectangle {
- id: blurOverlay
-
- color: rootPlayer.colors.setColorAlpha(rootPlayer.colors.playerBg, .55)
- anchors.fill: parent
- visible: false
- }
-
- Blend {
- id:screen
-
- anchors.fill: parent
- foregroundSource: blurOverlay
- source: blur
- mode: "screen"
- visible: false
- }
-
- Blend {
- anchors.fill: parent
- source: screen
- foregroundSource: blurOverlay
- mode: "multiply"
- }
-
- Rectangle {
- id: colorOverlay
+ source: cover
- anchors.fill: parent
- visible: true
- opacity: .4
- color: rootPlayer.colors.setColorAlpha(Qt.tint(rootPlayer.colors.playerFg, rootPlayer.colors.playerBg), 1)
- }
+ screenColor: rootPlayer.colors.setColorAlpha(rootPlayer.colors.playerBg, .55)
+ overlayColor: rootPlayer.colors.setColorAlpha(Qt.tint(rootPlayer.colors.playerFg, rootPlayer.colors.playerBg), 0.4)
}
}
@@ -326,27 +290,13 @@ FocusScope {
Component {
id: forMusicMedia
- Item {
+ Rectangle {
width: controlBarView.width
height: controlBarView.height - (rootPlayer.positionSliderY - controlBarView.y)
-
- Rectangle {
- id: controlBarBackground
-
- anchors.fill: parent
- visible: false
- color: rootPlayer.colors.isThemeDark
- ? Qt.darker(rootPlayer.colors.playerBg, 1.2)
- : Qt.lighter(rootPlayer.colors.playerBg, 1.2)
- }
-
- GaussianBlur {
- anchors.fill: parent
- source: controlBarBackground
- radius: 22
- samples: 46
- opacity: .7
- }
+ color: rootPlayer.colors.isThemeDark
+ ? Qt.darker(rootPlayer.colors.playerBg, 1.2)
+ : Qt.lighter(rootPlayer.colors.playerBg, 1.2)
+ opacity: 0.7
}
}
}
@@ -449,18 +399,27 @@ FocusScope {
visible: !rootPlayer.hasEmbededVideo
Item {
- Layout.preferredHeight: rootPlayer.height / heightConstant
+ id: coverItem
+ Layout.preferredHeight: rootPlayer.height / sizeConstant
Layout.preferredWidth: cover.paintedWidth
Layout.maximumHeight: centerContent.height
Layout.alignment: Qt.AlignHCenter
- readonly property real heightConstant: 2.7182
+ readonly property real sizeConstant: 2.7182
Image {
id: cover
//source aspect ratio
readonly property real sar: paintedWidth / paintedHeight
+ readonly property int maximumWidth: MainCtx.screen
+ ? Helpers.alignUp((MainCtx.screen.availableGeometry.width / coverItem.sizeConstant), 32)
+ : 1024
+ readonly property int maximumHeight: MainCtx.screen
+ ? Helpers.alignUp((MainCtx.screen.availableGeometry.height / coverItem.sizeConstant), 32)
+ : 1024
+
+ readonly property int maximumSize: Math.min(maximumWidth, maximumHeight)
anchors.top: parent.top
anchors.bottom: parent.bottom
@@ -470,12 +429,13 @@ FocusScope {
mipmap: true
cache: false
asynchronous: true
- sourceSize: Qt.size(maximumWidth, maximumHeight)
- readonly property real maximumWidth: MainCtx.screen ? (MainCtx.screen.availableVirtualSize.width * MainCtx.screen.devicePixelRatio)
- : 1024
- readonly property real maximumHeight: MainCtx.screen ? (MainCtx.screen.availableVirtualSize.height * MainCtx.screen.devicePixelRatio / parent.heightConstant)
- : 1024
+ sourceSize: Qt.size(maximumSize, maximumSize)
+
+ onStatusChanged: {
+ if (status === Image.Ready)
+ backgroundImage.scheduleUpdate()
+ }
}
Widgets.CoverShadow {
=====================================
modules/gui/qt/player/qml/PlayerBlurredBackground.frag
=====================================
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** 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 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$
+**
+****************************************************************************/
+
+//blending formulas are taken from Qt's Blend.qml implementation
+
+varying mediump vec2 qt_TexCoord0;
+uniform highp float qt_Opacity;
+uniform lowp sampler2D backgroundSource;
+uniform lowp vec4 screenColor;
+uniform lowp vec4 overlayColor;
+
+lowp vec4 toPremult(lowp vec4 color) {
+ lowp vec4 result = vec4(0.0);
+ result.rgb = color.rgb / max(1.0/256.0, color.a);
+ result.a = color.a;
+ return result;
+}
+
+lowp vec4 fromPremult(lowp vec4 color) {
+ lowp vec4 result = vec4(0.0);
+ result.rbg = color.rbg * color.a;
+ result.a = color.a;
+ return result;
+}
+
+lowp vec4 screen(lowp vec4 color1, lowp vec4 color2) {
+ lowp vec4 result = vec4(0.0);
+ highp float a = max(color1.a, color1.a * color2.a);
+
+ result.rgb = 1.0 - (vec3(1.0) - color1.rgb) * (vec3(1.0) - color2.rgb);
+
+ result.rgb = mix(color1.rgb, result.rgb, color2.a);
+ result.a = max(color1.a, color1.a * color2.a);
+ return result;
+}
+
+lowp vec4 multiply(lowp vec4 color1, lowp vec4 color2) {
+ lowp vec4 result = vec4(0.0);
+
+ result.rgb = color1.rgb * color2.rgb;
+
+ result.rgb = mix(color1.rgb, result.rgb, color2.a);
+ result.a = max(color1.a, color1.a * color2.a);
+ return result;
+}
+
+lowp vec4 normal(lowp vec4 color1, lowp vec4 color2) {
+ lowp vec4 result = vec4(0.0);
+ result.rgb = mix(color1.rgb, color2.rgb, color2.a);
+ result.a = max(color1.a, color2.a);
+ return result;
+}
+
+void main() {
+ lowp vec4 result = vec4(0.0);
+ lowp vec4 colorP = toPremult(texture2D(backgroundSource, qt_TexCoord0));
+ lowp vec4 screenColorP = toPremult(screenColor);
+ lowp vec4 overlayColorP = toPremult(overlayColor);
+
+ result = screen(colorP, screenColorP);
+ result = multiply(result, screenColorP);
+ result = normal(result, overlayColorP);
+
+ gl_FragColor = fromPremult(result) * qt_Opacity;
+}
=====================================
modules/gui/qt/player/qml/PlayerBlurredBackground.qml
=====================================
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+import QtQuick 2.11
+
+import QtGraphicalEffects 1.0
+
+Item {
+ id: rootItem
+
+ property alias source: blurSource.sourceItem
+ property alias screenColor: shaderItem.screenColor
+ property alias overlayColor: shaderItem.overlayColor
+
+ function scheduleUpdate() {
+ blurSource.scheduleUpdate()
+ }
+
+ onSourceChanged: blurSource.scheduleUpdate()
+
+ ShaderEffectSource {
+ id: blurSource
+
+ width: 512
+ height: 512
+ textureSize: Qt.size(512,512)
+
+ visible: false
+
+ live: false
+ hideSource: false
+ smooth: false
+ mipmap: false
+ }
+
+ FastBlur {
+ id: blur
+
+ source: blurSource
+
+ width: 512
+ height: 512
+
+ radius: 50
+ visible: false
+ }
+
+ ShaderEffectSource {
+ id: proxySource
+ live: true
+ hideSource: false
+ sourceItem: blur
+ smooth: false
+ visible: false
+ mipmap: false
+ }
+
+ ShaderEffect {
+ id: shaderItem
+
+ property var backgroundSource: proxySource
+ property color screenColor
+ property color overlayColor
+
+ anchors.fill: parent
+ visible: true
+ blending: false
+
+ fragmentShader: "qrc:///player/PlayerBlurredBackground.frag"
+ }
+}
=====================================
modules/gui/qt/util/qml/Helpers.js
=====================================
@@ -80,3 +80,11 @@ function isInteger(data) {
function compareFloat(a, b) {
return (Math.abs(a - b) < Number.EPSILON)
}
+
+function alignUp(a, b) {
+ return Math.ceil(a / b) * b
+}
+
+function alignDown(a, b) {
+ return Math.floor(a / b) * b
+}
=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -366,6 +366,8 @@
<file alias="ControlLayout.qml">player/qml/ControlLayout.qml</file>
<file alias="PlaybackSpeed.qml">player/qml/PlaybackSpeed.qml</file>
<file alias="PlayerPlaylistVisibilityFSM.qml">player/qml/PlayerPlaylistVisibilityFSM.qml</file>
+ <file alias="PlayerBlurredBackground.qml">player/qml/PlayerBlurredBackground.qml</file>
+ <file alias="PlayerBlurredBackground.frag">player/qml/PlayerBlurredBackground.frag</file>
</qresource>
<qresource prefix="/player/controlbarcontrols">
<file alias="HighResolutionTimeWidget.qml">player/qml/controlbarcontrols/HighResolutionTimeWidget.qml</file>
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/125a46cc6c8c60a5923084b525b02b509e8a9d7f...255a6be406eca6292eb219c00ab8b8ed9999d7d1
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/125a46cc6c8c60a5923084b525b02b509e8a9d7f...255a6be406eca6292eb219c00ab8b8ed9999d7d1
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list