gpt4 book ai didi

c++ - QMovie webp帧断断续续

转载 作者:行者123 更新时间:2023-11-28 04:28:58 25 4
gpt4 key购买 nike

我正在使用 QMovie 在 QLabal 上播放 webp 动画,代码如下:

Foo::Foo() {
movie_ = new QMovie("/path/to/my.webp", "", this);
ui->label->setMovie(movie_);
}
void Foo::on_pushButton_clicked() {
movie_->stop();
movie_->start();
}

但是当我播放动画时,帧断断续续,例如:

the screenshot

我尝试使用 QImage::save 提取 webp 帧,代码如下:

QImageReader *reader = new QImageReader("/path/to/my.webp");
reader->setDecideFormatFromContent(true);
for (int i = 0; i < reader->imageCount(); ++i) {
QImage image;
reader->read(&image);
image.save(QString("frame_%1.png").arg(i));
reader->jumpToNextImage();
}

所有提取的帧也都是断断续续的,比如:

frame_9.png

但是当我使用google libwebp工具提取帧时,没有任何问题。比如:

frame_9_2.png

// extract frame 9, not problem
webpmux.exe -get frame 9 -o "frame_9.webp"
// paly webp animation, there is no any problem
vwebp.exe /path/to/my.webp

是Qt的问题吗? Qt 5.9.4(我正在使用)和 Qt 最新版本(我正在尝试)都有这个问题。

最佳答案

这似乎是一个 Qt 错误,该错误已在 Qt 版本 5.9.1 上报告: WebP: animations don't respect alpha

Qt说这个bug在5.9.2版本已经解决了,但是即使是Qt 5.11问题依然存在。

有官方solution :

diff --git a/src/plugins/imageformats/webp/qwebphandler.cpp b/src/plugins/imageformats/webp/qwebphandler.cpp
index 5a0ae4a..ce90158 100644
--- a/src/plugins/imageformats/webp/qwebphandler.cpp
+++ b/src/plugins/imageformats/webp/qwebphandler.cpp
@@ -122,6 +122,8 @@ bool QWebpHandler::ensureScanned() const
that->m_bgColor = QColor::fromRgba(QRgb(WebPDemuxGetI(m_demuxer, WEBP_FF_BACKGROUND_COLOR)));

that->m_composited = new QImage(that->m_features.width, that->m_features.height, QImage::Format_ARGB32);
+ if (that->m_features.has_alpha)
+ that->m_composited->fill(Qt::transparent);

// We do not reset device position since we have read in all data
m_scanState = ScanSuccess;
@@ -193,6 +195,8 @@ bool QWebpHandler::read(QImage *image)
} else {
// Animation
QPainter painter(m_composited);
+ if (m_features.has_alpha && m_iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND)
+ m_composited->fill(Qt::transparent);
painter.drawImage(currentImageRect(), frame);

*image = *m_composited;

这是我的解决方案:

1.添加一些代码

// ${QT_SRC}/qtimageformats/src/plugins/imageformats/webp/qwebphandler.cpp
// function QWebpHandler::read
if (m_features.has_alpha && (m_iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ||
m_iter.blend_method == WEBP_MUX_NO_BLEND)) {
m_composited->fill(Qt::transparent);
}

2。重建qt webp插件

nmake module-qtimageformats

  1. 替换qwebp.dll

mv ${QT_DIR}/plugins/imageformats/qwebpd.dll ${QT_DIR}/plugins/imageformats/qwebpd.dll.bak

cp ${REBUILD_WEBP_PLUGINS} ${QT_DIR}/plugins/imageformats/qwebpd.dll

关于c++ - QMovie webp帧断断续续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53474445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com