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