User:Orlando/XINTRA8 Decoding: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 85: Line 85:
*** Read the differential rank order, which happens to be also the rank order index.
*** 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.
*** The predicted extrapolation mode is taken from the Rank Order table for the known meta-direction.
=== Reading Differential Rank Order/Rank Order Index ===
There are two different set of orientation tables, depending
if Low bitrate or High bitrate is selected.
There are two VLC tables for low bitrate and four VLC tables for high bitrate,
the encoder will transmit just once the table index for the current mode.
* For Low bitrate, read 1 bit for table index.
* For High bitrate, read 2 bits for table index.
Read the differential rank order/rank order index using the selected
VLC table.


=== Predict minimum number of AC Coefficients ===
=== Predict minimum number of AC Coefficients ===
Line 100: Line 114:
Exemplary prediction pattern:
Exemplary prediction pattern:


    0 1 2 3 4 5 6 7 8 9 A B C D E F  
  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
  1: - X - X - X - X - X - X - X - X
  2 - 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
  3: - X X X - X X X - X X X - X X X
  4 - - - 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
  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
  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
  7: - X X X X X X X - X X X X X X X
  8 - - - - - - - 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
  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
  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
  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
  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
  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
  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
  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.
X means the minimum of the three neighbor's values is taken.

Revision as of 10:34, 2 November 2009

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.

Reading Differential Rank Order/Rank Order Index

There are two different set of orientation tables, depending if Low bitrate or High bitrate is selected.

There are two VLC tables for low bitrate and four VLC tables for high bitrate, the encoder will transmit just once the table index for the current mode.

  • For Low bitrate, read 1 bit for table index.
  • For High bitrate, read 2 bits for table index.

Read the differential rank order/rank order index using the selected VLC table.

Predict 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 sierpinski pattern.

Exemplary prediction pattern:

  1 2 3 4 5 6 7 8 9 A B C D E F 
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 Level

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.

Reading AC Level

Like the case for DC level, there are four different modes to read AC coefficients, and there are two submodes, one for Low bitrate and one for High bitrate. There are in total eight modes, and in turn each of this mode use 8 different VLC tables.

The mode selection depends on the Differential Rank Order and the predicted minimum number of AC coefficients.

The modes are:

0 - INTER0  - Luma, differential rank order > 4
1 - INTRAY  - Luma, differential rank order <= 4
              The symbol count is LESS than the predicted AC coefficient count.
2 - INTRAY0 - Luma, differential rank order <= 4
              The symbol count is GREATER or EQUAL to the predicted AC coefficient count.
3 - INTER   - Chroma

Although there are four modes, only two tables are used, INTER0 and INTER share the same tables, so INTRAY and INTRAY0.

The encoder will transmit just once the table index for the current mode. The table index is 3 bits long, like the DC level case.

Once you read the VLC code, there are four different modes to read the AC level, the code itself determines the mode:

  • Mode 0 (Code Range: 0 - 45)
    If code > 22, signals there are no more AC coefficients following, subtract 23 to obtain the correct index.
   index < 16  | run= index    level=0
   index < 20  | run= index-16 level=1
   index < 22  | run= index-20 level=2
   index == 22 | run= index-22 level=3
  • Mode 1 (Code Range: 46 - 72)
    If code > 58, signals there are no more AC coefficients following, subtract 59 to obtain the correct index.
    • Use the index in a specific run/level table. TBD
  • Mode 2 (Code Range: 73 - 74)
    Code 74 signals there are no more AC coefficients.
    • Read 5 bits index from the bitstream.
    • Use the read index in another specific run/level table. TBD
  • Mode 3 (Code >= 75)
    If the code is odd, there are 4 bits per level, otherwise 7 bits are used.
    • Read 4 or 7 level bits.
    • Read 6 run bits.
    • Read 1 bit which signals if there are no more AC coefficients.

After reading the run/level, read 1 bit from the bitstream for the sign.

Perform dequantization of the AC level as follow:

  ac_level = quant_offset + (ac_level + 1) * 2 * luma_qp;
  if (sign) ac_level = -ac_level;