mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 02:15:42 +01:00 
			
		
		
		
	Container spec: Clarify frame disposal
- Add a note that disposal only applies to the frame rectangle - Add the formula for alpha-blending. - Note that alpha-blending would occur for the common rectangle - Also note the case when both color profile and disposal are present. Change-Id: I214787dd64453edf3b0cdaff3951015281a32ee4
This commit is contained in:
		| @@ -450,15 +450,45 @@ Reserved: 7 bits | |||||||
|  |  | ||||||
| Disposal method (D): 1 bit | Disposal method (D): 1 bit | ||||||
|  |  | ||||||
| : Indicates how the area used by this frame is to be treated before rendering | : Indicates how _the current frame_ is to be treated after it has been displayed | ||||||
| the next frame on canvas: | (before rendering the next frame) on the canvas: | ||||||
|  |  | ||||||
|   * `0`: Do not dispose. Keep the area used by this frame as it is and render |   * `0`: Do not dispose. Leave the canvas as is. | ||||||
|     the next frame on top of it. |  | ||||||
|  |  | ||||||
|   * `1`: Dispose to background color. Restore the area used by this frame to |   * `1`: Dispose to background color. Fill the _rectangle_ on the canvas covered | ||||||
|     background color before rendering the next frame. The background color is |     by the _current frame_ with background color specified in the | ||||||
|     part of the [ANIM chunk](#anim_chunk). |     [ANIM chunk](#anim_chunk). | ||||||
|  |  | ||||||
|  | After disposing the current frame, render the next frame on the canvas using | ||||||
|  | [alpha-blending](#alpha-blending). If the next frame does not have an alpha | ||||||
|  | channel, assume alpha value of 255, effectively replacing the rectangle. | ||||||
|  |  | ||||||
|  | **Notes**: | ||||||
|  |  | ||||||
|  |   * The frame disposal only applies to the _frame rectangle_, that is, the | ||||||
|  |     rectangle defined by _Frame X_, _Frame Y_, _frame width_ and _frame height_. | ||||||
|  |     It may or may not cover the whole canvas. | ||||||
|  |  | ||||||
|  | {:#alpha-blending} | ||||||
|  |   * **Alpha-blending**: | ||||||
|  |  | ||||||
|  |     Given that each of the R, G, B and A channels is 8-bit, and the RGB | ||||||
|  |     channels are _not premultiplied_ by alpha, the formula for blending | ||||||
|  |     'dst' onto 'src' is: | ||||||
|  |  | ||||||
|  | ~~~~~ | ||||||
|  |     blend.A = src.A + dst.A * (1 - src.A / 255) | ||||||
|  |     if blend.A = 0 then | ||||||
|  |       blend.RGB = 0 | ||||||
|  |     else | ||||||
|  |       blend.RGB = (src.RGB * src.A + | ||||||
|  |                    dst.RGB * dst.A * (1 - src.A / 255)) / blend.A | ||||||
|  | ~~~~~ | ||||||
|  |  | ||||||
|  |   * Alpha-blending SHOULD be done in linear color space, by taking into account | ||||||
|  |     the [color profile](#color-profile) of the image. If the color profile is | ||||||
|  |     not present, sRGB is to be assumed. (Note that sRGB also needs to be | ||||||
|  |     linearized due to a gamma of ~2.2). | ||||||
|  |  | ||||||
| Frame Data: _Chunk Size_ - `16` bytes | Frame Data: _Chunk Size_ - `16` bytes | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user