?? block_encoder.cpp
字號:
(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 *//*****************************************************************************/static kdu_int32 encode_mag_ref_pass(mq_encoder &coder, mqe_state states[], int p, bool causal, 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 32-bit integers 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 *sp = samples; register mqe_state *state_ref; register kdu_int32 sym; register kdu_int32 val; register kdu_int32 shift = 31-p; // Shift to get new mag bit to sign position register kdu_int32 refined_mask = (((kdu_int32)(-1))<<(p+2)) & KDU_INT32_MAX; int r, width_by2=width+width, width_by3=width_by2+width; kdu_int32 distortion_change = 0; kdu_int32 *distortion_lut = refinement_distortion_lut; if (lossless_pass) distortion_lut = refinement_distortion_lut_lossless; states += KAPPA_MAG_BASE; 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 & ((MU_BIT<<0)|(MU_BIT<<3)|(MU_BIT<<6)|(MU_BIT<<9))) == 0) { // Invoke speedup trick to skip over runs of all-0 neighbourhoods for (cp+=2; *cp == 0; cp+=2, c-=2, sp+=2); cp-=2; continue; } cword = *cp; if (cword & (MU_BIT<<0)) { // Process first row of stripe column val = sp[0]; // Get coding context state_ref = states; if (!(val & refined_mask)) { // This is the first magnitude refinement step if (cword & (NBRHD_MASK<<0)) state_ref++; } else state_ref += 2; val <<= shift; // Get new magnitude bit to sign position. sym = val & KDU_INT32_MIN; // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _mq_enc_(coder,sym,*state_ref); } if (cword & (MU_BIT<<3)) { // Process second row of stripe column val = sp[width]; // Get coding context state_ref = states; if (!(val & refined_mask)) { // This is the first magnitude refinement step if (cword & (NBRHD_MASK<<3)) state_ref++; } else state_ref += 2; val <<= shift; // Get new magnitude bit to sign position. sym = val & KDU_INT32_MIN; // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _mq_enc_(coder,sym,*state_ref); } if (cword & (MU_BIT<<6)) { // Process third row of stripe column val = sp[width_by2]; // Get coding context state_ref = states; if (!(val & refined_mask)) { // This is the first magnitude refinement step if (cword & (NBRHD_MASK<<6)) state_ref++; } else state_ref += 2; val <<= shift; // Get new magnitude bit to sign position. sym = val & KDU_INT32_MIN; // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _mq_enc_(coder,sym,*state_ref); } if (cword & (MU_BIT<<9)) { // Process fourth row of stripe column val = sp[width_by3]; // Get coding context state_ref = states; if (!(val & refined_mask)) { // This is the first magnitude refinement step if (cword & (NBRHD_MASK<<9)) state_ref++; } else state_ref += 2; val <<= shift; // Get new magnitude bit to sign position. sym = val & KDU_INT32_MIN; // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _mq_enc_(coder,sym,*state_ref); } } _mq_check_in_(coder); return distortion_change;}/*****************************************************************************//* STATIC encode_cleanup_pass *//*****************************************************************************/static kdu_int32 encode_cleanup_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) { // Enter the run mode sym = 0; val = -1; if ((sp[0] << shift) < 0) { val = 0; sym = KDU_INT32_MIN; } else if ((sp[width] << shift) < 0) { val = 1; sym = KDU_INT32_MIN; } else if ((sp[width_by2] << shift) < 0) { val = 2; sym = KDU_INT32_MIN; } else if ((sp[width_by3] << shift) < 0) { val = 3; sym = KDU_INT32_MIN; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -