WebP is a new image format from Google, which is using its ecosystem to push for adaptation.

License and Source

You can use libwebp to work with this format; source archive is available here. libwebp has a 3-clause, BSD-like Google license, available here.

Header and Data Structure

For decoding:

#include "webp/decode.h"

Main data structure is WebPDecoderConfig, which should be initialized via API WebPInitDecoderConfig() before use.

Format and Feature Identification

The first 12 bytes of file should contain strings RIFF and WEBP.

The API WebPGetFeatures() will parse byte stream and extract image information.

Decode Code

WebPDecoderConfig config;
WebPInitDecoderConfig(&config);

// Load data stream into data array
uint8_t* data = malloc(...);
size_t length = ...;

if( WebPGetFeatures(data, length, &config.input) == VP8_STATUS_OK ) {
  // Now that stream header is parsed, access information
  // such as image dimensions:
  // config.input.width x config.input.height
}

// Code below will decode image without scaling.
config.output.width = config.input.width;
config.output.height = config.input.height;

// Don't allocate memory, decode directly into framebuffer
// in pre-multiplied BGRA format.
config.output.is_external_memory = 1; 
config.output.colorspace = MODE_bgrA;

// Address and geometry information of framebuffer
config.output.u.RGBA.rgba = ...;
config.output.u.RGBA.stride = ...;
config.output.u.RGBA.size = ...;

if (WebPDecode(data, length, &config) == VP8_STATUS_OK) {
  // Decode successful!
}

References

  • Wikipedia entry for WebP.