home :: dct_coefficients

DCT Coefficients

DCT Coefficients are encoded in one of two ways. The DC term of an intracoded macroblock are differentially encoded relative to a plane-specific (i.e., Y, U, or V) DC predictor. The predictor is reset whenever a non-intracoded macroblock is encountered. For all other terms (i.e., all AC terms and the DC term of intercoded macroblocks), the coefficient is encoded as a run/value pair using a Huffman code. The run specifies the number of zero-valued coefficients before the encoded coefficient in the zigzag pattern and the value is the quantized value of the coefficient. The coding element events that are generated by these encodings are called DiffEncodedCoeff and HuffmanEncodedCoeff. The end of block marker that indicates no more coefficients exists for a particular block is parsed and published as a special case of HuffmanEncodedCoeff.

Because coefficients may be encoded in one of two different ways (not to mention the end of block marker is parsed as a coefficient but is not actually a coefficient), a coefficient interface is defined for obtaining general information about coefficients regardless of type. This interface, called ICoeff, is implemented by both DiffEncodedCoeff and HuffmanEncodedCoeff.

The ICoeff interface specifies 6 public read-only properties which are listed below with their return types.

  • int DequantizedValue
    Returns the dequantized value of the coefficient.
  • int Value
    Returns the quantized value that was encoded.
  • int ZigPos
    Returns the index of the coefficient in the zigzag order. This will be a value in the range [0,63].
  • int RelPos
    Returns the position of the coefficient relative to the other coefficients encoded for this block. A value of 0 means that this was the first encoded coefficient. A value of 1 means that this was the second encoded coefficient, and so on. This encoding position is not necessarily related to the the zigzag position.
  • bool IsEOB
    Returns true if this coefficient is really the end of block marker. If true, then the other property values do not have meaning.
  • bool IsImplicit
    The Block coding element maintains a value for the DC term even if, as may happen in an intercoded block, it is implicitly defined via its absense. When this occurs, the coefficient is stored in the block as an instance of the ImplicitDCCoeff class which implements ICoeff but is not in the coding element event hierarchy because technically it was not actually coded. If you are accessing coefficient information through a Block object, however, you may need to differentiate between DC coefficients that were actually coded versus those that were implicitly defined. This property of the ICoeff interface allows you to do so. If the coefficient is implicit, then the ZigPos and RelPos properties have no meaning.

The Block coding element event maintains an array of all the coefficients defined for that block and provides methods and properties for getting information about those coefficients. A block object also maintains a representation for the DC coefficient regardless of whether it was implicitly defined or explicitly coded. The properties and methods of a Block object that provide this access are listed and described below:

  • ICoeff DC
    A property that returns the DC coeffient of the block. Note, this may have been implicitly defined (see discussion above where IsImplicit property of the ICoeff interface is described).
  • IEnumerator GetACEnumerator()
    A method that returns a standard C# enumeration instance that can be used to get each encoded AC coefficient in turn. The objects returned by the enumerator must be cast to ICoeff.
  • int ACCount
    A property that returns the number of non-zero AC coefficients defined for this block.
  • ICoeff GetAC(int index)
    A method that returns a specific AC coefficient. The index parameter refers to the relative order (i.e., first encoded AC coefficient, second encoded AC coefficient, etc.). Note, this is different from its index in zigzag order.
  • ICoeff[] ACArray
    A property that returns an array of all the encoded non-zero AC coefficients in relative encode order (see note about relative vs. zigzag order above).
  • ulong ZigPosMask
    A property that returns an unsigned long integer which can be used to indicate which zigzag positions are associated with defined non-zero coefficients. The least significant bit corresponds to zigzag position zero (i.e., the DC coefficient). The second least significant bit corresponds to zigzag postion 1 and so on. The bit that corresponds to the DC coefficient is only set if the DC coefficient was explicitly coded (i.e., not implicit).

permalink 2004.11.23-09:24.00