github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/libwebp/README (about) 1 __ __ ____ ____ ____ 2 / \\/ \/ _ \/ _ )/ _ \ 3 \ / __/ _ \ __/ 4 \__\__/\____/\_____/__/ ____ ___ 5 / _/ / \ \ / _ \/ _/ 6 / \_/ / / \ \ __/ \__ 7 \____/____/\_____/_____/____/v0.4.0 8 9 Description: 10 ============ 11 12 WebP codec: library to encode and decode images in WebP format. This package 13 contains the library that can be used in other programs to add WebP support, 14 as well as the command line tools 'cwebp' and 'dwebp'. 15 16 See http://developers.google.com/speed/webp 17 18 Latest sources are available from http://www.webmproject.org/code/ 19 20 It is released under the same license as the WebM project. 21 See http://www.webmproject.org/license/software/ or the 22 file "COPYING" file for details. An additional intellectual 23 property rights grant can be found in the file PATENTS. 24 25 Building: 26 ========= 27 28 Windows build: 29 -------------- 30 31 By running: 32 33 nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output 34 35 the directory output\release-static\(x64|x86)\bin will contain the tools 36 cwebp.exe and dwebp.exe. The directory output\release-static\(x64|x86)\lib will 37 contain the libwebp static library. 38 The target architecture (x86/x64) is detected by Makefile.vc from the Visual 39 Studio compiler (cl.exe) available in the system path. 40 41 Unix build using makefile.unix: 42 ------------------------------- 43 44 On platforms with GNU tools installed (gcc and make), running 45 46 make -f makefile.unix 47 48 will build the binaries examples/cwebp and examples/dwebp, along 49 with the static library src/libwebp.a. No system-wide installation 50 is supplied, as this is a simple alternative to the full installation 51 system based on the autoconf tools (see below). 52 Please refer to makefile.unix for additional details and customizations. 53 54 Using autoconf tools: 55 --------------------- 56 When building from git sources, you will need to run autogen.sh to generate the 57 configure script. 58 59 ./configure 60 make 61 make install 62 63 should be all you need to have the following files 64 65 /usr/local/include/webp/decode.h 66 /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 71 72 installed. 73 74 Note: A decode-only library, libwebpdecoder, is available using the 75 '--enable-libwebpdecoder' flag. The encode library is built separately and can 76 be installed independently using a minor modification in the corresponding 77 Makefile.am configure files (see comments there). See './configure --help' for 78 more options. 79 80 SWIG bindings: 81 -------------- 82 83 To generate language bindings from swig/libwebp.swig at least swig-1.3 84 (http://www.swig.org) is required. 85 86 Currently the following functions are mapped: 87 Decode: 88 WebPGetDecoderVersion 89 WebPGetInfo 90 WebPDecodeRGBA 91 WebPDecodeARGB 92 WebPDecodeBGRA 93 WebPDecodeBGR 94 WebPDecodeRGB 95 96 Encode: 97 WebPGetEncoderVersion 98 WebPEncodeRGBA 99 WebPEncodeBGRA 100 WebPEncodeRGB 101 WebPEncodeBGR 102 WebPEncodeLosslessRGBA 103 WebPEncodeLosslessBGRA 104 WebPEncodeLosslessRGB 105 WebPEncodeLosslessBGR 106 107 See swig/README for more detailed build instructions. 108 109 Java bindings: 110 111 To build the swig-generated JNI wrapper code at least JDK-1.5 (or equivalent) 112 is necessary for enum support. The output is intended to be a shared object / 113 DLL that can be loaded via System.loadLibrary("webp_jni"). 114 115 Python bindings: 116 117 To build the swig-generated Python extension code at least Python 2.6 is 118 required. Python < 2.6 may build with some minor changes to libwebp.swig or the 119 generated code, but is untested. 120 121 Encoding tool: 122 ============== 123 124 The examples/ directory contains tools for encoding (cwebp) and 125 decoding (dwebp) images. 126 127 The easiest use should look like: 128 cwebp input.png -q 80 -o output.webp 129 which will convert the input file to a WebP file using a quality factor of 80 130 on a 0->100 scale (0 being the lowest quality, 100 being the best. Default 131 value is 75). 132 You 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 134 control the amount of processing time spent trying to make the output file as 135 small as possible. 136 137 A longer list of options is available using the -longhelp command line flag: 138 139 > cwebp -longhelp 140 Usage: 141 cwebp [-preset <...>] [options] in_file [-o out_file] 142 143 If input size (-s) for an image is not specified, it is assumed to be a PNG, 144 JPEG or TIFF file. 145 options: 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) 163 -strong ................ use strong filter instead of simple (default). 164 -nostrong .............. use simple filter instead of strong. 165 -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) 170 -mt .................... use multi-threading if available 171 -low_memory ............ reduce memory usage (slower encoding) 172 -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. 181 -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. 185 -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 190 -metadata <string> ..... comma separated list of metadata to 191 copy from the input to the output if present. 192 Valid values: all, none (default), exif, icc, xmp 193 194 -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 201 Experimental Options: 202 -jpeg_like ............. Roughly match expected JPEG size. 203 -af .................... auto-adjust filter strength. 204 -pre <int> ............. pre-processing filter 205 206 207 The main options you might want to try in order to further tune the 208 visual quality are: 209 -preset 210 -sns 211 -f 212 -m 213 214 Namely: 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 230 option -strong/-nostrong will change the type of filtering. Use "-f 0" to 231 turn filtering off. 232 * '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 237 Decoding tool: 238 ============== 239 240 There is a decoding sample in examples/dwebp.c which will take 241 a .webp file and decode it to a PNG image file (amongst other formats). 242 This is simply to demonstrate the use of the API. You can verify the 243 file 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 249 The full list of options is available using -h: 250 251 > dwebp -h 252 Usage: dwebp in_file [options] [-o out_file] 253 254 Decodes the WebP image file to PNG format [Default] 255 Use 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 258 -bmp ......... save as uncompressed BMP format 259 -tiff ........ save as uncompressed TIFF format 260 -pgm ......... save the raw YUV samples as a grayscale PGM 261 file with IMC4 layout 262 -yuv ......... save the raw YUV samples in flat layout 263 264 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. 268 -nodither .... disable dithering. 269 -dither <d> .. dithering strength (in 0..100) 270 -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. 274 -incremental . use incremental decoding (useful for tests) 275 -h ....... this help message. 276 -v ....... verbose (e.g. print encoding/decoding times) 277 -noasm ....... disable all assembly optimizations. 278 279 Visualization tool: 280 =================== 281 282 There's a little self-serve visualization tool called 'vwebp' under the 283 examples/ directory. It uses OpenGL to open a simple drawing window and show 284 a decoded WebP file. It's not yet integrated in the automake build system, but 285 you can try to manually compile it using the recommendations below. 286 287 Usage: vwebp in_file [options] 288 289 Decodes the WebP image file and visualize it using OpenGL 290 Options 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. 295 -dither <int> dithering strength (0..100). Default=50. 296 -mt .......... use multi-threading. 297 -info ........ print info. 298 -h ....... this help message. 299 300 Keyboard shortcuts: 301 'c' ................ toggle use of color profile. 302 'i' ................ overlay file information. 303 'q' / 'Q' / ESC .... quit. 304 305 Building: 306 --------- 307 308 Prerequisites: 309 1) 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 317 2) (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 326 Build 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 330 331 Animated GIF conversion: 332 ======================== 333 Animated GIF files can be converted to WebP files with animation using the 334 gif2webp utility available under examples/. The files can then be viewed using 335 vwebp. 336 337 Usage: 338 gif2webp [options] gif_file -o webp_file 339 options: 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 358 Building: 359 --------- 360 With the libgif development files installed, gif2webp can be built using 361 makefile.unix: 362 $ make -f makefile.unix examples/gif2webp 363 364 or using autoconf: 365 $ ./configure --enable-everything 366 $ make 367 368 Encoding API: 369 ============= 370 371 The main encoding functions are available in the header src/webp/encode.h 372 The ready-to-use ones are: 373 size_t WebPEncodeRGB(const uint8_t* rgb, int width, int height, int stride, 374 float quality_factor, uint8_t** output); 375 size_t WebPEncodeBGR(const uint8_t* bgr, int width, int height, int stride, 376 float quality_factor, uint8_t** output); 377 size_t WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride, 378 float quality_factor, uint8_t** output); 379 size_t WebPEncodeBGRA(const uint8_t* bgra, int width, int height, int stride, 380 float quality_factor, uint8_t** output); 381 382 They will convert raw RGB samples to a WebP data. The only control supplied 383 is the quality factor. 384 385 There are some variants for using the lossless format: 386 387 size_t WebPEncodeLosslessRGB(const uint8_t* rgb, int width, int height, 388 int stride, uint8_t** output); 389 size_t WebPEncodeLosslessBGR(const uint8_t* bgr, int width, int height, 390 int stride, uint8_t** output); 391 size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, int width, int height, 392 int stride, uint8_t** output); 393 size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, int width, int height, 394 int stride, uint8_t** output); 395 396 Of course in this case, no quality factor is needed since the compression 397 occurs without loss of the input values, at the expense of larger output sizes. 398 399 Advanced encoding API: 400 ---------------------- 401 402 A more advanced API is based on the WebPConfig and WebPPicture structures. 403 404 WebPConfig contains the encoding settings and is not tied to a particular 405 picture. 406 WebPPicture contains input data, on which some WebPConfig will be used for 407 compression. 408 The 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 457 Decoding API: 458 ============= 459 460 This is mainly just one function to call: 461 462 #include "webp/decode.h" 463 uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size, 464 int* width, int* height); 465 466 Please have a look at the file src/webp/decode.h for the details. 467 There are variants for decoding in BGR/RGBA/ARGB/BGRA order, along with 468 decoding to raw Y'CbCr samples. One can also decode the image directly into a 469 pre-allocated buffer. 470 471 To 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); 474 is supplied. No decoding is involved when using it. 475 476 Incremental decoding API: 477 ========================= 478 479 In the case when data is being progressively transmitted, pictures can still 480 be incrementally decoded using a slightly more complicated API. Decoder state 481 is stored into an instance of the WebPIDecoder object. This object can be 482 created with the purpose of decoding either RGB or Y'CbCr samples. 483 For instance: 484 485 WebPDecBuffer buffer; 486 WebPInitDecBuffer(&buffer); 487 buffer.colorspace = MODE_BGR; 488 ... 489 WebPIDecoder* idec = WebPINewDecoder(&buffer); 490 491 As data is made progressively available, this incremental-decoder object 492 can be used to decode the picture further. There are two (mutually exclusive) 493 ways to pass freshly arrived data: 494 495 either by appending the fresh bytes: 496 497 WebPIAppend(idec, fresh_data, size_of_fresh_data); 498 499 or by just mentioning the new size of the transmitted data: 500 501 WebPIUpdate(idec, buffer, size_of_transmitted_buffer); 502 503 Note that 'buffer' can be modified between each call to WebPIUpdate, in 504 particular when the buffer is resized to accommodate larger data. 505 506 These functions will return the decoding status: either VP8_STATUS_SUSPENDED if 507 decoding is not finished yet or VP8_STATUS_OK when decoding is done. Any other 508 status is an error condition. 509 510 The 'idec' object must always be released (even upon an error condition) by 511 calling: WebPDelete(idec). 512 513 To retrieve partially decoded picture samples, one must use the corresponding 514 method: WebPIDecGetRGB or WebPIDecGetYUVA. 515 It will return the last displayable pixel row. 516 517 Lastly, note that decoding can also be performed into a pre-allocated pixel 518 buffer. This buffer must be passed when creating a WebPIDecoder, calling 519 WebPINewRGB() or WebPINewYUVA(). 520 521 Please have a look at the src/webp/decode.h header for further details. 522 523 Advanced Decoding API: 524 ====================== 525 526 WebP decoding supports an advanced API which provides on-the-fly cropping and 527 rescaling, something of great usefulness on memory-constrained environments like 528 mobile phones. Basically, the memory usage will scale with the output's size, 529 not the input's, when one only needs a quick preview or a zoomed in portion of 530 an 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 588 589 Bugs: 590 ===== 591 592 Please report all bugs to our issue tracker: 593 http://code.google.com/p/webp/issues 594 Patches welcome! See this page to get started: 595 http://www.webmproject.org/code/contribute/submitting-patches/ 596 597 Discuss: 598 ======== 599 600 Email: webp-discuss@webmproject.org 601 Web: http://groups.google.com/a/webmproject.org/group/webp-discuss