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

📄 image.c

📁 AVS编解码是学习AVS程序开发的入门资料,可以帮助初学者获得很多的收获.
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void split_field_top()
{
  int i;

  imgY = imgY_top;
  imgUV = imgUV_top;
  
  for (i=0; i<img->height; i++)
  {
    memcpy(imgY[i], imgY_frm[i*2], img->width); 
  }
  
  for (i=0; i<img->height_cr; i++)
  {
    memcpy(imgUV[0][i], imgUV_frm[0][i*2], img->width_cr);
    memcpy(imgUV[1][i], imgUV_frm[1][i*2], img->width_cr);
  }
}

  
/*
*************************************************************************
* Function:extract bottom field from a frame 
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void split_field_bot()
{
  int i;
	
  imgY = imgY_bot;
  imgUV = imgUV_bot;
    
  for (i=0; i<img->height; i++)
  {
    memcpy(imgY[i], imgY_frm[i*2 + 1], img->width);
  }
  
  for (i=0; i<img->height_cr; i++)
  {
    memcpy(imgUV[0][i], imgUV_frm[0][i*2 + 1], img->width_cr);
    memcpy(imgUV[1][i], imgUV_frm[1][i*2 + 1], img->width_cr);
  }
}


/*
*************************************************************************
* Function:decodes one picture
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void picture_data(struct img_par *img,struct inp_par *inp)
{
	unsigned char *Buf;
	int startcodepos,length; 
	const int mb_nr = img->current_mb_nr;
	int mb_width = img->width/16;
    	Macroblock *currMB = &mb_data[mb_nr];
    	img->current_slice_nr = -1;             // jlzheng 6.30
	currentbitoffset = currStream->frame_bitoffset;   // jlzheng 6.30
	currStream->frame_bitoffset = 0;                  // jlzheng 6.30
	if ((Buf = (char*)calloc (MAX_CODED_FRAME_SIZE , sizeof(char))) == NULL) 
		no_mem_exit("GetAnnexbNALU: Buf");	 //jlzheng  6.30

   	img->cod_counter=-1;

  while (img->current_mb_nr<img->PicSizeInMbs) // loop over macroblocks
  {
	  //decode slice header   jlzheng 6.30
	  if( img->current_mb_nr%mb_width ==0 ) 
	  {
		  if(img->cod_counter<=0)
		  {
			  if(checkstartcode())
			  {
				  GetOneUnit(Buf,&startcodepos,&length);
				  SliceHeader(Buf,startcodepos,length);
				  img->current_slice_nr++;
				  img->cod_counter = -1; // Yulj 2004.07.15
			  }
		  }
	  }  //decode slice header   

    if(img->current_mb_nr == 0)
		img->current_slice_nr = 0;
	mb_data[img->current_mb_nr].slice_nr = img->current_slice_nr;     // jlzheng 6.30

#if TRACE
    // Here was the slice nr from the mb_data used.  This slice number is only set after 
    // the reconstruction of an MB and hence here not yet valid
    fprintf(p_trace,"\n*********** Pic: %i (I/P) MB: %i Slice: %i Type %d **********\n", img->tr, img->current_mb_nr, img->current_slice_nr, img->type);
#endif
    
    // Initializes the current macroblock
    start_macroblock(img,inp);
    // Get the syntax elements from the NAL
    read_one_macroblock(img,inp);
    // decode one macroblock
    decode_one_macroblock(img,inp);
    img->current_mb_nr++;
  }

  free(Buf);

  DeblockFrame (img, imgY, imgUV);

}


void top_field(struct img_par *img,struct inp_par *inp)
{

  	unsigned char *Buf;
	int startcodepos,length; 
	const int mb_nr = img->current_mb_nr;
	int mb_width = img->width/16;
    	Macroblock *currMB = &mb_data[mb_nr];
    	img->current_slice_nr = -1;     // jlzheng 6.30
	currentbitoffset = currStream->frame_bitoffset;    // jlzheng 6.30
	currStream->frame_bitoffset = 0;   // jlzheng 6.30
	if ((Buf = (char*)calloc (MAX_CODED_FRAME_SIZE , sizeof(char))) == NULL)
		no_mem_exit("GetAnnexbNALU: Buf");	 //jlzheng

	img->cod_counter=-1;
	
	
  while (img->current_mb_nr<img->PicSizeInMbs) // loop over macroblocks
  {
      //decode slice header   jlzheng 6.30
	  if( img->current_mb_nr%mb_width ==0 ) 
	  {
		  if(img->cod_counter<=0)
		  {
			  if(checkstartcode())
			  {
				  GetOneUnit(Buf,&startcodepos,&length);
				  SliceHeader(Buf,startcodepos,length);
				  img->current_slice_nr++;
				  img->cod_counter = -1; // Yulj 2004.07.15
			  }
		  }
	  }  //decode slice header 

	if(img->current_mb_nr == 0)
    img->current_slice_nr = 0;
	mb_data[img->current_mb_nr].slice_nr = img->current_slice_nr;   // jlzheng 6.30
		
#if TRACE
    // Here was the slice nr from the mb_data used.  This slice number is only set after 
    // the reconstruction of an MB and hence here not yet valid
    
    fprintf(p_trace,"\n*********** Pic: %i (I/P) MB: %i Slice: %i Type %d **********\n", img->tr, img->current_mb_nr, img->current_slice_nr, img->type);
#endif
    
    // Initializes the current macroblock
    start_macroblock(img,inp);
	img->current_mb_nr_fld = img->current_mb_nr;
    // Get the syntax elements from the NAL
    read_one_macroblock(img,inp);
    // decode one macroblock
    decode_one_macroblock(img,inp);
    img->current_mb_nr++;

  }

  free(Buf);
  DeblockFrame (img, imgY, imgUV);
	
}


void bot_field(struct img_par *img,struct inp_par *inp)
{

  	unsigned char *Buf;
	int startcodepos,length; 
	const int mb_nr = img->current_mb_nr;
	int mb_width = img->width/16;
        Macroblock *currMB = &mb_data[mb_nr];
        img->current_slice_nr = -1;    // jlzheng 6.30
	currentbitoffset = currStream->frame_bitoffset;    // jlzheng 6.30
	currStream->frame_bitoffset = 0;   // jlzheng 6.30
	if ((Buf = (char*)calloc (MAX_CODED_FRAME_SIZE , sizeof(char))) == NULL) 
		no_mem_exit("GetAnnexbNALU: Buf");	 //jlzheng

	img->cod_counter=-1;
	
	
  while (img->current_mb_nr<img->PicSizeInMbs) // loop over macroblocks
  {
	  //decode slice header   jlzheng 6.30
	  if( img->current_mb_nr%mb_width ==0 ) 
	  {
		  if(img->cod_counter<=0)
		  {
			  if(checkstartcode())
			  {
				  GetOneUnit(Buf,&startcodepos,&length);
				  SliceHeader(Buf,startcodepos,length);
				  img->current_slice_nr++;
				  img->cod_counter = -1; // Yulj 2004.07.15
			  }
		  }
	  }  //decode slice header 

    if(img->current_mb_nr == 0)
    img->current_slice_nr = 0;
	mb_data[img->current_mb_nr].slice_nr = img->current_slice_nr;   // jlzheng 6.30

#if TRACE
    // Here was the slice nr from the mb_data used.  This slice number is only set after 
    // the reconstruction of an MB and hence here not yet valid
	
    fprintf(p_trace,"\n*********** Pic: %i (I/P) MB: %i Slice: %i Type %d **********\n", img->tr, img->current_mb_nr, img->current_slice_nr, img->type);
#endif
    
    // Initializes the current macroblock
    start_macroblock(img,inp);
	img->current_mb_nr_fld = img->current_mb_nr + img->PicSizeInMbs;
    // Get the syntax elements from the NAL
    read_one_macroblock(img,inp);
    // decode one macroblock
    decode_one_macroblock(img,inp);
    img->current_mb_nr++;
 }

  free(Buf);
  DeblockFrame (img, imgY, imgUV);
	
}

/*!
************************************************************************
* \brief
*    Generate a frame from top and bottom fields
************************************************************************
*/
void combine_field(struct img_par *img)
{
  int i;
	
  for (i=0; i<img->height; i++)
  {
    memcpy(imgY_frm[i*2], imgY_top[i], img->width);     // top field
    memcpy(imgY_frm[i*2 + 1], imgY_bot[i], img->width); // bottom field
  }
	
  for (i=0; i<img->height_cr; i++)
  {
    memcpy(imgUV_frm[0][i*2], imgUV_top[0][i], img->width_cr);
    memcpy(imgUV_frm[0][i*2 + 1], imgUV_bot[0][i], img->width_cr);
    memcpy(imgUV_frm[1][i*2], imgUV_top[1][i], img->width_cr);
    memcpy(imgUV_frm[1][i*2 + 1], imgUV_bot[1][i], img->width_cr);
  }
}


/*
*************************************************************************
* Function:Prepare field and frame buffer after frame decoding
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void frame_postprocessing(struct img_par *img)
{
  if((img->number)&&(img->type==I_IMG || img->type == P_IMG))
  {
    nextP_tr_frm = nextP_tr;
  }

  //pic dist by Grandview Semi. @ [06-07-20 15:25]
  if (img->type==I_IMG || img->type == P_IMG) {
	img->PrevPicDistanceLsb = img->pic_distance;
	img->PicDistanceMsb = img->CurrPicDistanceMsb;
  }
}

/*
*************************************************************************
* Function:
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
static void rotate_buffer ()
{
  Frame *f;
  
  f = fb->picbuf_short[1];
  fb->picbuf_short[1] = fb->picbuf_short[0];
  fb->picbuf_short[0] = f;
  
  mref[0] = fb->picbuf_short[0]->mref;
  mcef[0] = fb->picbuf_short[0]->mcef;
  mref[1] = fb->picbuf_short[1]->mref;
  mcef[1] = fb->picbuf_short[1]->mcef;
}


/*!
 ************************************************************************
 * \brief
 *    Store information for use in B picture
 ************************************************************************
 */
void store_field_MV(struct img_par *img)
{
  int i, j;

  if(img->type!=B_IMG)
  {
    if (img->picture_structure != FRAME)
    {
      for (i=0 ; i<img->width/8 ; i++)
      {
        for (j=0 ; j<img->height/16 ; j++)
        {
          img->mv_frm[i+4][2*j][0] = img->mv_frm[i+4][2*j+1][0] = img->mv_top[i+4][j][0];
          img->mv_frm[i+4][2*j][0] = img->mv_frm[i+4][2*j+1][0] = img->mv_top[i+4][j][0];
          img->mv_frm[i+4][2*j][1] = img->mv_frm[i+4][2*j+1][1] = img->mv_top[i+4][j][1]*2;
          img->mv_frm[i+4][2*j][1] = img->mv_frm[i+4][2*j+1][1] = img->mv_top[i+4][j][1]*2;
         

          if (refFrArr_top[j][i] == -1)
          {
            refFrArr_frm[2*j][i] = refFrArr_frm[2*j+1][i] = -1;
          }
          else
          {
            refFrArr_frm[2*j][i] = refFrArr_frm[2*j+1][i] = (int)(refFrArr_top[j][i]/2);
          }
        }
      }
    }
    else
    {
      for (i=0 ; i<img->width/8; i++)
      {
        for (j=0 ; j<img->height/16 ; j++)
        {
          img->mv_top[i+4][j][0] = img->mv_bot[i+4][j][0] = (int)(img->mv_frm[i+4][2*j][0]);
          img->mv_top[i+4][j][1] = img->mv_bot[i+4][j][1] = (int)((img->mv_frm[i+4][2*j][1])/2);

            if (refFrArr_frm[2*j][i] == -1)
            {
              refFrArr_top[j][i] = refFrArr_bot[j][i] = -1;
            }
            else
            {
             // refFrArr_top[j][i] = refFrArr_bot[j][i] = refFrArr_frm[2*j][i]*2;
				 refFrArr_top[j][i] = refFrArr_frm[2*j][i]*2;
              refFrArr_bot[j][i] = refFrArr_frm[2*j][i]*2 + 1;
                     //by oliver 0512
            }
        }
      }
    }
  }
}

⌨️ 快捷键说明

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