📄 image.c
字号:
//{ //a b c d e f g h i j k l m n o
// {1,0},{2,0},{3,0},{0,1},{1,1},{2,1},{3,1},{0,2},{1,2},{2,2},{3,2},{0,3},{1,3},{2,3},{3,3}
// //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
//};
int comp_block[2][BLOCK_SIZE][BLOCK_SIZE];
int comp_loc[][2][2] =
{
{{2,0},{0,0}}, //a {half, integer}
{{2,0},{2,0}}, //b
{{2,0},{4,0}}, //c {half, integer}
{{0,2},{0,0}}, //d {half, integer}
{{2,0},{0,2}}, //e {half, half}
{{2,0},{2,2}}, //f {half, "j"}
{{2,0},{4,2}}, //g {half, half}
{{0,2},{0,2}}, //h
{{0,2},{2,2}}, //i {half, "j"}
{{2,2},{2,2}}, //j
{{4,2},{2,2}}, //k {half, "j"}
{{0,2},{0,4}}, //l {half, integer}
{{2,4},{0,2}}, //m {half, half}
{{2,4},{2,2}}, //n {half, "j"}
{{2,4},{4,2}}, //o {half, half}
};
int comp_num[] = {2,1,2,2,2,2,2,1,2,1,2,2,2,2,2}; // number of contributing components
//int acdl_idx[4]={0, 2, 3, 11};
//int egmo_idx[4]={4, 6, 12, 14};
//int fikn_idx[4]={5, 8, 10, 13};
int temp_1D[6], AF[3], is;
#else
//short int sub_loc[15][2] =
//{ //a b c d e f g h i j k l m n o
// {1,0},{2,0},{3,0},{0,1},{1,1},{2,1},{3,1},{0,2},{1,2},{2,2},{3,2},{0,3},{1,3},{2,3},{3,3}
// //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
//};
short int comp_block[2][BLOCK_SIZE][BLOCK_SIZE];
short int comp_loc[][2][2] =
{
{{2,0},{0,0}}, //a {half, integer}
{{2,0},{2,0}}, //b
{{2,0},{4,0}}, //c {half, integer}
{{0,2},{0,0}}, //d {half, integer}
{{2,0},{0,2}}, //e {half, half}
{{2,0},{2,2}}, //f {half, "j"}
{{2,0},{4,2}}, //g {half, half}
{{0,2},{0,2}}, //h
{{0,2},{2,2}}, //i {half, "j"}
{{2,2},{2,2}}, //j
{{4,2},{2,2}}, //k {half, "j"}
{{0,2},{0,4}}, //l {half, integer}
{{2,4},{0,2}}, //m {half, half}
{{2,4},{2,2}}, //n {half, "j"}
{{2,4},{4,2}}, //o {half, half}
};
short int comp_num[] = {2,1,2,2,2,2,2,1,2,1,2,2,2,2,2}; // number of contributing components
//short int acdl_idx[4]={0, 2, 3, 11};
//short int egmo_idx[4]={4, 6, 12, 14};
//short int fikn_idx[4]={5, 8, 10, 13};
short int temp_1D[6], AF[3], is;
#endif
imgpel **imgY = list[ref_frame]->imgY;
if (list[ref_frame] == no_reference_picture && img->framepoc < img->recovery_poc)
{
printf("list[ref_frame] is equal to 'no reference picture' before RAP\n");
/* fill the block with sample value 128 */
for (j = 0; j < BLOCK_SIZE; j++)
for (i = 0; i < BLOCK_SIZE; i++)
block[i][j] = 128;
return;
}
if (x_pos < 0)
x_sub = (4-abs(x_pos)%4)%4;
else
x_sub = x_pos%4; // x-sub-coordinate in a 4x4block
if (y_pos < 0)
y_sub = (4-abs(y_pos)%4)%4;
else
y_sub = y_pos%4; // y-sub-coordinate in a 4x4bloc
sub_pos = x_sub + 4*y_sub; // pos 1..15 in a 4x4 block
// the upper left integer pel position
if(x_pos < 0 && x_sub != 0)
x_pos = (x_pos-4)/4;
else
x_pos /= 4;
if(y_pos < 0 && y_sub != 0)
y_pos = (y_pos-4)/4;
else
y_pos /= 4;
maxold_x = dec_picture->size_x-1;
maxold_y = dec_picture->size_y-1;
if (dec_picture->mb_field[img->current_mb_nr])
maxold_y = dec_picture->size_y/2 - 1;
if (sub_pos==0)
{ /* fullpel position */
for (i = 0; i < BLOCK_SIZE; i++)
for (j = 0; j < BLOCK_SIZE; j++)
block[j][i] = imgY[max(0,min(maxold_y,y_pos+i))][max(0,min(maxold_x,x_pos+j))]; //block[x][y]
}
else
{
int inter_loc_x, inter_loc_y; // the location of to-be-interpolated subpel
for(ci=0; ci<comp_num[sub_pos-1]; ci++) // contributing components
{
comp_x = comp_loc[sub_pos-1][ci][0];
comp_y = comp_loc[sub_pos-1][ci][1];
comp_sub_pos = comp_x%4 + 4*(comp_y%4); // pos 1..15 in a 4x4 block
if(comp_sub_pos==0) // integer pel
{
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
comp_block[ci][j][i] = imgY[max(0,min(maxold_y,y_pos+comp_y/4+i))][max(0,min(maxold_x,x_pos+comp_x/4+j))]; //comp_block[ci][x][y]
}
}
else if(comp_sub_pos ==10 ) // "j"
{
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
for(ii=-2; ii<=3; ii++)// y
{
is=0;
inter_loc_y = i+y_pos+ii;
pos_y1 = max(0, min(maxold_y, inter_loc_y) );
if(inter_loc_y<0 && pos_y1 > 0)
pos_y1 -=1;
for(jj = 0; jj < 3; jj++) //x
{
inter_loc_x = (x_pos+j)*4+2;
pos_x1 = max(0, min(maxold_x, inter_loc_x/4-2+jj ) );
if(inter_loc_x<0 && pos_x1 > 0)
pos_x1 -=1;
inter_loc_x = (x_pos+j)*4+2;
pos_x2 = max(0, min(maxold_x, inter_loc_x/4-2+(5-jj) ) );
if(inter_loc_x<0 && pos_x2 > 0)
pos_x2 -=1;
is += ONE_FOURTH_TAP[2-jj][0]*(imgY[pos_y1][pos_x1]+imgY[pos_y1][pos_x2]);
}
temp_1D[ii+2]=is;
}
//AF[0]=A+F; AF[1]=B+E; AF[2]=C+D;
for(ii = 0; ii < 3; ii++)
{
AF[ii] = temp_1D[ii]+temp_1D[5-ii];
}
AF[0] -= AF[1]; //(A+F)-(B+E)
AF[0] >>= 2;
#ifdef INTERNAL_BIT_DEPTH_INCREASE
if (img->BitDepthIncrease==0)
{
AF[2] = max(-2371, min(18640, AF[2]));
}
#else
AF[2] = max(-2371, min(18640, AF[2]));
#endif
AF[1] = AF[2] - AF[1]; // (C+D)-(B+E)
AF[0] += AF[1];
AF[0] >>= 2;
AF[0] += AF[2];
comp_block[ci][j][i] = AF[0];
}
}
else //1-D half pel
{
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
is = 0;
if(comp_sub_pos/4 == 0) // horizontal 1/2 position
{
inter_loc_y = (i+y_pos)*4+comp_y;
pos_y1 = max(0, min(maxold_y, inter_loc_y/4) );
if(inter_loc_y<0 && pos_y1 > 0)// to be removed
pos_y1 -=1;
for(jj = 0; jj < 3; jj++)
{
inter_loc_x = (j+x_pos)*4+comp_x;
pos_x1 = max(0, min(maxold_x, inter_loc_x/4-2+jj ) );
if(inter_loc_x<0 && pos_x1 > 0)
pos_x1 -=1;
inter_loc_x = (j+x_pos)*4+comp_x;
pos_x2 = max(0, min(maxold_x, inter_loc_x/4-2+(5-jj) ) );
if(inter_loc_x<0 && pos_x2 > 0)
pos_x2 -=1;
is += ONE_FOURTH_TAP[2-jj][0]*(imgY[pos_y1][pos_x1]+imgY[pos_y1][pos_x2]);
}
comp_block[ci][j][i] = is;
}
else if(comp_sub_pos%4 == 0) // vertical 1/2 position
{
inter_loc_x = (j+x_pos)*4+comp_x;
pos_x1 = max(0, min(maxold_x, inter_loc_x/4) );
if(inter_loc_x<0 && pos_x1 > 0)
pos_x1 -=1;
for(ii = 0; ii < 3; ii++)
{
inter_loc_y = (i+y_pos)*4+comp_y;
pos_y1 = max(0, min(maxold_y, inter_loc_y/4-2+ii ) );
if(inter_loc_y<0 && pos_y1 > 0)
pos_y1 -=1;
inter_loc_y = (i+y_pos)*4+comp_y;
pos_y2 = max(0, min(maxold_y, inter_loc_y/4-2+(5-ii) ) );
if(inter_loc_y<0 && pos_y2 > 0)
pos_y2 -=1;
is += ONE_FOURTH_TAP[2-ii][0]*(imgY[pos_y1][pos_x1]+imgY[pos_y2][pos_x1]);
}
comp_block[ci][j][i] = is;
}
}
}
}
// interpolate quarter-pel and shift down half-pel at the same time
switch(sub_pos)
{
case 1:
case 3:
case 4:
case 12: // a, c, d, l
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
block[i][j] = (comp_block[0][i][j] + (comp_block[1][i][j]<<5) + 32) >> 6;
}
break;
case 2:
case 8: // b, h,
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
block[i][j] = (comp_block[0][i][j] + 16)>>5;
}
break;
case 10: // j
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
block[i][j] = (comp_block[0][i][j] + 32)>>6;
}
break;
case 5:
case 7:
case 13:
case 15: // e, g, m, o
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
block[i][j] = (comp_block[0][i][j] + comp_block[1][i][j] + 32) >> 6;
}
break;
case 6:
case 9:
case 11:
case 14: // i, k,f, n
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
block[i][j] = (comp_block[0][i][j] + (comp_block[1][i][j]>>1) + 32) >> 6;
}
break;
default:
printf("sub_pos is out of range!\n");
exit(1);
}
for(i=0; i<BLOCK_SIZE; i++)
for(j=0; j<BLOCK_SIZE; j++)
{
#ifdef INTERNAL_BIT_DEPTH_INCREASE
block[i][j] = max(0, min(block[i][j], (1<<img->bitdepth_luma)-1));
#else
block[i][j] = max(0, min(block[i][j], 255));
#endif
}
}
}
#endif
#ifdef EIGHTH_PEL
void get_block(int ref_frame, StorablePicture **list, int x_pos, int y_pos, struct img_par *img, int block[BLOCK_SIZE][BLOCK_SIZE])
{
if( img->mv_res )
get_eighthpel_block( ref_frame, list, x_pos, y_pos, img, block );
else
#ifdef USE_HP_FILTER
if( img->use_high_precision_flag==2)
get_quarterpel_block_enhanced_FDIF( ref_frame, list, x_pos, y_pos, img, block );
else if( img->use_high_precision_flag==1)
get_quarterpel_block_16( ref_frame, list, x_pos, y_pos, img, block );
else
get_quarterpel_block( ref_frame, list, x_pos, y_pos, img, block );
#else
get_quarterpel_block( ref_frame, list, x_pos, y_pos, img, block );
#endif
}
#endif
void reorder_lists(int currSliceType, Slice * currSlice)
{
if ((currSliceType != I_SLICE)&&(currSliceType != SI_SLICE))
{
if (currSlice->ref_pic_list_reordering_flag_l0)
{
reorder_ref_pic_list(listX[0], &listXsize[0],
img->num_ref_idx_l0_active - 1,
currSlice->reordering_of_pic_nums_idc_l0,
currSlice->abs_diff_pic_num_minus1_l0,
currSlice->long_term_pic_idx_l0);
}
if (no_reference_picture == listX[0][img->num_ref_idx_l0_active-1])
{
if (non_conforming_stream)
printf("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture'\n");
else
error("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500);
}
// that's a definition
listXsize[0] = img->num_ref_idx_l0_active;
}
if (currSliceType == B_SLICE)
{
if (currSlice->ref_pic_list_reordering_flag_l1)
{
reorder_ref_pic_list(listX[1], &listXsize[1],
img->num_ref_idx_l1_active - 1,
currSlice->reordering_of_pic_nums_idc_l1,
currSlice->abs_diff_pic_num_minus1_l1,
currSlice->long_term_pic_idx_l1);
}
if (no_reference_picture == listX[1][img->num_ref_idx_l1_active-1])
{
if (non_conforming_stream)
printf("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture'\n");
else
error("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500);
}
// that's a definition
listXsize[1] = img->num_ref_idx_l1_active;
}
free_ref_pic_list_reordering_buffer(currSlice);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -