📄 ztscan_enc.cpp
字号:
Function Name ------------- static Void cachb_encode_SQ_band() Arguments --------- None. Description ----------- Encode AC information for single quant mode, tree-depth scan. Functions Called ---------------- codeBlocks(); encode_pixel_SQ() Return Value ------------ None.********************************************************/ Void CVTCEncoder::cachb_encode_SQ_band(SNR_IMAGE *snr_image){ Int h,w,ac_h,ac_w,ac_h2,ac_w2; Int n; /* layer index - for codeBlocks function */ Int k; /* block jump for the layer */ // hjlee 0928 /* ac_h, ac_w init */ ac_h2=mzte_codec.m_SPlayer[color].height; ac_w2=mzte_codec.m_SPlayer[color].width; ac_h=ac_h2>>1; ac_w=ac_w2>>1; height=mzte_codec.m_Image[color].height; width=mzte_codec.m_Image[color].width; /* Get layer index - for codeBlocks function */ // hjlee 0928 n = -1; for (w=mzte_codec.m_iDCWidth; w < ac_w2; w<<=1) n++; setProbModelsSQ(color); // hjlee 0901 coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo; /* scan each coefficients in the spatial layer */ k = 1<<n; // hjlee 0928//Modified by Sarnoff for error resilience, 3/5/99 if(mzte_codec.m_usErrResiDisable){ //no error resilience case for(h=0;h<ac_h;h+=k) for(w=ac_w;w<ac_w2;w+=k) { /* LH */ encodeSQBlocks(h,w,n); /* HL */ h += ac_h; w -= ac_w; encodeSQBlocks(h,w,n); /* HH */ w += ac_w; encodeSQBlocks(h,w,n); /* Set h back to where it started. w is already there */ h -= ac_h; } } else{ //error resilience case for(h=0;h<ac_h;h+=k) { for(w=ac_w;w<ac_w2;w+=k) { /* LH */ encodeSQBlocks_ErrResi(h,w,n,color); if (n>0 && n<5) check_segment_size(color); /* HL */ h += ac_h; w -= ac_w; encodeSQBlocks_ErrResi(h,w,n,color); if (n>0 && n<5) check_segment_size(color); /* HH */ w += ac_w; encodeSQBlocks_ErrResi(h,w,n,color); if (n>0 && n<5) check_segment_size(color); /* Set h back to where it started. w is already there */ h -= ac_h; } /* new texture unit */ check_end_of_packet(color); } }//End modified by Sarnoff for error resilience, 3/5/99} /******************************************************* The following single quant routines are for tree depth scan order.*******************************************************//******************************************************** Function Name ------------- Void wavelet_higher_bands_encode_SQ_tree() Arguments --------- None. Description ----------- Control program for encoding AC information for one color component. Single quant mode. Functions Called ---------------- cachb_encode_SQ_tree() mzte_ac_encoder_init() mzte_ac_model_init() mzte_ac_model_done() mzte_ac_encoder_done() Return Value ------------ None.********************************************************/ Void CVTCEncoder::wavelet_higher_bands_encode_SQ_tree() // hjlee 0928{ noteDetail("Encoding AC (wavelet_higher_bands_encode_SQ)....");//Modified by Sarnoff for error resilience, 3/5/99 if(mzte_codec.m_usErrResiDisable){ //no error resilience case /* init arithmetic coder */ mzte_ac_encoder_init(&ace); // hjlee 0901 for (color=0; color<mzte_codec.m_iColors; color++) probModelInitSQ(color); cachb_encode_SQ_tree(); // hjlee 0928 // hjlee 0901 for (color=0; color<mzte_codec.m_iColors; color++) /* close arithmetic coder */ probModelFreeSQ(color); bit_stream_length=mzte_ac_encoder_done(&ace); } else{ //error resilience init_arith_encoder_model(-1); cachb_encode_SQ_tree(); // hjlee 0928 if (packet_size+ace.bitCount>0){ TU_last--; close_arith_encoder_model(-1,1); // write packet header } }//End modified by Sarnoff for error resilience, 3/5/99 noteDetail("Completed encoding AC.");}/******************************************************** Function Name ------------- static Void cachb_encode_SQ_tree() Arguments --------- None. Description ----------- Encode AC information for single quant mode, tree-depth scan. Functions Called ---------------- encode_pixel_SQ_tree() Return Value ------------ None.********************************************************/ Void CVTCEncoder::cachb_encode_SQ_tree(){ Int h,w,dc_h,dc_w,dc_h2,dc_w2; dc_h=mzte_codec.m_iDCHeight; dc_w=mzte_codec.m_iDCWidth; dc_h2=dc_h<<1; dc_w2=dc_w<<1;//Modified by Sarnoff for error resilience, 3/5/99 if(mzte_codec.m_usErrResiDisable){ //no error resi case for(h=0;h<dc_h;h++) for(w=0;w<dc_w;w++) // 1124 for (color=0; color<mzte_codec.m_iColors; color++) { SNR_IMAGE *snr_image; Int tw,sw,sh,n; // 1124 snr_image=&(mzte_codec.m_SPlayer[color].SNRlayer.snr_image); height=mzte_codec.m_Image[color].height; width=mzte_codec.m_Image[color].width; setProbModelsSQ(color); // hjlee 0901 coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo; /* LH */ n = 0; for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1) { sh = h << n; sw = (w+dc_w) << n; encodeSQBlocks(sh,sw,n); n++; } /* HL */ n = 0; for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1) { sh = (h+dc_h) << n; sw = w << n; encodeSQBlocks(sh,sw,n); n++; } /* HH */ n = 0; for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1) { sh = (h+dc_h) << n; sw = (w+dc_w) << n; encodeSQBlocks(sh,sw,n); n++; } } } else{ //error resilience for(h=0;h<dc_h;h++) for(w=0;w<dc_w;w++) // 1124 for (color=0; color<mzte_codec.m_iColors; color++) { SNR_IMAGE *snr_image; Int tw,sw,sh,n; // 1124 snr_image=&(mzte_codec.m_SPlayer[color].SNRlayer.snr_image); height=mzte_codec.m_Image[color].height; width=mzte_codec.m_Image[color].width; setProbModelsSQ(color); // hjlee 0901 coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo; /* LH */ n = 0; for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1) { sh = h << n; sw = (w+dc_w) << n; encodeSQBlocks_ErrResi(sh,sw,n,color); if (n>0 && n<5) check_segment_size(color); n++; } check_end_of_packet(-1); /* HL */ n = 0; for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1) { sh = (h+dc_h) << n; sw = w << n; encodeSQBlocks_ErrResi(sh,sw,n,color); if (n>0 && n<5) check_segment_size(color); n++; } if(TU_last==91) printf("Debug.\n"); check_end_of_packet(-1); /* HH */ n = 0; for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1) { sh = (h+dc_h) << n; sw = (w+dc_w) << n; encodeSQBlocks_ErrResi(sh,sw,n,color); if (n>0 && n<5) check_segment_size(color); n++; } check_end_of_packet(-1); } }//End modified by Sarnoff for error resilience, 3/5/99}/******************************************************** Function Name ------------- static Void encode_pixel_SQ_tree(Int h,Int w) Arguments --------- Int h,Int w - position of a pixel in height and width Description ----------- Encoding the type and/or value of a coefficient, a recursive function. Functions Called ---------------- mag_sign_encode_SQ() mzte_ac_encode_symbol() encode_pixel_SQ_tree() Return Value ------------ None.********************************************************/ Void CVTCEncoder::encode_pixel_SQ(Int h,Int w){ UChar zt_type; Int l; if(coeffinfo[h][w].type == ZTR_D) return; l=xy2wvtDecompLev(w,h); /* code leave coefficients, value only, no type */ if(IS_STATE_LEAF(coeffinfo[h][w].state)){ /* Map type to leaf code word ZTR->0, VZTR->1 */ zt_type = (coeffinfo[h][w].type!=ZTR); mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_LINIT],zt_type); if (coeffinfo[h][w].type==VZTR) mag_sign_encode_SQ(h,w); return; } /* code zerotree symbol */ mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_INIT], zt_type=coeffinfo[h][w].type); /* code magnitude and sign */ /* For Arbitrary-Shape, out-node will always has zero coefficient, so only IZ or ZTR may be the zt_type -- SL*/ switch(zt_type){ case IZ : break; /* will code the four children */ case VZTR: mag_sign_encode_SQ(h,w); case ZTR: mark_ZTR_D(h,w); /* necessary, for bandwise scan */ break; case VAL: mag_sign_encode_SQ(h,w); break; default: errorHandler("invalid zerotree symbol in single quant encode"); }}#if 0Void CVTCEncoder::encode_pixel_SQ_tree(Int h0,Int w0){ UChar zt_type; Int h, w, k; Int dcc[4]; /* Don't Code Children */ Int nSib; /* number siblings */ Int l; l=xy2wvtDecompLev(w0,h0); nSib = (h0<(mzte_codec.m_iDCHeight<<1) && w0<(mzte_codec.m_iDCWidth<<1)) ? 1 : 4; /********************* CODE SIBLINGS *****************************/ for (k=0; k<nSib; ++k) { h = h0 + (k/2); w = w0 + (k%2); /* code leave coefficients, value only, no type */ if(IS_STATE_LEAF(coeffinfo[h][w].state)) {#ifdef _SHAPE_ /* skip out-node */ if(coeffinfo[h][w].mask == 1) {#endif /* Map type to leaf code word ZTR->0, VZTR->1 */ zt_type = (coeffinfo[h][w].type!=ZTR); mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_LINIT],zt_type); if (coeffinfo[h][w].type==VZTR) mag_sign_encode_SQ(h,w);#ifdef _SHAPE_ }#endif continue; } /* code zerotree symbol */#ifdef _SHAPE_ /* skip out-node */ if(coeffinfo[h][w].mask == 1) #endif mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_INIT], zt_type=coeffinfo[h][w].type);#ifdef _SHAPE_ else zt_type=coeffinfo[h][w].type;#endif /* code magnitude and sign */ /* For Arbitrary-Shape, out-node will always has zero coefficient, so only IZ or ZTR may be the zt_type -- SL*/ switch(zt_type){ case IZ : dcc[k]=0; break; /* will code the four children */ case VZTR: mag_sign_encode_SQ(h,w); case ZTR: dcc[k]=1;#ifdef _SHAPE_ if(coeffinfo[h][w].mask != 1) { /* TBE for four children of out-node */ dcc[k] = 0; }#endif break; case VAL: dcc[k]=0; mag_sign_encode_SQ(h,w); break; default: errorHandler("invalid zerotree symbol in single quant encode"); } } /********************* 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; encode_pixel_SQ_tree(i,j); } } }}#endif /******************************************************** Function Name ------------- static Void mag_sign_encode_SQ(Int h,Int w) Arguments --------- Int h,Int w - position of a pixel Description ----------- Encode the value of a coefficient. Functions Called ---------------- mzte_ac_encode_symbol() Return Value ------------ None.********************************************************/ Void CVTCEncoder::mag_sign_encode_SQ(Int h,Int w){ Int val,v_sign; Int l; if((val=coeffinfo[h][w].quantized_value)>0) v_sign=0; else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -