Comments (9)
I seem to have found the issue and it looks like a Qt bug. Setting aside that it equals Quality with Compression (probably influenced by imagemagick), it has a wrong assumption: more quality == less compression, or they read the libpng API wrong.
This is what the libpng headers say about setting the compression level.:
/* Set the library compression level. Currently, valid values range from
* 0 - 9, corresponding directly to the zlib compression levels 0 - 9
* (0 - no compression, 9 - "maximal" compression). Note that tests have
* shown that zlib compression levels 3-6 usually perform as well as level 9
* for PNG images, and do considerably fewer caclulations. In the future,
* these values may not correspond directly to the zlib compression levels.
*/
This is the problem code in qpnghandler.cpp
:
static bool write_png_image(const QImage &image, QIODevice *device,
int quality, float gamma, const QString &description)
{
QPNGImageWriter writer(device);
if (quality >= 0) {
quality = qMin(quality, 100);
quality = (100-quality) * 9 / 91; // map [0,100] -> [9,0]
}
writer.setGamma(gamma);
return writer.writeImage(image, quality, description);
}
It reverses the magnitude of the specified quality/compression setting, from 0 to 9 and from 100 to 0. Thus PNG images set to be saved with the highest quality are saved with the least compression.
from qimgv.
And it's been fixed for Qt 5.12 but you must set compression
option and must not set quality
for saving PNG images. The behavior in Qt is to map 0
quality to the highest compression of PNG images and 100
to the least compression.
from qimgv.
This is the current dev
branch code in qpnghandler.cpp
:
static bool write_png_image(const QImage &image, QIODevice *device,
int compression, int quality, float gamma, const QString &description)
{
// quality is used for backward compatibility, maps to compression
QPNGImageWriter writer(device);
if (compression >= 0)
compression = qMin(compression, 100);
else if (quality >= 0)
compression = 100 - qMin(quality, 100);
if (compression >= 0)
compression = (compression * 9) / 91; // map [0,100] -> [0,9]
writer.setGamma(gamma);
return writer.writeImage(image, compression, description);
}
from qimgv.
So if you could detect the Qt version at runtime and the file format you could handle both Qt behaviors and fix this bug.
from qimgv.
Or just use the correct old quality behavior when saving PNG images. No Qt version detection needed.
from qimgv.
Just now I noticed there is a dev
branch and it hardcodes quality to 0
. Are you sure it won't save JPEG files with lower quality?
from qimgv.
Just now I noticed there is a dev branch and it hardcodes quality to 0. Are you sure it won't save JPEG files with lower quality?
Yeah it will corrupt jpegs. That's a leftover code from when i was testing different compression
/ quality
values.
And it's been fixed for Qt 5.12
Could you please post a link to a bugreport? I wanna see what they did
from qimgv.
Also do you think i should present a compression quality option in ui (for lossy formats) or leave it hardcoded at some value?
from qimgv.
There doesn't seem to be a bug report but a direct to review patch
https://code.qt.io/cgit/qt/qtbase.git/commit/?id=1192c463db34e3f69be4d9ef976246ce265143a3
I think a sensible hardcoded value is fine for PNG but not so much for JPEG. On the other hand if quality or file size is a concern then the user should use a different tool for image editing. Considering these I think no option is needed. Gwenview doesn't have it and many other image viewers don't either.
from qimgv.
Related Issues (20)
- Network shares won't render images
- Image has wrong scale with multiple monitors in different scale HOT 2
- Update Qt to 6.6 HOT 1
- Time to switch HOT 9
- The application crashes when trying to view some JXL files HOT 1
- App crashes on ICO (v1.0.3-alpha-101) HOT 1
- Some SVG images, aren't displayed at all
- [Feature] German translation HOT 1
- [FEATURE] manual labels on the "move to" quick folders.
- How do I designate a quick folder? HOT 2
- [Feature request] Automatically switch to nearest neighbour upscaling for very small pictures (Pixelart)
- Failed to build with exiv2 v0.28.0 HOT 1
- Dark fusion theme [Qt6, Win11] HOT 4
- advices
- Zoom out less than 100% HOT 2
- Some keystroke detection is broken [Qt 6.7.0] HOT 4
- Feature: Add option to use embedded cover as thumbnail (for video files)
- Video playback detaches on mpv v0.38.0 HOT 3
- I can't delete gif file in it
- NEED IMPROVEMENTS FOR WINDOWS 11!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qimgv.