📄 ztscan_dec.cpp
字号:
break;
case IZ:
dcc[k]=0;
coeffinfo[h][w].quantized_value=0;
break;
case VZTR:
dcc[k]=1;
mark_ZTR_D(h,w); /* here it's just to zero out descendents */
#ifdef _SHAPE_
if(coeffinfo[h][w].mask==1)
#endif
mag_sign_decode_MQ(h,w);
break;
case VAL:
dcc[k]=0;
#ifdef _SHAPE_
if(coeffinfo[h][w].mask==1)
#endif
mag_sign_decode_MQ(h,w);
break;
default:
errorHandler("Invalid type in multi quant decoding.");
}
}
/********************* CODE CHILDREN *****************************/
if (!IS_STATE_LEAF(coeffinfo[h0][w0].state))
{
Int i, j;
for (k=0; k<nSib; ++k)
{
if (dcc[k]==0)
{
h = h0 + (k/2);
w = w0 + (k%2);
/* scan children */
i=h<<1; j=w<<1;
decode_pixel_MQ_tree(i,j);
}
}
}
}
#endif
/********************************************************
Function Name
-------------
static Void mark_ZTR_D(Int h,Int w)
Arguments
---------
Int h,Int w - position of a pixel
Description
-----------
Mark the coefficient at (h,w) and its descendents as
zerotree descendents.
Functions Called
----------------
mark_ZTR_D()
Return Value
------------
None.
********************************************************/
Void CVTCDecoder::mark_ZTR_D(Int h,Int w)
{
Int i,j;
i=h<<1; j=w<<1;
if(i<height && j<width)
{
coeffinfo[i][j].quantized_value = 0;
coeffinfo[i+1][j].quantized_value = 0;
coeffinfo[i][j+1].quantized_value = 0;
coeffinfo[i+1][j+1].quantized_value = 0;
coeffinfo[i][j].type = ZTR_D;
coeffinfo[i+1][j].type = ZTR_D;
coeffinfo[i][j+1].type = ZTR_D;
coeffinfo[i+1][j+1].type = ZTR_D;
mark_ZTR_D(i,j);
mark_ZTR_D(i+1,j);
mark_ZTR_D(i,j+1);
mark_ZTR_D(i+1,j+1);
}
}
/********************************************************
Function Name
-------------
static Void mag_sign_decode_MQ(Int h,Int w)
Arguments
---------
Int h,Int w - position of a pixel
Description
-----------
Decode the value of a coefficient.
Functions Called
----------------
mzte_ac_decode_symbol()
Return Value
------------
None.
********************************************************/
// hjlee 0901
Void CVTCDecoder::mag_sign_decode_MQ(Int h,Int w)
{
Int val,v_sign;
Int l;
if(coeffinfo[h][w].skip)
{
coeffinfo[h][w].quantized_value=0;
return;
}
l=xy2wvtDecompLev(w,h);
if (IS_RESID(w,h,color))
{
val=bitplane_res_decode(l,WVTDECOMP_RES_NUMBITPLANES(color));
coeffinfo[h][w].quantized_value=val;
}
else
{
val=bitplane_decode(l,WVTDECOMP_NUMBITPLANES(color,l))+1;
v_sign=mzte_ac_decode_symbol(&acd,acm_sign[l]);
coeffinfo[h][w].quantized_value=(v_sign==0) ? val : -val;
}
}
/*************************************************************
Function Name
-------------
Void decodeSQBlocks()
Arguments
---------
Int y, Int x - Coordinate of upper left hand corner of block.
Int n - Number of 4 blocks in a side of the total block. 0 means do only
pixel at (x,y).
Void (*pixelFunc)(Int, Int) - Function to call for pixel locations.
Description
-----------
Call function pixelFunc(y,x) for all pixels (x,y) in block in band scan
manner.
Functions Called
----------------
decodeBlocks recursively.
Return Value
------------
None.
*************************************************************/
Void CVTCDecoder::decodeSQBlocks(Int y, Int x, Int n)
{
/* Call the encoding function for the 4 block pixels */
if (n == 0)
{
/* For checking scan-order : use 16x16 mono image
for comparison with Figure 7-38 scan order table in
document.
static Int i=4;
noteStat("%d: y=%d, x=%d\n",i++, y,x);
*/
decode_pixel_SQ(y,x);
}
else
{
Int k;
--n;
k = 1<<n;
decodeSQBlocks(y,x,n);
x += k;
decodeSQBlocks(y,x,n);
x -= k;
y += k;
decodeSQBlocks(y,x,n);
x += k;
decodeSQBlocks(y,x,n);
}
}
/*************************************************************
Function Name
-------------
Void decodeSQBlocks()
Arguments
---------
Int y, Int x - Coordinate of upper left hand corner of block.
Int n - Number of 4 blocks in a side of the total block. 0 means do only
pixel at (x,y).
Void (*pixelFunc)(Int, Int) - Function to call for pixel locations.
Description
-----------
Call function pixelFunc(y,x) for all pixels (x,y) in block in band scan
manner.
Functions Called
----------------
decodeBlocks recursively.
Return Value
------------
None.
*************************************************************/
Void CVTCDecoder::decodeMQBlocks(Int y, Int x, Int n)
{
/* Call the encoding function for the 4 block pixels */
if (n == 0)
{
/* For checking scan-order : use 16x16 mono image
for comparison with Figure 7-38 scan order table in
document.
static Int i=4;
noteStat("%d: y=%d, x=%d\n",i++, y,x);
*/
decode_pixel_MQ(y,x);
}
else
{
Int k;
--n;
k = 1<<n;
decodeMQBlocks(y,x,n);
x += k;
decodeMQBlocks(y,x,n);
x -= k;
y += k;
decodeMQBlocks(y,x,n);
x += k;
decodeMQBlocks(y,x,n);
}
}
//Added by Sarnoff for error resilience, 3/5/99
/* ----------------------------------------------------------------- */
/* ----------------- Error resilience related routines ------------- */
/* ----------------------------------------------------------------- */
/*************************************************************
Function Name
-------------
Void decodeSQBlocks_ErrResi()
Arguments
---------
Int y, Int x - Coordinate of upper left hand corner of block.
Int n - Number of 4 blocks in a side of the total block. 0 means do only
pixel at (x,y).
Int c - color.
Description
-----------
Call function decode_pixel_SQ for all pixels (x,y) in block in band scan
manner.
Functions Called
----------------
decodeSQBlocks recursively.
Return Value
------------
None.
*************************************************************/
Void CVTCDecoder::decodeSQBlocks_ErrResi(Int y, Int x, Int n, Int c)
{
/* Call the encoding function for the 4 block pixels */
if (n == 0)
{
/* For checking scan-order : use 16x16 mono image
for comparison with Figure 7-38 scan order table in
document.
static Int i=4;
noteStat("%d: y=%d, x=%d\n",i++, y,x);
*/
decode_pixel_SQ(y,x);
}
else
{
Int k;
--n;
k = 1<<n;
decodeSQBlocks_ErrResi(y,x,n,c);
if (n==4)
found_segment_error(c);
x += k;
decodeSQBlocks_ErrResi(y,x,n,c);
if (n==4)
found_segment_error(c);
x -= k;
y += k;
decodeSQBlocks_ErrResi(y,x,n,c);
if (n==4)
found_segment_error(c);
x += k;
decodeSQBlocks_ErrResi(y,x,n,c);
if (n==4)
found_segment_error(c);
}
}
/* init all ac_decoder and models, bbc, 11/6/98 */
/* ph, 11/13/98 - added color argument for band-by-band */
Void CVTCDecoder::init_arith_decoder_model(Int color)
{
if(init_ac!=0) /* check for not closed ac coder. bbc, 7/2/98 */
errorHandler("didn't close arithmetic decoder before.");
else
init_ac=1;
/* init arithmetic coder */
mzte_ac_decoder_init(&acd);
if(mzte_codec.m_iScanDirection ==0 ){ /* tree depth */
for (color=0; color<mzte_codec.m_iColors; color++)
probModelInitSQ(color);
}
else { /* band-by-band */
probModelInitSQ(color); /* ph - 11/13/98 */
}
}
/* close all ac_decoder and models, bbc, 11/6/98 */
/* ph, 11/13/98 - added color argument for band-by-band */
Void CVTCDecoder::close_arith_decoder_model(Int color)
{
if(init_ac==0) /* didn't init ac before. */
return;
else
init_ac=0;
if(errSignal ==0)
noteProgress(" ==>D found packet at [TU_%d,TU_%d], l=%d bits",TU_first,
TU_last,packet_size-16);
if(mzte_codec.m_iScanDirection==0){ /* TD */
for (color=0; color<mzte_codec.m_iColors; color++)
/* close arithmetic coder */
probModelFreeSQ(color);
}
else{ /* BB */
probModelFreeSQ(color); /* ph - 11/13/98 */
}
mzte_ac_decoder_done(&acd);
}
/*****************************************************/
/* to check if a segment in a packet has exceeded a */
/* threshold. Look for a marker if so. bbc, 11/6/98 */
/*****************************************************/
Int CVTCDecoder::found_segment_error(Int col)
{
/* segment not long enough, bbc, 11/16/98 */
if(packet_size-16-prev_segs_size<(Int)mzte_codec.m_usSegmentThresh)
return 2;
noteProgress("\tDecode segment marker.");
prev_segs_size=packet_size-16;
/* search for the marker, bbc, 11/10/98
if(mzte_ac_decode_symbol(&acd,acm_type[0][CONTEXT_INIT])==ZTR)
return 0; */
if(mzte_ac_decode_symbol(&acd,&acmType[col][0][CONTEXT_INIT])==ZTR)
return 0;
prev_segs_size=0;
return 1;
}
/* Check if a new packet will start, bbc, 11/9/98 */
Void CVTCDecoder::check_end_of_packet()
{
if(LTU==TU_last){ /* reach the end of a packet */
close_arith_decoder_model(color);
align_byte();
if(TU_last == TU_max){ /* successfully decoded last packet */
if(end_of_stream())
error_bits_stat(0);
else{
while(!end_of_stream())
get_X_bits(8);
rewind_bits(16);
error_bits_stat(1);
}
return;
}
packet_size=0;
prev_segs_size=0;
/* start new packet */
CTU_no=get_err_resilience_header();
LTU=CTU_no-1;
get_TU_location(TU_first-1);
if(mzte_codec.m_iScanDirection==0)
{
/* TD */
if(TU_color==0)
set_prev_good_TD_segment(TU_first-1,
((start_h+1)<<(mzte_codec.m_iWvtDecmpLev-1))-1,
((start_w+1)<<(mzte_codec.m_iWvtDecmpLev-1))-1);
else
set_prev_good_TD_segment(TU_first-1,
((start_h+1)<<(mzte_codec.m_iWvtDecmpLev-2))-1,
((start_w+1)<<(mzte_codec.m_iWvtDecmpLev-2))-1);
}
else
{
/* BB */
}
if(CTU_no>TU_max)
return;
Int iTmp = get_X_bits(1);
//if(iTmp != 0) /* no repeated header info for now, bbc, 6/27/98 */
/* errorHandler("Error in decoding HEC.") */;
if (mzte_codec.m_iScanDirection==0)
init_arith_decoder_model(color);
else
{
/* don't reinitialize if color change */
if ((LTU-TU_max_dc+1) % mzte_codec.m_iDCHeight != 0)
init_arith_decoder_model(color);
}
}
}
#ifdef _DC_PACKET_
/* check if end of packet is reached, bbc, 11/18/98 */
Void CVTCDecoder::check_end_of_DC_packet(int numBP)
{
int i;
if(LTU==TU_last){
if(errSignal ==0)
noteProgress(" ==>D found packet at [TU_%d,TU_%d], l=%d bits",
TU_first,TU_last,packet_size-16);
for (i=0; i<numBP; i++)
mzte_ac_model_done(&(acm_bpdc[i]));
mzte_ac_model_done(&acmType[color][0][CONTEXT_INIT]);
mzte_ac_decoder_done(&acd);
align_byte();
/* start new packet */
packet_size=0;
prev_segs_size=0;
CTU_no=get_err_resilience_header();
LTU=CTU_no-1;
if(get_X_bits(1) != 0)
/* errorHandler("Error in decoding HEC.") */;
mzte_ac_decoder_init(&acd);
for (i=0; i<numBP; i++) {
acm_bpdc[i].Max_frequency = Bitplane_Max_frequency;
mzte_ac_model_init(&(acm_bpdc[i]),2,NULL,ADAPT,1);
}
mzte_ac_model_init(&acmType[color][0][CONTEXT_INIT],NUMCHAR_TYPE,
NULL,ADAPT,1); /* bbc, 11/20/98 */
coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo;
}
}
#endif _DC_PACKET_
//End: Added by Sarnoff for error resilience, 3/5/99
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -