Skip to content

Commit

Permalink
Guard Qt 5.14 dependent code (#55)
Browse files Browse the repository at this point in the history
fixes #53
  • Loading branch information
zzag authored Jul 8, 2020
1 parent f3c0573 commit 90d0fbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/kdynamicwallpaperreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#include <KLocalizedString>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#include <QColorSpace>
#endif
#include <QFile>
#include <QImage>

Expand Down Expand Up @@ -214,6 +216,7 @@ KDynamicWallpaperMetaData KDynamicWallpaperReaderPrivate::metaDataAt(int imageIn
return metaData;
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
static QColorSpace colorProfileForImage(heif_image *image)
{
QColorSpace colorSpace;
Expand All @@ -234,6 +237,7 @@ static QColorSpace colorProfileForImage(heif_image *image)

return colorSpace;
}
#endif

QImage KDynamicWallpaperReaderPrivate::imageAt(int imageIndex)
{
Expand Down Expand Up @@ -274,9 +278,11 @@ QImage KDynamicWallpaperReaderPrivate::imageAt(int imageIndex)
auto cleanupFunc = [](void *data) { heif_image_release(static_cast<heif_image *>(data)); };
QImage decodedImage(data, width, height, stride, format, cleanupFunc, image);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QColorSpace colorSpace = colorProfileForImage(image);
if (colorSpace.isValid())
decodedImage.setColorSpace(colorSpace);
#endif

heif_image_handle_release(handle); // heif_image will be destroyed by QImage

Expand Down
6 changes: 6 additions & 0 deletions src/lib/kdynamicwallpaperwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#include <KLocalizedString>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#include <QColorSpace>
#endif
#include <QFile>
#include <QImage>

Expand Down Expand Up @@ -226,13 +228,17 @@ bool KDynamicWallpaperWriterPrivate::write(const QImage &image, const KDynamicWa
}

if (options & KDynamicWallpaperWriter::PreserveColorProfile) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QByteArray iccProfile = image.colorSpace().iccProfile();
error = heif_image_set_raw_color_profile(heifImage, "prof", iccProfile.data(), iccProfile.size());
if (error.code != heif_error_Ok) {
wallpaperWriterError = KDynamicWallpaperWriter::EncoderError;
errorString = i18n("Failed to set ICC profile: %1", error.message);
goto error_image;
}
#else
qWarning() << "You need at least Qt 5.14 to preserve color profiles";
#endif
}

data = heif_image_get_plane(heifImage, heif_channel_interleaved, &stride);
Expand Down

0 comments on commit 90d0fbd

Please sign in to comment.