Allow the user to select the JPEG save/compression quality
ClosedPublic

Authored by ngraham on Aug 12 2019, 4:44 AM.

Details

Summary

Currently, anytime Gwenview is used to save a non-JPEG file as a JPEG, or anytime JPEG file is saved or re-saved after performing a lossy edit (e.g. crop or red eye, but not rotation), the new file is saved with 75% quality level, resulting in a noticeable degradation in appearance.

This patch implements a user-selectable JPEG save/compression quality setting, which can be temporarily overridden in the Save As dialog when saving a file as a JPEG. The new default quality level is 90% -- same as Spectacle. This should prevent people from accdientally destroying their JPEGs.

As before, when saving an existing JPEG file with a new name or after performing a non-lossy edit (e.g. rotation, which only changes the EXIF rotation tag), the appearance of the file is not changed because no actual image manipulation is done.

FEATURE: 277996
FIXED-IN: 19.12.0

Test Plan

Set JPEG quality to 5% in the config file and test the following use cases:

  • Non-JPEG image: do Save or Save As in non-JPEG formats -> No changes or regressions.
  • JPEG image: do Save or Save As without changing the image format or the image's pixels at all -> No changes; quality level not taken into consideration because these are lossless operations that do not re-compress the image (which is good)
  • JPEG image: do Save or Save As after changing the image's pixels in some way (e.g. a crop operation) -> Image is saved with the user-specified 5% quality level and looks terrible
  • JPEG image: do Save As into a non-JPEG file format after changing the image image's pixels in some way, or not -> No changes or regressions (in particular, lossless images like PNG are not hugely ballooned in file size)

Set JPEG quality to 90% in the config file and test the following use cases:

  • Non-JPEG image: do Save As in non-JPEG formats -> No changes or regressions; dialog box does not show quality spinbox
  • Non-JPEG image: do Save As into a JPEG and in the {nav Save As] dialog, change the quality from 90% to 5%-> Image is saved with the user-specified 5% quality level and looks terrible
  • JPEG image: do Save As into a non-JPEG file format -> No changes or regressions; dialog box does not show quality spinbox
  • JPEG image: do Save As after changing the image's pixels in some way (e.g. a crop operation), and in the {nav Save As] dialog, change the quality from 90% to 5%-> Image is saved with the user-specified 5% quality level and looks terrible

Diff Detail

Repository
R260 Gwenview
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ngraham created this revision.Aug 12 2019, 4:44 AM
Restricted Application added a project: Gwenview. · View Herald TranscriptAug 12 2019, 4:44 AM
ngraham requested review of this revision.Aug 12 2019, 4:44 AM
pino added a subscriber: pino.Aug 12 2019, 4:48 AM

It is implemented purely as a setting in the settings dialog rather than a new
part of the save dialog because that would add a kdelibs4support dependency and
not be compatible with Flatpak portals.

Not true, see KFileCustomDialog in kio.

In D23106#510665, @pino wrote:

It is implemented purely as a setting in the settings dialog rather than a new
part of the save dialog because that would add a kdelibs4support dependency and
not be compatible with Flatpak portals.

Not true, see KFileCustomDialog in kio.

Ah, that's nice. But is it portal-compatible as well?

ngraham updated this revision to Diff 63613.Aug 12 2019, 5:44 PM

Add custom quality chooser UI in Save As dialog when saving as a JPEG file

ngraham edited the summary of this revision. (Show Details)Aug 12 2019, 5:48 PM
ngraham edited the test plan for this revision. (Show Details)
ngraham edited the test plan for this revision. (Show Details)
ngraham planned changes to this revision.Aug 12 2019, 6:08 PM

Doesn't work unless the image is somehow otherwise changed; fixing

ngraham edited the test plan for this revision. (Show Details)Aug 12 2019, 6:38 PM
ngraham updated this revision to Diff 63619.Aug 12 2019, 8:06 PM
ngraham edited the test plan for this revision. (Show Details)

Fix remaining issues; ready for review

ngraham updated this revision to Diff 63621.Aug 12 2019, 8:21 PM

Don't set quality when saving a non-JPEG image (it triggers https://bugreports.qt.io/browse/QTBUG-43618)

ngraham updated this revision to Diff 63623.Aug 12 2019, 8:25 PM

Populate the quality in the Save As dialog's spinbox correctly every time

ngraham edited the test plan for this revision. (Show Details)Aug 12 2019, 8:29 PM
filipf added a subscriber: filipf.Aug 12 2019, 8:48 PM

I believe I've just recently had some noticeable image quality loss after doing a save in Gwenview; the fact that it would happen was unbeknownst to me.

So this patch is much-appreciated from my POV, and I think the same will go for many other users.

+100

ngraham edited the summary of this revision. (Show Details)Aug 13 2019, 2:11 AM
ngraham added a reviewer: VDG.Aug 13 2019, 2:13 AM

Question for VDG people: is the settings UI unnecessary? I'm now wondering if it would make more sense to only put the UI in the Save as dialog, and not even bother with showing it elsewhere.

Actually, I think it is, since when using portals, you'll see the standard save dialog, not our customized one.

If there are no further comments or objections, I will land this in a week.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 24 2019, 5:37 PM
This revision was automatically updated to reflect the committed changes.

Just a side note:

This patch actually increases KF5 dependency to 5.61. Although KFileCustomDialog was introduced in 2017 (KF 5.42), it was only exposed in KF 5.61. All previous versions of KF5 KIO need minor patching of the "-devel" package to compile Gwenview 19.12.

https://phabricator.kde.org/D22018

MrPepe added a subscriber: MrPepe.Aug 25 2019, 3:24 PM

Spectacle 19.08.0 has a different look and feel for that option. Is there a reason why this is implemented in two different ways? It increases inconsistency between KDE apps in my opinion.

Just a side note:

This patch actually increases KF5 dependency to 5.61. Although KFileCustomDialog was introduced in 2017 (KF 5.42), it was only exposed in KF 5.61. All previous versions of KF5 KIO need minor patching of the "-devel" package to compile Gwenview 19.12.

https://phabricator.kde.org/D22018

Ohh, darn, I missed that. I guess I'll bump the frameworks dep to 5.61 then. :/

Spectacle 19.08.0 has a different look and feel for that option. Is there a reason why this is implemented in two different ways? It increases inconsistency between KDE apps in my opinion.

I can't remember why I did it this way instead of Spectacle's way. Changing one or the other is pretty trivial, though. Would you like to submit a patch?

Would be my first patch of that sort but let me give it a try.

volkov added a subscriber: volkov.Jul 13 2020, 5:22 PM

kf5 version is still not bumped.

Done in //invent.kde.org/graphics/gwenview/commit/9f9c9f45b605b11c2f3e22d3f9ff6eed77330bcd, sorry about that.