Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/plugin-qt/wallpapercache/imageeffectprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define PIXMIX_OPACITY 90 // Color opacity
#define PIXMIX_SATURATION 50 // Saturation
#define PIXMIX_BRIGHTNESS -60 // Brightness
#define PIXMIX_MAX_DIM 7680 // 8K UHD long side cap

DGUI_USE_NAMESPACE

Expand Down Expand Up @@ -67,9 +68,25 @@ ImageEffectProcessor::EffectType ImageEffectProcessor::effectTypeFromString(cons

QImage ImageEffectProcessor::processPixmixEffect(const QString &imagePath)
{
QImage originalImage;
if (!originalImage.load(imagePath)) {
qWarning() << "Failed to load image:" << imagePath;
QImageReader reader(imagePath);
if (!reader.canRead()) {
qWarning() << "Cannot read image:" << imagePath;
return QImage();
}

QSize originalSize = reader.size();
if (!originalSize.isEmpty()
&& (originalSize.width() > PIXMIX_MAX_DIM || originalSize.height() > PIXMIX_MAX_DIM)) {
QSize decodeSize = originalSize;
decodeSize.scale(PIXMIX_MAX_DIM, PIXMIX_MAX_DIM, Qt::KeepAspectRatio);
reader.setScaledSize(decodeSize);
qDebug() << "Decoding image at" << decodeSize
<< "(original:" << originalSize << ")";
}

QImage originalImage = reader.read();
if (originalImage.isNull()) {
qWarning() << "Failed to load image:" << imagePath << reader.errorString();
return QImage();
}

Expand Down
39 changes: 28 additions & 11 deletions src/plugin-qt/wallpapercache/scaleimagethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <QImage>
#include <QDebug>
#include <QFileInfo>
#include <QDateTime>

Check warning on line 10 in src/plugin-qt/wallpapercache/scaleimagethread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDateTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCoreApplication>

Check warning on line 11 in src/plugin-qt/wallpapercache/scaleimagethread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCryptographicHash>

Check warning on line 12 in src/plugin-qt/wallpapercache/scaleimagethread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCryptographicHash> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QImageReader>

Check warning on line 13 in src/plugin-qt/wallpapercache/scaleimagethread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QImageReader> not found. Please note: Cppcheck does not need standard library headers to get proper results.

ScaleImageThread::ScaleImageThread(QObject *parent)
: QThread(parent)
Expand Down Expand Up @@ -142,21 +143,37 @@
QImage ScaleImageThread::scaleImage(const TaskData &task)
{
qDebug() << "scale image info:" << task.originalPath << " targetSize:" << task.targetSize;
QImage image;
image.load(task.originalPath);

QImageReader reader(task.originalPath);
if (!reader.canRead()) {
qWarning() << "Cannot read image:" << task.originalPath;
return QImage();
}

QSize originalSize = reader.size();
if (originalSize.isEmpty()) {
qWarning() << "Cannot get image size:" << task.originalPath;
return QImage();
}

QSize decodeSize = originalSize;
decodeSize.scale(task.targetSize, Qt::KeepAspectRatioByExpanding);
reader.setScaledSize(decodeSize);

QImage image = reader.read();
if (image.isNull()) {
qWarning() << "load image failed:" << task.originalPath;
qWarning() << "load image failed:" << task.originalPath << reader.errorString();
return image;
}

QSize size = task.targetSize;
image = image.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::FastTransformation);
image = image.copy(QRect((image.width() - size.width()) / 2,
(image.height() - size.height()) / 2,
size.width(),
size.height()));

return image;
const QSize &size = task.targetSize;
if (image.width() < size.width() || image.height() < size.height()) {
return image;
}
return image.copy(QRect((image.width() - size.width()) / 2,
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
(image.height() - size.height()) / 2,
size.width(),
size.height()));
}

QString ScaleImageThread::cacheImageToDisk(QImage &image, const TaskData &task, const QString &md5String)
Expand Down
12 changes: 8 additions & 4 deletions src/plugin-qt/wallpapercache/wallpapercacheservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,14 @@ QString WallpaperCacheService::saveImageFromFd(const QDBusUnixFileDescriptor &fd
}
originFile.close();

// Detect format and rename with extension
QImageReader reader(originPath);
QString format = reader.format();
QString destinationPath = originPath + QString(".%1").arg(format);
// Detect format using static method to avoid loading entire image
QByteArray format = QImageReader::imageFormat(originPath);
if (format.isEmpty()) {
qWarning() << "Failed to detect image format:" << originPath;
QFile::remove(originPath);
return QString();
}
QString destinationPath = originPath + QString(".%1").arg(QString::fromLatin1(format));
QFile file(originPath);
if (!file.rename(destinationPath)) {
qWarning() << "originPath rename failed";
Expand Down
Loading