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

📄 p_picture.c

📁 tmn3.2编解码源程序 Linux C环境编写 文件齐全 压缩包完整 试用正常 欢迎试用
💻 C
📖 第 1 页 / 共 5 页
字号:
		             * the previous quantizer,current quantizer is coded into dquant parameter*/                dquant = QP_new;              }            }          }        }	      pic->DQUANT = dquant;        /* modify mode if dquant != 0 (e.g. MODE_INTER -> MODE_INTER_Q           * or MODE_INTER4V -> MODE_INTER4V_Q) */        Mode = ModifyMode(MV[0][j+1][i+1]->Mode,pic->DQUANT, EPTYPE);        MV[0][j+1][i+1]->Mode = Mode;      }      pic->MB = i + j * (pels/MB_SIZE);            /* store the QP for every macroblock */      quant_map[j+1][i+1] = QP_xmitted;      if ((rcoeff = (int *)malloc(sizeof(int)*384)) == NULL)       {        fprintf(stderr,"MB_Coder: Could not allocate space for rcoeff\n");        exit(-1);      }        if ( Mode == MODE_INTER || Mode == MODE_INTER_Q ||           Mode == MODE_INTER4V || Mode==MODE_INTER4V_Q)      {        /* Predict P-MB */	      diff = Predict_P( curr,prev_recon,prev_ipol, pred_P,                          i*MB_SIZE,j*MB_SIZE,MV,pic->PB, pic->RTYPE);      }      else       {        /* fill prediction array with 0s */        memset (pred_P, 0, sizeof (MB_Structure));        /* fill the difference array with the current macroblock pixels */        diff = (MB_Structure *)malloc(sizeof(MB_Structure));      	FillLumBlock(i*MB_SIZE, j*MB_SIZE, curr, diff);        FillChromBlock(i*MB_SIZE, j*MB_SIZE, curr, diff);      }      /* P or INTRA Macroblock */      if ((qcoeff_P=(int *)malloc(sizeof(int)*384)) == 0)       {        fprintf(stderr,"coder(): Couldn't allocate qcoeff_P.\n");        exit(-1);      }      coeff = MB_Encode(diff);      if (advanced_intra_coding)       {        if (!(Mode == MODE_INTRA || Mode == MODE_INTRA_Q))         {          for (k=0;k<6;k++)           {                /* store default coeff if non-intra macroblock */            store_coeff[(i + j * pels/MB_SIZE) * 384 + k * 64] = 1024;            store_rcoeff[(i + j * pels/MB_SIZE) * 384 + k * 64] = 1024;          }          for (k=0;k<6;k++)          {            Quant_blk(coeff,qcoeff_P,QP_xmitted, Mode,k);          }          CBP = FindCBP(qcoeff_P, Mode, 64);          if (CBP == 0 && (Mode == MODE_INTER || Mode == MODE_INTER_Q))           {            ZeroMBlock(diff);          }          else          {              for (k=0;k<6;k++)            {              Quant_blk(coeff,qcoeff_P,QP_xmitted, Mode,k);              Dequant(qcoeff_P, rcoeff, QP_xmitted, Mode,k);            }            MB_Decode(rcoeff, diff);          }        }        else         {          if ((pcoeff=(int *)malloc(sizeof(int)*384)) == 0)           {            fprintf(stderr,"coder(): Couldn't allocate pcoeff.\n");            exit(-1);          }          /* store the quantized DCT coefficients */          memcpy( (void *) (store_coeff + (i + j*pels/MB_SIZE)*384), (void *) coeff, sizeof(int) * 384);          /* Do Intra mode prediction */          pic->Intra_Mode = Choose_Intra_Mode(pcoeff, store_coeff, i, j, newgob);          for (k=0;k<6;k++)           {             Intra_AC_DC_Encode(coeff, store_rcoeff, pic->Intra_Mode, i, j, newgob,k);            Quant_blk(coeff,pcoeff,QP_xmitted,Mode,k);            Dequant(pcoeff, rcoeff, QP_xmitted, Mode,k);            Intra_AC_DC_Decode(rcoeff, store_rcoeff, pic->Intra_Mode, i, j, newgob,k);          }          MB_Decode(rcoeff, diff);          CBP = FindCBP(pcoeff,Mode,64);        }          }      else      {          for (k=0;k<6;k++)          Quant_blk(coeff,qcoeff_P,QP_xmitted, Mode,k);        CBP = FindCBP(qcoeff_P, Mode, 64);        if (CBP == 0 && (Mode == MODE_INTER || Mode == MODE_INTER_Q))           ZeroMBlock(diff);        else        {          for (k=0;k<6;k++)              Dequant(qcoeff_P, rcoeff, QP_xmitted, Mode,k);           MB_Decode(rcoeff, diff);        }      }      recon_data_P = MB_Reconstruct (diff, pred_P);      Clip(recon_data_P);      free(diff);      free(coeff);              /* Predict B-MB using reconstructed P-MB and prev. recon. image */      if (pic->PB)       {        diff = Predict_B( B_image, prev_recon, prev_ipol_woRTYPE,pred_B,i*MB_SIZE, j*MB_SIZE,                          MV,B_f_MV, recon_data_P, frameskip, pic->TRB, pic->PB,                           &PB_pred_type);        if (QP_xmitted == 0)        {          /* (QP = 0 means no quantization) */          QP_B = 0;          }        else         {          QP_B = mmax(1,mmin(31,bquant[pic->BQUANT]*QP_xmitted/4));        }        if ((qcoeff_B=(int *)malloc(sizeof(int)*384)) == 0)         {		      fprintf(stderr,"coder(): Couldn't allocate qcoeff_B.\n");          exit(-1);        }        coeff = MB_Encode(diff);        for (k=0;k<6;k++)          Quant_blk(coeff,qcoeff_B,QP_B, MODE_INTER,k);        CBPB = FindCBP(qcoeff_B, MODE_INTER, 64);                 if (CBPB)        {           for (k=0;k<6;k++)            Dequant(qcoeff_B, rcoeff, QP_B, MODE_INTER,k);          MB_Decode(rcoeff, diff);        }        else          ZeroMBlock(diff);        recon_data_B = MB_Reconstruct(diff,pred_B);        Clip(recon_data_B);        /* decide MODB */         if (pic->PB == IM_PB_FRAMES)         {          if (CBPB)          {            if (PB_pred_type == FORWARD_PREDICTION)              pic->MODB = PBMODE_CBPB_FRW_PRED;            else if (PB_pred_type == BACKWARD_PREDICTION)            pic->MODB = PBMODE_CBPB_BCKW_PRED;            else              pic->MODB = PBMODE_CBPB_BIDIR_PRED;          }           else          {            if (PB_pred_type == FORWARD_PREDICTION)              pic->MODB = PBMODE_FRW_PRED;             else if (PB_pred_type == BACKWARD_PREDICTION)              pic->MODB = PBMODE_BCKW_PRED;            else              pic->MODB = PBMODE_BIDIR_PRED;          }          if (PB_pred_type == FORWARD_PREDICTION)          {            /* Store the forward predicted MV instead of PB delta. */            MV[6][j + 1][i + 1]->x = B_f_MV[0][j + 1][i + 1]->x;            MV[6][j + 1][i + 1]->y = B_f_MV[0][j + 1][i + 1]->y;            MV[6][j + 1][i + 1]->x_half = B_f_MV[0][j + 1][i + 1]->x_half;            MV[6][j + 1][i + 1]->y_half = B_f_MV[0][j + 1][i + 1]->y_half;          }          if (PB_pred_type == BACKWARD_PREDICTION)          {            MV[6][j + 1][i + 1]->x = 0;            MV[6][j + 1][i + 1]->y = 0;            MV[6][j + 1][i + 1]->x_half = 0;            MV[6][j + 1][i + 1]->y_half = 0;          }        }        else         {          if (CBPB)           {            pic->MODB = PBMODE_CBPB_MVDB;          }          else            {            if (MV[6][j+1][i+1]->x == 0 && MV[6][j+1][i+1]->y == 0)              pic->MODB = PBMODE_NORMAL;            else              pic->MODB = PBMODE_MVDB;          }        }        free(diff);        free(coeff);              }      else        ZeroVec(MV[6][j+1][i+1]); /* Zero out PB deltas */      if ((CBP==0) && (CBPB==0) && (EqualVec(MV[0][j+1][i+1],&ZERO)) &&           (EqualVec(MV[6][j+1][i+1],&ZERO)) &&          (Mode == MODE_INTER || Mode == MODE_INTER_Q) &&          (pic->MODB==0))       {         /* Skipped MB : both CBP and CBPB are zero, 16x16 vector is zero,         * PB delta vector is zero, Mode = MODE_INTER and B picture is         * predicted bidirectionally. */        coded_map[j+1][i+1] = 0;        quant_map[j+1][i+1] = 0;        if (Mode == MODE_INTER_Q || Mode == MODE_INTER4V_Q)         {          /* DQUANT != 0 but not coded anyway */          QP_xmitted = QP_prev;          pic->DQUANT = 0;          Mode = MODE_INTER;        }        if (!syntax_arith_coding)          CountBitsMB(Mode,1,CBP,CBPB,pic,bits,0);        else          Count_sac_BitsMB(Mode,1,CBP,CBPB,pic,bits);      }      else       {        /* Normal MB */        if (!syntax_arith_coding)         {           /* VLC */          CountBitsMB(Mode,0,CBP,CBPB,pic,bits,0);          if (!CBP || !CBPB)            intra_refresh[j+1][i+1] += 1;          if (Mode == MODE_INTER  || Mode == MODE_INTER_Q)           {            coded_map[j+1][i+1] = 1;            quant_map[j+1][i+1] = QP_xmitted;            bits->no_inter++;            CountBitsVectors(MV, bits, i, j, Mode, newgob, pic, 0);          }          else if (Mode == MODE_INTER4V || Mode == MODE_INTER4V_Q)           {            coded_map[j+1][i+1] = 1;            quant_map[j+1][i+1] = QP_xmitted;            bits->no_inter4v++;            CountBitsVectors(MV, bits, i, j, Mode, newgob, pic, 0);          }          else           {            /* MODE_INTRA or MODE_INTRA_Q */            coded_map[j+1][i+1] = 2;            quant_map[j+1][i+1] = QP_xmitted;            intra_refresh[j+1][i+1] = 0;                       bits->no_intra++;            if (pic->PB)            {              CountBitsVectors(MV, bits, i, j, Mode, newgob, pic, 0);            }          }          if ( (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) &&                advanced_intra_coding )          {            Scan(pcoeff,pic->Intra_Mode);            CountBitsCoeff(pcoeff, Mode, CBP, bits, 64);          }          else if (CBP || Mode == MODE_INTRA || Mode == MODE_INTRA_Q)          {            Scan(qcoeff_P,0);            CountBitsCoeff(qcoeff_P, Mode, CBP, bits, 64);            }                  if (CBPB)          {            Scan(qcoeff_B,0);            CountBitsCoeff(qcoeff_B, MODE_INTER, CBPB, bits, 64);          }        }         /* end VLC */        else         {           /* SAC */          Count_sac_BitsMB(Mode,0,CBP,CBPB,pic,bits);          if (!CBP || !CBPB)            intra_refresh[j+1][i+1] += 1;          if (Mode == MODE_INTER  || Mode == MODE_INTER_Q)           {            coded_map[j+1][i+1] = 1;            quant_map[j+1][i+1] = QP_xmitted;                  bits->no_inter++;            Count_sac_BitsVectors(MV, bits, i, j, Mode, newgob, pic);          }          else if (Mode == MODE_INTER4V || Mode == MODE_INTER4V_Q)           {            coded_map[j+1][i+1] = 1;            quant_map[j+1][i+1] = QP_xmitted;            bits->no_inter4v++;            Count_sac_BitsVectors(MV, bits, i, j, Mode, newgob, pic);          }          else           {            /* MODE_INTRA or MODE_INTRA_Q */            coded_map[j+1][i+1] = 2;            quant_map[j+1][i+1] = QP_xmitted;            intra_refresh[j+1][i+1] = 0;            bits->no_intra++;            if (pic->PB)	            Count_sac_BitsVectors(MV, bits, i, j, Mode, newgob, pic);          }          if ((Mode == MODE_INTRA || Mode == MODE_INTRA_Q) &&               advanced_intra_coding)          {            Scan(pcoeff, pic->Intra_Mode);            Count_sac_BitsCoeff(pcoeff, Mode, CBP, bits, 64);          }          else if ( CBP || Mode == MODE_INTRA || Mode == MODE_INTRA_Q)          {            Scan(qcoeff_P,0);                       Count_sac_BitsCoeff(qcoeff_P, Mode, CBP, bits, 64);          }          if (CBPB)          {            Scan(qcoeff_B,0);            Count_sac_BitsCoeff(qcoeff_B, MODE_INTER, CBPB, bits, 64);          }         }        /* end SAC */        QP_prev = QP_xmitted;      }      /* update the rate control parameters for TMN-8 rate control */      if (rate_control_method == TMN8_RC)       {         AddBitsPicture (bits);          UpdateRateControlMB((bits->total - bits_prev->total),                            ((bits->Y + bits->C)-(bits_prev->Y + bits_prev->C)), i, j, QP_xmitted);          bits_prev->total = bits->total;        bits_prev->Y = bits->Y;        bits_prev->C = bits->C;      }       abs_mb_num++;      QP_cumulative += QP_xmitted;     #ifdef PRINTQ       /* most useful when quantizer changes within a picture */      if (QuantChangePostponed)        fprintf(stdout,"@%2d",QP_xmitted);      else        fprintf(stdout," %2d",QP_xmitted);#endif      if (pic->PB)       {        ReconImage(i,j,recon_data_B,B_recon);      }      ReconImage(i,j,recon_data_P,recon);      if ( (PCT_IPB == pic->picture_coding_type) || PCT_PB == pic->picture_coding_type )      {        free(qcoeff_B);        free(recon_data_B);      }      free(recon_data_P);      free(qcoeff_P);      free(rcoeff);      if (advanced_intra_coding && (Mode == MODE_INTRA || Mode == MODE_INTRA_Q))          free(pcoeff);    }    }#ifdef PRINTQ    fprintf(stdout,"\n");#endif  }  /* Do the deblocking filtering, not used in true B pictures. */  if (deblocking_filter)   {

⌨️ 快捷键说明

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