📄 downconvert.inl
字号:
//TMM_INTERLACE}
deltaa = ((input_height<<16) + (crop_h>>1))/crop_h;
if(uv_flag)
{
deltab = ((input_height<<14) + (crop_h>>1))/crop_h;
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = ((j*deltaa + (4 + output_chroma_phase_shift_y)*(deltab>>1) + 2048)>>12) - 2*(4 + input_chroma_phase_shift_y);
}
}
else
{
deltab = ((input_height<<15) + (crop_h>>1))/crop_h;
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = (j*deltaa + deltab - 30720)>>12;
}
}
} //TMM_INTERLACE}
}
//========== horizontal upsampling ===========
for( j = 0; j < input_height; j++ )
{
int* piSrc = &m_paiImageBuffer[j*m_iImageStride];
for( i = 0; i < output_width; i++ ){
if( px[i]==-128 ) continue;
x16 = px[i]&0x0f;
x = px[i]>>4;
m_paiTmp1dBuffer[i] = 0;
for( k=0; k<6; k++) {
m = x - 2 + k;
if( m<0 ) m = 0;
else if( m>(input_width-1) ) m=input_width-1;
m_paiTmp1dBuffer[i] += filter16[x16][k]*piSrc[m];
}
m_paiTmp1dBuffer[i] = m_paiTmp1dBuffer[i];
}
//----- copy row back to image buffer -----
::memcpy( piSrc, m_paiTmp1dBuffer, output_width*sizeof(int) );
}
//========== vertical upsampling ===========
for( i = 0; i < output_width; i++ )
{
int* piSrc = &m_paiImageBuffer[i];
for( j = 0; j < output_height; j++ ){
if( py[j]==-128 || px[i]==-128)
{
m_paiTmp1dBuffer[j] = 128;
continue;
}
y16 = py[j]&0x0f;
y = py[j]>>4;
m_paiTmp1dBuffer[j] = 0;
for( k=0; k<6; k++) {
m = y - 2 + k;
if( m<0 ) m = 0;
else if( m>(input_height-1) ) m=input_height-1;
m_paiTmp1dBuffer[j] += filter16[y16][k]*piSrc[m*m_iImageStride];
}
m_paiTmp1dBuffer[j] = (m_paiTmp1dBuffer[j]+512)/1024;
}
//----- scale and copy back to image buffer -----
for( j = 0; j < output_height; j++ )
{
piSrc[j*m_iImageStride] = m_paiTmp1dBuffer[j];
}
}
// free memory
delete [] px;
delete [] py;
}
#ifdef _JVTV074_
//cixunzhang
__inline
void
DownConvert::xUpsampling4 ( 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 uv_flag, int iResampleFilter[16][4])
{
int filter16[16][6] = { // Cubic-spline JVT-U042
{0,0,32,0,0,0},
{0,-1,32,2,-1,0},
{0,-2,31,4,-1,0},
{0,-3,30,6,-1,0},
{0,-3,28,8,-1,0},
{0,-4,26,11,-1,0},
{0,-4,24,14,-2,0},
{0,-3,22,16,-3,0},
{0,-3,19,19,-3,0},
{0,-3,16,22,-3,0},
{0,-2,14,24,-4,0},
{0,-1,11,26,-4,0},
{0,-1,8,28,-3,0},
{0,-1,6,30,-3,0},
{0,-1,4,31,-2,0},
{0,-1,2,32,-1,0}
};
int filter16_chroma[16][6] = { // bilinear
{0,0,32,0,0,0},
{0,0,30,2,0,0},
{0,0,28,4,0,0},
{0,0,26,6,0,0},
{0,0,24,8,0,0},
{0,0,22,10,0,0},
{0,0,20,12,0,0},
{0,0,18,14,0,0},
{0,0,16,16,0,0},
{0,0,14,18,0,0},
{0,0,12,20,0,0},
{0,0,10,22,0,0},
{0,0,8,24,0,0},
{0,0,6,26,0,0},
{0,0,4,28,0,0},
{0,0,2,30,0,0}
};
int i1, j1;
for (i1=0; i1<16; i1++)
for (j1=0; j1<4; j1++)
filter16[i1][j1+1] = iResampleFilter[i1][j1];
if(uv_flag)
{
for (int i=0; i<16; i++)
for (int j=0; j<6; j++)
filter16[i][j] = filter16_chroma[i][j];
}
//end
//JVT-U067
int i, j, k, *px, *py;
int x16, y16, x, y, m;
bool ratio1_flag = ( input_width == crop_w );
unsigned short deltaa, deltab;
// initialization
px = new int[output_width];
py = new int[output_height];
//int F=4;
// int G = 2, J, M, S = 12;
// unsigned short C, C1, D1;
// int D, E, q, w;
for(i=0; i<crop_x0; i++) px[i] = -128;
for(i=crop_x0+crop_w; i<output_width; i++) px[i] = -128;
if(ratio1_flag)
{
for(i = 0; i < crop_w; i++)
{
px[i+crop_x0] = i*16+2*(4+output_chroma_phase_shift_x)-2*(4+input_chroma_phase_shift_x);
}
}
else
{
deltaa = ((input_width<<16) + (crop_w>>1))/crop_w;
if(uv_flag)
{
deltab = ((input_width<<14) + (crop_w>>1))/crop_w;
for(i = 0; i < crop_w; i++)
{
px[i+crop_x0] = ((i*deltaa + (4 + output_chroma_phase_shift_x)*(deltab>>1) + 2048)>>12) - 2*(4 + input_chroma_phase_shift_x);
}
}
else
{
deltab = ((input_width<<15) + (crop_w>>1))/crop_w;
for(i = 0; i < crop_w; i++)
{
px[i+crop_x0] = (i*deltaa + deltab - 30720)>>12;
}
}
}
ratio1_flag = ( input_height == crop_h );
for(j=0; j<crop_y0; j++) py[j] = -128;
for(j=crop_y0+crop_h; j<output_height; j++) py[j] = -128;
if(ratio1_flag)
{
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = j*16+2*(4+output_chroma_phase_shift_y)-2*(4+input_chroma_phase_shift_y);
}
}
else
{
//TMM_INTERLACE {
if ( input_height > crop_h )
{
// refering to JVT-S067, S=11, M+G=15, G-1+J+M=14
// x'=(x.C+D)>>S with C=((M+G)<<2.WB+(WS>>1))/WS and D=-1<<(G-1+J+M) + 1<<(S-1)
deltaa = ((input_height<<15) + (crop_h>>1))/crop_h;
if(uv_flag)
{
deltab = ((input_height<<13) + (crop_h>>1))/crop_h;
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = ((j*deltaa + (4 + output_chroma_phase_shift_y)*(deltab>>1) + 1024)>>11) - 2*(4 + input_chroma_phase_shift_y);
}
}
else
{
deltab = ((input_height<<14) + (crop_h>>1))/crop_h;
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = (j*deltaa + deltab - 15360)>>11;
}
}
}
else {
// refering to JVT-S067, S=12, M+G=16, G-1+J+M=15
// x'=(x.C+D)>>S with C=((M+G)<<2.WB+(WS>>1))/WS and D=-1<<(G-1+J+M) + 1<<(S-1)
//TMM_INTERLACE}
deltaa = ((input_height<<16) + (crop_h>>1))/crop_h;
if(uv_flag)
{
deltab = ((input_height<<14) + (crop_h>>1))/crop_h;
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = ((j*deltaa + (4 + output_chroma_phase_shift_y)*(deltab>>1) + 2048)>>12) - 2*(4 + input_chroma_phase_shift_y);
}
}
else
{
deltab = ((input_height<<15) + (crop_h>>1))/crop_h;
for(j = 0; j < crop_h; j++)
{
py[j+crop_y0] = (j*deltaa + deltab - 30720)>>12;
}
}
} //TMM_INTERLACE}
}
//========== horizontal upsampling ===========
for( j = 0; j < input_height; j++ )
{
int* piSrc = &m_paiImageBuffer[j*m_iImageStride];
for( i = 0; i < output_width; i++ ){
if( px[i]==-128 ) continue;
x16 = px[i]&0x0f;
x = px[i]>>4;
m_paiTmp1dBuffer[i] = 0;
for( k=0; k<6; k++) {
m = x - 2 + k;
if( m<0 ) m = 0;
else if( m>(input_width-1) ) m=input_width-1;
m_paiTmp1dBuffer[i] += filter16[x16][k]*piSrc[m];
}
m_paiTmp1dBuffer[i] = m_paiTmp1dBuffer[i];
}
//----- copy row back to image buffer -----
::memcpy( piSrc, m_paiTmp1dBuffer, output_width*sizeof(int) );
}
//========== vertical upsampling ===========
for( i = 0; i < output_width; i++ )
{
int* piSrc = &m_paiImageBuffer[i];
for( j = 0; j < output_height; j++ ){
if( py[j]==-128 || px[i]==-128)
{
m_paiTmp1dBuffer[j] = 128;
continue;
}
y16 = py[j]&0x0f;
y = py[j]>>4;
m_paiTmp1dBuffer[j] = 0;
for( k=0; k<6; k++) {
m = y - 2 + k;
if( m<0 ) m = 0;
else if( m>(input_height-1) ) m=input_height-1;
m_paiTmp1dBuffer[j] += filter16[y16][k]*piSrc[m*m_iImageStride];
}
m_paiTmp1dBuffer[j] = (m_paiTmp1dBuffer[j]+512)/1024;
}
//----- scale and copy back to image buffer -----
for( j = 0; j < output_height; j++ )
{
piSrc[j*m_iImageStride] = m_paiTmp1dBuffer[j];
}
}
// free memory
delete [] px;
delete [] py;
}
#endif // _JVTV074_
__inline
void
DownConvert::xUpsampling_ver( int iWidth, // low-resolution width
int iHeight, // low-resolution height
int iPosY,
int iCropY,
int aiFilter[], // downsampling filter [15coeff+sum]
bool top_flg )
{
int i, j, im3, im2, im1, i0, ip1, ip2, ip3, ip4;
int div = ( aiFilter[15] ) / 2;
int add = div / 2;
int y0 = iPosY/2;
int y1 = y0 + iCropY/2;
//========== vertical upsampling ===========
for( j = 0; j < iWidth; j++ )
{
int* piSrc = &m_paiImageBuffer[j];
//----- upsample column -----
for( i = 0; i < iHeight; i++)
{
if(i<y0 || i>=y1){
m_paiTmp1dBuffer[2*i+1-top_flg] = m_paiTmp1dBuffer[2*i+top_flg] = piSrc[i*m_iImageStride];
continue;
}
if(top_flg)
{
im3 = ( (i< y0+3) ? y0 : i -3 ) * m_iImageStride;
im2 = ( (i< y0+2) ? y0 : i -2 ) * m_iImageStride;
im1 = ( (i< y0+1) ? y0 : i -1 ) * m_iImageStride;
i0 = ( (i< y1 ) ? i : y1 -1 ) * m_iImageStride;
ip1 = ( (i< y1-1) ? i+1 : y1 -1 ) * m_iImageStride;
ip2 = ( (i< y1-2) ? i+2 : y1 -1 ) * m_iImageStride;
ip3 = ( (i< y1-3) ? i+3 : y1 -1 ) * m_iImageStride;
ip4 = ( (i< y1-4) ? i+4 : y1 -1 ) * m_iImageStride;
}
else
{
ip4 = ( (i< y0+4) ? y0 : i -4 ) * m_iImageStride;
ip3 = ( (i< y0+3) ? y0 : i -3 ) * m_iImageStride;
ip2 = ( (i< y0+2) ? y0 : i -2 ) * m_iImageStride;
ip1 = ( (i< y0+1) ? y0 : i -1 ) * m_iImageStride;
i0 = ( (i< y1 ) ? i : y1 -1 ) * m_iImageStride;
im1 = ( (i< y1-1) ? i+1 : y1 -1 ) * m_iImageStride;
im2 = ( (i< y1-2) ? i+2 : y1 -1 ) * m_iImageStride;
im3 = ( (i< y1-3) ? i+3 : y1 -1 ) * m_iImageStride;
}
//--- even sample ---
m_paiTmp1dBuffer[2*i+1-top_flg] = aiFilter[13]*piSrc[im3]
+ aiFilter[11]*piSrc[im2]
+ aiFilter[ 9]*piSrc[im1]
+ aiFilter[ 7]*piSrc[i0 ]
+ aiFilter[ 5]*piSrc[ip1]
+ aiFilter[ 3]*piSrc[ip2]
+ aiFilter[ 1]*piSrc[ip3];
//--- odd sample ---
m_paiTmp1dBuffer[2*i+top_flg] = aiFilter[14]*piSrc[im3]
+ aiFilter[12]*piSrc[im2]
+ aiFilter[10]*piSrc[im1]
+ aiFilter[ 8]*piSrc[i0 ]
+ aiFilter[ 6]*piSrc[ip1]
+ aiFilter[ 4]*piSrc[ip2]
+ aiFilter[ 2]*piSrc[ip3]
+ aiFilter[ 0]*piSrc[ip4];
}
//----- copy back to image buffer -----
for( i = 0; i < iHeight*2; i++ )
piSrc[i*m_iImageStride] = ( m_paiTmp1dBuffer[i] + add ) / div;
}
}
__inline
void
DownConvert::xUpsampling_ver_res( int iWidth, // low-resolution width
int iHeight, // low-resolution height
int iPosY,
int iCropY,
int chroma,
bool top_flg )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -