⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transform.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
📖 第 1 页 / 共 2 页
字号:
  int i;  int sad;  /*   *  A = a + b + c + d   *  B = a + b - c - d   *  C = a - b - c + d   *  D = a - b + c - d   *   *  e = a + d   *  f = b + c   *  A = e + f   *  C = e - f   *  e = a - d   *  f = b - c   *  B = e + f   *  D = e - f   */  /* Difference and horizontal transform */  for (i = 0; i < 4; i++) {    a = orig[i][0] - pred[i][0];    b = orig[i][1] - pred[i][1];    c = orig[i][2] - pred[i][2];    d = orig[i][3] - pred[i][3];    e = a + d;    f = b + c;    tmp[i][0] = e + f;    tmp[i][2] = e - f;    e = a - d;    f = b - c;    tmp[i][1] = e + f;    tmp[i][3] = e - f;  }  /* Vertical transform and SATD */  for (sad = 0, i = 0; i < 4; i++) {    e = tmp[0][i] + tmp[3][i];    f = tmp[1][i] + tmp[2][i];    sad += abs(e + f);    sad += abs(e - f);    e = tmp[0][i] - tmp[3][i];    f = tmp[1][i] - tmp[2][i];    sad += abs(e + f);    sad += abs(e - f);  }  return sad;}/* * * traDiffSATD4x4RetDc: * * Parameters: *      orig            Original values *      pred            Prediction values *      dc              Return pointer for DC value * * Function: *      Compute difference between orig and pred, compute hadamard *      transform on difference matrix and compute sum of absolute *      transformed differences. Write DC coefficient to location *      pointed by dc. * * Returns: *      Sum of absolute transformed differences * */int traDiffSATD4x4RetDc(u_int8 orig[BLK_SIZE][MBK_SIZE],                        u_int8 pred[BLK_SIZE][MBK_SIZE], int *dc){  int tmp[4][4];  int a, b, c, d;  int e;  int f;  int i;  int sad;  /*   *  A = a + b + c + d   *  B = a + b - c - d   *  C = a - b - c + d   *  D = a - b + c - d   *   *  e = a + d   *  f = b + c   *  A = e + f   *  C = e - f   *  e = a - d   *  f = b - c   *  B = e + f   *  D = e - f   */  /* Difference and horizontal transform */  for (i = 0; i < 4; i++) {    a = orig[i][0] - pred[i][0];    b = orig[i][1] - pred[i][1];    c = orig[i][2] - pred[i][2];    d = orig[i][3] - pred[i][3];    e = a + d;    f = b + c;    tmp[i][0] = e + f;    tmp[i][2] = e - f;    e = a - d;    f = b - c;    tmp[i][1] = e + f;    tmp[i][3] = e - f;  }  /* Vertical transform and SATD */  for (sad = 0, i = 0; i < 4; i++) {    e = tmp[0][i] + tmp[3][i];    f = tmp[1][i] + tmp[2][i];    if (i == 0)      *dc = e + f;    else      sad += abs(e + f);    sad += abs(e - f);    e = tmp[0][i] - tmp[3][i];    f = tmp[1][i] - tmp[2][i];    sad += abs(e + f);    sad += abs(e - f);  }  return sad;}int simpleSad4x4(int src[4][4]){  int sad;  sad  = abs(src[0][0]) + abs(src[0][1]) + abs(src[0][2]) + abs(src[0][3]);  sad += abs(src[1][0]) + abs(src[1][1]) + abs(src[1][2]) + abs(src[1][3]);  sad += abs(src[2][0]) + abs(src[2][1]) + abs(src[2][2]) + abs(src[2][3]);  sad += abs(src[3][0]) + abs(src[3][1]) + abs(src[3][2]) + abs(src[3][3]);  return sad;}/* * * traDiffSAD4x4: * * Parameters: *      orig            Original values *      pred            Prediction values * * Function: *      Compute difference between orig and pred and compute sum of absolute *      differences. * * Returns: *      Sum of absolute differences * */int traDiffSAD4x4(u_int8 orig[BLK_SIZE][MBK_SIZE],                  u_int8 pred[BLK_SIZE][MBK_SIZE]){  int sad;  int i;  for (sad = 0, i = 0; i < BLK_SIZE; i++) {    sad += abs(orig[i][0] - pred[i][0]);    sad += abs(orig[i][1] - pred[i][1]);    sad += abs(orig[i][2] - pred[i][2]);    sad += abs(orig[i][3] - pred[i][3]);  }  return sad;}/* * traQuant4x4: * * Parameters: *      src                   Source values *      skip                  Indicates whether to skip DC coefficient *      qp                    Quantization parameter *      mode                  Intra/inter picture *      n                     Number of coefficients * * Function: *      Quantize block of coefficients. * * Returns: *      Number of nonzero quantized coefficients */int traQuant4x4(int *src, int skip, int qp, int mode){  int i;  int qAdd;  int threshold;  int nonZero;  int qp_per = qpPerTab[qp-MIN_QP];  int qp_rem = qpRemTab[qp-MIN_QP];  int q_bits = TRA_QUANT_BITS + qp_per;  if (IS_SLICE_I(mode))    qAdd = ((1 << TRA_QUANT_BITS)/3) << qp_per;  else    qAdd = ((1 << TRA_QUANT_BITS)/6) << qp_per;   threshold = (1 << q_bits) - qAdd;  for (nonZero = 0, i = skip; i < BLK_SIZE * BLK_SIZE; i ++) {    int tmp;    tmp = src[i] * quantCoef[qp_rem][i];    src[i] = 0;    // perform more processing, only if quantized coefficient might be nonzero    if ((tmp >= threshold) || (tmp <= -threshold))    {      if (tmp < 0)        tmp = -((-tmp + qAdd) >> q_bits);      else        tmp = (tmp + qAdd) >> q_bits;      if (tmp != 0)      {        src[i] = tmp;        nonZero ++;      }    }  }  return nonZero;}/* * traQuant4x4: * * Parameters: *      src                   Source values *      dest                  Return pointer for quantized coefficients *      qp                    Quantization parameter *      mode                  Intra/inter picture *      n                     Number of coefficients * * Function: *      Quantize block of DC coefficients. * * Returns: *      Number of nonzero quantized coefficients */int traQuantDC(int *src, int qp, int mode, int n, int comp){  int i;  int qAdd;  int tmp;  int nonZero;  int qp_per = qpPerTab[qp-MIN_QP];  int qp_rem = qpRemTab[qp-MIN_QP];  int q_bits = TRA_QUANT_BITS+qp_per+1;  if (IS_SLICE_I(mode) || (comp == 0))    qAdd = ((2<<TRA_QUANT_BITS)/3)<<qp_per;  else    qAdd = ((2<<TRA_QUANT_BITS)/6)<<qp_per;   for (nonZero = 0, i = 0; i < n; i++) {    tmp = src[i]*quantCoef[qp_rem][0];    if (src[i] < 0)      tmp = -((-tmp + qAdd) >> q_bits);    else      tmp = (tmp + qAdd) >> q_bits;    src[i] = tmp;    if (tmp != 0)      nonZero++;  }  return nonZero;}/* * traGetCoefCost: * * Parameters: *      coef                  Source coefficients *      nonZero               Number of non-zero coefficients * * Function: *      Compute cost of block of coefficients. Coefficients with magnitude 1 *      have cost of 3-0 depending on length of run. All other coefficients *      have cost of 9. * * Returns: *      Cost of coefficients */int traGetCoefCost(int *coef,                    int nonZero){  int cost;  int prev;  int i;  int nonZeroCount;  /*   * Compute cost of coefficients based on run&level. Coefficients with   * |level|==1 and long run have smallest cost.   */  nonZeroCount = 0;  cost = 0;  prev = 0;  i = 0;  do   {    if (coef[i] != 0) {      if (coef[i] == 1 || coef[i] == -1)        cost += COEFF_COST[i - prev];  /* run = i-prev */      else        cost += 9;      // the threshold should not be larger than 9      nonZeroCount ++;      prev = i + 1;    }    i ++;  } while (nonZeroCount < nonZero);  return cost;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -