Libwebp
WebP codec: library to encode and decode images in WebP format.
Install / Use
/learn @jacklicn/LibwebpREADME
__ __ ____ ____ ____
/ \\/ \/ _ \/ _ )/ _ \
\ / __/ _ \ __/
\__\__/\____/\_____/__/ ____ ___
/ _/ / \ \ / _ \/ _/
/ \_/ / / \ \ __/ \__
\____/____/\_____/_____/____/v0.4.3
Description:
WebP codec: library to encode and decode images in WebP format. This package contains the library that can be used in other programs to add WebP support, as well as the command line tools 'cwebp' and 'dwebp'.
See http://developers.google.com/speed/webp
Latest sources are available from http://www.webmproject.org/code/
It is released under the same license as the WebM project. See http://www.webmproject.org/license/software/ or the file "COPYING" file for details. An additional intellectual property rights grant can be found in the file PATENTS.
Building:
Windows build:
By running:
nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
the directory output\release-static(x64|x86)\bin will contain the tools cwebp.exe and dwebp.exe. The directory output\release-static(x64|x86)\lib will contain the libwebp static library. The target architecture (x86/x64) is detected by Makefile.vc from the Visual Studio compiler (cl.exe) available in the system path.
Unix build using makefile.unix:
On platforms with GNU tools installed (gcc and make), running
make -f makefile.unix
will build the binaries examples/cwebp and examples/dwebp, along with the static library src/libwebp.a. No system-wide installation is supplied, as this is a simple alternative to the full installation system based on the autoconf tools (see below). Please refer to makefile.unix for additional details and customizations.
Using autoconf tools:
When building from git sources, you will need to run autogen.sh to generate the configure script.
./configure make make install
should be all you need to have the following files
/usr/local/include/webp/decode.h /usr/local/include/webp/encode.h /usr/local/include/webp/types.h /usr/local/lib/libwebp.* /usr/local/bin/cwebp /usr/local/bin/dwebp
installed.
Note: A decode-only library, libwebpdecoder, is available using the '--enable-libwebpdecoder' flag. The encode library is built separately and can be installed independently using a minor modification in the corresponding Makefile.am configure files (see comments there). See './configure --help' for more options.
SWIG bindings:
To generate language bindings from swig/libwebp.swig at least swig-1.3 (http://www.swig.org) is required.
Currently the following functions are mapped: Decode: WebPGetDecoderVersion WebPGetInfo WebPDecodeRGBA WebPDecodeARGB WebPDecodeBGRA WebPDecodeBGR WebPDecodeRGB
Encode: WebPGetEncoderVersion WebPEncodeRGBA WebPEncodeBGRA WebPEncodeRGB WebPEncodeBGR WebPEncodeLosslessRGBA WebPEncodeLosslessBGRA WebPEncodeLosslessRGB WebPEncodeLosslessBGR
See swig/README for more detailed build instructions.
Java bindings:
To build the swig-generated JNI wrapper code at least JDK-1.5 (or equivalent) is necessary for enum support. The output is intended to be a shared object / DLL that can be loaded via System.loadLibrary("webp_jni").
Python bindings:
To build the swig-generated Python extension code at least Python 2.6 is required. Python < 2.6 may build with some minor changes to libwebp.swig or the generated code, but is untested.
Encoding tool:
The examples/ directory contains tools for encoding (cwebp) and decoding (dwebp) images.
The easiest use should look like: cwebp input.png -q 80 -o output.webp which will convert the input file to a WebP file using a quality factor of 80 on a 0->100 scale (0 being the lowest quality, 100 being the best. Default value is 75). You might want to try the -lossless flag too, which will compress the source (in RGBA format) without any loss. The -q quality parameter will in this case control the amount of processing time spent trying to make the output file as small as possible.
A longer list of options is available using the -longhelp command line flag:
cwebp -longhelp Usage: cwebp [-preset <...>] [options] in_file [-o out_file]
If input size (-s) for an image is not specified, it is assumed to be a PNG, JPEG, TIFF or WebP file.
Options: -h / -help ............ short help -H / -longhelp ........ long help -q <float> ............. quality factor (0:small..100:big) -alpha_q <int> ......... transparency-compression quality (0..100) -preset <string> ....... preset setting, one of: default, photo, picture, drawing, icon, text -preset must come first, as it overwrites other parameters -z <int> ............... activates lossless preset with given level in [0:fast, ..., 9:slowest]
-m <int> ............... compression method (0=fast, 6=slowest) -segments <int> ........ number of segments to use (1..4) -size <int> ............ target size (in bytes) -psnr <float> .......... target PSNR (in dB. typically: 42)
-s <int> <int> ......... input size (width x height) for YUV -sns <int> ............. spatial noise shaping (0:off, 100:max) -f <int> ............... filter strength (0=off..100) -sharpness <int> ....... filter sharpness (0:most .. 7:least sharp) -strong ................ use strong filter instead of simple (default) -nostrong .............. use simple filter instead of strong -partition_limit <int> . limit quality to fit the 512k limit on the first partition (0=no degradation ... 100=full) -pass <int> ............ analysis pass number (1..10) -crop <x> <y> <w> <h> .. crop picture with the given rectangle -resize <w> <h> ........ resize picture (after any cropping) -mt .................... use multi-threading if available -low_memory ............ reduce memory usage (slower encoding) -map <int> ............. print map of extra info -print_psnr ............ prints averaged PSNR distortion -print_ssim ............ prints averaged SSIM distortion -print_lsim ............ prints local-similarity distortion -d <file.pgm> .......... dump the compressed output (PGM file) -alpha_method <int> .... transparency-compression method (0..1) -alpha_filter <string> . predictive filtering for alpha plane, one of: none, fast (default) or best -alpha_cleanup ......... clean RGB values in transparent area -blend_alpha <hex> ..... blend colors against background color expressed as RGB values written in hexadecimal, e.g. 0xc0e0d0 for red=0xc0 green=0xe0 and blue=0xd0 -noalpha ............... discard any transparency information -lossless .............. encode image losslessly -hint <string> ......... specify image characteristics hint, one of: photo, picture or graph
-metadata <string> ..... comma separated list of metadata to copy from the input to the output if present. Valid values: all, none (default), exif, icc, xmp
-short ................. condense printed message -quiet ................. don't print anything -version ............... print version number and exit -noasm ................. disable all assembly optimizations -v ..................... verbose, e.g. print encoding/decoding times -progress .............. report encoding progress
Experimental Options: -jpeg_like ............. roughly match expected JPEG size -af .................... auto-adjust filter strength -pre <int> ............. pre-processing filter
The main options you might want to try in order to further tune the visual quality are: -preset -sns -f -m
Namely:
- 'preset' will set up a default encoding configuration targeting a particular type of input. It should appear first in the list of options, so that subsequent options can take effect on top of this preset. Default value is 'default'.
- 'sns' will progressively turn on (when going from 0 to 100) some additional visual optimizations (like: segmentation map re-enforcement). This option will balance the bit allocation differently. It tries to take bits from the "easy" parts of the picture and use them in the "difficult" ones instead. Usually, raising the sns value (at fixed -q value) leads to larger files, but with better quality. Typical value is around '75'.
- 'f' option directly links to the filtering strength used by the codec's in-loop processing. The higher the value, the smoother the highly-compressed area will look. This is particularly useful when aiming at very small files. Typical values are around 20-30. Note that using the option -strong/-nostrong will change the type of filtering. Use "-f 0" to turn filtering off.
- 'm' controls the trade-off between encoding speed and quality. Default is 4. You can try -m 5 or -m 6 to explore more (time-consuming) encoding possibilities. A lower value will result in faster encoding at the expense of quality.
Decoding tool:
There is a decoding sample in examples/dwebp.c which will take a .webp file and decode it to a PNG image file (amongst other formats). This is simply to demonstrate the use of the API. You can verify the file test.webp decodes to exactly the same as test_ref.ppm by using:
cd examples ./dwebp test.webp -ppm -o test.ppm diff test.ppm test_ref.ppm
The full list of options is available using -h:
dwebp -h Usage: dwebp in_file [options] [-o out_file]
Decodes the WebP image file to PNG format [Default] Use following options to convert into alternate image formats: -pam ......... save the raw RGBA samples as a color PAM -ppm .......
