Commit a401e666 authored by Madhav Kanbur's avatar Madhav Kanbur
Browse files

Use Quality level when saving JPEG images

Previously, GwenviewConfig::jPEGQuality() was being used only by
updateRawDataFromImage() in jpegcontent.cpp. updateRawDataFromImage() is called
only when d->mImage is not null, implying that only "modified" jpeg
images get written to disk with the user's set quality level. This patch
unconditionally saves jpeg images to disk at the set quality level.

Also, this patch fixes a race condition introduced by merge request !26


We now wait for the save KJob to finish before restoring the quality
level.
Signed-off-by: Madhav Kanbur's avatarMadhav Kanbur <abcdjdj@gmail.com>
parent 955df5ad
......@@ -425,8 +425,10 @@ void GvCore::saveAs(const QUrl &url)
} else {
// Regardless of job result, reset JPEG config value if it was changed by
// the Save As dialog
if (GwenviewConfig::jPEGQuality() != d->configFileJPEGQualityValue)
GwenviewConfig::setJPEGQuality(d->configFileJPEGQualityValue);
connect(job, &KJob::result, [=]() {
if (GwenviewConfig::jPEGQuality() != d->configFileJPEGQualityValue)
GwenviewConfig::setJPEGQuality(d->configFileJPEGQualityValue);
});
connect(job, SIGNAL(result(KJob*)), SLOT(slotSaveResult(KJob*)));
}
}
......
......@@ -687,8 +687,14 @@ bool JpegContent::save(QIODevice* device)
d->mRawData.resize(io.size());
io.read((unsigned char*)d->mRawData.data(), io.size());
QDataStream stream(device);
stream.writeRawData(d->mRawData.data(), d->mRawData.size());
QImage _image;
_image.loadFromData(d->mRawData);
QImageWriter writer(device, "jpeg");
writer.setQuality(GwenviewConfig::jPEGQuality());
if (!writer.write(_image)) {
d->mErrorString = writer.errorString();
return false;
}
// Make sure we are up to date
loadFromData(d->mRawData);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment