3 Although you may be viewing an alternate representation, this document
4 is sourced in Markdown, a light-duty markup scheme, and is optimized for
5 the [kramdown](http://kramdown.rubyforge.org/) transformer.
7 See the accompanying README. External link targets are referenced at the
13 WebP Container Specification
14 ============================
23 WebP is an image format that uses either (i) the VP8 key frame encoding
24 to compress image data in a lossy way, or (ii) the WebP lossless encoding
25 (and possibly other encodings in the future). These encoding schemes should
26 make it more efficient than currently used formats. It is optimized for fast
27 image transfer over the network (e.g., for websites). The WebP format has
28 feature parity (color profile, metadata, animation etc) with other formats as
29 well. This document describes the structure of a WebP file.
31 The WebP container (i.e., RIFF container for WebP) allows feature support over
32 and above the basic use case of WebP (i.e., a file containing a single image
33 encoded as a VP8 key frame). The WebP container provides additional support
36 * **Lossless compression.** An image can be losslessly compressed, using the
39 * **Metadata.** An image may have metadata stored in EXIF or XMP formats.
41 * **Transparency.** An image may have transparency, i.e., an alpha channel.
43 * **Color Profile.** An image may have an embedded ICC profile as described
44 by the [International Color Consortium][iccspec].
46 * **Animation.** An image may have multiple frames with pauses between them,
47 making it an animation.
49 * **Image Fragmentation.** A single bitstream in WebP has an inherent
50 limitation for width or height of 2^14 pixels, and, when using VP8, a 512
51 KiB limit on the size of the first compressed partition. To support larger
52 images, the format supports images that are composed of multiple fragments,
53 each encoded as a separate bitstream. All fragments logically form a single
54 image: they have common metadata, color profile, etc. Image fragmentation
55 may also improve efficiency for larger images, e.g., grass can be encoded
58 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
59 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
60 document are to be interpreted as described in [RFC 2119][].
62 **Note:** Out of the features mentioned above, lossy compression, lossless
63 compression, transparency, metadata, color profile and animation are finalized
64 and are to be considered stable. On the other hand, image fragmentation is
65 experimental as of now, and is open to discussion, feedback and comments.
66 The same is indicated using annotation "_status: experimental_" in the relevant
67 sections of this document.
69 Terminology & Basics
70 ------------------------
72 A WebP file contains either a still image (i.e., an encoded matrix of pixels)
73 or an [animation](#animation). Optionally, it can also contain transparency
74 information, color profile and metadata. In case we need to refer only to the
75 matrix of pixels, we will call it the _canvas_ of the image.
77 Below are additional terms used throughout this document:
81 : Code that reads WebP files is referred to as a _reader_, while code that
82 writes them is referred to as a _writer_.
86 : A 16-bit, little-endian, unsigned integer.
90 : A 24-bit, little-endian, unsigned integer.
94 : A 32-bit, little-endian, unsigned integer.
98 : A _FourCC_ (four-character code) is a _uint32_ created by concatenating four
99 ASCII characters in little-endian order.
103 : An unsigned integer field storing values offset by `-1`. e.g., Such a field
104 would store value _25_ as _24_.
108 The WebP file format is based on the RIFF (resource interchange file format)
111 The basic element of a RIFF file is a _chunk_. It consists of:
114 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
115 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123 Chunk FourCC: 32 bits
125 : ASCII four-character code used for chunk identification.
127 Chunk Size: 32 bits (_uint32_)
129 : The size of the chunk not including this field, the chunk identifier or
132 Chunk Payload: _Chunk Size_ bytes
134 : The data payload. If _Chunk Size_ is odd, a single padding byte -- that
135 SHOULD be `0` -- is added.
137 _ChunkHeader('ABCD')_
139 : This is used to describe the _FourCC_ and _Chunk Size_ header of individual
140 chunks, where 'ABCD' is the FourCC for the chunk. This element's
143 **Note:** RIFF has a convention that all-uppercase chunk FourCCs are standard
144 chunks that apply to any RIFF file format, while FourCCs specific to a file
145 format are all lowercase. WebP does not follow this convention.
151 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
152 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 | 'R' | 'I' | 'F' | 'F' |
154 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
156 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
157 | 'W' | 'E' | 'B' | 'P' |
158 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
162 : The ASCII characters 'R' 'I' 'F' 'F'.
164 File Size: 32 bits (_uint32_)
166 : The size of the file in bytes starting at offset 8. The maximum value of
167 this field is 2^32 minus 10 bytes and thus the size of the whole file is at
168 most 4GiB minus 2 bytes.
172 : The ASCII characters 'W' 'E' 'B' 'P'.
174 A WebP file MUST begin with a RIFF header with the FourCC 'WEBP'. The file size
175 in the header is the total size of the chunks that follow plus `4` bytes for
176 the 'WEBP' FourCC. The file SHOULD NOT contain anything after it. As the size
177 of any chunk is even, the size given by the RIFF header is also even. The
178 contents of individual chunks will be described in the following sections.
180 Simple file format (lossy)
181 --------------------------
183 This layout SHOULD be used if the image requires _lossy_ encoding and does not
184 require transparency or other advanced features provided by the extended format.
185 Files with this layout are smaller and supported by older software.
187 Simple WebP (lossy) file format:
190 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
191 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192 | WebP file header (12 bytes) |
193 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
195 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
201 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202 | ChunkHeader('VP8 ') |
203 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
205 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
207 VP8 data: _Chunk Size_ bytes
209 : VP8 bitstream data.
211 The VP8 bitstream format specification can be found at [VP8 Data Format and
212 Decoding Guide][vp8spec]. Note that the VP8 frame header contains the VP8 frame
213 width and height. That is assumed to be the width and height of the canvas.
215 The VP8 specification describes how to decode the image into Y'CbCr
216 format. To convert to RGB, Rec. 601 SHOULD be used.
218 Simple file format (lossless)
219 -----------------------------
221 **Note:** Older readers may not support files using the lossless format.
223 This layout SHOULD be used if the image requires _lossless_ encoding (with an
224 optional transparency channel) and does not require advanced features provided
225 by the extended format.
227 Simple WebP (lossless) file format:
230 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
231 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
232 | WebP file header (12 bytes) |
233 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
241 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 | ChunkHeader('VP8L') |
243 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
245 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
247 VP8L data: _Chunk Size_ bytes
249 : VP8L bitstream data.
251 The current specification of the VP8L bitstream can be found at
252 [WebP Lossless Bitstream Format][webpllspec]. Note that the VP8L header
253 contains the VP8L image width and height. That is assumed to be the width
254 and height of the canvas.
259 **Note:** Older readers may not support files using the extended format.
261 An extended format file consists of:
263 * A 'VP8X' chunk with information about features used in the file.
265 * An optional 'ICCP' chunk with color profile.
267 * An optional 'ANIM' chunk with animation control data.
271 * An optional 'EXIF' chunk with EXIF metadata.
273 * An optional 'XMP ' chunk with XMP metadata.
275 * An optional list of [unknown chunks](#unknown-chunks). _\[status: experimental\]_
277 For a _still image_, the _image data_ consists of a single frame, whereas for
278 an _animated image_, it consists of multiple frames. More details about frames
279 can be found in the [Animation](#animation) section.
281 Moreover, each frame can be fragmented or non-fragmented, as will be described
282 in the [Extended WebP file header](#extended_header) section. More details about
283 fragments can be found in the [Fragments](#fragments) section.
285 All chunks SHOULD be placed in the same order as listed above. If a chunk
286 appears in the wrong place, the file is invalid, but readers MAY parse the
287 file, ignoring the chunks that come too late.
289 **Rationale:** Setting the order of chunks should allow quicker file
290 parsing. For example, if an 'ALPH' chunk does not appear in its required
291 position, a decoder can choose to stop searching for it. The rule of
292 ignoring late chunks should make programs that need to do a full search
293 give the same results as the ones stopping early.
295 Extended WebP file header:
299 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
300 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
301 | WebP file header (12 bytes) |
302 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
303 | ChunkHeader('VP8X') |
304 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
305 |Rsv|I|L|E|X|A|F| Reserved |
306 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
307 | Canvas Width Minus One | ...
308 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
309 ... Canvas Height Minus One |
310 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312 Reserved (Rsv): 2 bits
316 ICC profile (I): 1 bit
318 : Set if the file contains an ICC profile.
322 : Set if any of the frames of the image contain transparency information
325 EXIF metadata (E): 1 bit
327 : Set if the file contains EXIF metadata.
329 XMP metadata (X): 1 bit
331 : Set if the file contains XMP metadata.
335 : Set if this is an animated image. Data in 'ANIM' and 'ANMF' chunks should be
336 used to control the animation.
338 Image Fragmentation (F): 1 bit _\[status: experimental\]_
340 : Set if any of the frames in the image are represented by fragments.
346 Canvas Width Minus One: 24 bits
348 : _1-based_ width of the canvas in pixels.
349 The actual canvas width is '1 + Canvas Width Minus One'
351 Canvas Height Minus One: 24 bits
353 : _1-based_ height of the canvas in pixels.
354 The actual canvas height is '1 + Canvas Height Minus One'
356 The product of _Canvas Width_ and _Canvas Height_ MUST be at most `2^32 - 1`.
358 Future specifications MAY add more fields.
364 An animation is controlled by ANIM and ANMF chunks.
369 For an animated image, this chunk contains the _global parameters_ of the
373 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
374 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
375 | ChunkHeader('ANIM') |
376 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
378 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
380 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
382 Background Color: 32 bits (_uint32_)
384 : The default background color of the canvas in \[Blue, Green, Red, Alpha\]
385 byte order. This color is used to fill the unused space on the canvas around the
386 frames, as well as the transparent pixels of the first frame. Background color
387 is also used when disposal method is `1`.
389 **Note**: Viewers that have a preferred background against which to present the
390 images (web browsers, for example) should ignore this value and use their
391 preferred background color instead.
393 Loop Count: 16 bits (_uint16_)
395 : The number of times to loop the animation. `0` means infinitely.
397 This chunk MUST appear if the _Animation_ flag in the VP8X chunk is set.
398 If the _Animation_ flag is not set and this chunk is present, it
404 For animated images, this chunk contains information about a _single_ frame.
405 If the _Animation flag_ is not set, then this chunk SHOULD NOT be present.
408 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
409 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
410 | ChunkHeader('ANMF') |
411 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
413 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
414 ... Frame Y | Frame Width Minus One ...
415 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
416 ... | Frame Height Minus One |
417 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
418 | Frame Duration | Reserved |D|
419 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
421 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
423 Frame X: 24 bits (_uint24_)
425 : The X coordinate of the upper left corner of the frame is `Frame X * 2`
427 Frame Y: 24 bits (_uint24_)
429 : The Y coordinate of the upper left corner of the frame is `Frame Y * 2`
431 Frame Width Minus One: 24 bits (_uint24_)
433 : The _1-based_ width of the frame.
434 The frame width is `1 + Frame Width Minus One`
436 Frame Height Minus One: 24 bits (_uint24_)
438 : The _1-based_ height of the frame.
439 The frame height is `1 + Frame Height Minus One`
441 Frame Duration: 24 bits (_uint24_)
443 : The time to wait before displaying the next frame, in 1 millisecond units.
444 In particular, frame duration of 0 is useful when one wants to update multiple
445 areas of the canvas at once during the animation.
451 Disposal method (D): 1 bit
453 : Indicates how _the current frame_ is to be treated after it has been displayed
454 (before rendering the next frame) on the canvas:
456 * `0`: Do not dispose. Leave the canvas as is.
458 * `1`: Dispose to background color. Fill the _rectangle_ on the canvas covered
459 by the _current frame_ with background color specified in the
460 [ANIM chunk](#anim_chunk).
462 After disposing the current frame, render the next frame on the canvas using
463 [alpha-blending](#alpha-blending). If the next frame does not have an alpha
464 channel, assume alpha value of 255, effectively replacing the rectangle.
468 * The frame disposal only applies to the _frame rectangle_, that is, the
469 rectangle defined by _Frame X_, _Frame Y_, _frame width_ and _frame height_.
470 It may or may not cover the whole canvas.
473 * **Alpha-blending**:
475 Given that each of the R, G, B and A channels is 8-bit, and the RGB
476 channels are _not premultiplied_ by alpha, the formula for blending
480 blend.A = src.A + dst.A * (1 - src.A / 255)
484 blend.RGB = (src.RGB * src.A +
485 dst.RGB * dst.A * (1 - src.A / 255)) / blend.A
488 * Alpha-blending SHOULD be done in linear color space, by taking into account
489 the [color profile](#color-profile) of the image. If the color profile is
490 not present, sRGB is to be assumed. (Note that sRGB also needs to be
491 linearized due to a gamma of ~2.2).
493 Frame Data: _Chunk Size_ - `16` bytes
495 : For a fragmented frame, it consists of multiple [fragment chunks](#fragments).
497 : For a non-fragmented frame, it consists of:
499 * An optional [alpha subchunk](#alpha) for the frame.
501 * A [bitstream subchunk](#bitstream-vp8vp8l) for the frame.
503 * An optional list of [unknown chunks](#unknown-chunks).
505 **Note**: The 'ANMF' payload, _Frame Data_ above, consists of individual
506 _padded_ chunks as described by the [RIFF file format](#riff-file-format).
508 #### Fragments _\[status: experimental\]_
510 For images that are represented by fragments, this chunk contains data for
511 a single fragment. If the _Image Fragmentation Flag_ is not set, then this chunk
512 SHOULD NOT be present.
515 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
516 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
517 | ChunkHeader('FRGM') |
518 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
521 ... Fragment Y | Fragment Data |
522 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
524 Fragment X: 24 bits (_uint24_)
526 : The X coordinate of the upper left corner of the fragment is `Fragment X * 2`
528 Fragment Y: 24 bits (_uint24_)
530 : The Y coordinate of the upper left corner of the fragment is `Fragment Y * 2`
532 Fragment Data: _Chunk Size_ - `6` bytes
536 * An optional [alpha subchunk](#alpha) for the fragment.
537 * The [bitstream subchunk](#bitstream-vp8vp8l) for the fragment.
538 * An optional list of [unknown chunks](#unknown-chunks).
540 Note: The width and height of the fragment is obtained from the bitstream
543 The fragments of a frame SHOULD have the following properties:
545 * They collectively cover the whole frame.
547 * No pair of fragments have any overlapping region on the frame.
549 * No portion of any fragment should be located outside of the canvas.
554 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
555 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
556 | ChunkHeader('ALPH') |
557 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
558 |Rsv| P | F | C | Alpha Bitstream... |
559 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
561 Reserved (Rsv): 2 bits
565 Pre-processing (P): 2 bits
567 : These INFORMATIVE bits are used to signal the pre-processing that has
568 been performed during compression. The decoder can use this information to
569 e.g. dither the values or smooth the gradients prior to display.
571 * `0`: no pre-processing
572 * `1`: level reduction
574 Filtering method (F): 2 bits
576 : The filtering method used:
579 * `1`: Horizontal filter.
580 * `2`: Vertical filter.
581 * `3`: Gradient filter.
583 For each pixel, filtering is performed using the following calculations.
584 Assume the alpha values surrounding the current `X` position are labeled as:
590 We seek to compute the alpha value at position `X`. First, a prediction is
591 made depending on the filtering method:
593 * Method `0`: predictor = 0
594 * Method `1`: predictor = A
595 * Method `2`: predictor = B
596 * Method `3`: predictor = clip(A + B - C)
598 where `clip(v)` is equal to:
604 The final value is derived by adding the decompressed value `X` to the
605 predictor and using modulo-256 arithmetic to wrap the \[256-511\] range
606 into the \[0-255\] one:
608 `alpha = (predictor + X) % 256`
610 There are special cases for left-most and top-most pixel positions:
612 * Top-left value at location (0,0) uses 0 as predictor value. Otherwise,
613 * For horizontal or gradient filtering methods, the left-most pixels at
614 location (0, y) are predicted using the location (0, y-1) just above.
615 * For vertical or gradient filtering methods, the top-most pixels at
616 location (x, 0) are predicted using the location (x-1, 0) on the left.
619 Decoders are not required to use this information in any specified way.
621 Compression method (C): 2 bits
623 : The compression method used:
625 * `0`: No compression.
626 * `1`: Compressed using the WebP lossless format.
628 Alpha bitstream: _Chunk Size_ - `1` bytes
630 : Encoded alpha bitstream.
632 This optional chunk contains encoded alpha data for this frame/fragment. A
633 frame/fragment containing a 'VP8L' chunk SHOULD NOT contain this chunk.
635 **Rationale**: The transparency information is already part of the 'VP8L'
638 The alpha channel data is stored as uncompressed raw data (when
639 compression method is '0') or compressed using the lossless format
640 (when the compression method is '1').
642 * Raw data: consists of a byte sequence of length width * height,
643 containing all the 8-bit transparency values in scan order.
645 * Lossless format compression: the byte sequence is a compressed
646 image-stream (as described in the [WebP Lossless Bitstream Format]
647 [webpllspec]) of implicit dimension width x height. That is, this
648 image-stream does NOT contain any headers describing the image dimension.
650 **Rationale**: the dimension is already known from other sources,
651 so storing it again would be redundant and error-prone.
653 Once the image-stream is decoded into ARGB color values, following
654 the process described in the lossless format specification, the
655 transparency information must be extracted from the *green* channel
656 of the ARGB quadruplet.
658 **Rationale**: the green channel is allowed extra transformation
659 steps in the specification -- unlike the other channels -- that can
662 #### Bitstream (VP8/VP8L)
664 This chunk contains compressed bitstream data for a single frame/fragment.
666 A bitstream chunk may be either (i) a VP8 chunk, using "VP8 " (note the
667 significant fourth-character space) as its tag _or_ (ii) a VP8L chunk, using
670 The formats of VP8 and VP8L chunks are as described in sections
671 [Simple file format (lossy)](#simple-file-format-lossy)
672 and [Simple file format (lossless)](#simple-file-format-lossless) respectively.
677 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
678 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
679 | ChunkHeader('ICCP') |
680 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
682 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
684 Color Profile: _Chunk Size_ bytes
688 This chunk MUST appear before the image data.
690 There SHOULD be at most one such chunk. If there are more such chunks, readers
691 MAY ignore all except the first one.
692 See the [ICC Specification][iccspec] for details.
694 If this chunk is not present, sRGB SHOULD be assumed.
698 Metadata can be stored in 'EXIF' or 'XMP ' chunks.
700 There SHOULD be at most one chunk of each type ('EXIF' and 'XMP '). If there
701 are more such chunks, readers MAY ignore all except the first one. Also, a file
702 may possibly contain both 'EXIF' and 'XMP ' chunks.
704 The chunks are defined as follows:
709 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
710 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
711 | ChunkHeader('EXIF') |
712 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
714 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
716 EXIF Metadata: _Chunk Size_ bytes
718 : image metadata in EXIF format.
724 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
725 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
726 | ChunkHeader('XMP ') |
727 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
729 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
731 XMP Metadata: _Chunk Size_ bytes
733 : image metadata in XMP format.
735 Additional guidance about handling metadata can be found in the
736 Metadata Working Group's [Guidelines for Handling Metadata][metadata].
738 #### Unknown Chunks _\[status: experimental\]_
740 A RIFF chunk (described in [this](#terminology-amp-basics) section) whose _chunk
741 tag_ is different from any of the chunks described in this document, is
742 considered an _unknown chunk_.
744 **Rationale**: Allowing unknown chunks gives a provision for future extension
745 of the format, and also allows storage of any application-specific data.
747 A file MAY contain unknown chunks:
749 * At the end of the file as described in [Extended WebP file
750 header](#extended_header) section.
751 * At the end of FRGM and ANMF chunks as described in [Fragments](#fragments)
752 and [Animation](#animation) sections.
754 Readers SHOULD ignore these chunks. Writers SHOULD preserve them in their
755 original order (unless they specifically intend to modify these chunks).
757 ### Assembling the Canvas from fragments/frames
759 Here we provide an overview of how a reader should assemble a canvas in case
760 of a fragmented-image and in case of an animated image. The notation
761 _VP8X.field_ means the field in the 'VP8X' chunk with the same description.
763 Displaying a _fragmented image_ canvas MUST be equivalent to the following
764 pseudocode: _\[status: experimental\]_
766 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
767 assert VP8X.flags.hasFragments
768 canvas ← new black image of size VP8X.canvasWidth x VP8X.canvasHeight.
770 for chunk in image_data:
771 assert chunk.tag is "FRGM"
772 frgm_params.fragmentX = Fragment X
773 frgm_params.fragmentY = Fragment Y
774 for subchunk in 'Fragment Data':
775 if subchunk.tag == "ALPH":
776 assert alpha subchunks not found in 'Fragment Data' earlier
777 frgm_params.alpha = alpha_data
778 else if subchunk.tag == "VP8 " OR subchunk.tag == "VP8L":
779 assert bitstream subchunks not found in 'Fragment Data' earlier
780 frgm_params.bitstream = bitstream_data
781 frgm_params.fragmentWidth = Width extracted from bitstream subchunk
782 frgm_params.fragmentHeight = Height extracted from bitstream subchunk
783 assert VP8X.canvasWidth >=
784 frgm_params.fragmentX + frgm_params.fragmentWidth
785 assert VP8X.canvasHeight >=
786 frgm_params.fragmentY + frgm_params.fragmentHeight
787 assert fragment has the properties mentioned in "Image Fragments" section.
788 render fragment with frame_params.alpha and frame_params.bitstream on canvas
789 with top-left corner in (frgm_params.fragmentX, frgm_params.fragmentY).
790 canvas contains the decoded canvas.
791 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
793 Displaying an _animated image_ canvas MUST be equivalent to the following
796 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
797 assert VP8X.flags.hasAnimation
798 canvas ← new image of size VP8X.canvasWidth x VP8X.canvasHeight with
799 background color ANIM.background_color.
800 loop_count ← ANIM.loopCount
801 dispose_method ← ANIM.disposeMethod
805 for loop = 0, ..., loop_count - 1
806 assert next chunk in image_data is ANMF
807 frame_params.frameX = Frame X
808 frame_params.frameY = Frame Y
809 frame_params.frameWidth = Frame Width Minus One + 1
810 frame_params.frameHeight = Frame Height Minus One + 1
811 frame_params.frameDuration = Frame Duration
812 assert VP8X.canvasWidth >= frame_params.frameX + frame_params.frameWidth
813 assert VP8X.canvasHeight >= frame_params.frameY + frame_params.frameHeight
814 if VP8X.flags.hasFragments and first subchunk in 'Frame Data' is FRGM
816 frame_params.{bitstream,alpha} = canvas decoded from subchunks in
817 'Frame Data' as per the pseudocode for
818 _fragmented image_ above.
820 // Non-fragmented frame.
821 for subchunk in 'Frame Data':
822 if subchunk.tag == "ALPH":
823 assert alpha subchunks not found in 'Frame Data' earlier
824 frame_params.alpha = alpha_data
825 else if subchunk.tag == "VP8 " OR subchunk.tag == "VP8L":
826 assert bitstream subchunks not found in 'Frame Data' earlier
827 frame_params.bitstream = bitstream_data
828 render frame with frame_params.alpha and frame_params.bitstream on canvas
829 with top-left corner in (frame_params.frameX, frame_params.frameY), using
830 dispose method dispose_method.
831 Show the contents of the image for frame_params.frameDuration * 1ms.
832 canvas contains the decoded canvas.
833 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
838 A lossy encoded image with alpha may look as follows:
840 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
842 +- VP8X (descriptions of features used)
843 +- ALPH (alpha bitstream)
845 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
847 A losslessly encoded image may look as follows:
849 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
851 +- VP8X (descriptions of features used)
852 +- XYZW (unknown chunk)
853 +- VP8L (lossless bitstream)
854 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
856 A lossless image with ICC profile and XMP metadata may
859 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
861 +- VP8X (descriptions of features used)
862 +- ICCP (color profile)
863 +- VP8L (lossless bitstream)
865 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
867 A fragmented image may look as follows:
869 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
871 +- VP8X (descriptions of features used)
872 +- FRGM (fragment1 parameters + data)
873 +- FRGM (fragment2 parameters + data)
874 +- FRGM (fragment3 parameters + data)
875 +- FRGM (fragment4 parameters + data)
876 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
878 An animated image with EXIF metadata may look as follows:
880 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
882 +- VP8X (descriptions of features used)
883 +- ANIM (global animation parameters)
884 +- ANMF (frame1 parameters + data)
885 +- ANMF (frame2 parameters + data)
886 +- ANMF (frame3 parameters + data)
887 +- ANMF (frame4 parameters + data)
889 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
891 [vp8spec]: http://tools.ietf.org/html/rfc6386
892 [webpllspec]: https://gerrit.chromium.org/gerrit/gitweb?p=webm/libwebp.git;a=blob;f=doc/webp-lossless-bitstream-spec.txt;hb=master
893 [iccspec]: http://www.color.org/icc_specs2.xalter
894 [metadata]: http://www.metadataworkinggroup.org/pdf/mwg_guidance.pdf
895 [rfc 2119]: http://tools.ietf.org/html/rfc2119