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

📄 main.cpp

📁 JVT-Z203_jsvm.rar
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      i++;
      cRP.m_iExtendedSpatialScalability = atoi( argv[i++] ) + 1;
      print_usage_and_exit( cRP.m_iExtendedSpatialScalability != 1 && cRP.m_iExtendedSpatialScalability != 2, argv[0], "unsupported cropping mode" );
      if( cRP.m_iExtendedSpatialScalability == 1 )
      {
        cRP.m_iLeftFrmOffset      = atoi( argv[i++] );
        cRP.m_iTopFrmOffset       = atoi( argv[i++] );
        cRP.m_iScaledRefFrmWidth  = atoi( argv[i++] );
        cRP.m_iScaledRefFrmHeight = atoi( argv[i++] );
        print_usage_and_exit( cRP.m_iLeftFrmOffset     & 1 || cRP.m_iTopFrmOffset       & 1,                                              argv[0], "cropping parameters must be even values" );
        print_usage_and_exit( cRP.m_iScaledRefFrmWidth & 1 || cRP.m_iScaledRefFrmHeight & 1,                                              argv[0], "cropping parameters must be even values" );
        print_usage_and_exit( resamplingMethod == 2 && cRP.m_iScaledRefFrmWidth  != min( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),  argv[0], "crop dimensions must be the same as the minimal dimensions" );
        print_usage_and_exit( resamplingMethod == 2 && cRP.m_iScaledRefFrmHeight != min( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),  argv[0], "crop dimensions must be the same as the minimal dimensions" );
        print_usage_and_exit( cRP.m_iScaledRefFrmWidth  > max( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),                            argv[0], "wrong crop window size" );
        print_usage_and_exit( cRP.m_iScaledRefFrmHeight > max( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),                            argv[0], "wrong crop window size" );
        print_usage_and_exit( cRP.m_iScaledRefFrmWidth  < min( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),                            argv[0], "wrong crop window size" );
        print_usage_and_exit( cRP.m_iScaledRefFrmHeight < min( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),                            argv[0], "wrong crop window size" );
        print_usage_and_exit( cRP.m_iLeftFrmOffset + cRP.m_iScaledRefFrmWidth  > max( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),     argv[0], "wrong crop window size and origin" );
        print_usage_and_exit( cRP.m_iTopFrmOffset  + cRP.m_iScaledRefFrmHeight > max( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),     argv[0], "wrong crop window size and origin" );
      }
      else
      {
        croppingParametersFile = fopen( argv[i++], "rb" );
        print_usage_and_exit( ! croppingParametersFile, argv[0], "failed to open cropping parameters file" );
      }
    }
    else if( ! strcmp( argv[i], "-phase" ) )
    {
      print_usage_and_exit( resamplingMethod != 0,          argv[0], "phases only supported in normative resampling" );
      print_usage_and_exit( phaseInitialized || argc < i+5, argv[0], "wrong number of phase parameters" );
      phaseInitialized = true;
      i++;
      cRP.m_iRefLayerChromaPhaseX = atoi( argv[i++] );
      cRP.m_iRefLayerChromaPhaseY = atoi( argv[i++] );
      cRP.m_iChromaPhaseX         = atoi( argv[i++] );
      cRP.m_iChromaPhaseY         = atoi( argv[i++] );
      print_usage_and_exit( cRP.m_iRefLayerChromaPhaseX > 0 || cRP.m_iRefLayerChromaPhaseX < -1, argv[0], "wrong phase x parameters (range : [-1, 0])");
      print_usage_and_exit( cRP.m_iRefLayerChromaPhaseY > 1 || cRP.m_iRefLayerChromaPhaseY < -1, argv[0], "wrong phase x parameters (range : [-1, 1])");
      print_usage_and_exit( cRP.m_iChromaPhaseX         > 0 || cRP.m_iChromaPhaseX         < -1, argv[0], "wrong phase x parameters (range : [-1, 0])");
      print_usage_and_exit( cRP.m_iChromaPhaseY         > 1 || cRP.m_iChromaPhaseY         < -1, argv[0], "wrong phase x parameters (range : [-1, 1])");
    }
    else if( ! strcmp( argv[i], "-resample_mode" ) )
    {
      print_usage_and_exit( resamplingMethod != 0,                    argv[0], "resample_mode only supported in normative resampling" );
      resampling      = true;
      i++;
      resamplingMode  = atoi( argv[i++] );
      print_usage_and_exit( resamplingMode < 0 || resamplingMode > 5, argv[0], "unsupported resample_mode" );
    }      
    else if (i == 7)
    {
      methodInitialized = true;
      resamplingMethod  = atoi( argv[i++] );
      print_usage_and_exit( resamplingMethod < 0 || resamplingMethod > 4, argv[0], "unsupported method" );
      if( resamplingMethod > 2 )
      {
        print_usage_and_exit( cRP.m_iRefLayerFrmWidth  > cRP.m_iFrameWidth,  argv[0], "method 3 and 4 are not supported for downsampling" );
        print_usage_and_exit( cRP.m_iRefLayerFrmHeight > cRP.m_iFrameHeight, argv[0], "method 3 and 4 are not supported for downsampling" );
      }
      if( resamplingMethod != 2 )
      {
        resampling  = true;
        upsampling  = ( cRP.m_iRefLayerFrmWidth < cRP.m_iFrameWidth );
      }
      if( resamplingMethod == 1 )
      {
        if( upsampling )
        {
          int      div  = cRP.m_iFrameWidth / cRP.m_iRefLayerFrmWidth;
          if     ( div == 1) numSpatialDyadicStages =  0;
          else if( div == 2) numSpatialDyadicStages =  1;
          else if( div == 4) numSpatialDyadicStages =  2;
          else if( div == 8) numSpatialDyadicStages =  3;
          else               numSpatialDyadicStages = -1;
          print_usage_and_exit( numSpatialDyadicStages < 0,                           argv[0], "ratio not supported for dyadic upsampling method" );
          print_usage_and_exit( div * cRP.m_iRefLayerFrmWidth  != cRP.m_iFrameWidth,  argv[0], "ratio is not dyadic in dyadic mode" );
          print_usage_and_exit( div * cRP.m_iRefLayerFrmHeight != cRP.m_iFrameHeight, argv[0], "different horizontal and vertical ratio in dyadic mode" );
        }
        else
        {
          int      div  = cRP.m_iRefLayerFrmWidth / cRP.m_iFrameWidth;
          if     ( div == 1) numSpatialDyadicStages =  0;
          else if( div == 2) numSpatialDyadicStages =  1;
          else if( div == 4) numSpatialDyadicStages =  2;
          else if( div == 8) numSpatialDyadicStages =  3;
          else               numSpatialDyadicStages = -1;
          print_usage_and_exit( numSpatialDyadicStages < 0,                           argv[0], "ratio not supported for dyadic downsampling method" );
          print_usage_and_exit( div * cRP.m_iFrameWidth  != cRP.m_iRefLayerFrmWidth,  argv[0], "ratio is not dyadic in dyadic mode" );
          print_usage_and_exit( div * cRP.m_iFrameHeight != cRP.m_iRefLayerFrmHeight, argv[0], "different horizontal and vertical ratio in dyadic mode" );
        }
      }
    }
    else if( i == 8 )
    {
      int TStages = atoi( argv[i++] );
      skipBetween = ( 1 << TStages ) - 1;
      print_usage_and_exit( TStages < 0,              argv[0], "negative number of temporal stages" );
    }
    else if( i == 9 )
    {
      skipAtStart = atoi( argv[i++] );
      print_usage_and_exit( skipAtStart < 0,          argv[0], "negative number of skipped frames at start" );
    }
    else if( i == 10 )
    {
      maxNumOutputFrames = atoi( argv[i++] );
      print_usage_and_exit( maxNumOutputFrames < 0 ,  argv[0], "negative number of output frames" );
    }
    else
    {
      print_usage_and_exit( true, argv[0], "error in command line parameters" );
    }
  }
  if( ! methodInitialized )
  {
    resampling  = true;
    upsampling  = ( cRP.m_iRefLayerFrmWidth < cRP.m_iFrameWidth );
  }
  if( ! croppingInitialized )
  {
    if( resamplingMethod == 2 )
    {
      cRP.m_iScaledRefFrmWidth  = min( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
      cRP.m_iScaledRefFrmHeight = min( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
    }
    else
    {
      cRP.m_iScaledRefFrmWidth  = max( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
      cRP.m_iScaledRefFrmHeight = max( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
    }
  }

  //===== set basic parameters for resampling control =====
  if( resamplingMethod == 0 )
  {
    if( resamplingMode == 1 )
    {
      cRP.m_bRefLayerFrameMbsOnlyFlag = false;
      cRP.m_bFrameMbsOnlyFlag         = false;
    }
    else if( resamplingMode == 2 || resamplingMode == 3 )
    {
      cRP.m_bFrameMbsOnlyFlag     = false;
      if( ! upsampling )
      {
        cRP.m_bFieldPicFlag       = true;
        cRP.m_bBotFieldFlag       = ( resamplingMode == 3 );
      }
    }
    else if( resamplingMode == 4 || resamplingMode == 5 )
    {
      cRP.m_bRefLayerFrameMbsOnlyFlag = false;
      cRP.m_bRefLayerFieldPicFlag     = true;
    }
  }

  //===== initialize classes =====
  YuvFrame    cFrame;
  DownConvert cDownConvert;
  {
    int maxWidth  = max( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
    int maxHeight = max( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
    createFrame( cFrame, maxWidth, maxHeight );
    cDownConvert.init(   maxWidth, maxHeight );
  }

  printf("Resampler\n\n");

  //===== loop over frames =====
  int   skip              = skipAtStart;
  int   writtenFrames     = 0;
  int   numInputFrames    = ( resamplingMode >= 4 && ! upsampling ? 2 : 1 );
  int   numOutputFrames   = ( resamplingMode >= 4 &&   upsampling ? 2 : 1 );
  bool  bFinished         = false;
  long  startTime         = clock();
  while( ! bFinished )
  {
    for( int inputFrame = 0; inputFrame < numInputFrames && ! bFinished; inputFrame++ )
    {
      //===== read input frame =====
      for( int numToRead = skip + 1; numToRead > 0 && ! bFinished; numToRead-- )
      {
        bFinished = ( readFrame( cFrame, inputFile, cRP.m_iRefLayerFrmWidth, cRP.m_iRefLayerFrmHeight, inputFrame != 0 ) != 0 );
      }
      skip = skipBetween;
      if( cRP.m_iExtendedSpatialScalability == 2 && ! bFinished )
      {
        updateCropParametersFromFile( cRP, croppingParametersFile, resamplingMethod, argv[0] );
      }

      //===== set resampling parameter =====
      if( resamplingMethod != 0 &&
          cRP.m_iScaledRefFrmWidth  == min( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ) &&
          cRP.m_iScaledRefFrmHeight == min( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight )   )
      {
        resampling = false;
      }
      else
      {
        resampling = true;
      }

      //===== resample input frame =====
      if( ! bFinished )
      {
        resampleFrame( cFrame, cDownConvert, cRP, resamplingMethod, resamplingMode, resampling, upsampling, inputFrame != 0 );
      }
    }

    //===== write output frame =====
    if( ! bFinished )
    {
      Bool bWriteTwoFrames = ( numOutputFrames == 2 && ( maxNumOutputFrames == 0 || writtenFrames + 1 < maxNumOutputFrames ) );
      writeFrame( cFrame, outputFile, cRP.m_iFrameWidth, cRP.m_iFrameHeight, bWriteTwoFrames );
      writtenFrames += ( bWriteTwoFrames ? 2 : 1 );
      bFinished      = ( maxNumOutputFrames != 0 && writtenFrames == maxNumOutputFrames );
      fprintf( stderr, "\r%6d frames converted", writtenFrames );
    }
  }
  long  endTime           = clock();

  deleteFrame( cFrame );
  fclose     ( inputFile );
  fclose     ( outputFile );
  if( croppingParametersFile )
  {
    fclose   ( croppingParametersFile );
  }

  fprintf( stderr, "\n" );
  double deltaInSecond = (double)( endTime - startTime) / (double)CLOCKS_PER_SEC;
  fprintf( stderr, "in %.2lf seconds => %.0lf ms/frame\n", deltaInSecond, deltaInSecond / (double)writtenFrames * 1000.0 );
  if( writtenFrames < maxNumOutputFrames )
  {
    fprintf( stderr, "\nNOTE: less output frames generated than specified!!!\n\n" );
  }
  return 0;
}

⌨️ 快捷键说明

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