• Home
Name Date Size #Lines LOC

..--

examples/03-May-2024-148112

include/webp/03-May-2024-1,071483

src/03-May-2024-25,45419,126

AUTHORSD03-May-2024144 75

Android.mkD03-May-202437 21

COPYINGD03-May-20241.5 KiB3124

ChangeLogD03-May-2024213 65

INSTALLD03-May-20249.3 KiB238179

NEWSD03-May-202491 32

PATENTSD03-May-20241.3 KiB2320

READMED03-May-202420.4 KiB540431

README.androidD03-May-20241.5 KiB3429

README

1          __   __  ____  ____  ____
2         /  \\/  \/  _ \/  _ )/  _ \
3         \       /   __/  _  \   __/
4          \__\__/\____/\_____/__/ ____  ___
5                / _/ /    \    \ /  _ \/ _/
6               /  \_/   / /   \ \   __/  \__
7               \____/____/\_____/_____/____/v0.2.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
18Latest sources are available from http://www.webmproject.org/code/
19
20It is released under the same license as the WebM project.
21See http://www.webmproject.org/license/software/ or the
22file "COPYING" file for details. An additional intellectual
23property rights grant can be found in the file PATENTS.
24
25Building:
26=========
27
28Windows build (without experimental features):
29----------------------------------------------
30
31By running:
32
33  nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
34
35the directory output\release-static\(x64|x86)\bin will contain the tools
36cwebp.exe and dwebp.exe. The directory output\release-static\(x64|x86)\lib will
37contain the libwebp static library.
38The target architecture (x86/x64) is detected by Makefile.vc from the Visual
39Studio compiler (cl.exe) available in the system path.
40
41Windows build (with experimental features):
42-------------------------------------------
43
44This release requires the zlib library. This library is not common under
45Windows nor can it be replaced with calls to the Windows API, so you will need
46to download it or build it yourself.
47
48You can either:
49(a) Link zlib dynamically (as a DLL).
50(b) Link zlib statically.
51
52Linking it dynamically is easier to do (as you can download a precompiled DLL),
53but a bit more cumbersome to use - you need to keep zlib1.dll in the same
54directory as the created EXEs.
55
56a. With dynamic zlib
57~~~~~~~~~~~~~~~~~~~~
581. Download and unpack the archive from http://zlib.net/zlib125-dll.zip.
592. Compile libwebp with the command:
60  nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output \
61      ZDLLDIR=C:\path\to\the\unpacked\archive EXPERIMENTAL=y
623. Copy C:\path\to\the\unpacked\archive\zlib1.dll to
63   output\release-static\x86\bin for binaries there to work.
64Note: only a 32-bit DLL is currently available for download, so for a 64-bit
65build, you will need to build the DLL yourself.
66
67b. With static zlib
68~~~~~~~~~~~~~~~~~~~
69
701. Download and unpack the source code from http://zlib.net/zlib125.zip.
712. For a 32-bit build of zlib compatible with libwebp:
72  a. Edit zlib's win32\Makefile.msc, adding "-SAFESEH" to ASFLAGS.
73  b. Compile zlib with the command:
74    nmake /f win32/Makefile.msc LOC="-DASMV -DASMINF -MT" \
75        OBJA="inffas32.obj match686.obj"
763. Compile libwebp with the command
77  nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output \
78      ZLIBDIR=C:\path\to\the\unpacked\archive experimental
794. Use the binaries in output\release-static\x86\bin.
80Note: a 64-bit build of zlib requires different modifications of
81Makefile.msc.
82
83
84Unix build using makefile.unix:
85-------------------------------
86
87On platforms with GNU tools installed (gcc and make), running
88
89  make -f makefile.unix
90
91will build the binaries examples/cwebp and examples/dwebp, along
92with the static library src/libwebp.a. No system-wide installation
93is supplied, as this is a simple alternative to the full installation
94system based on the autoconf tools (see below).
95Please refer to the makefile.unix for additional details and customizations.
96
97Using autoconf tools:
98---------------------
99When building from git sources, you will need to run autogen.sh to generate the
100configure script.
101
102./configure
103make
104make install
105
106should be all you need to have the following files
107
108/usr/local/include/webp/decode.h
109/usr/local/include/webp/encode.h
110/usr/local/include/webp/types.h
111/usr/local/lib/libwebp.*
112/usr/local/bin/cwebp
113/usr/local/bin/dwebp
114
115installed.
116
117Note: The encoding and decoding libraries are compiled separately
118(as src/dec/libwebpdecode.* and src/dec/libwebpencode.*). They
119can be installed independently using a minor modification in the
120corresponding Makefile.am configure files (see comments there).
121
122SWIG bindings:
123--------------
124
125To generate language bindings from swig/libwebp.i swig-1.3
126(http://www.swig.org) is required. 2.0 may work, but has not been tested.
127
128Currently the following functions are mapped:
129Decode:
130  WebPGetDecoderVersion
131  WebPGetInfo
132  WebPDecodeRGBA
133  WebPDecodeARGB
134  WebPDecodeBGRA
135  WebPDecodeBGR
136  WebPDecodeRGB
137
138Encode:
139  WebPGetEncoderVersion
140  WebPEncodeRGBA
141  WebPEncodeBGRA
142  WebPEncodeRGB
143  WebPEncodeBGR
144  WebPEncodeLosslessRGBA
145  WebPEncodeLosslessBGRA
146  WebPEncodeLosslessRGB
147  WebPEncodeLosslessBGR
148
149Java bindings:
150
151To build the swig-generated JNI wrapper code at least JDK-1.5 (or equivalent)
152is necessary for enum support. The output is intended to be a shared object /
153DLL that can be loaded via System.loadLibrary("webp_jni").
154
155Encoding tool:
156==============
157
158The examples/ directory contains tools for encoding (cwebp) and
159decoding (dwebp) images.
160
161The easiest use should look like:
162  cwebp input.png -q 80 -o output.webp
163which will convert the input file to a WebP file using a quality factor of 80
164on a 0->100 scale (0 being the lowest quality, 100 being the best. Default
165value is 75).
166You might want to try the -lossless flag too, which will compress the source
167(in RGBA format) without any loss. The -q quality parameter will in this case
168control the amount of processing time spent trying to make the output file as
169small as possible.
170
171A longer list of options is available using the -longhelp command line flag:
172
173> cwebp -longhelp
174Usage:
175 cwebp [-preset <...>] [options] in_file [-o out_file]
176
177If input size (-s) for an image is not specified, it is assumed to be a PNG,
178JPEG or TIFF file.
179options:
180  -h / -help  ............ short help
181  -H / -longhelp  ........ long help
182  -q <float> ............. quality factor (0:small..100:big)
183  -alpha_q <int> ......... Transparency-compression quality (0..100).
184  -preset <string> ....... Preset setting, one of:
185                            default, photo, picture,
186                            drawing, icon, text
187     -preset must come first, as it overwrites other parameters.
188  -m <int> ............... compression method (0=fast, 6=slowest)
189  -segments <int> ........ number of segments to use (1..4)
190  -size <int> ............ Target size (in bytes)
191  -psnr <float> .......... Target PSNR (in dB. typically: 42)
192
193  -s <int> <int> ......... Input size (width x height) for YUV
194  -sns <int> ............. Spatial Noise Shaping (0:off, 100:max)
195  -f <int> ............... filter strength (0=off..100)
196  -sharpness <int> ....... filter sharpness (0:most .. 7:least sharp)
197  -strong ................ use strong filter instead of simple.
198  -partition_limit <int> . limit quality to fit the 512k limit on
199                           the first partition (0=no degradation ... 100=full)
200  -pass <int> ............ analysis pass number (1..10)
201  -crop <x> <y> <w> <h> .. crop picture with the given rectangle
202  -resize <w> <h> ........ resize picture (after any cropping)
203  -map <int> ............. print map of extra info.
204  -print_psnr ............ prints averaged PSNR distortion.
205  -print_ssim ............ prints averaged SSIM distortion.
206  -print_lsim ............ prints local-similarity distortion.
207  -d <file.pgm> .......... dump the compressed output (PGM file).
208  -alpha_method <int> .... Transparency-compression method (0..1)
209  -alpha_filter <string> . predictive filtering for alpha plane.
210                           One of: none, fast (default) or best.
211  -alpha_cleanup ......... Clean RGB values in transparent area.
212  -noalpha ............... discard any transparency information.
213  -lossless .............. Encode image losslessly.
214  -hint <string> ......... Specify image characteristics hint.
215                           One of: photo, picture or graph
216
217  -short ................. condense printed message
218  -quiet ................. don't print anything.
219  -version ............... print version number and exit.
220  -noasm ................. disable all assembly optimizations.
221  -v ..................... verbose, e.g. print encoding/decoding times
222  -progress .............. report encoding progress
223
224Experimental Options:
225  -af .................... auto-adjust filter strength.
226  -pre <int> ............. pre-processing filter
227
228
229The main options you might want to try in order to further tune the
230visual quality are:
231 -preset
232 -sns
233 -f
234 -m
235
236Namely:
237  * 'preset' will set up a default encoding configuration targeting a
238     particular type of input. It should appear first in the list of options,
239     so that subsequent options can take effect on top of this preset.
240     Default value is 'default'.
241  * 'sns' will progressively turn on (when going from 0 to 100) some additional
242     visual optimizations (like: segmentation map re-enforcement). This option
243     will balance the bit allocation differently. It tries to take bits from the
244     "easy" parts of the picture and use them in the "difficult" ones instead.
245     Usually, raising the sns value (at fixed -q value) leads to larger files,
246     but with better quality.
247     Typical value is around '75'.
248  * 'f' option directly links to the filtering strength used by the codec's
249     in-loop processing. The higher the value, the smoother the
250     highly-compressed area will look. This is particularly useful when aiming
251     at very small files. Typical values are around 20-30. Note that using the
252     option -strong will change the type of filtering. Use "-f 0" to turn
253     filtering off.
254  * 'm' controls the trade-off between encoding speed and quality. Default is 4.
255     You can try -m 5 or -m 6 to explore more (time-consuming) encoding
256     possibilities. A lower value will result in faster encoding at the expense
257     of quality.
258
259Decoding tool:
260==============
261
262There is a decoding sample in examples/dwebp.c which will take
263a .webp file and decode it to a PNG image file (amongst other formats).
264This is simply to demonstrate the use of the API. You can verify the
265file test.webp decodes to exactly the same as test_ref.ppm by using:
266
267 cd examples
268 ./dwebp test.webp -ppm -o test.ppm
269 diff test.ppm test_ref.ppm
270
271The full list of options is available using -h:
272
273> dwebp -h
274Usage: dwebp in_file [options] [-o out_file]
275
276Decodes the WebP image file to PNG format [Default]
277Use following options to convert into alternate image formats:
278  -pam ......... save the raw RGBA samples as a color PAM
279  -ppm ......... save the raw RGB samples as a color PPM
280  -pgm ......... save the raw YUV samples as a grayscale PGM
281                 file with IMC4 layout.
282 Other options are:
283  -version  .... print version number and exit.
284  -nofancy ..... don't use the fancy YUV420 upscaler.
285  -nofilter .... disable in-loop filtering.
286  -mt .......... use multi-threading
287  -crop <x> <y> <w> <h> ... crop output with the given rectangle
288  -scale <w> <h> .......... scale the output (*after* any cropping)
289  -alpha ....... only save the alpha plane.
290  -h     ....... this help message.
291  -v     ....... verbose (e.g. print encoding/decoding times)
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 or makefile.unix
300build system, but you can try to manually compile it using the recommendations
301at the top of the source file.
302
303Usage: 'vwebp my_picture.webp'
304
305
306Encoding API:
307=============
308
309The main encoding functions are available in the header src/webp/encode.h
310The ready-to-use ones are:
311size_t WebPEncodeRGB(const uint8_t* rgb, int width, int height, int stride,
312                     float quality_factor, uint8_t** output);
313size_t WebPEncodeBGR(const uint8_t* bgr, int width, int height, int stride,
314                     float quality_factor, uint8_t** output);
315size_t WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride,
316                      float quality_factor, uint8_t** output);
317size_t WebPEncodeBGRA(const uint8_t* bgra, int width, int height, int stride,
318                      float quality_factor, uint8_t** output);
319
320They will convert raw RGB samples to a WebP data. The only control supplied
321is the quality factor.
322
323There are some variants for using the lossless format:
324
325size_t WebPEncodeLosslessRGB(const uint8_t* rgb, int width, int height,
326                             int stride, uint8_t** output);
327size_t WebPEncodeLosslessBGR(const uint8_t* bgr, int width, int height,
328                             int stride, uint8_t** output);
329size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, int width, int height,
330                              int stride, uint8_t** output);
331size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, int width, int height,
332                              int stride, uint8_t** output);
333
334Of course in this case, no quality factor is needed since the compression
335occurs without loss of the input values, at the expense of larger output sizes.
336
337Advanced encoding API:
338----------------------
339
340A more advanced API is based on the WebPConfig and WebPPicture structures.
341
342WebPConfig contains the encoding settings and is not tied to a particular
343picture.
344WebPPicture contains input data, on which some WebPConfig will be used for
345compression.
346The encoding flow looks like:
347
348-------------------------------------- BEGIN PSEUDO EXAMPLE
349
350#include <webp/encode.h>
351
352  // Setup a config, starting form a preset and tuning some additional
353  // parameters
354  WebPConfig config;
355  if (!WebPConfigPreset(&config, WEBP_PRESET_PHOTO, quality_factor))
356    return 0;   // version error
357  }
358  // ... additional tuning
359  config.sns_strength = 90;
360  config.filter_sharpness = 6;
361  config_error = WebPValidateConfig(&config);  // not mandatory, but useful
362
363  // Setup the input data
364  WebPPicture pic;
365  if (!WebPPictureInit(&pic)) {
366    return 0;  // version error
367  }
368  pic.width = width;
369  pic.height = height;
370  // allocated picture of dimension width x height
371  if (!WebPPictureAllocate(&pic)) {
372    return 0;   // memory error
373  }
374  // at this point, 'pic' has been initialized as a container,
375  // and can receive the Y/U/V samples.
376  // Alternatively, one could use ready-made import functions like
377  // WebPPictureImportRGB(), which will take care of memory allocation.
378  // In any case, past this point, one will have to call
379  // WebPPictureFree(&pic) to reclaim memory.
380
381  // Set up a byte-output write method. WebPMemoryWriter, for instance.
382  WebPMemoryWriter wrt;
383  pic.writer = MyFileWriter;
384  pic.custom_ptr = my_opaque_structure_to_make_MyFileWriter_work;
385  // initialize 'wrt' here...
386
387  // Compress!
388  int ok = WebPEncode(&config, &pic);   // ok = 0 => error occurred!
389  WebPPictureFree(&pic);  // must be called independently of the 'ok' result.
390
391  // output data should have been handled by the writer at that point.
392
393-------------------------------------- END PSEUDO EXAMPLE
394
395Decoding API:
396=============
397
398This is mainly just one function to call:
399
400#include "webp/decode.h"
401uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size,
402                       int* width, int* height);
403
404Please have a look at the file src/webp/decode.h for the details.
405There are variants for decoding in BGR/RGBA/ARGB/BGRA order, along with
406decoding to raw Y'CbCr samples. One can also decode the image directly into a
407pre-allocated buffer.
408
409To detect a WebP file and gather the picture's dimensions, the function:
410  int WebPGetInfo(const uint8_t* data, size_t data_size,
411                  int* width, int* height);
412is supplied. No decoding is involved when using it.
413
414Incremental decoding API:
415=========================
416
417In the case when data is being progressively transmitted, pictures can still
418be incrementally decoded using a slightly more complicated API. Decoder state
419is stored into an instance of the WebPIDecoder object. This object can be
420created with the purpose of decoding either RGB or Y'CbCr samples.
421For instance:
422
423  WebPDecBuffer buffer;
424  WebPInitDecBuffer(&buffer);
425  buffer.colorspace = MODE_BGR;
426  ...
427  WebPIDecoder* idec = WebPINewDecoder(&buffer);
428
429As data is made progressively available, this incremental-decoder object
430can be used to decode the picture further. There are two (mutually exclusive)
431ways to pass freshly arrived data:
432
433either by appending the fresh bytes:
434
435  WebPIAppend(idec, fresh_data, size_of_fresh_data);
436
437or by just mentioning the new size of the transmitted data:
438
439  WebPIUpdate(idec, buffer, size_of_transmitted_buffer);
440
441Note that 'buffer' can be modified between each call to WebPIUpdate, in
442particular when the buffer is resized to accommodate larger data.
443
444These functions will return the decoding status: either VP8_STATUS_SUSPENDED if
445decoding is not finished yet or VP8_STATUS_OK when decoding is done. Any other
446status is an error condition.
447
448The 'idec' object must always be released (even upon an error condition) by
449calling: WebPDelete(idec).
450
451To retrieve partially decoded picture samples, one must use the corresponding
452method: WebPIDecGetRGB or WebPIDecGetYUVA.
453It will return the last displayable pixel row.
454
455Lastly, note that decoding can also be performed into a pre-allocated pixel
456buffer. This buffer must be passed when creating a WebPIDecoder, calling
457WebPINewRGB() or WebPINewYUVA().
458
459Please have a look at the src/webp/decode.h header for further details.
460
461Advanced Decoding API:
462======================
463
464WebP decoding supports an advanced API which provides on-the-fly cropping and
465rescaling, something of great usefulness on memory-constrained environments like
466mobile phones. Basically, the memory usage will scale with the output's size,
467not the input's, when one only needs a quick preview or a zoomed in portion of
468an otherwise too-large picture. Some CPU can be saved too, incidentally.
469
470-------------------------------------- BEGIN PSEUDO EXAMPLE
471     // A) Init a configuration object
472     WebPDecoderConfig config;
473     CHECK(WebPInitDecoderConfig(&config));
474
475     // B) optional: retrieve the bitstream's features.
476     CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK);
477
478     // C) Adjust 'config' options, if needed
479     config.options.no_fancy_upsampling = 1;
480     config.options.use_scaling = 1;
481     config.options.scaled_width = scaledWidth();
482     config.options.scaled_height = scaledHeight();
483     // etc.
484
485     // D) Specify 'config' output options for specifying output colorspace.
486     // Optionally the external image decode buffer can also be specified.
487     config.output.colorspace = MODE_BGRA;
488     // Optionally, the config.output can be pointed to an external buffer as
489     // well for decoding the image. This externally supplied memory buffer
490     // should be big enough to store the decoded picture.
491     config.output.u.RGBA.rgba = (uint8_t*) memory_buffer;
492     config.output.u.RGBA.stride = scanline_stride;
493     config.output.u.RGBA.size = total_size_of_the_memory_buffer;
494     config.output.is_external_memory = 1;
495
496     // E) Decode the WebP image. There are two variants w.r.t decoding image.
497     // The first one (E.1) decodes the full image and the second one (E.2) is
498     // used to incrementally decode the image using small input buffers.
499     // Any one of these steps can be used to decode the WebP image.
500
501     // E.1) Decode full image.
502     CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK);
503
504     // E.2) Decode image incrementally.
505     WebPIDecoder* const idec = WebPIDecode(NULL, NULL, &config);
506     CHECK(idec != NULL);
507     while (bytes_remaining > 0) {
508       VP8StatusCode status = WebPIAppend(idec, input, bytes_read);
509       if (status == VP8_STATUS_OK || status == VP8_STATUS_SUSPENDED) {
510         bytes_remaining -= bytes_read;
511       } else {
512         break;
513       }
514     }
515     WebPIDelete(idec);
516
517     // F) Decoded image is now in config.output (and config.output.u.RGBA).
518     // It can be saved, displayed or otherwise processed.
519
520     // G) Reclaim memory allocated in config's object. It's safe to call
521     // this function even if the memory is external and wasn't allocated
522     // by WebPDecode().
523     WebPFreeDecBuffer(&config.output);
524
525-------------------------------------- END PSEUDO EXAMPLE
526
527Bugs:
528=====
529
530Please report all bugs to our issue tracker:
531    http://code.google.com/p/webp/issues
532Patches welcome! See this page to get started:
533    http://www.webmproject.org/code/contribute/submitting-patches/
534
535Discuss:
536========
537
538Email: webp-discuss@webmproject.org
539Web: http://groups.google.com/a/webmproject.org/group/webp-discuss
540

README.android

1URL: http://review.webmproject.org/gitweb?p=libwebp.git
2Version: 43/1443/1
3License: Google BSD like
4
5Local modifications:
6- Rewrite Android.mk to remove duplicate definitions and set module name
7  in a consistent way with other external libraries
8- Move public headers from src/webp to include/webp, so path to headers
9  may be appended into CFLAGS without risk for other private headers
10  (e.g. bits.h) to leak into
11- Sync-patch with libwebp ver 0.1.2
12- Removed Build files necessary for building via autoconf/automake tools
13  These files are not required to build via Android.mk
14  - Makefile.am  Makefile.vc Makefile.in
15  - config.h.in configure config.guess config.sub configure.ac
16  - autogen.sh install-sh missing depcomp ltmain.sh aclocal.m4
17- Added WebP Encoder (ver 0.1.2) as well
18  - Removed some more unused Makefile.am & Makefile.in
19  - Added Android.mk to encoder & decoder code levels.
20- Synced the WebP Code (Encoder/Decoder) with the head change#Ia53f845b
21  - Added three color-spaces viz ARGB_8888, RGBA_4444, RGB_565
22    supported by Android.
23- Fixed the Endian'ness bug for Color-Configs (RGB_565 & ARGB_4444).
24  The fix is similar to jpeglib handling for JCS_RGB_565 & JCS_RGBA_8888
25  color configs. Added the code under "ANDROID_WEBP_RGB" flag.
26- Sync-patch with libwebp ver 0.2.0 (head change#I3da2063b).
27
28The Android.mk file creates WebP Decoder and Encoder static libraries which
29can be added to any application by Adding to LOCAL_STATIC_LIBRARIES
30libwebp-decode libwebp-encode:
31
32  LOCAL_STATIC_LIBRARIES += libwebp-decode libwebp-encode
33
34