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