📄 block_encoder.cpp
字号:
bool lossless_pass){ /* Ideally, register storage is available for 9 32-bit integers. Two 32-bit integers are declared inside the "_raw_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; _raw_check_out_(coder); // Declares t and temp as registers. register kdu_int32 *sp = samples; register kdu_int32 sym; register kdu_int32 val; register kdu_int32 shift = 31-p; // Shift to get new mag bit to sign position 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; 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]; val <<= shift; // Get new magnitude bit to sign position. sym = (kdu_int32)(((kdu_uint32) val)>>31); // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _raw_enc_(coder,sym); } if (cword & (MU_BIT<<3)) { // Process second row of stripe column val = sp[width]; val <<= shift; // Get new magnitude bit to sign position. sym = (kdu_int32)(((kdu_uint32) val)>>31); // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _raw_enc_(coder,sym); } if (cword & (MU_BIT<<6)) { // Process third row of stripe column val = sp[width_by2]; val <<= shift; // Get new magnitude bit to sign position. sym = (kdu_int32)(((kdu_uint32) val)>>31); // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _raw_enc_(coder,sym); } if (cword & (MU_BIT<<9)) { // Process fourth row of stripe column val = sp[width_by3]; val <<= shift; // Get new magnitude bit to sign position. sym = (kdu_int32)(((kdu_uint32) val)>>31); // Compute distortion change val = (val >> (31-DISTORTION_LSBS)) & (REFINEMENT_DISTORTIONS-1); distortion_change += distortion_lut[val]; // Encode magnitude bit _raw_enc_(coder,sym); } } _raw_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; } state_ref = states + KAPPA_RUN_BASE; _mq_enc_(coder,sym,*state_ref); if (val < 0) continue; _mq_enc_run_(coder,val); cword = *cp; switch (val) { case 0: val = sp[0]<<shift; goto row_0_significant; case 1: val = sp[width]<<shift; goto row_1_significant; case 2: val = sp[width_by2]<<shift; goto row_2_significant; case 3: val = sp[width_by3]<<shift; goto row_3_significant; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -