Support WebP format for Card Images (#4950)

- Fix #4939
This commit is contained in:
Zach H 2023-12-09 00:52:14 -05:00 committed by GitHub
parent 519531f3a0
commit b73ef58567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 17 deletions

View file

@ -9,6 +9,7 @@ RUN pacman --sync --refresh --sysupgrade --needed --noconfirm \
mariadb-libs \ mariadb-libs \
protobuf \ protobuf \
qt6-base \ qt6-base \
qt6-imageformats \
qt6-multimedia \ qt6-multimedia \
qt6-svg \ qt6-svg \
qt6-tools \ qt6-tools \

View file

@ -17,6 +17,7 @@ RUN apt-get update && \
libqt5svg5-dev \ libqt5svg5-dev \
libqt5websockets5-dev \ libqt5websockets5-dev \
protobuf-compiler \ protobuf-compiler \
qt5-image-formats-plugins \
qtmultimedia5-dev \ qtmultimedia5-dev \
qttools5-dev \ qttools5-dev \
qttools5-dev-tools \ qttools5-dev-tools \

View file

@ -18,6 +18,7 @@ RUN apt-get update && \
qt6-svg-dev \ qt6-svg-dev \
qt6-websockets-dev \ qt6-websockets-dev \
protobuf-compiler \ protobuf-compiler \
qt6-image-formats-plugins \
qt6-l10n-tools \ qt6-l10n-tools \
qt6-multimedia-dev \ qt6-multimedia-dev \
qt6-tools-dev \ qt6-tools-dev \

View file

@ -7,7 +7,7 @@ RUN dnf install -y \
git \ git \
mariadb-devel \ mariadb-devel \
protobuf-devel \ protobuf-devel \
qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets}-devel \ qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets,imageformats}-devel \
rpm-build \ rpm-build \
xz-devel \ xz-devel \
zlib-devel \ zlib-devel \

View file

@ -7,7 +7,7 @@ RUN dnf install -y \
git \ git \
mariadb-devel \ mariadb-devel \
protobuf-devel \ protobuf-devel \
qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets}-devel \ qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets,imageformats}-devel \
rpm-build \ rpm-build \
xz-devel \ xz-devel \
zlib-devel \ zlib-devel \

View file

@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libqt5websockets5-dev \ libqt5websockets5-dev \
protobuf-compiler \ protobuf-compiler \
qt5-default \ qt5-default \
qt5-image-formats-plugins \
qtmultimedia5-dev \ qtmultimedia5-dev \
qttools5-dev \ qttools5-dev \
qttools5-dev-tools \ qttools5-dev-tools \

View file

@ -18,6 +18,7 @@ RUN apt-get update && \
libqt5websockets5-dev \ libqt5websockets5-dev \
protobuf-compiler \ protobuf-compiler \
qt5-default \ qt5-default \
qt5-image-formats-plugins \
qtmultimedia5-dev \ qtmultimedia5-dev \
qttools5-dev \ qttools5-dev \
qttools5-dev-tools \ qttools5-dev-tools \

View file

@ -18,6 +18,7 @@ RUN apt-get update && \
libqt6svg6-dev \ libqt6svg6-dev \
libqt6websockets6-dev \ libqt6websockets6-dev \
protobuf-compiler \ protobuf-compiler \
qt6-image-formats-plugins \
qt6-l10n-tools \ qt6-l10n-tools \
qt6-multimedia-dev \ qt6-multimedia-dev \
qt6-tools-dev \ qt6-tools-dev \

View file

@ -18,6 +18,7 @@ RUN apt-get update && \
qt6-svg-dev \ qt6-svg-dev \
qt6-websockets-dev \ qt6-websockets-dev \
protobuf-compiler \ protobuf-compiler \
qt6-image-formats-plugins \
qt6-l10n-tools \ qt6-l10n-tools \
qt6-multimedia-dev \ qt6-multimedia-dev \
qt6-tools-dev \ qt6-tools-dev \

View file

@ -311,15 +311,7 @@ if(WIN32)
PATTERN "audio/qtaudio_wasapi.dll" PATTERN "audio/qtaudio_wasapi.dll"
PATTERN "audio/qtaudio_windows.dll" PATTERN "audio/qtaudio_windows.dll"
PATTERN "iconengines/qsvgicon.dll" PATTERN "iconengines/qsvgicon.dll"
PATTERN "imageformats/qgif.dll" PATTERN "imageformats/*.dll"
PATTERN "imageformats/qicns.dll"
PATTERN "imageformats/qico.dll"
PATTERN "imageformats/qjpeg.dll"
PATTERN "imageformats/qsvg.dll"
PATTERN "imageformats/qtga.dll"
PATTERN "imageformats/qtiff.dll"
PATTERN "imageformats/qwbmp.dll"
PATTERN "imageformats/qwebp.dll"
PATTERN "mediaservice/dsengine.dll" PATTERN "mediaservice/dsengine.dll"
PATTERN "mediaservice/wmfengine.dll" PATTERN "mediaservice/wmfengine.dll"
PATTERN "platforms/qdirect2d.dll" PATTERN "platforms/qdirect2d.dll"

View file

@ -6,12 +6,14 @@
#include "thememanager.h" #include "thememanager.h"
#include <QApplication> #include <QApplication>
#include <QBuffer>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
#include <QFile> #include <QFile>
#include <QImageReader> #include <QImageReader>
#include <QMovie>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkDiskCache> #include <QNetworkDiskCache>
#include <QNetworkReply> #include <QNetworkReply>
@ -499,21 +501,40 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply)
imgReader.setDecideFormatFromContent(true); imgReader.setDecideFormatFromContent(true);
imgReader.setDevice(reply); imgReader.setDevice(reply);
if (imgReader.read(&testImage)) { bool logSuccessMessage = false;
static const int riffHeaderSize = 12; // RIFF_HEADER_SIZE from webp/format_constants.h
auto replyHeader = reply->peek(riffHeaderSize);
if (replyHeader.startsWith("RIFF") && replyHeader.endsWith("WEBP")) {
auto imgBuf = QBuffer(this);
imgBuf.setData(reply->readAll());
auto movie = QMovie(&imgBuf);
movie.start();
movie.stop();
imageLoaded(cardBeingDownloaded.getCard(), movie.currentImage());
logSuccessMessage = true;
} else if (imgReader.read(&testImage)) {
imageLoaded(cardBeingDownloaded.getCard(), testImage); imageLoaded(cardBeingDownloaded.getCard(), testImage);
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() logSuccessMessage = true;
<< " set: " << cardBeingDownloaded.getSetName() << "]: Image successfully "
<< (isFromCache ? "loaded from cached" : "downloaded from") << " url "
<< reply->url().toDisplayString();
} else { } else {
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
<< " set: " << cardBeingDownloaded.getSetName() << "]: Possible " << " set: " << cardBeingDownloaded.getSetName() << "]: Possible "
<< (isFromCache ? "cached" : "downloaded") << " picture at " << (isFromCache ? "cached" : "downloaded") << " picture at "
<< reply->url().toDisplayString() << " could not be loaded"; << reply->url().toDisplayString() << " could not be loaded: " << reply->errorString();
picDownloadFailed(); picDownloadFailed();
} }
if (logSuccessMessage) {
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
<< " set: " << cardBeingDownloaded.getSetName() << "]: Image successfully "
<< (isFromCache ? "loaded from cached" : "downloaded from") << " url "
<< reply->url().toDisplayString();
}
reply->deleteLater(); reply->deleteLater();
startNextPicDownload(); startNextPicDownload();
} }