1 __ __ ____ ____ ____
2 / \\/ \/ _ \/ _ )/ _ \
3 \ / __/ _ \ __/
4 \__\__/\____/\_____/__/ ____ ___
5 / _/ / \ \ / _ \/ _/
6 / \_/ / / \ \ __/ \__
7 \____/____/\_____/_____/____/v0.5.0
8
9Description:
10============
11
12WebP codec: library to encode and decode images in WebP format. This package
13contains the library that can be used in other programs to add WebP support,
14as well as the command line tools 'cwebp' and 'dwebp'.
15
16See http://developers.google.com/speed/webp
17
18The latest source tree is available at
19https://chromium.googlesource.com/webm/libwebp
20
21It is released under the same license as the WebM project.
22See http://www.webmproject.org/license/software/ or the
23file "COPYING" file for details. An additional intellectual
24property rights grant can be found in the file PATENTS.
25
26Building:
27=========
28
29Windows build:
30--------------
31
32By running:
33
34 nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
35
36the directory output\release-static\(x64|x86)\bin will contain the tools
37cwebp.exe and dwebp.exe. The directory output\release-static\(x64|x86)\lib will
38contain the libwebp static library.
39The target architecture (x86/x64) is detected by Makefile.vc from the Visual
40Studio compiler (cl.exe) available in the system path.
41
42Unix build using makefile.unix:
43-------------------------------
44
45On platforms with GNU tools installed (gcc and make), running
46
47 make -f makefile.unix
48
49will build the binaries examples/cwebp and examples/dwebp, along
50with the static library src/libwebp.a. No system-wide installation
51is supplied, as this is a simple alternative to the full installation
52system based on the autoconf tools (see below).
53Please refer to makefile.unix for additional details and customizations.
54
55Using autoconf tools:
56---------------------
57Prerequisites:
58A compiler (e.g., gcc), make, autoconf, automake, libtool.
59On a Debian-like system the following should install everything you need for a
60minimal build:
61$ sudo apt-get install gcc make autoconf automake libtool
62
63When building from git sources, you will need to run autogen.sh to generate the
64configure script.
65
66./configure
67make
68make install
69
70should be all you need to have the following files
71
72/usr/local/include/webp/decode.h
73/usr/local/include/webp/encode.h
74/usr/local/include/webp/types.h
75/usr/local/lib/libwebp.*
76/usr/local/bin/cwebp
77/usr/local/bin/dwebp
78
79installed.
80
81Note: A decode-only library, libwebpdecoder, is available using the
82'--enable-libwebpdecoder' flag. The encode library is built separately and can
83be installed independently using a minor modification in the corresponding
84Makefile.am configure files (see comments there). See './configure --help' for
85more options.
86
87SWIG bindings:
88--------------
89
90To generate language bindings from swig/libwebp.swig at least swig-1.3
91(http://www.swig.org) is required.
92
93Currently the following functions are mapped:
94Decode:
95 WebPGetDecoderVersion
96 WebPGetInfo
97 WebPDecodeRGBA
98 WebPDecodeARGB
99 WebPDecodeBGRA
100 WebPDecodeBGR
101 WebPDecodeRGB
102
103Encode:
104 WebPGetEncoderVersion
105 WebPEncodeRGBA
106 WebPEncodeBGRA
107 WebPEncodeRGB
108 WebPEncodeBGR
109 WebPEncodeLosslessRGBA
110 WebPEncodeLosslessBGRA
111 WebPEncodeLosslessRGB
112 WebPEncodeLosslessBGR
113
114See swig/README for more detailed build instructions.
115
116Java bindings:
117
118To build the swig-generated JNI wrapper code at least JDK-1.5 (or equivalent)
119is necessary for enum support. The output is intended to be a shared object /
120DLL that can be loaded via System.loadLibrary("webp_jni").
121
122Python bindings:
123
124To build the swig-generated Python extension code at least Python 2.6 is
125required. Python < 2.6 may build with some minor changes to libwebp.swig or the
126generated code, but is untested.
127
128Encoding tool:
129==============
130
131The examples/ directory contains tools for encoding (cwebp) and
132decoding (dwebp) images.
133
134The easiest use should look like:
135 cwebp input.png -q 80 -o output.webp
136which will convert the input file to a WebP file using a quality factor of 80
137on a 0->100 scale (0 being the lowest quality, 100 being the best. Default
138value is 75).
139You might want to try the -lossless flag too, which will compress the source
140(in RGBA format) without any loss. The -q quality parameter will in this case
141control the amount of processing time spent trying to make the output file as
142small as possible.
143
144A longer list of options is available using the -longhelp command line flag:
145
146> cwebp -longhelp
147Usage:
148 cwebp [-preset <...>] [options] in_file [-o out_file]
149
150If input size (-s) for an image is not specified, it is
151assumed to be a PNG, JPEG, TIFF or WebP file.
152
153Options:
154 -h / -help ............ short help
155 -H / -longhelp ........ long help
156 -q <float> ............. quality factor (0:small..100:big)
157 -alpha_q <int> ......... transparency-compression quality (0..100)
158 -preset <string> ....... preset setting, one of:
159 default, photo, picture,
160 drawing, icon, text
161 -preset must come first, as it overwrites other parameters
162 -z <int> ............... activates lossless preset with given
163 level in [0:fast, ..., 9:slowest]
164
165 -m <int> ............... compression method (0=fast, 6=slowest)
166 -segments <int> ........ number of segments to use (1..4)
167 -size <int> ............ target size (in bytes)
168 -psnr <float> .......... target PSNR (in dB. typically: 42)
169
170 -s <int> <int> ......... input size (width x height) for YUV
171 -sns <int> ............. spatial noise shaping (0:off, 100:max)
172 -f <int> ............... filter strength (0=off..100)
173 -sharpness <int> ....... filter sharpness (0:most .. 7:least sharp)
174 -strong ................ use strong filter instead of simple (default)
175 -nostrong .............. use simple filter instead of strong
176 -partition_limit <int> . limit quality to fit the 512k limit on
177 the first partition (0=no degradation ... 100=full)
178 -pass <int> ............ analysis pass number (1..10)
179 -crop <x> <y> <w> <h> .. crop picture with the given rectangle
180 -resize <w> <h> ........ resize picture (after any cropping)
181 -mt .................... use multi-threading if available
182 -low_memory ............ reduce memory usage (slower encoding)
183 -map <int> ............. print map of extra info
184 -print_psnr ............ prints averaged PSNR distortion
185 -print_ssim ............ prints averaged SSIM distortion
186 -print_lsim ............ prints local-similarity distortion
187 -d <file.pgm> .......... dump the compressed output (PGM file)
188 -alpha_method <int> .... transparency-compression method (0..1)
189 -alpha_filter <string> . predictive filtering for alpha plane,
190 one of: none, fast (default) or best
191 -exact ................. preserve RGB values in transparent area
192 -blend_alpha <hex> ..... blend colors against background color
193 expressed as RGB values written in
194 hexadecimal, e.g. 0xc0e0d0 for red=0xc0
195 green=0xe0 and blue=0xd0
196 -noalpha ............... discard any transparency information
197 -lossless .............. encode image losslessly
198 -near_lossless <int> ... use near-lossless image
199 preprocessing (0..100=off)
200 -hint <string> ......... specify image characteristics hint,
201 one of: photo, picture or graph
202
203 -metadata <string> ..... comma separated list of metadata to
204 copy from the input to the output if present.
205 Valid values: all, none (default), exif, icc, xmp
206
207 -short ................. condense printed message
208 -quiet ................. don't print anything
209 -version ............... print version number and exit
210 -noasm ................. disable all assembly optimizations
211 -v ..................... verbose, e.g. print encoding/decoding times
212 -progress .............. report encoding progress
213
214Experimental Options:
215 -jpeg_like ............. roughly match expected JPEG size
216 -af .................... auto-adjust filter strength
217 -pre <int> ............. pre-processing filter
218
219The main options you might want to try in order to further tune the
220visual quality are:
221 -preset
222 -sns
223 -f
224 -m
225
226Namely:
227 * 'preset' will set up a default encoding configuration targeting a
228 particular type of input. It should appear first in the list of options,
229 so that subsequent options can take effect on top of this preset.
230 Default value is 'default'.
231 * 'sns' will progressively turn on (when going from 0 to 100) some additional
232 visual optimizations (like: segmentation map re-enforcement). This option
233 will balance the bit allocation differently. It tries to take bits from the
234 "easy" parts of the picture and use them in the "difficult" ones instead.
235 Usually, raising the sns value (at fixed -q value) leads to larger files,
236 but with better quality.
237 Typical value is around '75'.
238 * 'f' option directly links to the filtering strength used by the codec's
239 in-loop processing. The higher the value, the smoother the
240 highly-compressed area will look. This is particularly useful when aiming
241 at very small files. Typical values are around 20-30. Note that using the
242 option -strong/-nostrong will change the type of filtering. Use "-f 0" to
243 turn filtering off.
244 * 'm' controls the trade-off between encoding speed and quality. Default is 4.
245 You can try -m 5 or -m 6 to explore more (time-consuming) encoding
246 possibilities. A lower value will result in faster encoding at the expense
247 of quality.
248
249Decoding tool:
250==============
251
252There is a decoding sample in examples/dwebp.c which will take
253a .webp file and decode it to a PNG image file (amongst other formats).
254This is simply to demonstrate the use of the API. You can verify the
255file test.webp decodes to exactly the same as test_ref.ppm by using:
256
257 cd examples
258 ./dwebp test.webp -ppm -o test.ppm
259 diff test.ppm test_ref.ppm
260
261The full list of options is available using -h:
262
263> dwebp -h
264Usage: dwebp in_file [options] [-o out_file]
265
266Decodes the WebP image file to PNG format [Default]
267Use following options to convert into alternate image formats:
268 -pam ......... save the raw RGBA samples as a color PAM
269 -ppm ......... save the raw RGB samples as a color PPM
270 -bmp ......... save as uncompressed BMP format
271 -tiff ........ save as uncompressed TIFF format
272 -pgm ......... save the raw YUV samples as a grayscale PGM
273 file with IMC4 layout
274 -yuv ......... save the raw YUV samples in flat layout
275
276 Other options are:
277 -version .... print version number and exit
278 -nofancy ..... don't use the fancy YUV420 upscaler
279 -nofilter .... disable in-loop filtering
280 -nodither .... disable dithering
281 -dither <d> .. dithering strength (in 0..100)
282 -alpha_dither use alpha-plane dithering if needed
283 -mt .......... use multi-threading
284 -crop <x> <y> <w> <h> ... crop output with the given rectangle
285 -resize <w> <h> ......... scale the output (*after* any cropping)
286 -flip ........ flip the output vertically
287 -alpha ....... only save the alpha plane
288 -incremental . use incremental decoding (useful for tests)
289 -h ....... this help message
290 -v ....... verbose (e.g. print encoding/decoding times)
291 -quiet ....... quiet mode, don't print anything
292 -noasm ....... disable all assembly optimizations
293
294Visualization tool:
295===================
296
297There's a little self-serve visualization tool called 'vwebp' under the
298examples/ directory. It uses OpenGL to open a simple drawing window and show
299a decoded WebP file. It's not yet integrated in the automake build system, but
300you can try to manually compile it using the recommendations below.
301
302Usage: vwebp in_file [options]
303
304Decodes the WebP image file and visualize it using OpenGL
305Options are:
306 -version .... print version number and exit
307 -noicc ....... don't use the icc profile if present
308 -nofancy ..... don't use the fancy YUV420 upscaler
309 -nofilter .... disable in-loop filtering
310 -dither <int> dithering strength (0..100), default=50
311 -noalphadither disable alpha plane dithering
312 -mt .......... use multi-threading
313 -info ........ print info
314 -h ....... this help message
315
316Keyboard shortcuts:
317 'c' ................ toggle use of color profile
318 'i' ................ overlay file information
319 'q' / 'Q' / ESC .... quit
320
321Building:
322---------
323
324Prerequisites:
3251) OpenGL & OpenGL Utility Toolkit (GLUT)
326 Linux:
327 $ sudo apt-get install freeglut3-dev mesa-common-dev
328 Mac + XCode:
329 - These libraries should be available in the OpenGL / GLUT frameworks.
330 Windows:
331 http://freeglut.sourceforge.net/index.php#download
332
3332) (Optional) qcms (Quick Color Management System)
334 i. Download qcms from Mozilla / Chromium:
335 http://hg.mozilla.org/mozilla-central/file/0e7639e3bdfb/gfx/qcms
336 http://src.chromium.org/viewvc/chrome/trunk/src/third_party/qcms
337 ii. Build and archive the source files as libqcms.a / qcms.lib
338 iii. Update makefile.unix / Makefile.vc
339 a) Define WEBP_HAVE_QCMS
340 b) Update include / library paths to reference the qcms directory.
341
342Build using makefile.unix / Makefile.vc:
343$ make -f makefile.unix examples/vwebp
344> nmake /f Makefile.vc CFG=release-static \
345 ../obj/x64/release-static/bin/vwebp.exe
346
347Animated GIF conversion:
348========================
349Animated GIF files can be converted to WebP files with animation using the
350gif2webp utility available under examples/. The files can then be viewed using
351vwebp.
352
353Usage:
354 gif2webp [options] gif_file -o webp_file
355Options:
356 -h / -help ............ this help
357 -lossy ................. encode image using lossy compression
358 -mixed ................. for each frame in the image, pick lossy
359 or lossless compression heuristically
360 -q <float> ............. quality factor (0:small..100:big)
361 -m <int> ............... compression method (0=fast, 6=slowest)
362 -min_size .............. minimize output size (default:off)
363 lossless compression by default; can be
364 combined with -q, -m, -lossy or -mixed
365 options
366 -kmin <int> ............ min distance between key frames
367 -kmax <int> ............ max distance between key frames
368 -f <int> ............... filter strength (0=off..100)
369 -metadata <string> ..... comma separated list of metadata to
370 copy from the input to the output if present
371 Valid values: all, none, icc, xmp (default)
372 -mt .................... use multi-threading if available
373
374 -version ............... print version number and exit
375 -v ..................... verbose
376 -quiet ................. don't print anything
377
378Building:
379---------
380With the libgif development files installed, gif2webp can be built using
381makefile.unix:
382$ make -f makefile.unix examples/gif2webp
383
384or using autoconf:
385$ ./configure --enable-everything
386$ make
387
388Comparison of animated images:
389==============================
390Test utility anim_diff under examples/ can be used to compare two animated
391images (each can be GIF or WebP).
392
393Usage: anim_diff <image1> <image2> [options]
394
395Options:
396 -dump_frames <folder> dump decoded frames in PAM format
397 -min_psnr <float> ... minimum per-frame PSNR
398 -raw_comparison ..... if this flag is not used, RGB is
399 premultiplied before comparison
400
401Building:
402---------
403With the libgif development files and a C++ compiler installed, anim_diff can
404be built using makefile.unix:
405$ make -f makefile.unix examples/anim_diff
406
407or using autoconf:
408$ ./configure --enable-everything
409$ make
410
411Encoding API:
412=============
413
414The main encoding functions are available in the header src/webp/encode.h
415The ready-to-use ones are:
416size_t WebPEncodeRGB(const uint8_t* rgb, int width, int height, int stride,
417 float quality_factor, uint8_t** output);
418size_t WebPEncodeBGR(const uint8_t* bgr, int width, int height, int stride,
419 float quality_factor, uint8_t** output);
420size_t WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride,
421 float quality_factor, uint8_t** output);
422size_t WebPEncodeBGRA(const uint8_t* bgra, int width, int height, int stride,
423 float quality_factor, uint8_t** output);
424
425They will convert raw RGB samples to a WebP data. The only control supplied
426is the quality factor.
427
428There are some variants for using the lossless format:
429
430size_t WebPEncodeLosslessRGB(const uint8_t* rgb, int width, int height,
431 int stride, uint8_t** output);
432size_t WebPEncodeLosslessBGR(const uint8_t* bgr, int width, int height,
433 int stride, uint8_t** output);
434size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, int width, int height,
435 int stride, uint8_t** output);
436size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, int width, int height,
437 int stride, uint8_t** output);
438
439Of course in this case, no quality factor is needed since the compression
440occurs without loss of the input values, at the expense of larger output sizes.
441
442Advanced encoding API:
443----------------------
444
445A more advanced API is based on the WebPConfig and WebPPicture structures.
446
447WebPConfig contains the encoding settings and is not tied to a particular
448picture.
449WebPPicture contains input data, on which some WebPConfig will be used for
450compression.
451The encoding flow looks like:
452
453-------------------------------------- BEGIN PSEUDO EXAMPLE
454
455#include <webp/encode.h>
456
457 // Setup a config, starting form a preset and tuning some additional
458 // parameters
459 WebPConfig config;
460 if (!WebPConfigPreset(&config, WEBP_PRESET_PHOTO, quality_factor))
461 return 0; // version error
462 }
463 // ... additional tuning
464 config.sns_strength = 90;
465 config.filter_sharpness = 6;
466 config_error = WebPValidateConfig(&config); // not mandatory, but useful
467
468 // Setup the input data
469 WebPPicture pic;
470 if (!WebPPictureInit(&pic)) {
471 return 0; // version error
472 }
473 pic.width = width;
474 pic.height = height;
475 // allocated picture of dimension width x height
476 if (!WebPPictureAllocate(&pic)) {
477 return 0; // memory error
478 }
479 // at this point, 'pic' has been initialized as a container,
480 // and can receive the Y/U/V samples.
481 // Alternatively, one could use ready-made import functions like
482 // WebPPictureImportRGB(), which will take care of memory allocation.
483 // In any case, past this point, one will have to call
484 // WebPPictureFree(&pic) to reclaim memory.
485
486 // Set up a byte-output write method. WebPMemoryWriter, for instance.
487 WebPMemoryWriter wrt;
488 WebPMemoryWriterInit(&wrt); // initialize 'wrt'
489
490 pic.writer = MyFileWriter;
491 pic.custom_ptr = my_opaque_structure_to_make_MyFileWriter_work;
492
493 // Compress!
494 int ok = WebPEncode(&config, &pic); // ok = 0 => error occurred!
495 WebPPictureFree(&pic); // must be called independently of the 'ok' result.
496
497 // output data should have been handled by the writer at that point.
498 // -> compressed data is the memory buffer described by wrt.mem / wrt.size
499
500 // deallocate the memory used by compressed data
501 WebPMemoryWriterClear(&wrt);
502
503-------------------------------------- END PSEUDO EXAMPLE
504
505Decoding API:
506=============
507
508This is mainly just one function to call:
509
510#include "webp/decode.h"
511uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size,
512 int* width, int* height);
513
514Please have a look at the file src/webp/decode.h for the details.
515There are variants for decoding in BGR/RGBA/ARGB/BGRA order, along with
516decoding to raw Y'CbCr samples. One can also decode the image directly into a
517pre-allocated buffer.
518
519To detect a WebP file and gather the picture's dimensions, the function:
520 int WebPGetInfo(const uint8_t* data, size_t data_size,
521 int* width, int* height);
522is supplied. No decoding is involved when using it.
523
524Incremental decoding API:
525=========================
526
527In the case when data is being progressively transmitted, pictures can still
528be incrementally decoded using a slightly more complicated API. Decoder state
529is stored into an instance of the WebPIDecoder object. This object can be
530created with the purpose of decoding either RGB or Y'CbCr samples.
531For instance:
532
533 WebPDecBuffer buffer;
534 WebPInitDecBuffer(&buffer);
535 buffer.colorspace = MODE_BGR;
536 ...
537 WebPIDecoder* idec = WebPINewDecoder(&buffer);
538
539As data is made progressively available, this incremental-decoder object
540can be used to decode the picture further. There are two (mutually exclusive)
541ways to pass freshly arrived data:
542
543either by appending the fresh bytes:
544
545 WebPIAppend(idec, fresh_data, size_of_fresh_data);
546
547or by just mentioning the new size of the transmitted data:
548
549 WebPIUpdate(idec, buffer, size_of_transmitted_buffer);
550
551Note that 'buffer' can be modified between each call to WebPIUpdate, in
552particular when the buffer is resized to accommodate larger data.
553
554These functions will return the decoding status: either VP8_STATUS_SUSPENDED if
555decoding is not finished yet or VP8_STATUS_OK when decoding is done. Any other
556status is an error condition.
557
558The 'idec' object must always be released (even upon an error condition) by
559calling: WebPDelete(idec).
560
561To retrieve partially decoded picture samples, one must use the corresponding
562method: WebPIDecGetRGB or WebPIDecGetYUVA.
563It will return the last displayable pixel row.
564
565Lastly, note that decoding can also be performed into a pre-allocated pixel
566buffer. This buffer must be passed when creating a WebPIDecoder, calling
567WebPINewRGB() or WebPINewYUVA().
568
569Please have a look at the src/webp/decode.h header for further details.
570
571Advanced Decoding API:
572======================
573
574WebP decoding supports an advanced API which provides on-the-fly cropping and
575rescaling, something of great usefulness on memory-constrained environments like
576mobile phones. Basically, the memory usage will scale with the output's size,
577not the input's, when one only needs a quick preview or a zoomed in portion of
578an otherwise too-large picture. Some CPU can be saved too, incidentally.
579
580-------------------------------------- BEGIN PSEUDO EXAMPLE
581 // A) Init a configuration object
582 WebPDecoderConfig config;
583 CHECK(WebPInitDecoderConfig(&config));
584
585 // B) optional: retrieve the bitstream's features.
586 CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK);
587
588 // C) Adjust 'config' options, if needed
589 config.options.no_fancy_upsampling = 1;
590 config.options.use_scaling = 1;
591 config.options.scaled_width = scaledWidth();
592 config.options.scaled_height = scaledHeight();
593 // etc.
594
595 // D) Specify 'config' output options for specifying output colorspace.
596 // Optionally the external image decode buffer can also be specified.
597 config.output.colorspace = MODE_BGRA;
598 // Optionally, the config.output can be pointed to an external buffer as
599 // well for decoding the image. This externally supplied memory buffer
600 // should be big enough to store the decoded picture.
601 config.output.u.RGBA.rgba = (uint8_t*) memory_buffer;
602 config.output.u.RGBA.stride = scanline_stride;
603 config.output.u.RGBA.size = total_size_of_the_memory_buffer;
604 config.output.is_external_memory = 1;
605
606 // E) Decode the WebP image. There are two variants w.r.t decoding image.
607 // The first one (E.1) decodes the full image and the second one (E.2) is
608 // used to incrementally decode the image using small input buffers.
609 // Any one of these steps can be used to decode the WebP image.
610
611 // E.1) Decode full image.
612 CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK);
613
614 // E.2) Decode image incrementally.
615 WebPIDecoder* const idec = WebPIDecode(NULL, NULL, &config);
616 CHECK(idec != NULL);
617 while (bytes_remaining > 0) {
618 VP8StatusCode status = WebPIAppend(idec, input, bytes_read);
619 if (status == VP8_STATUS_OK || status == VP8_STATUS_SUSPENDED) {
620 bytes_remaining -= bytes_read;
621 } else {
622 break;
623 }
624 }
625 WebPIDelete(idec);
626
627 // F) Decoded image is now in config.output (and config.output.u.RGBA).
628 // It can be saved, displayed or otherwise processed.
629
630 // G) Reclaim memory allocated in config's object. It's safe to call
631 // this function even if the memory is external and wasn't allocated
632 // by WebPDecode().
633 WebPFreeDecBuffer(&config.output);
634
635-------------------------------------- END PSEUDO EXAMPLE
636
637Bugs:
638=====
639
640Please report all bugs to our issue tracker:
641 https://bugs.chromium.org/p/webp
642Patches welcome! See this page to get started:
643 http://www.webmproject.org/code/contribute/submitting-patches/
644
645Discuss:
646========
647
648Email: webp-discuss@webmproject.org
649Web: http://groups.google.com/a/webmproject.org/group/webp-discuss
650