项目作者: till213

项目描述 :
Qt image plugin for Google's optimised JPEG encoder named "guetzli".
高级语言: C++
项目地址: git://github.com/till213/GuetzliImageIOPlugin.git
创建时间: 2017-03-23T07:08:51Z
项目社区:https://github.com/till213/GuetzliImageIOPlugin

开源协议:GNU Lesser General Public License v3.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:

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

Alternatively you can also initialise the submodules after cloning with:

  1. git clone https://github.com/till213/GuetzliImageIOPlugin
  2. cd GuetzliImageIOPlugin
  3. git submodule init
  4. 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

  1. cd GuetzliImageIOPlugin
  2. qmake -r
  3. make

On MinGW (Windows)

  1. cd GuetzliImageIOPlugin
  2. qmake -r
  3. 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

  1. bin/release/imageformats

and the SimpleGuetzliGUI will be located at

  1. bin/release

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

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

Like this the plugin is directly found by the application.

Debug Build

  1. qmake -r CONFIG+=debug
  2. 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:

  1. 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:

  1. su root
  2. 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

  1. #include <QApplication>
  2. #include <QImage>
  3. #include <QImageWriter>
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. QImage image;
  8. QImageWriter imageWriter;
  9. // Load or generate some QImage
  10. image = ...;
  11. // Set the output file path
  12. imageWriter.setFileName("guetzli.jpg");
  13. // The plugin format identifier is simply "guetzli"
  14. imageWriter.setFormat("guetzli");
  15. // The default quality is set to 85, the lowest possible value is 84
  16. imageWriter.setQuality(90);
  17. bool success = imageWriter.write(image);
  18. if (success) {
  19. return 0;
  20. } else {
  21. // Error processing
  22. ...
  23. return -1;
  24. }
  25. }

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

  1. QImage image;
  2. ...
  3. bool success = image.save("guetzli.jpg", "guetzli", 90);

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

  1. [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.