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

📄 main.cpp

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 CPP
📖 第 1 页 / 共 3 页
字号:
           
      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 (strcmp(argv[i], "-resample_mode")==0)
    {
      print_usage_and_exit ((method != 0), argv[0], "resample_mode only in normative resampling");
           
      resample = true;
      i++;
      resample_mode     = atoi  ( argv[i] );
      if (resample_mode > 5 || resample_mode < 0) resample_mode = 0;
      i++;
    }      
    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;
					downsample_flg = !upsample;//TMM_INTERLACE
        }
      }
      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;
			downsample_flg = !upsample;//TMM_INTERLACE
    }
  }
  
  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*2, frame_height*2 );
  cDownConvert.init( frame_width*2, frame_height*2 );
  
  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 )
  {
    for( int num_skip = skip; num_skip > 0; num_skip-- )
    {
      fseek( input_file, 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 );
      
      if(method)
      readFrame       ( &cFrame, input_file, rp->m_iInWidth, rp->m_iInHeight );      
      else
        ess_readPic   ( &cFrame, input_file, rp->m_iInWidth, rp->m_iInHeight, downsample_flg, resample_mode );
      
      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))&&
           method!=0)
      {
        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:
            {
              ess_resamplePic ( &cFrame, cDownConvert, rp->m_iInWidth, rp->m_iInHeight, rp->m_iGlobWidth, rp->m_iGlobHeight,
                                rp->m_iPosX, rp->m_iPosY, rp->m_iOutWidth, rp->m_iOutHeight, rp->m_iBaseChromaPhaseX, rp->m_iChromaPhaseY,
                                rp->m_iChromaPhaseX, rp->m_iChromaPhaseY, downsample_flg, resample_mode);
              break;
            }
          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);
              ess_resamplePic ( &cFrame, cDownConvert, rp->m_iInWidth, rp->m_iInHeight, rp->m_iGlobWidth, rp->m_iGlobHeight,
                                rp->m_iPosX, rp->m_iPosY, rp->m_iOutWidth, rp->m_iOutHeight, rp->m_iBaseChromaPhaseX, rp->m_iChromaPhaseY,
                                rp->m_iChromaPhaseX, rp->m_iChromaPhaseY, downsample_flg, resample_mode);
              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");
            }
          }
        }
      }

      if(method!=0)
      writeFrame ( &cFrame, output_file,  rp->m_iGlobWidth, rp->m_iGlobHeight );
      else
      ess_writePic ( &cFrame, output_file, rp->m_iGlobWidth, rp->m_iGlobHeight, downsample_flg, resample_mode );

      if(resample_mode>3){
        if(downsample_flg){
          fseek( input_file, skip*rp->m_iInWidth*rp->m_iInHeight*3/2, SEEK_CUR);
          rp->m_iPoc += skip;
       //   written++;
        }
        if (crop_file_init&&rp->m_iExtendedSpatialScalability==2)
        {
          updateCropParametersFromFile(rp, crop_file, method, argv[0]);
        }
        ess_readPic   ( &cFrame, input_file, rp->m_iInWidth, rp->m_iInHeight, downsample_flg, resample_mode+2 );
        ess_resamplePic ( &cFrame, cDownConvert, rp->m_iInWidth, rp->m_iInHeight, rp->m_iGlobWidth, rp->m_iGlobHeight,
                          rp->m_iPosX, rp->m_iPosY, rp->m_iOutWidth, rp->m_iOutHeight, rp->m_iBaseChromaPhaseX, rp->m_iChromaPhaseY,
                          rp->m_iChromaPhaseX, rp->m_iChromaPhaseY, downsample_flg, resample_mode+2 );
        ess_writePic ( &cFrame, output_file, rp->m_iGlobWidth, rp->m_iGlobHeight, downsample_flg, resample_mode+2 );
      }

      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);
  //TMM_FIX
  delete rp;

  return 0;
}

⌨️ 快捷键说明

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