Skip to content

Commit

Permalink
Improve writer error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zzag committed Apr 21, 2022
1 parent ef3eaf8 commit 032b0ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib/kdynamicwallpaperwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ bool KDynamicWallpaperWriterPrivate::flush(QIODevice *device)

for (const auto &view : images) {
const QImage image = view.data().convertToFormat(QImage::Format_RGB888);
if (image.isNull())
if (image.isNull()) {
wallpaperWriterError = KDynamicWallpaperWriter::UnknownError;
errorString = QStringLiteral("Failed to read: %1").arg(view.fileName());
return false;
}

avifImage *avif = avifImageCreate(image.width(), image.height(), 8, AVIF_PIXEL_FORMAT_YUV444);
avifImageSetMetadataXMP(avif, reinterpret_cast<const uint8_t *>(xmp.constData()), xmp.size());
Expand All @@ -116,14 +119,18 @@ bool KDynamicWallpaperWriterPrivate::flush(QIODevice *device)
avifResult result = avifImageRGBToYUV(avif, &rgb);
if (result != AVIF_RESULT_OK) {
wallpaperWriterError = KDynamicWallpaperWriter::UnknownError;
errorString = avifResultToString(result);
errorString = QStringLiteral("Failed to encode %1: %2")
.arg(view.fileName())
.arg(avifResultToString(result));
return false;
}

result = avifEncoderAddImage(encoder, avif, 0, AVIF_ADD_IMAGE_FLAG_NONE);
if (result != AVIF_RESULT_OK) {
wallpaperWriterError = KDynamicWallpaperWriter::UnknownError;
errorString = avifResultToString(result);
errorString = QStringLiteral("Failed to encode %1: %2")
.arg(view.fileName())
.arg(avifResultToString(result));
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/lib/kdynamicwallpaperwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class KDYNAMICWALLPAPER_EXPORT KDynamicWallpaperWriter
return QImage(m_fileName);
}

QString fileName() const
{
return m_fileName;
}

private:
QString m_fileName;
};
Expand Down

0 comments on commit 032b0ba

Please sign in to comment.