📄 main.cpp
字号:
int top_first=(resample_mode==6 || resample_mode==1);
for(y=0; y<output_height/2; y++)
{
memcpy(f->lum.data+(2*y+top_first)*output_width, f->lum.data+buf_siz+y*output_width, output_width);
memcpy(f->lum.data+(2*y+1-top_first)*output_width, f->lum.data+buf_siz+buf_siz/2+y*output_width, output_width);
}
buf_siz >>= 2;
for(y=0; y<output_height/4; y++)
{
memcpy(f->cb.data+(2*y+top_first)*output_width/2, f->cb.data+buf_siz+y*output_width/2, output_width/2);
memcpy(f->cb.data+(2*y+1-top_first)*output_width/2, f->cb.data+buf_siz+buf_siz/2+y*output_width/2, output_width/2);
memcpy(f->cr.data+(2*y+top_first)*output_width/2, f->cr.data+buf_siz+y*output_width/2, output_width/2);
memcpy(f->cr.data+(2*y+1-top_first)*output_width/2, f->cr.data+buf_siz+buf_siz/2+y*output_width/2, output_width/2);
}
}
// write Y
int rsize = fwrite( f->lum.data, output_height, output_width, file );
if( rsize != output_width )
{
fprintf(stderr, "\nERROR: while reading from input file!\n\n");
exit(1);
}
// write Cb
rsize = fwrite( f->cb.data, output_height/2, output_width/2, file );
if( rsize != output_width/2 )
{
fprintf(stderr, "\nERROR: while reading from input file!\n\n");
exit(1);
}
// write Cr
rsize = fwrite( f->cr.data, output_height/2, output_width/2, file );
if( rsize != output_width/2 )
{
fprintf(stderr, "\nERROR: while reading from input file!\n\n");
exit(1);
}
}
void ess_resamplePic ( YuvFrame* pcFrame, DownConvert& rcDownConvert, int input_width, int input_height,
int output_width, int output_height, int crop_x0, int crop_y0, int crop_w, int crop_h,
int input_chroma_phase_shift_x, int input_chroma_phase_shift_y,
int output_chroma_phase_shift_x, int output_chroma_phase_shift_y,
bool ess_downsample_flg, int resample_mode)
{
if(ess_downsample_flg)
{
if(resample_mode==4 || resample_mode==7)
{
rcDownConvert.downsample_ver( pcFrame->lum.data, pcFrame->lum.width,
pcFrame->cb .data, pcFrame->cb .width,
pcFrame->cr .data, pcFrame->cr .width,
input_width, input_height, 1 );
}
else if(resample_mode==5 || resample_mode==6)
{
rcDownConvert.downsample_ver( pcFrame->lum.data, pcFrame->lum.width,
pcFrame->cb .data, pcFrame->cb .width,
pcFrame->cr .data, pcFrame->cr .width,
input_width, input_height, 0 );
}
rcDownConvert.downsample3( pcFrame->lum.data, pcFrame->cb.data, pcFrame->cr.data,
input_width, input_height, output_width, output_height,
crop_x0, crop_y0, crop_w, crop_h,
input_chroma_phase_shift_x, input_chroma_phase_shift_y,
output_chroma_phase_shift_x, output_chroma_phase_shift_y,
resample_mode, pcFrame->lum.height*pcFrame->lum.width/2);
}
else
{
rcDownConvert.upsample3( pcFrame->lum.data, pcFrame->cb.data, pcFrame->cr.data,
input_width, input_height, output_width, output_height,
crop_x0, crop_y0, crop_w, crop_h,
input_chroma_phase_shift_x, input_chroma_phase_shift_y,
output_chroma_phase_shift_x, output_chroma_phase_shift_y,
resample_mode, pcFrame->lum.height*pcFrame->lum.width/2);
if(resample_mode==2 || resample_mode==4 || resample_mode==7)
{
rcDownConvert.upsample_ver( pcFrame->lum.data, pcFrame->lum.width,
pcFrame->cb .data, pcFrame->cb .width,
pcFrame->cr .data, pcFrame->cr .width,
output_width, output_height/2,
crop_y0, crop_h, 1 );
}
else if(resample_mode==3 || resample_mode==5 || resample_mode==6)
{
rcDownConvert.upsample_ver( pcFrame->lum.data, pcFrame->lum.width,
pcFrame->cb .data, pcFrame->cb .width,
pcFrame->cr .data, pcFrame->cr .width,
output_width, output_height/2,
crop_y0, crop_h, 0 );
}
}
}
void print_usage_and_exit( int test, char* name, char* message = 0 )
{
if( test )
{
if( message )
{
fprintf ( stderr, "\nERROR: %s\n", message );
}
fprintf ( stderr, "\nUsage: %s <win> <hin> <in> <wout> <hout> <out> [<method> [<t> [<skip> [<frms>]]]] [[-crop <args>] [-phase <args>] [-resample_mode <arg>]]\n\n", name );
fprintf ( stderr, " win : input width (luma samples)\n" );
fprintf ( stderr, " hin : input height (luma samples)\n" );
fprintf ( stderr, " in : input file\n" );
fprintf ( stderr, " wout : output width (luma samples)\n" );
fprintf ( stderr, " hout : output height (luma samples)\n" );
fprintf ( stderr, " out : output file\n" );
fprintf ( stderr, "\n--------------------------- OPTIONAL ---------------------------\n\n" );
fprintf ( stderr, " method : rescaling methods (default: 0)\n" );
fprintf ( stderr, " 0: normative upsampling\n" );
fprintf ( stderr, " non-normative downsampling (JVT-R006)\n" );
fprintf ( stderr, " 1: dyadic upsampling (AVC 6-tap (1/2 pel) on odd samples\n" );
fprintf ( stderr, " dyadic downsampling (MPEG-4 downsampling filter)\n" );
fprintf ( stderr, " 2: crop only\n" );
fprintf ( stderr, " 3: upsampling (Three-lobed Lanczos-windowed sinc)\n" );
fprintf ( stderr, " 4: upsampling (JVT-O041: AVC 6-tap 1/2 pel + bilinear 1/4 pel)\n" );
fprintf ( stderr, " t : number of temporal downsampling stages (default: 0)\n" );
fprintf ( stderr, " skip : number of frames to skip at start (default: 0)\n" );
fprintf ( stderr, " frms : number of frames wanted in output file (default: max)\n" );
fprintf ( stderr, "\n-------------------------- OVERLOADED --------------------------\n\n" );
fprintf ( stderr, " -crop <type> <params>\n");
fprintf ( stderr, " type : 0: Sequence level, 1: Picture level\n");
fprintf ( stderr, " params : IF Sequence level: <x_orig> <y_orig> <crop_width> <crop_height>\n");
fprintf ( stderr, " cropping window origin (x,y) and dimensions (width and height)\n");
fprintf ( stderr, " IF Picture level: <crop_file>\n");
fprintf ( stderr, " input file containing cropping window parameters.\n" );
fprintf ( stderr, " each line has four integer numbers separated by a comma\n" );
fprintf ( stderr, " as following: \"x_orig, y_orig, crop_width, crop_height\"\n");
fprintf ( stderr, " for each picture to be resampled;\n" );
fprintf ( stderr, "\n");
fprintf ( stderr, " -phase <in_uv_ph_x> <in_uv_ph_y> <out_uv_ph_x> <out_uv_ph_y>\n");
fprintf ( stderr, " in_uv_ph_x : input chroma phase shift in horizontal direction (default:-1)\n" );
fprintf ( stderr, " in_uv_ph_y : input chroma phase shift in vertical direction (default: 0)\n" );
fprintf ( stderr, " out_uv_ph_x: output chroma phase shift in horizontal direction (default:-1)\n" );
fprintf ( stderr, " out_uv_ph_y: output chroma phase shift in vertical direction (default: 0)\n" );
fprintf ( stderr, "\n");
fprintf ( stderr, " -resample_mode <resample_mode>\n");
fprintf ( stderr, " resample_mode : resampling modes, present when method==0 (default: 0)\n" );
fprintf ( stderr, " 0: low-res-frm = progressive, high-res-frm = progressive\n" );
fprintf ( stderr, " 1: low-res-frm = interlaced, high-res-frm = interlaced\n" );
fprintf ( stderr, " 2: low-res-frm = progressive (top-coincided)\n" );
fprintf ( stderr, " high-res-frm = interlaced\n" );
fprintf ( stderr, " 3: low-res-frm = progressive (bot-coincided)\n" );
fprintf ( stderr, " high-res-frm = interlaced\n" );
fprintf ( stderr, " 4: low-res-frm = interlaced (top-first)\n" );
fprintf ( stderr, " high-res-frm = progressive (double frm rate)\n" );
fprintf ( stderr, " 5: low-res-frm = interlaced (bot-first)\n" );
fprintf ( stderr, " high-res-frm = progressive (double frm rate)\n" );
fprintf ( stderr, "\n\n");
exit ( 1 );
}
}
void updateCropParametersFromFile(ResizeParameters * rp, FILE * crop_file, int method, char* name)
{
int crop_x0;
int crop_y0;
int crop_w;
int crop_h;
if ((fscanf(crop_file,"%d,%d,%d,%d\n", &crop_x0, &crop_y0, &crop_w,&crop_h))!=EOF)
{
rp->m_iPosX = crop_x0;
rp->m_iPosY = crop_y0;
rp->m_iOutWidth = crop_w;
rp->m_iOutHeight = crop_h;
}
print_usage_and_exit ((rp->m_iPosX&1||rp->m_iPosY&1||rp->m_iOutWidth&1||rp->m_iOutHeight&1), name, "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)))), name, "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)),name,"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)),name,"wrong crop window size and origin");
}
int main(int argc, char *argv[])
{
DownConvert cDownConvert;
ResizeParameters * rp = new ResizeParameters;
rp->m_iInWidth = 0;
rp->m_iInHeight = 0;
rp->m_iGlobWidth = 0;
rp->m_iGlobHeight = 0;
rp->m_iBaseChromaPhaseX =-1;
rp->m_iBaseChromaPhaseY = 0;
rp->m_iChromaPhaseX =-1;
rp->m_iChromaPhaseY = 0;
rp->m_iPosX = 0;
rp->m_iPosY = 0;
rp->m_iOutWidth = 0;
rp->m_iOutHeight = 0;
rp->m_iExtendedSpatialScalability= 0;
rp->m_iPoc = 0;
rp->m_pParamFile = 0;
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 resample_mode = 0;
bool downsample_flg = 1;
int written, skip;
YuvFrame cFrame;
print_usage_and_exit ((argc<7||argc>24), 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 = ((unsigned int)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");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -