[multimedia/kdenlive] src: Autodetect transparency in clip monitor to add compositing when useful

Jean-Baptiste Mardelle <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit aad6a47c335c0da991662d96adf1128ca2511f99 by Jean-Baptiste Mardelle.
Committed on 18/08/2026 at 09:29.
Pushed by mardelle into branch 'master'.

Autodetect transparency in clip monitor to add compositing when useful
Fixes #2226

M  +1    -1    src/bin/playlistclip.cpp
M  +1    -1    src/bin/playlistclip.h
M  +17   -11   src/bin/projectclip.cpp
M  +1    -1    src/bin/projectclip.h
M  +1    -1    src/monitor/monitor.cpp

https://invent.kde.org/multimedia/kdenlive/-/commit/aad6a47c335c0da991662d96adf1128ca2511f99

diff --git a/src/bin/playlistclip.cpp b/src/bin/playlistclip.cpp
index 2005c7348d..790564380d 100644
--- a/src/bin/playlistclip.cpp
+++ b/src/bin/playlistclip.cpp
@@ -421,7 +421,7 @@ const QString PlaylistClip::getPlaylistRoot()
     return m_playlistRoot;
 }
 
-bool PlaylistClip::hasAlpha()
+bool PlaylistClip::hasAlpha() const
 {
     if (clipUrl().isEmpty()) {
         return false;
diff --git a/src/bin/playlistclip.h b/src/bin/playlistclip.h
index 09b08c47c1..1bc6672706 100644
--- a/src/bin/playlistclip.h
+++ b/src/bin/playlistclip.h
@@ -61,7 +61,7 @@ public:
     static std::shared_ptr<PlaylistClip> construct(const QString &id, const QDomElement &description, const QIcon &thumb,
                                                    std::shared_ptr<ProjectItemModel> model);
     /** @brief returns true if an avformat producer has an alpha channel */
-    bool hasAlpha() override;
+    bool hasAlpha() const override;
 
 protected:
     PlaylistClip(const QString &id, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model, std::shared_ptr<Mlt::Producer> &producer);
diff --git a/src/bin/projectclip.cpp b/src/bin/projectclip.cpp
index 2a253d5703..b641445956 100644
--- a/src/bin/projectclip.cpp
+++ b/src/bin/projectclip.cpp
@@ -3222,19 +3222,25 @@ size_t ProjectClip::sequenceFrameDuration(const QUuid &)
     return frameDuration();
 }
 
-bool ProjectClip::hasAlpha()
-{
-    const QStringList alphaFormats = {QLatin1String("argb"), QLatin1String("abgr"), QLatin1String("bgra"), QLatin1String("rgba"),
-                                      QLatin1String("gbra"), QLatin1String("yuva"), QLatin1String("ya")};
-    int vindex = m_properties->get_int("video_index");
-    const QString codecInfo = QStringLiteral("meta.media.%1.codec.pix_fmt").arg(vindex);
-    const QString selected = getProducerProperty(codecInfo);
-    if (selected.isEmpty()) {
+bool ProjectClip::hasAlpha() const
+{
+    if (m_clipType == ClipType::Audio || m_clipType == ClipType::Color || m_clipType == ClipType::Timeline) {
         return false;
     }
-    for (auto &f : alphaFormats) {
-        if (selected.startsWith(f)) {
-            return true;
+    if (m_clipType == ClipType::Text || m_clipType == ClipType::TextTemplate || m_clipType == ClipType::Image || m_clipType == ClipType::Animation) {
+        return true;
+    }
+    if (m_clipType == ClipType::AV || m_clipType == ClipType::Video) {
+        const QStringList alphaFormats = {QLatin1String("argb"), QLatin1String("abgr"), QLatin1String("bgra"), QLatin1String("rgba"),
+                                          QLatin1String("gbra"), QLatin1String("yuva"), QLatin1String("ya")};
+        const QString codecInfo = videoCodecProperty(QStringLiteral("pix_fmt"));
+        if (codecInfo.isEmpty() || !codecInfo.contains(QLatin1Char('a'))) {
+            return false;
+        }
+        for (auto &f : alphaFormats) {
+            if (codecInfo.startsWith(f)) {
+                return true;
+            }
         }
     }
     return false;
diff --git a/src/bin/projectclip.h b/src/bin/projectclip.h
index 393700091b..783ec1cff6 100644
--- a/src/bin/projectclip.h
+++ b/src/bin/projectclip.h
@@ -323,7 +323,7 @@ public:
     const QString getControlUuid() const;
     virtual size_t sequenceFrameDuration(const QUuid &);
     /** @brief returns true if an avformat producer has an alpha channel */
-    virtual bool hasAlpha();
+    virtual bool hasAlpha() const;
     /** @brief Get a list of masks */
     QVector<MaskInfo> masks() const;
     /** @brief Get a list of masks with only {name, url} */
diff --git a/src/monitor/monitor.cpp b/src/monitor/monitor.cpp
index 577be2a914..e80aabef10 100644
--- a/src/monitor/monitor.cpp
+++ b/src/monitor/monitor.cpp
@@ -847,7 +847,7 @@ void Monitor::buildBackgroundedProducer(int pos)
     if (!m_openMutex.tryLock()) {
         return;
     }
-    if (m_controller->clipType() == ClipType::Audio) {
+    if (!m_controller->hasAlpha()) {
         // No compositing required
         m_glMonitor->setProducer(producer, isActive(), pos);
     } else {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.