From b73ef5856794d947b7b7738c4bf4ce5b285ac4fa Mon Sep 17 00:00:00 2001 From: Zach H Date: Sat, 9 Dec 2023 00:52:14 -0500 Subject: [PATCH] Support WebP format for Card Images (#4950) - Fix #4939 --- .ci/ArchLinux/Dockerfile | 1 + .ci/Debian11/Dockerfile | 1 + .ci/Debian12/Dockerfile | 1 + .ci/Fedora37/Dockerfile | 2 +- .ci/Fedora38/Dockerfile | 2 +- .ci/UbuntuBionic/Dockerfile | 1 + .ci/UbuntuFocal/Dockerfile | 1 + .ci/UbuntuJammy/Dockerfile | 1 + .ci/UbuntuLunar/Dockerfile | 1 + cockatrice/CMakeLists.txt | 10 +--------- cockatrice/src/pictureloader.cpp | 33 ++++++++++++++++++++++++++------ 11 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.ci/ArchLinux/Dockerfile b/.ci/ArchLinux/Dockerfile index 742d1818..ed46e08a 100644 --- a/.ci/ArchLinux/Dockerfile +++ b/.ci/ArchLinux/Dockerfile @@ -9,6 +9,7 @@ RUN pacman --sync --refresh --sysupgrade --needed --noconfirm \ mariadb-libs \ protobuf \ qt6-base \ + qt6-imageformats \ qt6-multimedia \ qt6-svg \ qt6-tools \ diff --git a/.ci/Debian11/Dockerfile b/.ci/Debian11/Dockerfile index a42967eb..8c4fbe72 100644 --- a/.ci/Debian11/Dockerfile +++ b/.ci/Debian11/Dockerfile @@ -17,6 +17,7 @@ RUN apt-get update && \ libqt5svg5-dev \ libqt5websockets5-dev \ protobuf-compiler \ + qt5-image-formats-plugins \ qtmultimedia5-dev \ qttools5-dev \ qttools5-dev-tools \ diff --git a/.ci/Debian12/Dockerfile b/.ci/Debian12/Dockerfile index f8ceedf7..21c4ffa2 100644 --- a/.ci/Debian12/Dockerfile +++ b/.ci/Debian12/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get update && \ qt6-svg-dev \ qt6-websockets-dev \ protobuf-compiler \ + qt6-image-formats-plugins \ qt6-l10n-tools \ qt6-multimedia-dev \ qt6-tools-dev \ diff --git a/.ci/Fedora37/Dockerfile b/.ci/Fedora37/Dockerfile index 3b4775be..a23f0a84 100644 --- a/.ci/Fedora37/Dockerfile +++ b/.ci/Fedora37/Dockerfile @@ -7,7 +7,7 @@ RUN dnf install -y \ git \ mariadb-devel \ protobuf-devel \ - qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets}-devel \ + qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets,imageformats}-devel \ rpm-build \ xz-devel \ zlib-devel \ diff --git a/.ci/Fedora38/Dockerfile b/.ci/Fedora38/Dockerfile index 2704142f..b0777500 100644 --- a/.ci/Fedora38/Dockerfile +++ b/.ci/Fedora38/Dockerfile @@ -7,7 +7,7 @@ RUN dnf install -y \ git \ mariadb-devel \ protobuf-devel \ - qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets}-devel \ + qt6-{qttools,qtsvg,qtmultimedia,qtwebsockets,imageformats}-devel \ rpm-build \ xz-devel \ zlib-devel \ diff --git a/.ci/UbuntuBionic/Dockerfile b/.ci/UbuntuBionic/Dockerfile index 10f340fd..03494dc6 100644 --- a/.ci/UbuntuBionic/Dockerfile +++ b/.ci/UbuntuBionic/Dockerfile @@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libqt5websockets5-dev \ protobuf-compiler \ qt5-default \ + qt5-image-formats-plugins \ qtmultimedia5-dev \ qttools5-dev \ qttools5-dev-tools \ diff --git a/.ci/UbuntuFocal/Dockerfile b/.ci/UbuntuFocal/Dockerfile index 1b6b47c8..d0f6d443 100644 --- a/.ci/UbuntuFocal/Dockerfile +++ b/.ci/UbuntuFocal/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get update && \ libqt5websockets5-dev \ protobuf-compiler \ qt5-default \ + qt5-image-formats-plugins \ qtmultimedia5-dev \ qttools5-dev \ qttools5-dev-tools \ diff --git a/.ci/UbuntuJammy/Dockerfile b/.ci/UbuntuJammy/Dockerfile index bff3e05c..f833a084 100644 --- a/.ci/UbuntuJammy/Dockerfile +++ b/.ci/UbuntuJammy/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get update && \ libqt6svg6-dev \ libqt6websockets6-dev \ protobuf-compiler \ + qt6-image-formats-plugins \ qt6-l10n-tools \ qt6-multimedia-dev \ qt6-tools-dev \ diff --git a/.ci/UbuntuLunar/Dockerfile b/.ci/UbuntuLunar/Dockerfile index 525e2118..791a2c92 100644 --- a/.ci/UbuntuLunar/Dockerfile +++ b/.ci/UbuntuLunar/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get update && \ qt6-svg-dev \ qt6-websockets-dev \ protobuf-compiler \ + qt6-image-formats-plugins \ qt6-l10n-tools \ qt6-multimedia-dev \ qt6-tools-dev \ diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 28d3c73b..121235c2 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -311,15 +311,7 @@ if(WIN32) PATTERN "audio/qtaudio_wasapi.dll" PATTERN "audio/qtaudio_windows.dll" PATTERN "iconengines/qsvgicon.dll" - PATTERN "imageformats/qgif.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 "imageformats/*.dll" PATTERN "mediaservice/dsengine.dll" PATTERN "mediaservice/wmfengine.dll" PATTERN "platforms/qdirect2d.dll" diff --git a/cockatrice/src/pictureloader.cpp b/cockatrice/src/pictureloader.cpp index d8519adb..625996f7 100644 --- a/cockatrice/src/pictureloader.cpp +++ b/cockatrice/src/pictureloader.cpp @@ -6,12 +6,14 @@ #include "thememanager.h" #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -499,21 +501,40 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) imgReader.setDecideFormatFromContent(true); 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); - qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() << "]: Image successfully " - << (isFromCache ? "loaded from cached" : "downloaded from") << " url " - << reply->url().toDisplayString(); + logSuccessMessage = true; } else { qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() << "]: Possible " << (isFromCache ? "cached" : "downloaded") << " picture at " - << reply->url().toDisplayString() << " could not be loaded"; + << reply->url().toDisplayString() << " could not be loaded: " << reply->errorString(); 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(); startNextPicDownload(); }