c/common/context.h
inline int WeightedAverageContext(const int* vals, int prev_row_delta) {
  int sum = 4 + vals[0] + (vals[-kDCTBlockSize] + vals[prev_row_delta]) * 2 +
            vals[-2 * kDCTBlockSize] + vals[prev_row_delta - kDCTBlockSize] +
            vals[prev_row_delta + kDCTBlockSize];
  if ((sum >> (kMaxAverageContext + 2)) != 0) {
    return kMaxAverageContext;
  }
  return Log2FloorNonZero(sum) - 2;
}
/**
 * Calculates the context on the base of average of already decoded
 * neighbour values.
 *
 * It is considered that vals[0] represents the value 2 rows above the current,
 * while the (locally) previous elements represent the current row. If y < 2,
 * then vals[0] should be 0.
 * Elements (locally) around vals[prev_row_delta] correspond to the row above
 * currnent one.
 *
 * Values are summed up with the following weights:
 *
 * 0|0|1|0
 * -+-+-+-
 * 0|1|2|1
 * -+-+-+-
 * 1|2|*|
 *     ^
 *     current position
 *
 * This method should not be invoked on the 0-th row or 0-th column.
 * It is also considered, that there are 2 extra fence columns before the 0-th
 * column and 1 fence column to the right of the last column,
 * all initialized with zeroes.
 */
Calculates the context on the base of average of already decoded
neighbour values.

It is considered that vals[0] represents the value 2 rows above the current,
while the (locally) previous elements represent the current row. If y < 2,
then vals[0] should be 0.
Elements (locally) around vals[prev_row_delta] correspond to the row above
currnent one.

Values are summed up with the following weights.



This method should not be invoked on the 0-th row or 0-th column.
It is also considered, that there are 2 extra fence columns before the 0-th
column and 1 fence column to the right of the last column,
all initialized with zeroes.
Calculates the context on the base of average of already decoded neighbour values . It is considered that vals [ 0 ] represents the value 2 rows above the current while the ( locally ) previous elements represent the current row . If y < 2 then vals [ 0 ] should be 0 . Elements ( locally ) around vals [ prev_row_delta ] correspond to the row above currnent one . Values are summed up with the following weights . This method should not be invoked on the 0 - th row or 0 - th column . It is also considered that there are 2 extra fence columns before the 0 - th column and 1 fence column to the right of the last column all initialized with zeroes .
inline int WeightedAverageContext(const int* vals, int prev_row_delta) {
  int sum = 4 + vals[0] + (vals[-kDCTBlockSize] + vals[prev_row_delta]) * 2 +
            vals[-2 * kDCTBlockSize] + vals[prev_row_delta - kDCTBlockSize] +
            vals[prev_row_delta + kDCTBlockSize];
  if ((sum >> (kMaxAverageContext + 2)) != 0) {
    return kMaxAverageContext;
  }
  return Log2FloorNonZero(sum) - 2;
}
inline int WeightedAverageContext ( const int * vals , int prev_row_delta ) { int sum = 4 + vals [ 0 ] + ( vals [ - kDCTBlockSize ] + vals [ prev_row_delta ] ) * 2 + vals [ -2 * kDCTBlockSize ] + vals [ prev_row_delta - kDCTBlockSize ] + vals [ prev_row_delta + kDCTBlockSize ] ; if ( ( sum >> ( kMaxAverageContext + 2 ) ) != 0 ) { return kMaxAverageContext ; } return Log2FloorNonZero ( sum ) - 2 ; }
Calculates the context on the base of average of already decoded
 neighbour values.
Calculates the context on the base of average of already decoded neighbour values .