User:Orlando/XINTRA8 Decoding

From MultimediaWiki
Revision as of 09:14, 2 November 2009 by Orlando (talk | contribs)
Jump to navigation Jump to search

Reading Residual Coefficients

In order to read residual coefficients from the bitstream, you need to perform the following steps:

  • Fill Top/Left vectors
  • Predict the meta-direction
  • Predict the extrapolation mode and differential rank order
  • Predict the minimum number of AC coefficient before table switch
  • Read DC
  • Read AC coefficients
  • Update meta-direction prediction (Luma blocks only)
  • Update AC coefficient count prediction (Luma blocks only)
  • Perform dequantization of the DC
  • Eventually, perform inverse lifting

Fill Top/Left vectors

TBD

Predict Meta Direction

There are three meta-directions:

 0 - NULL 
 1 - VERTICAL
 2 - HORIZONTAL

If the block is at the top or left edge, the predicted meta-direction is known a priori.

  • If block is at (0,0), meta-direction is NULL.
  • If block is at (0,y), meta-direction is VERTICAL.
  • If block is at (x,0), meta-direction is HORIZONTAL.

Now the prediction continues depending on the block plane.

  • For Chroma blocks:
    • Get the predicted meta-direction for the Luma block at the position (x * 2, y * 2), the prediction ends.
  • For Luma blocks:
    • Get the previously predicted meta-direction from top and left blocks.
    • If the left and top meta-directions are the same, then that's the predicted meta-direction.
    • If the left meta-direction is HORIZONTAL and the top is NULL, then it's HORIZONTAL.
    • If the left meta-direction is NULL and the top is VERTICAL, then it's VERTICAL.
    • In case of horizontal continuity, where left is HORIZONTAL and top is VERTICAL, the returned prediction is HORIZONTAL which overrides VERTICAL.
    • If the left meta-direction is VERTICAL and top is HORIZONTAL:
      • For low bitrate (QP > 12), use always the top block meta-direction.
      • For high bitrate, get the previously predicted top-left block meta-direction.
        • If the top-left meta-direction is equal to the top meta-direction, then predict from left.
        • If, instead, the meta-direction is equal to the left meta-direction, then predict from top.
        • In any other case, predict from top-left.
    • In any other case, the predicted meta-direction is NULL.

Predict Extrapolation Mode and Differential Rank Order

There are 13 different extrapolation modes (or orientations if you prefer), the known ones are:

 0 - NULL
 4 - VERTICAL
 8 - HORIZONTAL
10 - BLENDED HORIZONTALLY
11 - BLENDED VERTICALLY
   - FLAT

Modes 1-3,5-7,9 are diagonals of ~22.5 degrees, while FLAT mode has no mode index associated, and is signalled when certain conditions are met.

Algorithm:

  • Initially, the predicted extrapolation mode is set to NULL, likewise the differential rank order.
  • If the pixel range is less than the QP or less than 3, consider the predicted meta-direction as NULL and if range is less than 3, the FLAT mode is signalled.
  • For Chroma blocks:
    • The meta-direction needs to be mapped to its extrapolation mode counter part.
  • For Luma blocks:
    • If the aforementioned range is smaller than 2QP:
      • If block is at the top or left edge for non-FLAT mode, extrapolation mode is predicted to NULL.
      • If the block is not at top or left edge of the picture, then HORIZONTAL meta-direction maps into BLENDED HORIZONTALLY, while for VERTICAL meta-direction maps into BLENDED VERTICALLY.
      • In any other case the meta-direction is the predicted extrapolation mode.
    • Otherwise:
      • Read the differential rank order, which happens to be also the rank order index.
      • The predicted extrapolation mode is taken from the Rank Order table for the known meta-direction.

Predicting Minimum number of AC Coefficients

For Chroma blocks the predicted value is always 16.

For Luma blocks:

  • If block is at (0,0) the predicted minimum number of AC coefficients is always 16.
  • If block is at (0,y) predict from the left neighbor block.
  • If block is at (x,0) predict from the top neighbor block.

Otherwise the prediction is computed taking the minimum of the values between the top, left and top-left neighbor blocks in a sierpinksi pattern.

Exemplary prediction pattern:

   0 1 2 3 4 5 6 7 8 9 A B C D E F 
0: - - - - - - - - - - - - - - - -
1: - X - X - X - X - X - X - X - X
2: - - X X - - X X - - X X - - X X
3: - X X X - X X X - X X X - X X X
4: - - - - X X X X - - - - X X X X
5: - X - X X X X X - X - X X X X X
6: - - X X X X X X - - X X X X X X
7: - X X X X X X X - X X X X X X X
8: - - - - - - - - X X X X X X X X
9: - X - X - X - X X X X X X X X X
A: - - X X - - X X X X X X X X X X
B: - X X X - X X X X X X X X X X X
C: - - - - X X X X X X X X X X X X
D: - X - X X X X X X X X X X X X X
E: - - X X X X X X X X X X X X X X
F: - X X X X X X X X X X X X X X X

X means the minimum of the three neighbor's values is taken.

- means the minimum of only the top and left neighbors is taken.

Reading DC

Once finished all the required predictions, you can perform the selection of the DC mode based on the number of the predicted AC coefficients, there are 3 DC modes:

 0 - INTRAZ  - Luma, predicted AC coefficients == 0
 1 - INTRANZ - Luma, predicted AC coefficients > 0
 2 - INTRAC0 - Chroma

Depending on the QP value, there are two more submodes, one for Low bitrate and the other for High bitrate. There are in total six different modes and each one has eight VLC tables used to read the DC level.

The encoder will transmit just once the VLC table index for the current mode. The table index is 3 bits long.

  • The DC value is read from the VLC reader.
  • Values greater than 16 signals that there are no AC coefficients encoded, subtract 17 to obtain the correct index.
  • If index is 0 then the level is zero and the function ends.
  • Get the number of DC level extra bits for the given index.
  • Set DC level to zero.
  • If there are extra bits, read them as the DC level.
  • Add the DC level bias for the given index to the DC level.
  • Read sign bit.