Skip to content

Commit

Permalink
ShaderEffectState
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Jan 7, 2024
1 parent 1ed889a commit 95cbdda
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/MediaFX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ qt_add_qml_module(mediafx
qml/sequence.js
qml/MediaSequence.qml
qml/MultiEffectState.qml
qml/ShaderEffectState.qml
qml/effects/MediaMixer.qml
qml/effects/CrossFadeMixer.qml
qml/effects/LumaMixer.qml
Expand Down
15 changes: 8 additions & 7 deletions src/MediaFX/qml/MultiEffectState.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ import QtQuick.Effects
import QtMultimedia

State {
id: root
default required property MultiEffect effect
required property VideoOutput videoOutput

Component.onCompleted: effect.visible = false
Component.onCompleted: root.effect.visible = false

ParentChange {
parent: videoOutput.parent
target: effect
parent: root.videoOutput.parent
target: root.effect
}
PropertyChanges {
anchors.fill: videoOutput
source: videoOutput
anchors.fill: root.videoOutput
source: root.videoOutput
visible: true
target: effect
target: root.effect
}
PropertyChanges {
visible: false
target: videoOutput
target: root.videoOutput
}
}
29 changes: 29 additions & 0 deletions src/MediaFX/qml/ShaderEffectState.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2024 Andrew Wason
//
// This file is part of mediaFX.
//
// mediaFX 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 3 of the License, or (at your option) any later version.
//
// mediaFX 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 mediaFX.
// If not, see <https://www.gnu.org/licenses/>.

import QtQuick
import QtMultimedia

State {
id: root
required property VideoOutput videoOutput
default required property Component effect

PropertyChanges {
layer.enabled: true
layer.effect: root.effect
target: root.videoOutput
}
}
3 changes: 2 additions & 1 deletion tests/qml/animated.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Item {
name: "reanchored"

AnchorChanges {
anchors: { bottom: container.bottom; right: container.right; }
anchors.bottom: container.bottom
anchors.right: container.right
target: rect
}
}
Expand Down
15 changes: 5 additions & 10 deletions tests/qml/video-shadereffect.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,21 @@ Item {
videoClip.clipEnded.connect(MediaManager.finishEncoding);
}
}

VideoOutput {
id: videoOutput

anchors.fill: parent
Media.clip: videoClip
layer.enabled: false

// layer.samplerName: "source"

layer.effect: ShaderEffect {
fragmentShader: "grayscale.frag.qsb"
}
states: State {
states: ShaderEffectState {
name: "filter"
// From 1-2 sec into the video, switch to greyscale
when: (videoClip.clipCurrentTime.containedBy(1000, 2000))

PropertyChanges {
layer.enabled: true
target: videoOutput
videoOutput: videoOutput
ShaderEffect {
fragmentShader: "grayscale.frag.qsb"
}
}
}
Expand Down

0 comments on commit 95cbdda

Please sign in to comment.