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

📄 image.c

📁 davinci avs.......................................................
💻 C
📖 第 1 页 / 共 3 页
字号:
                }
            }
            for (j = 0; j < BLOCK_SIZE + 2; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += tmp_res[j + y + 3][i] * COEF_HALF_v[y + 3];
                    }
                    //tmp_res_2[2 * j][i] = max(0, min(255, (result + 32) / 64));
                    tmp_res_2[2 * j][i] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));
                    //tmp_res_2[2 * j + 1][i] =  max(0, min(255, (tmp_res[j + 2][i] + 4) / 8));
                    tmp_res_2[2 * j + 1][i] =  tmp_res[j + 4][i];
                }
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -1; y < 3; y++)
                    {
                        if(dy == 1)//e
                        {
                            result += tmp_res_2[2 * j + y + 1][i] * COEF_QUART[y + 1];
                        }
                        else//l
                        {
                            result += tmp_res_2[2 * j + y + 2][i] * COEF_QUART[3-(y + 1)];
                        }
                    }
                    //block[i][j] = max(0, min(255, (result + 8) / 16));
                    block[i][j] = max(0, min(255, (result + iWeight1_4 / 2) >>1));
                }
            }
        }
        else
        {//Diagonal 1/4 position : d, f, k and m
            for (j = -3; j < BLOCK_SIZE + 5; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, x = -3; x < 5; x++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j))]
                                         [max(0, min(maxold_x, x_pos + i + x))] 
                                  * COEF_HALF_h[x + 3];
                    }
                    tmp_res[j + 3][i] = max(0, min(255, (result + iWeight1_2_h / 2) >>6));//max(0, min(255, (result+4)/8));
                    //tmp_res[j + 1][i] = max(0, min(255, (result + iWeight1_2 / 2) / iWeight1_2));
                }       
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += tmp_res[j + y + 3][i] * COEF_HALF_v[y + 3];
                    }
                    //tmp_res_2[j][i] = max(0, min(255, (result + 32) / 64));
                    tmp_res_2[j][i] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));
                }
            }   
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    if( (dx == 1) && (dy == 1) )//d
                    {
                        result = tmp_res_2[j][i] + ref_pic[max(0, min(maxold_y, y_pos + j))]
                                                          [max(0, min(maxold_x, x_pos + i))];
                    }
                    else if( (dx == 3) && (dy == 1) )//f
                    {
                        result = tmp_res_2[j][i] + ref_pic[max(0, min(maxold_y, y_pos + j))]
                                                          [max(0, min(maxold_x, x_pos + i + 1))];
                    }
                    else if ((dx == 1) && (dy == 3))//k
                    {
                        result = tmp_res_2[j][i] + ref_pic[max(0, min(maxold_y, y_pos + j + 1))]
                                                          [max(0, min(maxold_x, x_pos + i))];
                    }
                    else if((dx == 3) && (dy == 3))//m
                    {
                        result = tmp_res_2[j][i] + ref_pic[max(0, min(maxold_y, y_pos + j + 1))]
                                                          [max(0, min(maxold_x, x_pos + i + 1))];
                    }
                    block[i][j] = max(0, min(255, (result + 1) / 2));
                }
            }
        }
    }//if (dx == 0 && dy == 0) else
}

/*!
************************************************************************
* \brief
*    Initializes the parameters for a new frame
************************************************************************
*/
void init_frame()   //qwang 2004-3-10
{
	int i,j;

	for(i=0;i<(pgImage->width/BLOCK_SIZE+2);i++)          // set edge to -1, indicate nothing to predict from
	for(j=0;j<(pgImage->height/BLOCK_SIZE+2);j++)
	{
		pgImage->ipredmode[i][j]=-1;
	}

	
	for(i=0; i<pgImage->max_mb_nr; i++)
	{
		mb_data[i].slice_nr = -1; 
	}
	

	pgImage->current_mb_nr = 0;
	imgY =  current_frame[0];
	imgUV = &current_frame[1];

	pgImage->current_slice_nr=-1;//WJP FOR SLICE_HEADER 050320
}
/*!
************************************************************************
* \brief
*    decodes one picture
************************************************************************
*/
void decode_picture_data()
{
	//WJP FOR SLICE
	//int tmp;
	int pos_of_NSLE_SC = 1;
	int next_slice_start_pos=0;//WJP FOR SLICE_HEADER 050320
	
	int slice_delta_qp;//WJP FOR SLICE_HEADER 050320
	int first_mb_nr_in_slice;//WJP FOR SLICE_HEADER 050320

 

  pgImage->cod_counter=-1;
  
	while (pgImage->current_mb_nr<pgImage->PicSizeInMbs) // loop over macroblocks
	{

    //decode_slice_header();
   if(pos_of_NSLE_SC!=0)
   {
		if(pgImage->current_mb_nr == next_slice_start_pos) 
		{
#if TRACE
    fprintf(p_trace,"\n");
    tracebits2("start_code_prefix",24,0x01);
#endif
     	pgImage->current_slice_nr++;
			//slice_nr=pgImage->current_slice_nr;
      
      pgImage->cod_counter=-1;
			
			pos_of_NSLE_SC = Position_of_Slice_in_Picbuff[pgImage->current_slice_nr + 1];

#if TRACE
     // fprintf(p_trace,"ANNEX B NALU, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d,\n",
     //         (pos_of_NSLE_SC+1),0,1,3);  /* temporary */
#endif


			next_slice_start_pos = search_ue_code(pos_of_NSLE_SC*8);

		  currStream->frame_bitoffset = Position_of_Slice_in_Picbuff[pgImage->current_slice_nr]*8;

			first_mb_nr_in_slice = ue_v("SliceHeader: first_mb_nr_in_slice");   

			if(!fixed_picture_qp_flag)
			{
				fixed_slice_qp_flag = u_v(1,"SliceHeader: fixed_slice_qp");
				slice_delta_qp = se_v("SliceHeader: slice_delta_qp");		          
        previous_qp = pgImage->qp + slice_delta_qp; // zhan ma 0714
			}
      else
      {
        fixed_slice_qp_flag = 1;      // zhan ma 0714
        slice_delta_qp = 0;
      }

     
     if(!pgImage->loop_filter_disable_flag) 
			{
				pgImage->disable_loop_filter_slice_flag = u_v(1,"SliceHeader: disable_loop_filter_slice_flag");
        pgImage->SliceLFDisbaleFlag[pgImage->current_slice_nr] = pgImage->disable_loop_filter_slice_flag;
			}

     //fprintf(stdout,"%2d",pgImage->SliceLFDisbaleFlag[pgImage->current_slice_nr]);

     CheckSliceHeaderValid(first_mb_nr_in_slice,slice_delta_qp);   /* check slice header conformance*/
		}
	}

   
   /* slice data decoding */
   decode_slice_data();
   


  //if (pgImage->current_mb_nr == (next_slice_start_pos))
  //   DecodeTrailingBits1(currStream,pos_of_NSLE_SC+1);
	  
#ifdef _ISOLATED_REGION_
    if(iREGenable)
    {
      if (pgImage->type == P_IMG)
      {
        int j, i;
        if (iREGmap[pgImage->mb_y][pgImage->mb_x] != 2)
          for (j = 0; j < 4; j++)
            for (i = 0; i < 4; i++)
              pgImage->ipredmode[pgImage->mb_x * 4 + i + 1][pgImage->mb_y * 4 + j + 1] = -1;
       }
    }
#endif // _ISOLATED_REGION_
//fprintf(stdout,"%2d",pgImage->disable_loop_filter_slice_flag);

  } //end of MB-loop
}

 /*! 
 *************************************************************************************
 * \brief : 
 *    decoding slice header including first_mb_in_slice etc.
 * \author :
 *    Ma Zhan
 *************************************************************************************
 */
void decode_slice_header()
{


}

 /*! 
 *************************************************************************************
 * \brief : 
 *    decoding slice header including first_mb_in_slice etc.
 * \author :
 *    Ma Zhan
 *************************************************************************************
 */
void decode_slice_data()
{
#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", pgImage->number, pgImage->current_mb_nr, pgImage->current_slice_nr, pgImage->type);
	fflush(p_trace);
#endif
    
	// Initializes the current macroblock
	start_macroblock();

	// Get the syntax elements from the NAL

	read_one_macroblock();

	// decode one macroblock
	decode_one_macroblock();
  
	

	pgImage->current_mb_nr++;
  previous_qp = pgcurrMB->qp;
}

 /*! 
 *************************************************************************************
 * \brief : 
 *    Write decoded frame to output file
 *************************************************************************************
 */
void write_frame( FILE *p_out)          //!< filestream to output file
{
  int i,j;

  for(i=0;i<pgImage->height;i++)
    for(j=0;j<pgImage->width;j++)
    {
      fputc(imgY[i][j],p_out);
    }

  for(i=0;i<pgImage->height_cr;i++)
    for(j=0;j<pgImage->width_cr;j++)
    {
      fputc(imgUV[0][i][j],p_out);
    }

  for(i=0;i<pgImage->height_cr;i++)
    for(j=0;j<pgImage->width_cr;j++)
    {
      fputc(imgUV[1][i][j],p_out);
    }

  fflush(p_out);

}























⌨️ 快捷键说明

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