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

📄 intrapred.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * Parameters: *      predBlk               Return pointer for predicted pixels *      mode                  16x16 mode to be computed *      reco                  Reconstruction pixels *      picWidth              Horizontal size of the frame *      mbAvailBits           Contains availability flags for neighboring MBs * * Function: *      Predict luma pixels using one of 16x16 intra modes. * * Returns: *      - * */int iprPredLuma16x16(u_int8 predBlk[MBK_SIZE][MBK_SIZE], int mode,                     u_int8 *reco, int picWidth, int mbAvailBits){  int dc;  int H, V;  int a, b, c;  int i, j;  int tmp, tmp2;  u_int8 *recoPtr, *recoPtr2;  switch (mode) {  case IPR_MODE2_DC:    /* DC PREDICTION */        if ((mbAvailBits & 1) && (mbAvailBits & 2)) {      recoPtr = &reco[picWidth];      for (dc = 0, i = 0; i < MBK_SIZE; i++) {        dc += reco[1+i] + (*recoPtr);        recoPtr += picWidth;      }      dc = (dc+16)>>5;    }    else if (mbAvailBits & 1) {      recoPtr = &reco[picWidth];      for (dc = 0, i = 0; i < MBK_SIZE; i++) {        dc += (*recoPtr);        recoPtr += picWidth;      }      dc = (dc+8)>>4;    }    else if (mbAvailBits & 2) {      for (dc = 0, i = 0; i < MBK_SIZE; i++)        dc += reco[1+i];      dc = (dc+8)>>4;    }    else      dc = 128;        for (j = 0; j < MBK_SIZE; j++) {      for (i = 0; i < MBK_SIZE; i+=4) {        predBlk[j][i+0] = (u_int8) dc;        predBlk[j][i+1] = (u_int8) dc;        predBlk[j][i+2] = (u_int8) dc;        predBlk[j][i+3] = (u_int8) dc;      }    }          break;  case IPR_MODE2_VERT:    /* VERTICAL PREDICTION */    if (!(mbAvailBits & 2)) return -1;    for (i = 0; i < MBK_SIZE; i++) {      tmp = reco[1+i];      for (j = 0; j < MBK_SIZE; j+=4) {        predBlk[j+0][i] = (u_int8) tmp;        predBlk[j+1][i] = (u_int8) tmp;        predBlk[j+2][i] = (u_int8) tmp;        predBlk[j+3][i] = (u_int8) tmp;      }    }    break;  case IPR_MODE2_HOR:    /* HORIZONTAL PREDICTION */    if (!(mbAvailBits & 1)) return -1;    recoPtr = &reco[picWidth];    for (j = 0; j < MBK_SIZE; j++) {      tmp = *recoPtr;      recoPtr += picWidth;      for (i = 0; i < MBK_SIZE; i+=4) {        predBlk[j][i+0] = (u_int8) tmp;        predBlk[j][i+1] = (u_int8) tmp;        predBlk[j][i+2] = (u_int8) tmp;        predBlk[j][i+3] = (u_int8) tmp;      }    }    break;  case IPR_MODE2_PLANE:    /* PLANE PREDICTION */    if (!(mbAvailBits & 1) || !(mbAvailBits & 2) || !(mbAvailBits & 8)) return -1;    recoPtr  = &reco[9*picWidth];    recoPtr2 = &reco[7*picWidth];    for (H = 0, V = 0, i = 1; i <= 8; i++) {      H += (i * (reco[8+i] - reco[8-i]));      V += (i * ((*recoPtr) - (*recoPtr2)));      recoPtr  += picWidth;      recoPtr2 -= picWidth;    }    a = 16*(reco[16*picWidth] + reco[16]);    b = (int)((5*((int32)H)+32)>>6);    c = (int)((5*((int32)V)+32)>>6);    tmp = a + c*(0-7) + 16;    for (j = 0; j < MBK_SIZE; j++, tmp+=c) {      tmp2 = tmp + b*(0-7);      for (i = 0; i < MBK_SIZE; i++, tmp2+=b) {        predBlk[j][i] = (u_int8) clip(0,255,tmp2>>5);      }    }    break;  }  return 1;}/* * * iprPredChroma * * Parameters: *      pred                  Storage for predicted pixels *      recoU                 Reconstruction pixels for U frame *      recoV                 Reconstruction pixels for V frame *      width                 Horizontal size of the frame *      mbAvailBits           Macroblock availability flags *      mode                  Chrominance intra mode * * Function: *      Make 8x8 chroma intra prediction for given macroblock. * * Returns: *      - * */int iprPredChroma(u_int8 pred[MBK_SIZE/2][MBK_SIZE],                  u_int8 *recoU, u_int8 *recoV,                  int width, int mbAvailBits, int mode){  int comp;  u_int8 *recoPic;  int S0, S1, S2, S3;  int A, B, C, D;  int H, V, a, b, c;  int i, j;  int tmp, tmp2;  switch (mode) {  case IPR_CHROMA_MODE_DC:    /*     * DC prediction     */        for (comp = 0; comp < MBK_SIZE; comp+=MBK_SIZE/2) {            recoPic = comp == 0 ? recoU : recoV;            S0 = S1 = S2 = S3 = 0;            if (mbAvailBits & 1) {        for (i = 0; i < 4; i++) {          S2 += recoPic[(1+i)*width];          S3 += recoPic[(5+i)*width];        }      }      if (mbAvailBits & 2) {        for (i = 0; i < 4; i++) {          S0 += recoPic[1+i];          S1 += recoPic[5+i];        }      }      if ((mbAvailBits & 1) && (mbAvailBits & 2)) {        A = (S0 + S2 + 4)>>3;        B = (S1 + 2)>>2;        C = (S3 + 2)>>2;        D = (S1 + S3 + 4)>>3;      }      else if (mbAvailBits & 1) {        A = B = (S2 + 2)>>2;        C = D = (S3 + 2)>>2;      }      else if (mbAvailBits & 2) {        A = C = (S0 + 2)>>2;        B = D = (S1 + 2)>>2;      }      else        A = B = C = D = 128;            for (j = 0; j < BLK_SIZE; j++) {        for (i = 0; i < BLK_SIZE; i++) {          pred[j  ][comp+i  ] = (u_int8) A;          pred[j  ][comp+4+i] = (u_int8) B;          pred[4+j][comp+i  ] = (u_int8) C;          pred[4+j][comp+4+i] = (u_int8) D;        }      }    }    break;  case IPR_CHROMA_MODE_VERT:    /*     * Vertical prediction     */    if (!(mbAvailBits & 2)) return -1;    for (comp = 0; comp < MBK_SIZE; comp+=MBK_SIZE/2) {      recoPic = comp == 0 ? recoU : recoV;      for (i = 0; i < MBK_SIZE/2; i++) {        tmp = recoPic[1+i];        for (j = 0; j < MBK_SIZE/2; j+=4) {          pred[j+0][comp+i] = (u_int8) tmp;          pred[j+1][comp+i] = (u_int8) tmp;          pred[j+2][comp+i] = (u_int8) tmp;          pred[j+3][comp+i] = (u_int8) tmp;        }      }    }    break;  case IPR_CHROMA_MODE_HOR:    /*     * Horizontal prediction     */    if (!(mbAvailBits & 1)) return -1;    for (comp = 0; comp < MBK_SIZE; comp+=MBK_SIZE/2) {      recoPic = comp == 0 ? recoU : recoV;      for (j = 0; j < MBK_SIZE/2; j++) {        tmp = recoPic[(1+j)*width];        for (i = 0; i < MBK_SIZE/2; i+=4) {          pred[j][comp+i+0] = (u_int8) tmp;          pred[j][comp+i+1] = (u_int8) tmp;          pred[j][comp+i+2] = (u_int8) tmp;          pred[j][comp+i+3] = (u_int8) tmp;        }      }    }    break;  case IPR_CHROMA_MODE_PLANE:    /*     * Plane Prediction     */    if (!(mbAvailBits & 1) || !(mbAvailBits & 2) || !(mbAvailBits & 8)) return -1;    for (comp = 0; comp < MBK_SIZE; comp+=MBK_SIZE/2) {      recoPic = comp == 0 ? recoU : recoV;      for (H = V = 0, i = 1; i <= 4; i++) {        H += i*(recoPic[4+i] - recoPic[4-i]);        V += i*(recoPic[(4+i)*width] - recoPic[(4-i)*width]);      }      a = 16*(recoPic[8*width] + recoPic[8]);      b = (int)((17*((int32)H)+16)>>5);      c = (int)((17*((int32)V)+16)>>5);      tmp = a + c*(0-3) + 16;      for (j = 0; j < MBK_SIZE/2; j++, tmp+=c) {        tmp2 = tmp + b*(0-3);        for (i = 0; i < MBK_SIZE/2; i++, tmp2+=b) {          pred[j][comp+i] = (u_int8) clip(0,255,tmp2>>5);        }      }            }    break;  }  return 1;}/* * * iprClearMBintraPred * * Parameters: *      modesLeftPred         Modes to the left *      modesUpPred           Upper modes * * Function: *      Set intra modes of all blocks within MB to DC prediction * * Returns: *      - * */void iprClearMBintraPred(int8 *modesLeftPred, int8 *modesUpPred){  int i;  for (i = 0; i < BLK_PER_MB; i++) {    *modesLeftPred++ = IPR_MODE_DC;    *modesUpPred++   = IPR_MODE_DC;  }}/* * * iprPutIntraModes * * Parameters: *      mbAvailBits           Macroblock availability flags *      ipModes               Encode intra modes/decoded intra modes *      modesLeftPred         Modes to the left *      modesUpPred           Upper modes * * Function: *      Set intra modes for current MB. Modes are predicted from *      the blocks up and left of the current block. * * Returns: *      - * */void iprPutIntraModes(int mbAvailBits, int8 *ipModes,                      int8 *modesLeftPred, int8 *modesUpPred){  int blkIdxX, blkIdxY;  int mostProbableMode;  int mode, codedMode;  int blkAvailBits;  int8 *upPred;  /* availability of the blocks to the left */  blkAvailBits = (mbAvailBits & 1) ? 0xffff : 0xeeee;    /* availability of the upper blocks */  if (!(mbAvailBits & 2))    blkAvailBits &= 0xfff0;  upPred = modesUpPred;  for (blkIdxY = 0; blkIdxY < BLK_PER_MB; blkIdxY++) {    /* Get mode of the block to the left */    mode = *modesLeftPred;    for (blkIdxX = 0; blkIdxX < BLK_PER_MB; blkIdxX++) {      if (blkAvailBits & 1)        /* If left and upper blocks are available, the most probable mode */        /* is minimum of the two modes */        mostProbableMode =  min(mode, upPred[blkIdxX]);      else        /* If either left or upper block is not available, */        /* DC mode is the most probable mode */        mostProbableMode =  IPR_MODE_DC;      /* Get coded mode of current block */      codedMode = *ipModes;      if (codedMode < 0)        mode = mostProbableMode;      else        mode = (codedMode < mostProbableMode ? codedMode : codedMode+1);      /* Overwrite coded mode with decoded mode. mode is used for prediction */      /* of the block to the right. */      *ipModes++ = (int8)mode;      blkAvailBits >>= 1;    }    /* This mode is used for prediction of the macroblock to the right */    *modesLeftPred++ = (int8)mode;    upPred = ipModes-BLK_PER_MB;  }  /* These mode are used for prediction of the below macroblock */  *modesUpPred++ = *upPred++;  *modesUpPred++ = *upPred++;  *modesUpPred++ = *upPred++;  *modesUpPred++ = *upPred++;}

⌨️ 快捷键说明

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