| |
| |
| #### 12.2 Chroma Prediction {#h-12-02} |
| |
| |
| The chroma prediction is a little simpler than the luma prediction, |
| so we treat it first. Each of the chroma modes treats U and V |
| identically; that is, the U and V prediction values are calculated in |
| parallel, using the same relative addressing and arithmetic in each |
| of the two planes. |
| |
| The modes extrapolate prediction values using the 8-pixel row "A" |
| lying immediately above the block (that is, the bottom chroma row of |
| the macroblock immediately above the current macroblock) and the |
| 8-pixel column "L" immediately to the left of the block (that is, the |
| rightmost chroma column of the macroblock immediately to the left of |
| the current macroblock). |
| |
| Vertical prediction (chroma mode `V_PRED`) simply fills each 8-pixel |
| row of the 8x8 chroma block with a copy of the "above" row (A). If |
| the current macroblock lies on the top row of the frame, all 8 of the |
| pixel values in A are assigned the value `127`. |
| |
| Similarly, horizontal prediction (`H_PRED`) fills each 8-pixel column |
| of the 8x8 chroma block with a copy of the "left" column (L). If the |
| current macroblock is in the left column of the frame, all 8 pixel |
| values in `L` are assigned the value `129`. |
| |
| DC prediction (`DC_PRED`) fills the 8x8 chroma block with a single |
| value. In the generic case of a macroblock lying below the top row |
| and right of the leftmost column of the frame, this value is the |
| average of the 16 (genuinely visible) pixels in the (union of the) |
| above row `A` and left column `L`. |
| |
| Otherwise, if the current macroblock lies on the top row of the |
| frame, the average of the 8 pixels in `L` is used; if it lies in the |
| left column of the frame, the average of the 8 pixels in `A` is used. |
| |
| Note that the averages used in these exceptional cases are not the |
| same as those that would be arrived at by using the out-of-bounds `A` |
| and `L` values defined for `V_PRED` and `H_PRED`. In the case of the |
| leftmost macroblock on the top row of the frame, the 8x8 block is |
| simply filled with the constant value `128`. |
| |
| For `DC_PRED`, apart from the exceptional case of the top-left |
| macroblock, we are averaging either 16 or 8 pixel values to get a |
| single prediction value that fills the 8x8 block. The rounding is |
| done as follows: |
| |
| |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| int sum; /* sum of 8 or 16 pixels at (at least) 16-bit precision */ |
| int shf; /* base 2 logarithm of the number of pixels (3 or 4) */ |
| |
| Pixel DCvalue = (sum + (1 << (shf-1))) >> shf; |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| {:lang="c"} |
| |
| |
| Because the summands are all valid pixels, no "clamp" is necessary in |
| the calculation of `DCvalue`. |
| |
| The remaining "True Motion" (`TM_PRED`) chroma mode gets its name from |
| an older technique of video compression used by On2 Technologies, to |
| which it bears some relation. In addition to the row "A" and column |
| "L", `TM_PRED` uses the pixel "P" above and to the left of the chroma |
| block. |
| |
| The following figure gives an example of how `TM_PRED` works: |
| |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | P | A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L0 | X00 | X01 | X02 | X03 | X04 | X05 | X06 | X07 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L1 | X10 | X11 | X12 | X13 | X14 | X15 | X16 | X17 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L2 | X20 | X21 | X22 | X23 | X24 | X25 | X26 | X27 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L3 | X30 | X31 | X32 | X33 | X34 | X35 | X36 | X37 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L4 | X40 | X41 | X42 | X43 | X44 | X45 | X46 | X47 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L5 | X50 | X51 | X52 | X53 | X54 | X55 | X56 | X57 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L6 | X60 | X61 | X62 | X63 | X64 | X65 | X66 | X67 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| | L7 | X70 | X71 | X72 | X73 | X74 | X75 | X76 | X77 | |
| |-----|-----|-----|-----|-----|-----|-----|-----|-----| |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| |
| |
| Where P, As, and Ls represent reconstructed pixel values from |
| previously coded blocks, and X00 through X77 represent predicted |
| values for the current block. `TM_PRED` uses the following equation |
| to calculate X_ij: |
| |
| X_ij = L_i + A_j - P (i, j=0, 1, 2, 3) |
| |
| The exact algorithm is as follows: |
| |
| |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| void TMpred( |
| Pixel b[8][8], /* chroma (U or V) prediction block */ |
| const Pixel A[8], /* row of already-constructed pixels |
| above block */ |
| const Pixel L[8], /* column of "" just to the left of |
| block */ |
| const Pixel P /* pixel just to the left of A and |
| above L*/ |
| ) { |
| int r = 0; /* row */ |
| do { |
| int c = 0; /* column */ |
| do { |
| b[r][c] = clamp255( L[r]+ A[c] - P); |
| } while( ++c < 8); |
| } while( ++r < 8); |
| } |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| {:lang="c"} |
| |
| |
| Note that the process could equivalently be described as propagating |
| the vertical differences between pixels in L (starting from P), using |
| the pixels from A to start each column. |
| |
| An implementation of chroma intra-prediction may be found in the |
| reference decoder file `predict.c` (Section 20.14). |
| |
| Unlike `DC_PRED`, for macroblocks on the top row or left edge, `TM_PRED` |
| does use the out-of-bounds values of `127` and `129` (respectively) |
| defined for `V_PRED` and `H_PRED`. |
| |