📄 image.c
字号:
}
else if(dx==1&&dy==1)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*six[y+2][x+2];
}
}
}
else if(dx==2&&dy==1)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*seven[y+2][x+2];
}
}
}
else if(dx==1&&dy==2)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*seven[x+2][y+2]; /* eight */
}
}
}
else if(dx==3&&dy==1)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*six[y+2][3-x]; /* nine */
}
}
}
else if(dx==1&&dy==3)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*six[3-y][x+2]; /* ten */
}
}
}
else if(dx==2&&dy==2)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*five[y+2][x+2];
}
}
}
else if(dx==3&&dy==2)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*seven[3-x][3-y]; /* eleven */
}
}
}
else if(dx==2&&dy==3)
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*seven[3-y][x+2]; /* twelve */
}
}
}
else if(dx==3&&dy==3) /* not used if funny position is on */
{
for(y=-2;y<4;y++)
{
pres_y=max(0,min(maxold_y,y_pos/4+y));
for(x=-2;x<4;x++)
{
pres_x=max(0,min(maxold_x,x_pos/4+x));
result+=mref[ref_frame][pres_y][pres_x]*six[3-y][3-x]; /* thirteen */
}
}
}
}
return max(0,min(255,(result+2048)/4096));
}
byte get_eighthpel_pixel(int ref_frame,int x_pos,int y_pos, struct img_par *img)
{
int dx=0, x=0;
int dy=0, y=0;
int pres_x=0;
int pres_y=0;
int max_x=0,max_y=0;
byte tmp1[8];
byte tmp2[8];
byte tmp3[8];
double result=0;
x_pos = max (0, min (x_pos, (img->width *8-2)));
y_pos = max (0, min (y_pos, (img->height*8-2)));
dx = x_pos%8;
dy = y_pos%8;
pres_x=x_pos/8;
pres_y=y_pos/8;
max_x=img->width-1;
max_y=img->height-1;
/* choose filter depending on subpel position */
if(dx==0 && dy==0) /* fullpel position */
{
return(mref[ref_frame][pres_y][pres_x]);
}
else if(dx%2==0 && dy==0)
{
for(x=-3;x<5;x++)
{
tmp3[x+3]= mref[ref_frame][pres_y][max(0,min(pres_x+x,max_x))];
}
return(interpolate(tmp3,dx/2) );
}
else if(dx==0 && dy%2==0)
{
for(y=-3;y<5;y++)
{
tmp1[y+3]= mref[ref_frame][max(0,min(pres_y+y,max_y))][pres_x];
}
return( interpolate(tmp1,dy/2) );
}
else if(dx%2==0 && dy%2==0)
{
for(y=-3;y<5;y++)
{
for(x=-3;x<5;x++)
{
tmp3[x+3]=mref[ref_frame][max(0,min(pres_y+y,max_y))][max(0,min(pres_x+x,max_x))];
}
tmp1[y+3]= interpolate(tmp3,dx/2);
}
return( interpolate(tmp1,dy/2) );
}
else if((dx==1 && dy==0)||(dx==7 && dy==0))
{
for(x=-3;x<5;x++)
{
tmp1[x+3]= mref[ref_frame][pres_y][max(0,min(pres_x+x,max_x))];
}
if(dx==1)
return( (byte) ((interpolate(tmp1,1) + mref[ref_frame][pres_y][pres_x] +1)/2 ));
else
return( (byte) ((interpolate(tmp1,3) + mref[ref_frame][pres_y][max(0,min(pres_x+1,max_x))] +1)/2 ));
}
else
{
for(y=-3;y<5;y++)
{
for(x=-3;x<5;x++)
{
tmp3[x+3]= mref[ref_frame][max(0,min(pres_y+y,max_y))][max(0,min(pres_x+x,max_x))];
}
tmp1[y+3]= interpolate(tmp3,dx/2);
tmp2[y+3]= interpolate(tmp3,(dx+1)/2);
}
return( (byte) (( interpolate(tmp1,dy/2) + interpolate(tmp2,dy/2) + interpolate(tmp1,(dy+1)/2) + interpolate(tmp2,(dy+1)/2) + 2 )/4 ));
}
}
byte interpolate(byte container[8],int modus)
{
int i=0;
int sum=0;
static int h1[8] = { -3, 12, -37, 229, 71, -21, 6, -1 };
static int h2[8] = { -3, 12, -39, 158, 158, -39, 12, -3 };
static int h3[8] = { -1, 6, -21, 71, 229, -37, 12, -3 };
switch(modus)
{
case 0:
return(container[3]);
case 1:
for(i=0;i<8;i++)
{
sum+=h1[i]*container[i];
}
return( (byte) max(0,min((sum+128)/256,255)) );
case 2:
for(i=0;i<8;i++)
{
sum+=h2[i]*container[i];
}
return ((byte) max(0,min((sum+128)/256,255)) );
case 3:
for(i=0;i<8;i++)
{
sum+=h3[i]*container[i];
}
return((byte) max(0,min((sum+128)/256,255)) );
case 4:
return( (byte) container[4] );
default: return(-1);
}
}
/************************************************************************
*
* Name : read_new_slice()
*
* Description: Reads new slice (picture) from bit_stream
*
*
************************************************************************/
int read_new_slice(struct img_par *img, struct inp_par *inp)
{
int current_header;
Slice *currSlice = img->currentSlice;
// int *partMap = assignSE2partition[inp->partition_mode];
/* read new slice */
current_header = currSlice->readSlice(img,inp);
return current_header;
}
/************************************************************************
*
* Name : init_frame()
*
* Description: Initializes the parameters for a new frame
*
************************************************************************/
void init_frame(struct img_par *img, struct inp_par *inp)
{
static int first_P = TRUE;
int i,j;
img->current_mb_nr=0;
img->current_slice_nr=0;
img->mb_y = img->mb_x = 0;
img->block_y = img->pix_y = img->pix_c_y = 0; /* define vertical positions */
img->block_x = img->pix_x = img->pix_c_x = 0; /* define horizontal positions */
if(img->type == INTER_IMG_1 || img->type == INTER_IMG_MULT) // P pictures
{
#ifdef _ADAPT_LAST_GROUP_
for (i = img->buf_cycle-1; i > 0; i--)
last_P_no[i] = last_P_no[i-1];
last_P_no[0] = nextP_tr;
#endif
nextP_tr=img->tr;
}
else if(img->type==INTRA_IMG) // I picture
nextP_tr=prevP_tr=img->tr;
if(img->type == INTER_IMG_1 || img->type == INTER_IMG_MULT)
{
if(first_P) // first P picture
{
first_P = FALSE;
P_interval=nextP_tr-prevP_tr;
}
else // all other P pictures
{
write_prev_Pframe(img, p_out); // imgY_prev, imgUV_prev -> file
}
}
if (img->type > B_IMG_MULT)
{
set_ec_flag(SE_PTYPE);
img->type = INTER_IMG_1; /* concealed element */
}
/* allocate memory for frame buffers */
if (img->number == 0) get_mem4global_buffers(inp, img);
init_loop_filter(img);
/* set edge to -1, indicate nothing to predict from */
for(i=0;i<img->width/BLOCK_SIZE+2;i++)
{
img->ipredmode[i][0] = -1;
img->ipredmode[i][img->height/BLOCK_SIZE+1] = -1;
}
for(j=0;j<img->height/BLOCK_SIZE+2;j++)
{
img->ipredmode[0][j] = -1;
img->ipredmode[img->width/BLOCK_SIZE+1][j] = -1;
}
}
void exit_frame(struct img_par *img, struct inp_par *inp)
{
if(img->type==INTRA_IMG || img->type == INTER_IMG_1 || img->type == INTER_IMG_MULT )
copy2mref(img);
}
/************************************************************************
*
* Name : decode_one_slice()
*
* Description: decodes one slice
*
************************************************************************/
void decode_one_slice(struct img_par *img,struct inp_par *inp)
{
Boolean end_of_slice = FALSE;
int read_flag;
Slice *currSlice = img->currentSlice;
reset_ec_flags();
while (end_of_slice == FALSE) /* loop over macroblocks */
{
#if TRACE
fprintf(p_trace,"\n*********** Pic: %i (I/P) MB: %i Slice: %i **********\n\n", img->tr, img->current_mb_nr, img->slice_numbers[img->current_mb_nr]);
#endif
/* Initializes the current macroblock */
start_macroblock(img,inp);
/* Get the syntax elements from the NAL */
read_flag = read_one_macroblock(img,inp);
/* decode one macroblock */
switch(read_flag)
{
case DECODE_MB:
decode_one_macroblock(img,inp);
break;
case DECODE_COPY_MB:
decode_one_CopyMB(img,inp);
break;
case DECODE_MB_BFRAME:
decode_one_macroblock_Bframe(img);
break;
default:
printf("need to trigger error concealment or something here\n ");
}
end_of_slice=exit_macroblock(img,inp);
}
}
/************************************************************************
*
* Name : init_loop_filter()
*
* Description: initializes loop filter
*
************************************************************************/
void init_loop_filter(struct img_par *img)
{
int i, j;
for (i=0;i<img->width/4+2;i++)
for (j=0;j<img->height/4+2;j++)
loopb[i+1][j+1]=0;
for (i=0;i<img->width_cr/4+2;i++)
for (j=0;j<img->height_cr/4+2;j++)
loopc[i+1][j+1]=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -