Skip to content

Implement quality setting for WebP export

Mathias Wein requested to merge mwein/krita:export_settings into master

Since WebP is not (just) a lossless format, this implements a quality setting for saving/exporting WebP images.

Originally I had plans for generic checking of the format capabilities through QImageWriter, but then realized that all other formats supporting useful options are already handled by krita plugins using related libs directly, and even though the WebP plugin reports a few other capabilities, only quality is actually used for writing, the others only for reading (oddly enough including background color).

So I ended up keeping it simple and just check for "image/webp" MIME type to create a default configuration and a configuration widget with a slider. The tooltip/"what's this" also mentions that setting quality to 100 saves the image as lossless WebP.

The lossless format was actually the main reason I wrote this, I'm not really impressed by lossy WebP, but the lossless format (despite the same basic compression algorithm AFAIK) often beats PNG quite clearly. Compared to vanilla libPNG, images are often 20-40% smaller.

Related observations

I encountered an issue while testing. For some reason, the last used configuration is not saved when using the "Export..." function in krita, only when using "Save As...". It depends on "showWarnings" passed to KisImportExportManager::convert(), which I traced all the way back to KisMainWindow::saveDocument(), see the different arguments to document->saveAs(...) and document->exportDocument(...) calls.

I don't really understand the intentions behind "showWarnings", would be nice if someone could look into this.

Also, I did run the test but I'm not sure it does anything useful, it tests for "image/x-gimp-brush" which seems unrelated to this plugin even...?

Test Plan

  • use "File"->"Save As..." and "Export..." with the formats handled by the qimageio plugin. Most common are probably 'WebP', 'Windows Bitmap' and 'Windows Icon' (although I can't even find the latter in Qt documentation, but it does work here...), the others are so exotic/ancient that I don't think I've ever worked with them in my life.
  • make sure that only WebP shows the dialog with quality slider, and that it affects the saved file properly. The webp package on Ubuntu also comes a utility called webpinfo that can verify if the file was saved as lossless or not, which should depend on whether quality was set to 100 or below.

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.

Merge request reports