/GuetzliImageIOPlugin

Qt image plugin for Google's optimised JPEG encoder named "guetzli".

Primary LanguageC++GNU Lesser General Public License v3.0LGPL-3.0

Guetzli

GuetzliImageIOPlugin

A Qt image plugin (QImageIOPlugin) for the Google guetzli JPEG encoder.

Introduction

Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg. Read more about it on the Google Research Blog.

This plugin incorporates the Google guetzli code into a QImageIOPlugin for easy use in Qt based applications.

A simple GUI (SimpleGuetzliGUI) for testing the plugin is provided, too.

Simple GuetzliGUI

Cloning

This repository includes the Google guetzli repository as Git submodule. The easiest way to fetch all submodules at once is with the --recursive option:

git clone --recursive https://github.com/till213/GuetzliImageIOPlugin

Alternatively you can also initialise the submodules after cloning with:

git clone https://github.com/till213/GuetzliImageIOPlugin
cd GuetzliImageIOPlugin
git submodule init
git submodule update

Building

The plugin is mainly developed on macOS, but in parallel also on Windows 10 and FreeBSD, using Qt 5.6.2 or higher and qmake with *.pro project files.

On Windows the stock binary Qt based on MinGW 4.9.2 is used.

On POSIX systems

cd GuetzliImageIOPlugin
qmake -r
make

On MinGW (Windows)

cd GuetzliImageIOPlugin
qmake -r
mingw32-make.exe

Qt Creator (all platforms)

Alternatively you can open the top-level GuetzliImageIOPlugin.pro file in Qt Creator and build the projects as usual, for instance with CTRL + B (CMD + B on macOS).

This will build all projects, including the GuetzliImageIOPlugin and the SimpleGuetzliGUI.

The GuetzliImageIOPlugin(macOS see below) will be located at

bin/release/imageformats

and the SimpleGuetzliGUI will be located at

bin/release

On macOS the plugin is directly copied into the application bundle SimpleGuetzliGUI, for convenience:

bin/release/SimpleGuetzliGUI.app/Contents/plugins/imageformats

Like this the plugin is directly found by the application.

Debug Build

qmake -r CONFIG+=debug
make

Build Options

By default images with an alpha channel are first blended against a black background before being encoded to JPEG with the Guetzli encoder. The original Google command line guetzli encoder does this as well.

This behaviour can be controlled by setting the environment variable GUETZLI_BLEND_MODE in the project include Common.pri prior to (re-)compiling:

GUETZLI_BLEND_MODE Behaviour
1 (default) Image is blended against a black background
2 Image is blended against a white background
3 Alpha channel is ignored (Qt does this when saving JPEG data)

Installation to Qt Plugin Directory

The plugin is installed into the (system) Qt image format plugin directory as follows:

make install

This will copy the plugin into the corresponding imageformats folder of the Qt installation.

If Qt is installed system-wide (which is typically the case for Linux/FreeBSD/Unix systems) then you need administrator rights, for instance:

su root
sudo make install

Qt Plugin Directory

With the stock binary Qt distribution, e.g. Qt version 5.6.2 the plugin will be copied into:

Platform Image Plugin Location
macOS ~/Qt5.6.2/5.6/clang_64/plugins/imageformats/libGuetzliImageIOPlugin.dylib
Windows C:\Qt\Qt5.6.2\5.6\mingw49_32\plugins\imageformats\GuetzliIOPlugin.dll
FreeBSD /usr/local/lib/qt5/plugins/imageformats/libGuetzliImageIOPlugin.so

Usage

#include <QApplication>
#include <QImage>
#include <QImageWriter>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QImage image;
  QImageWriter imageWriter;

  // Load or generate some QImage
  image = ...;

  // Set the output file path
  imageWriter.setFileName("guetzli.jpg");

  // The plugin format identifier is simply "guetzli"
  imageWriter.setFormat("guetzli");

  // The default quality is set to 85, the lowest possible value is 84
  imageWriter.setQuality(90);

  bool success = imageWriter.write(image);
  if (success) {
    return 0;
  } else {
    // Error processing
    ...
    return -1;
  }
}

Alternatively you can also use the QImage::save method:

QImage image;

...

bool success = image.save("guetzli.jpg", "guetzli", 90);

Deploy the GuetzliImageIOPlugin together with your application in a subdirectory called imageformats.

[application directory]/imageformats/libGuetzliImageIOPlugin.dylib

Credits

This is a simple derivative work done in my free time. All credits go to Robert Obryk and Jyrki Alakuijala, Software Engineers, Google Research Europe.

License

The Qt plugin code is under the LGPL 3.

Note that the Google guetzli code comes with its own Apache License 2.0.