⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 block_encoder.cpp

📁 JPEG2000压缩解压图像源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = sp[width];            sym = (kdu_int32)(((kdu_uint32) sym)>>31); // Move sign into LSB            _raw_enc_(coder,sym);            // Broadcast neighbourhood context changes            cp[-1] |= (SIGMA_CR_BIT<<3);            cp[1]  |= (SIGMA_CL_BIT<<3);            cword |= (SIGMA_CC_BIT<<3) | (PI_BIT<<3) | (sym<<(CHI_POS+3));          }row_2:        if ((cword & (NBRHD_MASK<<6)) && !(cword & (SIG_PROP_MEMBER_MASK<<6)))          { // Process third row of stripe column (row 2)            val = sp[width_by2]<<shift; // Move bit p to sign bit.            sym = (kdu_int32)(((kdu_uint32) val)>>31); // Move bit into LSB            _raw_enc_(coder,sym);            if (val >= 0) // New magnitude bit was 0, so still insignificant              { cword |= (PI_BIT<<6); goto row_3; }            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = sp[width_by2];            sym = (kdu_int32)(((kdu_uint32) sym)>>31); // Move sign into LSB            _raw_enc_(coder,sym);            // Broadcast neighbourhood context changes            cp[-1] |= (SIGMA_CR_BIT<<6);            cp[1]  |= (SIGMA_CL_BIT<<6);            cword |= (SIGMA_CC_BIT<<6) | (PI_BIT<<6) | (sym << (CHI_POS+6));          }row_3:        if ((cword & (NBRHD_MASK<<9)) && !(cword & (SIG_PROP_MEMBER_MASK<<9)))          { // Process fourth row of stripe column (row 3)            val = sp[width_by3]<<shift; // Move bit p to sign bit.            sym = (kdu_int32)(((kdu_uint32) val)>>31); // Move bit into LSB            _raw_enc_(coder,sym);            if (val >= 0) // New magnitude bit was 0, so still insignificant              { cword |= (PI_BIT<<9); goto done; }            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = sp[width_by3];            sym = (kdu_int32)(((kdu_uint32) sym)>>31); // Move sign into LSB            _raw_enc_(coder,sym);            // Broadcast neighbourhood context changes            cp[context_row_gap-1] |= SIGMA_TR_BIT;            cp[context_row_gap  ] |= SIGMA_TC_BIT | (sym<<PREV_CHI_POS);            cp[context_row_gap+1] |= SIGMA_TL_BIT;            cp[-1] |= (SIGMA_CR_BIT<<9);            cp[1]  |= (SIGMA_CL_BIT<<9);            cword |= (SIGMA_CC_BIT<<9) | (PI_BIT<<9) | (sym<<(CHI_POS+9));          }done:        *cp = cword;      }  _raw_check_in_(coder);  return distortion_change;}/*****************************************************************************//* STATIC                    encode_sig_prop_pass                            *//*****************************************************************************/static kdu_int32  encode_sig_prop_pass(mq_encoder &coder, mqe_state states[],                       int p, bool causal, int orientation,                       kdu_int32 *samples, kdu_int32 *contexts,                       int width, int num_stripes, int context_row_gap,                       bool lossless_pass){  /* Ideally, register storage is available for 12 32-bit integers. Three     are declared inside the "_mq_check_out_" macro.  The order of priority     for these registers corresponds roughly to the order in which their     declarations appear below.  Unfortunately, none of these register     requests are likely to be honored by the register-starved X86 family     of processors, but the register declarations may prove useful to     compilers for other architectures or for hand optimizations of     assembly code. */  register kdu_int32 *cp = contexts;  register int c;  register kdu_int32 cword;  _mq_check_out_(coder); // Declares A, C, and t as registers.  register kdu_int32 sym;  register kdu_int32 val;  register kdu_int32 *sp = samples;  register kdu_int32 shift = 31-p; assert(shift > 0);  register  kdu_byte *sig_lut = significance_luts[orientation];  register mqe_state *state_ref;  int r, width_by2=width+width, width_by3=width_by2+width;  kdu_int32 distortion_change = 0;  kdu_int32 *distortion_lut = significance_distortion_lut;  if (lossless_pass)    distortion_lut = significance_distortion_lut_lossless;  assert((context_row_gap - width) == EXTRA_ENCODE_CWORDS);  for (r=num_stripes; r > 0; r--, cp += EXTRA_ENCODE_CWORDS, sp += width_by3)    for (c=width; c > 0; c--, sp++, cp++)      {        if (*cp == 0)          { // Invoke speedup trick to skip over runs of all-0 neighbourhoods            for (cp+=3; *cp == 0; cp+=3, c-=3, sp+=3);            cp-=3;            continue;          }        cword = *cp;        if ((cword & (NBRHD_MASK<<0)) && !(cword & (SIG_PROP_MEMBER_MASK<<0)))          { // Process first row of stripe column (row 0)            state_ref = states+KAPPA_SIG_BASE+sig_lut[cword & NBRHD_MASK];            val = sp[0]<<shift; // Move bit p to sign bit.            sym = val & KDU_INT32_MIN;            _mq_enc_(coder,sym,*state_ref);            if (val >= 0) // New magnitude bit was 0, so still insignificant              { cword |= (PI_BIT<<0); goto row_1; }            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = cword & ((CHI_BIT>>3) | (SIGMA_CC_BIT>>3) |                           (CHI_BIT<<3) | (SIGMA_CC_BIT<<3));            sym >>= 1; // Shift down so that top sigma bit has address 0            sym |= (cp[-1] & ((CHI_BIT<<0) | (SIGMA_CC_BIT<<0))) >> (1+1);            sym |= (cp[ 1] & ((CHI_BIT<<0) | (SIGMA_CC_BIT<<0))) >> (1-1);            sym |= (sym >> (CHI_POS-1-SIGMA_CC_POS)); // Interleave chi & sigma            val = sign_lut[sym & 0x000000FF];            state_ref = states + KAPPA_SIGN_BASE + (val>>1);            sym = val << 31; // Get sign flipping to `sym'            val = sp[0] & KDU_INT32_MIN; // Get the sign bit            sym ^= val; // Moves flipped sign bit into `sym'            _mq_enc_(coder,sym,*state_ref);            // Broadcast neighbourhood context changes; sign bit is in `val'            cp[-1] |= (SIGMA_CR_BIT<<0);            cp[1]  |= (SIGMA_CL_BIT<<0);            if (val < 0)              {                cword |= (SIGMA_CC_BIT<<0) | (PI_BIT<<0) | (CHI_BIT<<0);                if (!causal)                  {                    cp[-context_row_gap-1] |= (SIGMA_BR_BIT<<9);                    cp[-context_row_gap  ] |= (SIGMA_BC_BIT<<9) | NEXT_CHI_BIT;                    cp[-context_row_gap+1] |= (SIGMA_BL_BIT<<9);                  }              }            else              {                cword |= (SIGMA_CC_BIT<<0) | (PI_BIT<<0);                if (!causal)                  {                    cp[-context_row_gap-1] |= (SIGMA_BR_BIT<<9);                    cp[-context_row_gap  ] |= (SIGMA_BC_BIT<<9);                    cp[-context_row_gap+1] |= (SIGMA_BL_BIT<<9);                  }              }          }row_1:        if ((cword & (NBRHD_MASK<<3)) && !(cword & (SIG_PROP_MEMBER_MASK<<3)))          { // Process second row of stripe column (row 1)            state_ref = states+KAPPA_SIG_BASE+sig_lut[(cword>>3) & NBRHD_MASK];            val = sp[width]<<shift; // Move bit p to sign bit.            sym = val & KDU_INT32_MIN;            _mq_enc_(coder,sym,*state_ref);            if (val >= 0) // New magnitude bit was 0, so still insignificant              { cword |= (PI_BIT<<3); goto row_2; }            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = cword & ((CHI_BIT<<0) | (SIGMA_CC_BIT<<0) |                           (CHI_BIT<<6) | (SIGMA_CC_BIT<<6));            sym >>= 4; // Shift down so that top sigma bit has address 0            sym |= (cp[-1] & ((CHI_BIT<<3) | (SIGMA_CC_BIT<<3))) >> (4+1);            sym |= (cp[ 1] & ((CHI_BIT<<3) | (SIGMA_CC_BIT<<3))) >> (4-1);            sym |= (sym >> (CHI_POS-1-SIGMA_CC_POS)); // Interleave chi & sigma            val = sign_lut[sym & 0x000000FF];            state_ref = states + KAPPA_SIGN_BASE + (val>>1);            sym = val << 31; // Get sign flipping to `sym'            val = sp[width] & KDU_INT32_MIN; // Get the sign bit            sym ^= val; // Moves flipped sign bit into `sym'            _mq_enc_(coder,sym,*state_ref);            // Broadcast neighbourhood context changes; sign bit is in `val'            cp[-1] |= (SIGMA_CR_BIT<<3);            cp[1]  |= (SIGMA_CL_BIT<<3);            cword |= (SIGMA_CC_BIT<<3) | (PI_BIT<<3);            val = (kdu_int32)(((kdu_uint32) val)>>(31-(CHI_POS+3))); // SRL            cword |= val;          }row_2:        if ((cword & (NBRHD_MASK<<6)) && !(cword & (SIG_PROP_MEMBER_MASK<<6)))          { // Process third row of stripe column (row 2)            state_ref = states+KAPPA_SIG_BASE+sig_lut[(cword>>6) & NBRHD_MASK];            val = sp[width_by2]<<shift; // Move bit p to sign bit.            sym = val & KDU_INT32_MIN;            _mq_enc_(coder,sym,*state_ref);            if (val >= 0) // New magnitude bit was 0, so still insignificant              { cword |= (PI_BIT<<6); goto row_3; }            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = cword & ((CHI_BIT<<3) | (SIGMA_CC_BIT<<3) |                           (CHI_BIT<<9) | (SIGMA_CC_BIT<<9));            sym >>= 7; // Shift down so that top sigma bit has address 0            sym |= (cp[-1] & ((CHI_BIT<<6) | (SIGMA_CC_BIT<<6))) >> (7+1);            sym |= (cp[ 1] & ((CHI_BIT<<6) | (SIGMA_CC_BIT<<6))) >> (7-1);            sym |= (sym >> (CHI_POS-1-SIGMA_CC_POS)); // Interleave chi & sigma            val = sign_lut[sym & 0x000000FF];            state_ref = states + KAPPA_SIGN_BASE + (val>>1);            sym = val << 31; // Get sign flipping to `sym'            val = sp[width_by2] & KDU_INT32_MIN; // Get the sign bit            sym ^= val; // Moves flipped sign bit into `sym'            _mq_enc_(coder,sym,*state_ref);            // Broadcast neighbourhood context changes; sign bit is in `val'            cp[-1] |= (SIGMA_CR_BIT<<6);            cp[1]  |= (SIGMA_CL_BIT<<6);            cword |= (SIGMA_CC_BIT<<6) | (PI_BIT<<6);            val = (kdu_int32)(((kdu_uint32) val)>>(31-(CHI_POS+6))); // SRL            cword |= val;          }row_3:        if ((cword & (NBRHD_MASK<<9)) && !(cword & (SIG_PROP_MEMBER_MASK<<9)))          { // Process fourth row of stripe column (row 3)            state_ref = states+KAPPA_SIG_BASE+sig_lut[(cword>>9) & NBRHD_MASK];            val = sp[width_by3]<<shift; // Move bit p to sign bit.            sym = val & KDU_INT32_MIN;            _mq_enc_(coder,sym,*state_ref);            if (val >= 0) // New magnitude bit was 0, so still insignificant              { cword |= (PI_BIT<<9); goto done; }            // Compute distortion change            val =  (val>>(31-DISTORTION_LSBS)) & (SIGNIFICANCE_DISTORTIONS-1);            distortion_change += distortion_lut[val];            // Encode sign bit            sym = cword & ((CHI_BIT<<6) | (SIGMA_CC_BIT<<6) |                                0       | (SIGMA_CC_BIT<<12));            sym >>= 10; // Shift down so that top sigma bit has address 0            if (cword < 0) // Use the fact that NEXT_CHI_BIT = 31              sym |= CHI_BIT<<(12-10);            sym |= (cp[-1] & ((CHI_BIT<<9) | (SIGMA_CC_BIT<<9))) >> (10+1);            sym |= (cp[ 1] & ((CHI_BIT<<9) | (SIGMA_CC_BIT<<9))) >> (10-1);            sym |= (sym >> (CHI_POS-1-SIGMA_CC_POS)); // Interleave chi & sigma            val = sign_lut[sym & 0x000000FF];            state_ref = states + KAPPA_SIGN_BASE + (val>>1);            sym = val << 31; // Get sign flipping to `sym'            val = sp[width_by3] & KDU_INT32_MIN; // Get the sign bit            sym ^= val; // Moves flipped sign bit into `sym'            _mq_enc_(coder,sym,*state_ref);            // Broadcast neighbourhood context changes; sign bit is in `val'            cp[context_row_gap-1] |= SIGMA_TR_BIT;            cp[context_row_gap+1] |= SIGMA_TL_BIT;            cp[-1] |= (SIGMA_CR_BIT<<9);            cp[1]  |= (SIGMA_CL_BIT<<9);            if (val < 0)              {                cp[context_row_gap  ] |= SIGMA_TC_BIT | PREV_CHI_BIT;                cword |= (SIGMA_CC_BIT<<9) | (PI_BIT<<9) | (CHI_BIT<<9);              }            else              {                cp[context_row_gap  ] |= SIGMA_TC_BIT;                cword |= (SIGMA_CC_BIT<<9) | (PI_BIT<<9);              }          }done:        *cp = cword;      }  _mq_check_in_(coder);  return distortion_change;}/*****************************************************************************//* STATIC                    encode_mag_ref_pass_raw                         *//*****************************************************************************/static kdu_int32  encode_mag_ref_pass_raw(mq_encoder &coder, int p, bool causal,                          kdu_int32 *samples, kdu_int32 *contexts,                          int width, int num_stripes, int context_row_gap,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -