📄 coder.c
字号:
int n; register int m; for (n = 0; n < MB_SIZE; n++) for (m = 0; m < MB_SIZE; m++) data->lum[n][m] = 0; for (n = 0; n < (MB_SIZE>>1); n++) for (m = 0; m < (MB_SIZE>>1); m++)
{ data->Cr[n][m] = 0; data->Cb[n][m] = 0; } return;}void MotionEstimatePicture(unsigned char *curr, unsigned char *prev, unsigned char *prev_ipol, int seek_dist, MotionVector *MV[6][MBR+1][MBC+2], int gobsync) { int i,j,k; int pmv0,pmv1,xoff,yoff; short int curr_mb[16][16]; int sad8 = INT_MAX, sad16, sad0; int newgob; MotionVector *f0,*f1,*f2,*f3,*f4; /* Do motion estimation and store result in array */ for ( j = 0; j < lines/MB_SIZE; j++)
{ newgob = 0; if (gobsync && j%gobsync == 0)
{ newgob = 1; } for ( i = 0; i < pels/MB_SIZE; i++)
{ for (k = 0; k < 6; k++) MV[k][j+1][i+1] = (MotionVector *)malloc(sizeof(MotionVector)); /* Integer pel search */ f0 = MV[0][j+1][i+1]; f1 = MV[1][j+1][i+1]; f2 = MV[2][j+1][i+1]; f3 = MV[3][j+1][i+1]; f4 = MV[4][j+1][i+1]; /* Here the PMV's are found using integer motion vectors */ /* (NB should add explanation for this )*/ FindPMV(MV,i+1,j+1,&pmv0,&pmv1,0,newgob,0); xoff = yoff = 0; MotionEstimation(curr, prev, i*MB_SIZE, j*MB_SIZE, xoff, yoff, seek_dist, MV, &sad0); sad16 = f0->min_error;
f0->Mode = ChooseMode_MY(curr,i*MB_SIZE,j*MB_SIZE, mmin(sad8,sad16));
/* Half pel search */ if (f0->Mode != MODE_INTRA)
{
FindMB_MY(i*MB_SIZE,j*MB_SIZE ,curr, curr_mb);
FindHalfPel_MY(i*MB_SIZE,j*MB_SIZE,f0, prev_ipol, &curr_mb[0][0],16,0); sad16 = f0->min_error; /* Choose Zero Vector or 16x16 vectors */ if (sad0 < sad16)
{ f0->x = f0->y = 0; } } else
{ for (k = 0; k < 5; k++) ZeroVec(MV[k][j+1][i+1]);
} } }#ifdef PRINTMV fprintf(stdout,"Motion estimation\n"); fprintf(stdout,"16x16 vectors:\n"); for ( j = 0; j < lines/MB_SIZE; j++)
{ for ( i = 0; i < pels/MB_SIZE; i++)
{ if (MV[0][j+1][i+1]->Mode != MODE_INTRA) fprintf(stdout," %3d%3d", 2*MV[0][j+1][i+1]->x + MV[0][j+1][i+1]->x_half, 2*MV[0][j+1][i+1]->y + MV[0][j+1][i+1]->y_half); else fprintf(stdout," . . "); } fprintf(stdout,"\n"); }#endif
return;}void MakeEdgeImage(unsigned char *src, unsigned char *dst, int width, int height, int edge){ int i,j; unsigned char *p1,*p2,*p3,*p4; unsigned char *o1,*o2,*o3,*o4; /* center image */ p1 = dst; o1 = src; for (j = 0; j < height;j++)
{ memcpy(p1,o1,width); p1 += width + (edge<<1); o1 += width; } /* left and right edges */ p1 = dst-1; o1 = src; for (j = 0; j < height;j++)
{ for (i = 0; i < edge; i++)
{ *(p1 - i) = *o1; *(p1 + width + i + 1) = *(o1 + width - 1); } p1 += width + (edge<<1); o1 += width; } /* top and bottom edges */ p1 = dst; p2 = dst + (width + (edge<<1))*(height-1); o1 = src; o2 = src + width*(height-1); for (j = 0; j < edge;j++)
{ p1 = p1 - (width + (edge<<1)); p2 = p2 + (width + (edge<<1)); for (i = 0; i < width; i++)
{ *(p1 + i) = *(o1 + i); *(p2 + i) = *(o2 + i); } } /* corners */ p1 = dst - (width+(edge<<1)) - 1; p2 = p1 + width + 1; p3 = dst + (width+(edge<<1))*(height)-1; p4 = p3 + width + 1; o1 = src; o2 = o1 + width - 1; o3 = src + width*(height-1); o4 = o3 + width - 1; for (j = 0; j < edge; j++)
{ for (i = 0; i < edge; i++)
{ *(p1 - i) = *o1; *(p2 + i) = *o2; *(p3 - i) = *o3; *(p4 + i) = *o4; } p1 = p1 - (width + (edge<<1)); p2 = p2 - (width + (edge<<1)); p3 = p3 + width + (edge<<1); p4 = p4 + width + (edge<<1); }}
void ReconImage_MY(int i, int j, MB_Structure *data, PictImage *recon)
{
int n, m;
int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
int *p1, *p2, *p3, *p4, *p5, *p6;
p1 = (int *)(data->lum);
p2 = (int *)(recon->lum + (i*MB_SIZE) + (j*MB_SIZE)*pels);
p3 = (int *)(data->Cr);
p4 = (int *)(recon->Cr + (i*MB_SIZE>>1) + (j*MB_SIZE>>1)*cpels);
p5 = (int *)(data->Cb);
p6 = (int *)(recon->Cb + (i*MB_SIZE>>1) + (j*MB_SIZE>>1)*cpels);
for( n=0; n<MB_SIZE; n++ )
{
temp0 = MERGEDUAL16LSB( p1[1], p1[0] );
temp1 = MERGEDUAL16LSB( p1[3], p1[2] );
temp2 = MERGEDUAL16LSB( p1[5], p1[4] );
temp3 = MERGEDUAL16LSB( p1[7], p1[6] );
p2[0] = temp0;
p2[1] = temp1;
p2[2] = temp2;
p2[3] = temp3;
p1 += MB_SIZE>>1;
p2 += pels>>2;
}
for( m=0; m<MB_SIZE>>1; m++ )
{
temp4 = MERGEDUAL16LSB( p3[1], p3[0] );
temp5 = MERGEDUAL16LSB( p3[3], p3[2] );
temp6 = MERGEDUAL16LSB( p5[1], p5[0] );
temp7 = MERGEDUAL16LSB( p5[3], p5[2] );
p4[0] = temp4;
p4[1] = temp5;
p6[0] = temp6;
p6[1] = temp7;
p3 += MB_SIZE>>2;
p4 += cpels>>2;
p5 += MB_SIZE>>2;
p6 += cpels>>2;
}
return;
}
void Clip_MY(MB_Structure *data)
{
int m,n;
int *p1, *p2, *p3;
int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
p1 = (int *)data->lum;
p2 = (int *)data->Cr;
p3 = (int *)data->Cb;
for (n=0; n<16; n++)
{
temp0 = DUALUCLIPI( p1[0], 255 );
temp1 = DUALUCLIPI( p1[1], 255 );
temp2 = DUALUCLIPI( p1[2], 255 );
temp3 = DUALUCLIPI( p1[3], 255 );
temp4 = DUALUCLIPI( p1[4], 255 );
temp5 = DUALUCLIPI( p1[5], 255 );
temp6 = DUALUCLIPI( p1[6], 255 );
temp7 = DUALUCLIPI( p1[7], 255 );
p1[0] = temp0;
p1[1] = temp1;
p1[2] = temp2;
p1[3] = temp3;
p1[4] = temp4;
p1[5] = temp5;
p1[6] = temp6;
p1[7] = temp7;
p1 += 8;
}
for (m=0; m<8; m++)
{
temp0 = DUALUCLIPI( p2[0], 255 );
temp1 = DUALUCLIPI( p2[1], 255 );
temp2 = DUALUCLIPI( p2[2], 255 );
temp3 = DUALUCLIPI( p2[3], 255 );
temp4 = DUALUCLIPI( p3[0], 255 );
temp5 = DUALUCLIPI( p3[1], 255 );
temp6 = DUALUCLIPI( p3[2], 255 );
temp7 = DUALUCLIPI( p3[3], 255 );
p2[0] = temp0;
p2[1] = temp1;
p2[2] = temp2;
p2[3] = temp3;
p3[0] = temp4;
p3[1] = temp5;
p3[2] = temp6;
p3[3] = temp7;
p2 += 4;
p3 += 4;
}
return;
}
void FillLumBlock_MY( int x, int y, PictImage *image, MB_Structure *data )
{
int n;
register int m;
int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
int temp8, temp9, temp10, temp11, temp12, temp13, temp14, temp15;
int *p1;
int *p2;
p1 = (int *)(image->lum + x + y*pels);
p2 = (int *)data->lum;
for (n = 0; n < MB_SIZE; n++)
{
temp0 = UBYTESEL( p1[0], 0 );
temp4 = UBYTESEL( p1[1], 0 );
temp8 = UBYTESEL( p1[2], 0 );
temp12 = UBYTESEL( p1[3], 0 );
temp1 = UBYTESEL( p1[0], 1 );
temp5 = UBYTESEL( p1[1], 1 );
temp9 = UBYTESEL( p1[2], 1 );
temp13 = UBYTESEL( p1[3], 1 );
p2[0] = PACK16LSB( temp1, temp0 );
p2[2] = PACK16LSB( temp5, temp4 );
p2[4] = PACK16LSB( temp9, temp8 );
p2[6] = PACK16LSB( temp13, temp12 );
temp2 = UBYTESEL( p1[0], 2 );
temp6 = UBYTESEL( p1[1], 2 );
temp10 = UBYTESEL( p1[2], 2 );
temp14 = UBYTESEL( p1[3], 2 );
temp3 = UBYTESEL( p1[0], 3 );
temp7 = UBYTESEL( p1[1], 3 );
temp11 = UBYTESEL( p1[2], 3 );
temp15 = UBYTESEL( p1[3], 3 );
p2[1] = PACK16LSB( temp3, temp2 );
p2[3] = PACK16LSB( temp7, temp6 );
p2[5] = PACK16LSB( temp11, temp10 );
p2[7] = PACK16LSB( temp15, temp14 );
p2 += 8;
p1 += pels>>2;
}
return;
}
void FillChromBlock_MY( int x_curr, int y_curr, PictImage *image, MB_Structure *data )
{
int n;
int i, j;
int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
int temp8, temp9, temp10, temp11, temp12, temp13, temp14, temp15;
int *p1;
int *p2;
int *p3;
int *p4;
int x, y;
x = x_curr>>1;
y = y_curr>>1;
p1 = (int *)(image->Cb + x + y*cpels);
p2 = (int *)(image->Cr + x + y*cpels);
p3 = (int *)data->Cb;
p4 = (int *)data->Cr;
for (n = 0; n < MB_SIZE>>1; n++)
{
temp0 = UBYTESEL( p1[0], 0 );
temp4 = UBYTESEL( p1[1], 0 );
temp1 = UBYTESEL( p1[0], 1 );
temp5 = UBYTESEL( p1[1], 1 );
temp8 = UBYTESEL( p2[0], 0 );
temp12 = UBYTESEL( p2[1], 0 );
temp9 = UBYTESEL( p2[0], 1 );
temp13 = UBYTESEL( p2[1], 1 );
p3[0] = PACK16LSB( temp1, temp0 );
p3[2] = PACK16LSB( temp5, temp4 );
p4[0] = PACK16LSB( temp9, temp8 );
p4[2] = PACK16LSB( temp13, temp12 );
temp2 = UBYTESEL( p1[0], 2 );
temp6 = UBYTESEL( p1[1], 2 );
temp3 = UBYTESEL( p1[0], 3 );
temp7 = UBYTESEL( p1[1], 3 );
temp10 = UBYTESEL( p2[0], 2 );
temp14 = UBYTESEL( p2[1], 2 );
temp11 = UBYTESEL( p2[0], 3 );
temp15 = UBYTESEL( p2[1], 3 );
p3[1] = PACK16LSB( temp3, temp2 );
p3[3] = PACK16LSB( temp7, temp6 );
p4[1] = PACK16LSB( temp11, temp10 );
p4[3] = PACK16LSB( temp15, temp14 );
p1 += cpels>>2;
p2 += cpels>>2;
p3 += 4;
p4 += 4;
}
return;
}
unsigned char *InterpolateImage_MY(unsigned char *image, int width, int height)
{
unsigned char *ipol_image, *ii, *oo;
int i,j;
int *p1, *p2, *p3, *p4;
int t0, t1, t2, t3, t4, t5, t6, t7;
int s0, s1, s2, s3, s4, s5, s6, s7;
int r0;
ipol_image = (unsigned char *)malloc(sizeof(char)*width*height*4);
ii = ipol_image;
oo = image;
p1 = (int *)image;
p2 = (int *)ipol_image;
/* main image */
for (j = 0; j < height; j++)
{
for (i = 0; i < (width>>4)-1; i++)
{
s0 = t0 = p1[0];
s1 = t1 = p1[1];
s2 = t2 = p1[2];
s3 = t3 = p1[3];
t4 = FUNSHIFT3( s1, s0 );
t5 = FUNSHIFT3( s2, s1 );
t6 = FUNSHIFT3( s3, s2 );
t7 = FUNSHIFT3( p1[4], s3 );
s4 = QUADAVG( t0, t4 );
s5 = QUADAVG( t1, t5 );
s6 = QUADAVG( t2, t6 );
s7 = QUADAVG( t3, t7 );
p2[0] = MERGELSB( s4, s0 );
p2[1] = MERGEMSB( s4, s0 );
p2[2] = MERGELSB( s5, s1 );
p2[3] = MERGEMSB( s5, s1 );
p2[4] = MERGELSB( s6, s2 );
p2[5] = MERGEMSB( s6, s2 );
p2[6] = MERGELSB( s7, s3 );
p2[7] = MERGEMSB( s7, s3 );
p1 += 4;
p2 += 8;
}
s0 = t0 = p1[0];
s1 = t1 = p1[1];
s2 = t2 = p1[2];
s3 = t3 = p1[3];
t4 = FUNSHIFT3( s1, s0 );
t5 = FUNSHIFT3( s2, s1 );
t6 = FUNSHIFT3( s3, s2 );
t7 = FUNSHIFT3( s3, s3 );
r0 = (t3 & 0xff000000) | t7;
s4 = QUADAVG( t0, t4 );
s5 = QUADAVG( t1, t5 );
s6 = QUADAVG( t2, t6 );
s7 = QUADAVG( t3, r0 );
p2[0] = MERGELSB( s4, s0 );
p2[1] = MERGEMSB( s4, s0 );
p2[2] = MERGELSB( s5, s1 );
p2[3] = MERGEMSB( s5, s1 );
p2[4] = MERGELSB( s6, s2 );
p2[5] = MERGEMSB( s6, s2 );
p2[6] = MERGELSB( s7, s3 );
p2[7] = MERGEMSB( s7, s3 );
p1 += 4;
p2 += (width>>1)+8;
}
p1 = (int *)ipol_image;
p2 = (int *)(ipol_image+(width<<2));
p3 = (int *)(ipol_image+(width<<1));
for (j = 0; j < height-1; j++)
{
for (i = 0; i < (width>>3); i++)
{
t0 = p1[0];
t1 = p2[0];
t2 = p1[1];
t3 = p2[1];
t4 = p1[2];
t5 = p2[2];
t6 = p1[3];
t7 = p2[3];
p3[0] = QUADAVG( t0, t1 );
p3[1] = QUADAVG( t2, t3 );
p3[2] = QUADAVG( t4, t5 );
p3[3] = QUADAVG( t6, t7 );
p1 += 4;
p2 += 4;
p3 += 4;
}
p1 += (width>>1);
p2 += (width>>1);
p3 += (width>>1);
}
for (i = 0; i < (width>>3); i++)
{
p3[0] = p1[0];
p3[1] = p1[1];
p3[2] = p1[2];
p3[3] = p1[3];
p1 += 4;
p3 += 4;
}
return ipol_image;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -