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

📄 transform8x8.c

📁 h.264 影像壓縮 必須在 .net 的環境 下操作
💻 C
📖 第 1 页 / 共 4 页
字号:
            for (j=0; j<2; j++)
              memcpy(cofAC8x8[b8][k][j],img->cofAC[b8][k][j], 65 * sizeof(int));
          }

          //--- set reconstruction ---
          for (y=0; y<8; y++)
          {
            memcpy(rec8x8[0][y],&enc_picture->imgY[pic_pix_y+y][pic_pix_x], 8 * sizeof(imgpel));
          }

          if (img->AdaptiveRounding)
          {
            for (j=block_y; j<block_y + 8; j++)
              memcpy(&fadjust8x8[1][j][block_x],&img->fadjust8x8[1][j][block_x], 8 * sizeof(int));

            if(img->yuv_format == YUV444 && !IS_INDEPENDENT(input))
            {
              for (j=block_y; j<block_y + 8; j++)
              {
                memcpy(&fadjust8x8Cr[0][1][j][block_x],&img->fadjust8x8Cr[0][1][j][block_x], 8 * sizeof(int));
                memcpy(&fadjust8x8Cr[1][1][j][block_x],&img->fadjust8x8Cr[1][1][j][block_x], 8 * sizeof(int));
              }
            }            
          }
          if( img->yuv_format == YUV444 && !IS_INDEPENDENT(input) ) 
          { 
            //--- set coefficients ---
            for (uv=0; uv < 2; uv++)
            {
              for(k=0; k<4; k++) // do 4x now
              {
                for (j=0; j<2; j++)
                {
                  memcpy(cofAC8x8CbCr[uv][b8][k][j],img->cofAC[4+b8+4*uv][k][j], 65 * sizeof(int));
                }
              }
              cr_cbp[uv + 1] = c_nzCbCr[uv + 1];
              //--- set reconstruction ---
              for (y=0; y<8; y++)
              {
                memcpy(rec8x8[uv + 1][y],&enc_picture->imgUV[uv][pic_pix_y+y][pic_pix_x], 8 * sizeof(imgpel));
              }
            }
          }

          //--- flag if dct-coefficients must be coded ---
          nonzero = c_nz;

          //--- set best mode update minimum cost ---
          *min_cost   = rdcost;
          min_rdcost  = rdcost;
          best_ipmode = ipmode;
        }
        reset_coding_state_cs_cm(currMB);
      }
    }
  }

  //===== set intra mode prediction =====
  img->ipredmode8x8[pic_block_y][pic_block_x] = (char) best_ipmode;
  ipmode_DPCM = best_ipmode; //For residual DPCM

  if( (active_sps->chroma_format_idc==YUV444) && (IS_INDEPENDENT(input)==0) )
  {
    ColorPlane k;
    CbCr_predmode_8x8[b8] = best_ipmode; 
    for (k = PLANE_U; k <= PLANE_V; k++)
    {
      cr_cbp[k] = 0; 
      select_plane(k);
      for (j=0; j<8; j++)
      {
        for (i=0; i<8; i++)
        {
          img->mpr[k][block_y+j][block_x+i]  = img->mpr_8x8[k][best_ipmode][j][i]; 
          img->m7[k][block_y+j][block_x+i]   = pImgOrg[k][img->pix_y+block_y+j][img->pix_x+block_x+i] - img->mpr_8x8[k][best_ipmode][j][i];
        }
      }
      if(lossless_qpprime)   //For residual DPCM
      {
        ipmode_DPCM=best_ipmode; 
        if((best_ipmode<2))
        {
          Residual_DPCM_8x8(best_ipmode, k, block_y, block_x);
        }
      }

      if (dct_8x8(currMB, k, b8, &dummy, 1))
        cr_cbp[k] = 1;
    }
    select_plane(PLANE_Y);
  }
  
  currMB->intra_pred_modes8x8[4*b8] = (mostProbableMode == best_ipmode)
    ? -1
    : (best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1);

  for(j = img->mb_y*4+(b8 >> 1)*2; j < img->mb_y*4+(b8 >> 1)*2 + 2; j++)   //loop 4x4s in the subblock for 8x8 prediction setting
   memset(&img->ipredmode8x8[j][img->mb_x*4+(b8 & 0x01)*2], best_ipmode, 2 * sizeof(char));

  if (!input->rdopt)
  {
    // get prediction and prediction error
    for (j = block_y; j < block_y + 8; j++)
    {
      memcpy(&curr_mpr[j][block_x],img->mpr_8x8[0][best_ipmode][j - block_y], 8 * sizeof(imgpel));
      img_org  = &pCurImg[img->opix_y+j][pic_opix_x];
      img_prd  = &curr_mpr[j][block_x];
      residual = &curr_res[j][block_x];
      for (i=0; i<8; i++)
      {
        *residual++ = *img_org++ - *img_prd++;
      }
    }

    if(lossless_qpprime)   //For residual DPCM
    {
      ipmode_DPCM=best_ipmode;

      if((best_ipmode<2))
      {
        Residual_DPCM_8x8(best_ipmode, 0, block_y, block_x);
      }
    }
    nonzero = dct_8x8 (currMB, PLANE_Y, b8, &dummy, 1);    
  }
  else
  {
    //===== restore coefficients =====
    for(k=0; k<4; k++) // do 4x now
    {
      for (j=0; j<2; j++)
        memcpy(img->cofAC[b8][k][j],cofAC8x8[b8][k][j], 65 * sizeof(int));
    }

    if (img->AdaptiveRounding)
    {
      for (j=block_y; j< block_y + 8; j++)
        memcpy(&img->fadjust8x8[1][j][block_x], &fadjust8x8[1][j][block_x], 8 * sizeof(int));
      if(img->yuv_format == YUV444 && !IS_INDEPENDENT (input))
      {
        for (j=0; j<8; j++)
        {
          memcpy(&img->fadjust8x8Cr[0][1][block_y+j][block_x], &fadjust8x8Cr[0][1][block_y+j][block_x], 8 * sizeof(int));
          memcpy(&img->fadjust8x8Cr[1][1][block_y+j][block_x], &fadjust8x8Cr[1][1][block_y+j][block_x], 8 * sizeof(int));
        }
      }
    }

    //===== restore reconstruction and prediction (needed if single coeffs are removed) =====
    for (y=0; y<8; y++)
    {
      memcpy(&enc_picture->imgY[pic_pix_y + y][pic_pix_x], rec8x8[0][y], 8 * sizeof(imgpel));
      memcpy(&curr_mpr[block_y + y][block_x], img->mpr_8x8[0][best_ipmode][y], 8 * sizeof(imgpel));
    }
    if (img->yuv_format==YUV444 && !IS_INDEPENDENT(input) )
    {
      //===== restore coefficients =====
      for(k=0; k<4; k++) // do 4x now    
      {
        for (j=0; j<2; j++)
        {
          memcpy(img->cofAC[4+b8+4*0][k][j], cofAC8x8CbCr[0][b8][k][j], 65 * sizeof(int));
          memcpy(img->cofAC[4+b8+4*1][k][j], cofAC8x8CbCr[1][b8][k][j], 65 * sizeof(int));
        }
      }
      //===== restore reconstruction and prediction (needed if single coeffs are removed) =====
      for (y=0; y<8; y++) 
      {
        memcpy(&enc_picture->imgUV[0][pic_pix_y+y][pic_pix_x], rec8x8[1][y], 8 * sizeof(imgpel));
        memcpy(&enc_picture->imgUV[1][pic_pix_y+y][pic_pix_x], rec8x8[2][y], 8 * sizeof(imgpel));
        memcpy(&img->mpr[1][block_y+y][block_x], img->mpr_8x8[1][best_ipmode][y], 8 * sizeof(imgpel));
        memcpy(&img->mpr[2][block_y+y][block_x], img->mpr_8x8[2][best_ipmode][y], 8 * sizeof(imgpel));
      }
    }
  }

  return nonzero;
}



// Notation for comments regarding prediction and predictors.
// The pels of the 4x4 block are labelled a..p. The predictor pels above
// are labelled A..H, from the left I..P, and from above left X, as follows:
//
//  Z  A  B  C  D  E  F  G  H  I  J  K  L  M   N  O  P
//  Q  a1 b1 c1 d1 e1 f1 g1 h1
//  R  a2 b2 c2 d2 e2 f2 g2 h2
//  S  a3 b3 c3 d3 e3 f3 g3 h3
//  T  a4 b4 c4 d4 e4 f4 g4 h4
//  U  a5 b5 c5 d5 e5 f5 g5 h5
//  V  a6 b6 c6 d6 e6 f6 g6 h6
//  W  a7 b7 c7 d7 e7 f7 g7 h7
//  X  a8 b8 c8 d8 e8 f8 g8 h8


// Predictor array index definitions
#define P_Z (PredPel[0])
#define P_A (PredPel[1])
#define P_B (PredPel[2])
#define P_C (PredPel[3])
#define P_D (PredPel[4])
#define P_E (PredPel[5])
#define P_F (PredPel[6])
#define P_G (PredPel[7])
#define P_H (PredPel[8])
#define P_I (PredPel[9])
#define P_J (PredPel[10])
#define P_K (PredPel[11])
#define P_L (PredPel[12])
#define P_M (PredPel[13])
#define P_N (PredPel[14])
#define P_O (PredPel[15])
#define P_P (PredPel[16])
#define P_Q (PredPel[17])
#define P_R (PredPel[18])
#define P_S (PredPel[19])
#define P_T (PredPel[20])
#define P_U (PredPel[21])
#define P_V (PredPel[22])
#define P_W (PredPel[23])
#define P_X (PredPel[24])

/*!
 ************************************************************************
 * \brief
 *    Make intra 8x8 prediction according to all 9 prediction modes.
 *    The routine uses left and upper neighbouring points from
 *    previous coded blocks to do this (if available). Notice that
 *    inaccessible neighbouring points are signalled with a negative
 *    value in the predmode array .
 *
 *  \par Input:
 *     Starting point of current 8x8 block image posision
 *
 *  \par Output:
 *      none
 ************************************************************************
 */
void intrapred_8x8(Macroblock *currMB, ColorPlane pl, int img_x,int img_y, int *left_available, int *up_available, int *all_available)
{
  int i,j;
  int s0;
  static imgpel PredPel[25];  // array of predictor pels
  imgpel **img_enc = enc_picture->p_curr_img;
  imgpel *img_pel;
  static imgpel (*cur_pred)[16];
  imgpel (*curr_mpr_8x8)[16][16]  = img->mpr_8x8[pl];
  unsigned int dc_pred_value = img->dc_pred_value;

  int ioff = (img_x & 15);
  int joff = (img_y & 15);

  PixelPos pix_a[8];
  PixelPos pix_b, pix_c, pix_d;

  int block_available_up;
  int block_available_left;
  int block_available_up_left;
  int block_available_up_right;

  for (i=0;i<8;i++)
  {
    getNeighbour(currMB, ioff - 1, joff + i , IS_LUMA, &pix_a[i]);
  }

  getNeighbour(currMB, ioff    , joff - 1, IS_LUMA, &pix_b);
  getNeighbour(currMB, ioff + 8, joff - 1, IS_LUMA, &pix_c);
  getNeighbour(currMB, ioff - 1, joff - 1, IS_LUMA, &pix_d);

  pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8);

  if (input->UseConstrainedIntraPred)
  {
    for (i=0, block_available_left=1; i<8;i++)
      block_available_left  &= pix_a[i].available ? img->intra_block[pix_a[i].mb_addr]: 0;

    block_available_up       = pix_b.available ? img->intra_block [pix_b.mb_addr] : 0;
    block_available_up_right = pix_c.available ? img->intra_block [pix_c.mb_addr] : 0;
    block_available_up_left  = pix_d.available ? img->intra_block [pix_d.mb_addr] : 0;
  }
  else
  {
    block_available_left     = pix_a[0].available;
    block_available_up       = pix_b.available;
    block_available_up_right = pix_c.available;
    block_available_up_left  = pix_d.available;
  }

  *left_available = block_available_left;
  *up_available   = block_available_up;
  *all_available  = block_available_up && block_available_left && block_available_up_left;

  i = (img_x & 15);
  j = (img_y & 15);

  // form predictor pels
  // form predictor pels
  if (block_available_up)
  {
    img_pel = &img_enc[pix_b.pos_y][pix_b.pos_x];
    P_A = *(img_pel++);
    P_B = *(img_pel++);
    P_C = *(img_pel++);
    P_D = *(img_pel++);
    P_E = *(img_pel++);
    P_F = *(img_pel++);
    P_G = *(img_pel++);
    P_H = *(img_pel);
  }
  else
  {
    P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = dc_pred_value;
  }

  if (block_available_up_right)
  {
    img_pel = &img_enc[pix_c.pos_y][pix_c.pos_x];
    P_I = *(img_pel++);
    P_J = *(img_pel++);
    P_K = *(img_pel++);
    P_L = *(img_pel++);
    P_M = *(img_pel++);
    P_N = *(img_pel++);
    P_O = *(img_pel++);
    P_P = *(img_pel);

  }
  else
  {
    P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H;
  }

  if (block_available_left)
  {
    P_Q = img_enc[pix_a[0].pos_y][pix_a[0].pos_x];
    P_R = img_enc[pix_a[1].pos_y][pix_a[1].pos_x];
    P_S = img_enc[pix_a[2].pos_y][pix_a[2].pos_x];
    P_T = img_enc[pix_a[3].pos_y][pix_a[3].pos_x];
    P_U = img_enc[pix_a[4].pos_y][pix_a[4].pos_x];
    P_V = img_enc[pix_a[5].pos_y][pix_a[5].pos_x];
    P_W = img_enc[pix_a[6].pos_y][pix_a[6].pos_x];
    P_X = img_enc[pix_a[7].pos_y][pix_a[7].pos_x];
  }
  else
  {
    P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = dc_pred_value;
  }

  if (block_available_up_left)
  {
    P_Z = img_enc[pix_d.pos_y][pix_d.pos_x];
  }
  else
  {
    P_Z = dc_pred_value;
  }

  for(i=0;i<9;i++)
    curr_mpr_8x8[i][0][0]=-1;

  LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left);

  ///////////////////////////////
  // make DC prediction
  ///////////////////////////////
  s0 = 0;
  if (block_available_up && block_available_left)
  {
    // no edge
    s0 = rshift_rnd_sf((P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X), 4);
  }
  else if (!block_available_up && block_available_left)
  {
    // upper edge
    s0 = rshift_rnd_sf((P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X), 3);
  }
  else if (block_available_up && !block_available_left)
  {
    // left edge
    s0 = rshift_rnd_sf((P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H), 3);
  }
  else //if (!block_available_up && !block_available_left)
  {
    // top left corner, nothing to predict from
    s0 = dc_pred_value;
  }

  // store DC prediction
  cur_pred = curr_mpr_8x8[DC_PRED];
  for (j=0; j < BLOCK_SIZE_8x8; j++)
  {
    for (i=0; i < BLOCK_SIZE_8x8; i++)
    {
      cur_pred[j][i] = (imgpel) s0;
    }
  }


  ///////////////////////////////
  // make horiz and vert prediction
  ///////////////////////////////
  cur_pred = curr_mpr_8x8[VERT_PRED];
  for (i=0; i < BLOCK_SIZE_8x8; i++)
  {
    cur_pred[0][i] =
    cur_pred[1][i] =
    cur_pred[2][i] =
    cur_pred[3][i] =
    cur_pred[4][i] =
    cur_pred[5][i] =
    cur_pred[6][i] =
    cur_pred[7][i] = (imgpel)(&P_A)[i];
  }
  if(!block_available_up)
    cur_pred[0][0]=-1;

  cur_pred = curr_mpr_8x8[HOR_PRED];
  for (i=0; i < BLOCK_SIZE_8x8; i++)
  {
    cur_pred[i][0]  =
    cur_pred[i][1]  =
    cur_pred[i][2]  =
    cur_pred[i][3]  =
    cur_pred[i][4]  =

⌨️ 快捷键说明

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