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

📄 main.cpp

📁 JMVM MPEG MVC/3DAV 测试平台 国际通用标准
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  
  int   iStage              = 0;
  int   temporal_stages     = 0;
  int   skip_at_start       = 0;
  int   number_frames       = (1<<30);
  FILE* input_file          = 0;
  FILE* output_file         = 0;
  FILE* crop_file           = 0;
  int   method              = 0;
  bool  resample            = false;
  bool  upsample            = false;
  bool  crop_init           = false;
  bool  phase_init          = false;
  bool  method_init         = false;
  bool  crop_file_init      = false;
  int   sequence_length     = 0;
  int   skip_between        = 0;
  int   i;
  int   frame_width;
  int   frame_height;
  
  int           written, skip;
  YuvFrame      cFrame;
  
  print_usage_and_exit ((argc<7||argc>22), argv[0],"number of arguments");
  rp->m_iInWidth        = atoi  ( argv[1] );
  rp->m_iInHeight       = atoi  ( argv[2] );
  input_file            = fopen ( argv[3], "rb" );
  rp->m_iGlobWidth      = atoi  ( argv[4] );
  rp->m_iGlobHeight     = atoi  ( argv[5] );
  output_file           = fopen ( argv[6], "wb" );
  
  print_usage_and_exit ((input_file == NULL||output_file == NULL),argv[0],"failed to open file");
  print_usage_and_exit(((rp->m_iInWidth>rp->m_iGlobWidth&&rp->m_iInHeight<rp->m_iGlobHeight)||(rp->m_iInWidth<rp->m_iGlobWidth&&rp->m_iInHeight>rp->m_iGlobHeight)),argv[0],"mixed Upsample and Downsample");
  
  fseek(  input_file, 0, SEEK_END );
  sequence_length = (ftell(input_file)/(3*rp->m_iInWidth*rp->m_iInHeight/2));
  fseek(  input_file, 0, SEEK_SET );
  
  i = 7;
  while (i<argc)
  {
    if (strcmp(argv[i], "-crop")==0)
    {
      print_usage_and_exit ((method == 1), argv[0], "No crop in Dyadic method");
      print_usage_and_exit (((method == 2)&&(rp->m_iInWidth<rp->m_iGlobWidth)), argv[0], "No crop only while upsampling");
            
      print_usage_and_exit ((crop_init||argc<(i+3)||argc==(i+4)||argc==(i+5)),argv[0],"Error in crop parameters");
      crop_init = true;
      i++;
      print_usage_and_exit (!(atoi(argv[i])==0||atoi(argv[i])==1),argv[0],"Wrong crop type");
      rp->m_iExtendedSpatialScalability = (atoi(argv[i]))+1;
      print_usage_and_exit(((rp->m_iExtendedSpatialScalability!=1)&&(rp->m_iExtendedSpatialScalability!=2)),argv[0],"Wrong crop type");
      i++;
      if (rp->m_iExtendedSpatialScalability==1)
      {
        rp->m_iPosX = atoi  ( argv[i] );
        i++;
        rp->m_iPosY = atoi  ( argv[i] );
        i++;
        rp->m_iOutWidth   = atoi  ( argv[i] );
        i++;
        rp->m_iOutHeight  = atoi  ( argv[i] );
        i++;
        print_usage_and_exit ((rp->m_iPosX&1||rp->m_iPosY&1||rp->m_iOutWidth&1||rp->m_iOutHeight&1), argv[0], "Crop parameters must be event values");
        print_usage_and_exit (((method==2)&&((rp->m_iOutWidth != min(rp->m_iInWidth, rp->m_iGlobWidth))||(rp->m_iOutHeight != min(rp->m_iInHeight, rp->m_iGlobHeight)))), argv[0], "Crop dimensions must be the same as the minimal dimensions");
        print_usage_and_exit ((rp->m_iOutWidth>max(rp->m_iInWidth,rp->m_iGlobWidth)||rp->m_iOutHeight>max(rp->m_iInHeight,rp->m_iGlobHeight)||rp->m_iOutWidth<min(rp->m_iInWidth,rp->m_iGlobWidth)||rp->m_iOutHeight<min(rp->m_iInHeight,rp->m_iGlobHeight)),argv[0],"wrong crop window size");
        print_usage_and_exit (!((rp->m_iPosX+rp->m_iOutWidth)<=max(rp->m_iInWidth,rp->m_iGlobWidth)&&(rp->m_iPosY+rp->m_iOutHeight)<=max(rp->m_iInHeight,rp->m_iGlobHeight)),argv[0],"wrong crop window size and origin");
      }
      else
      {
        crop_file_init = true;
        crop_file = fopen ( argv[i], "rb" );
        i++;
        print_usage_and_exit ((crop_file == NULL),argv[0],"failed to open crop parameters file");
      }
    }
    else if (strcmp(argv[i], "-phase")==0)
    {
      print_usage_and_exit ((method != 0), argv[0], "Phase only in normative resampling");
           
      print_usage_and_exit ((phase_init||argc<(i+5)),argv[0],"wrong number of phase parameters");
      i++;
      phase_init = true;
      rp->m_iBaseChromaPhaseX  = atoi  ( argv[i] );
      i++;
      rp->m_iBaseChromaPhaseY  = atoi  ( argv[i] );
      i++;
      rp->m_iChromaPhaseX = atoi  ( argv[i] );
      i++;
      rp->m_iChromaPhaseY = atoi  ( argv[i] );
      i++;
      print_usage_and_exit ((rp->m_iBaseChromaPhaseX>1||rp->m_iBaseChromaPhaseX<-1||rp->m_iBaseChromaPhaseY>1||rp->m_iBaseChromaPhaseY<-1||rp->m_iChromaPhaseX>1||rp->m_iChromaPhaseX<-1||rp->m_iChromaPhaseY>1||rp->m_iChromaPhaseY<-1),argv[0],"Wrong phase parameters (range : [-1, 1])");
    }
    else if (i == 7)
    {
      method_init = true;
      method = atoi  ( argv[i] );
      i++;
      print_usage_and_exit ((method<0||method>4),argv[0],"wrong method");
      if (method>2)
      {
        fprintf( stderr, "\nNot normative, nor dyadic resampling or not crop only\n");
        print_usage_and_exit((rp->m_iInWidth>rp->m_iGlobWidth||rp->m_iInHeight>rp->m_iGlobHeight),argv[0],"Wrong method for downsampling");
      }
      if (!(method == 2))
      {
        resample = true;
        if (rp->m_iInWidth < rp->m_iGlobWidth)
        {
          upsample = true;
        }
      }
      if (method==1)
      {
        if (upsample)
        {
          int div = rp->m_iGlobWidth / rp->m_iInWidth;
          if      (div == 1) iStage = 0;
          else if (div == 2) iStage = 1;
          else if (div == 4) iStage = 2;
          else if (div == 8) iStage = 3;
          else { print_usage_and_exit(true, argv[0], "ratio not supported for dyadic upsampling method"); }
          print_usage_and_exit((((rp->m_iGlobWidth / rp->m_iInWidth)*rp->m_iInWidth)!=rp->m_iGlobWidth), argv[0],"ratio is not dyadic");
          print_usage_and_exit((rp->m_iInHeight*div != rp->m_iGlobHeight), argv[0], "Not the same ratio for Height and Width in dyadic mode");
        }
        else
        {
          int div = rp->m_iInWidth / rp->m_iGlobWidth;
          if      (div == 1) {iStage = 0; fprintf( stderr, "\nNo resampling in dyadic method\n");}
          else if (div == 2)  iStage = 1;
          else if (div == 4)  iStage = 2;
          else if (div == 8)  iStage = 3;
          else { print_usage_and_exit(true, argv[0], "ratio not supported for dyadic upsampling method"); }
          print_usage_and_exit((((rp->m_iInWidth / rp->m_iGlobWidth)*rp->m_iGlobWidth)!=rp->m_iInWidth), argv[0],"ratio is not dyadic");
          print_usage_and_exit((rp->m_iGlobHeight*div != rp->m_iInHeight), argv[0], "Not the same ratio for Height and Width in dyadic mode");
        }
      }
    }
    else if (i == 8)
    {
      temporal_stages = atoi ( argv[i] );
      i++;
      print_usage_and_exit ((temporal_stages<0),argv[0],"Error in temporal stage");
    }
    else if (i == 9)
    {
      skip_at_start = atoi ( argv[i] );
      i++;
      print_usage_and_exit (((skip_at_start<0)||(skip_at_start>=sequence_length)),argv[0],"Error in number of frame to skip at start");
    }
    else if (i == 10)
    {
      number_frames = atoi ( argv[i] );
      i++;
      print_usage_and_exit ((number_frames<0),argv[0],"Error in number of frames");
    }
    else
    {
      print_usage_and_exit (true,argv[0]);
    }
  }
  
  if (!method_init)
  {
    resample = true;
    if (rp->m_iInWidth < rp->m_iGlobWidth)
    {
      upsample = true;
    }
  }
  
  if (!crop_init)
  {
    rp->m_iOutWidth = max(rp->m_iInWidth,rp->m_iGlobWidth);
    rp->m_iOutHeight = max(rp->m_iInHeight,rp->m_iGlobHeight);
  }
  
  if (method == 2)
  {
    if (!crop_init)
    {
      rp->m_iOutWidth = min(rp->m_iInWidth,rp->m_iGlobWidth);
      rp->m_iOutHeight = min(rp->m_iInHeight,rp->m_iGlobHeight);
      fprintf( stderr, "\nCrop parameters set to default 0,0,min_width,min_height\n");
    }
  }
  
  skip_between    = ( 1 << temporal_stages ) - 1;
  
  if ( number_frames > ((sequence_length - skip_at_start+((1<<temporal_stages)-1))>>temporal_stages) )
  {
    if (number_frames != (1 << 30))
    {
      fprintf( stderr, "\nWrong number of frames\n");
    }
    number_frames   = ((sequence_length - skip_at_start+((1<<temporal_stages)-1))>>temporal_stages);
  }
    
  frame_width = (rp->m_iInWidth > rp->m_iGlobWidth) ? rp->m_iInWidth : rp->m_iGlobWidth;
  frame_height = (rp->m_iInHeight > rp->m_iGlobHeight) ? rp->m_iInHeight : rp->m_iGlobHeight;  
    
  createFrame( &cFrame, frame_width, frame_height );
  cDownConvert.init( frame_width, frame_height );
  
  long start_time = clock();
  
  for( skip = skip_at_start, rp->m_iPOC = 0, written = 0; ((rp->m_iPOC < sequence_length)&&(written < number_frames)); rp->m_iPOC++, skip = skip_between )
  {
    fseek( input_file, skip*rp->m_iInWidth*rp->m_iInHeight*3/2, SEEK_CUR);
    rp->m_iPOC += skip;
    
    if ((rp->m_iPOC < sequence_length)&&(written < number_frames))
    {
      clearFrame      ( &cFrame );
      
      readFrame       ( &cFrame, input_file, rp->m_iInWidth, rp->m_iInHeight );      
      
      if (crop_file_init&&rp->m_iExtendedSpatialScalability==2)
      {
        updateCropParametersFromFile(rp, crop_file, method, argv[0]);
      }
      if ((rp->m_iOutWidth==min(rp->m_iInWidth, rp->m_iGlobWidth))&&(rp->m_iOutHeight==min(rp->m_iInHeight, rp->m_iGlobHeight)))
      {
        resample = false;
      }
      else
      {
        resample = true;
      }
      
      if ((!resample) && (!upsample))
      {
        cDownConvert.crop(cFrame.lum.data, cFrame.lum.width, cFrame.cb.data, cFrame.cb.width, cFrame.cr.data, cFrame.cr.width, rp);      
      }
      else
      {
        if (upsample)
        {
          switch (method)
          {
          case 1:
            {
              FILTER_UP
#ifdef OLD_DYADIC_UPSAMPLE
              int* piFilter_chroma=pifilter;
#else
              FILTER_UP_CHROMA
#endif
              cDownConvert.upsample(cFrame.lum.data, cFrame.lum.width, cFrame.cb.data, cFrame.cb.width, cFrame.cr.data, cFrame.cr.width, rp, iStage, piFilter, piFilter_chroma);
              break;
            }
          case 0:
          case 3:
          case 4:
            {
              cDownConvert.upsample_non_dyadic(cFrame.lum.data, cFrame.lum.width, cFrame.cb.data, cFrame.cb.width, cFrame.cr.data, cFrame.cr.width, rp, method);
              break;
            }
          default:
            {
              print_usage_and_exit (true, argv[0], "Wrong upsample");
            }
          }
        }
        if (!upsample)
        {
          switch (method)
          {
          case 0:
            {
              cDownConvert.downsample3(cFrame.lum.data, cFrame.lum.width, cFrame.cb.data, cFrame.cb.width, cFrame.cr.data, cFrame.cr.width, rp);
              break;
            }
          case 1:
            {
              FILTER_DOWN
              cDownConvert.downsample(cFrame.lum.data, cFrame.lum.width, cFrame.cb.data, cFrame.cb.width, cFrame.cr.data, cFrame.cr.width, rp, iStage, piFilter);
              break;
            }
          default:
            {
              print_usage_and_exit (true, argv[0], "Wrong downsample");
            }
          }
        }
      }
      writeFrame ( &cFrame, output_file,  rp->m_iGlobWidth, rp->m_iGlobHeight );
      fprintf( stderr, "\r%6d frames converted", ++written );
    }
  }
  long end_time = clock();
  
  deleteFrame( &cFrame     );
  fclose     ( input_file  );
  fclose     ( output_file );
  
  if (crop_file_init)
  {
    fclose   ( crop_file   );
  }
  
  fprintf(stderr, "\n" );
  double delta_in_s = (double)(end_time - start_time) / CLOCKS_PER_SEC;
  fprintf(stderr, "in %.2lf seconds => %.0lf ms/frame\n", delta_in_s, delta_in_s/written*1000);

  return 0;
}

⌨️ 快捷键说明

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