From 44a09a3ccd82bd6fb3c68b6737d9d54715445f60 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Tue, 10 Jul 2012 19:50:30 -0700 Subject: [PATCH] add missing description of the alpha filtering methods Change-Id: Id7bdf5e30121ce5d610b7fa00f64bcd2d7bed2bf --- doc/webp-container-spec.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doc/webp-container-spec.txt b/doc/webp-container-spec.txt index 187616a9..6bf560ca 100644 --- a/doc/webp-container-spec.txt +++ b/doc/webp-container-spec.txt @@ -523,6 +523,42 @@ Filtering method (F): 2 bits * `2`: Vertical filter. * `3`: Gradient filter. +For each pixel, filtering is performed using the following calculations. +Assume the alpha values surrounding the current `X` position are labeled as: + + C | B | + ---+---+ + A | X | + +We seek to compute the alpha value at position `X`. First, a prediction is +made depending on the filtering method: + + * Method `0`: predictor = 0 + * Method `1`: predictor = A + * Method `2`: predictor = B + * Method `3`: predictor = clip(A + B - C) + +where `clip(v)` is equal to: + + * 0 if v < 0 + * 255 if v > 255 + * v otherwise + +The final value is derived by adding the decompressed value `X` to the +predictor and using modulo-256 arithmetic to wrap the [256-511] range +into the [0-255] one: + +`alpha = (predictor + X) % 256` + +There are special cases for left-most and top-most pixel positions: + + * Top-left value at location (0,0) uses 0 as predictor value. Otherwise, + * For horizontal or gradient filtering methods, the left-most pixels at + location (0, y) are predicted using the location (0, y-1) just above. + * For vertical or gradient filtering methods, the top-most pixels at + location (x, 0) are predicted using the location (x-1, 0) on the left. + + Pre-processing (P): 2 bits : These INFORMATIVE bits are used to signal the pre-processing that has