static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){ int i; for(i=0; i<128; i++){ int level= i-64; int run; if (!level) continue; for(run=0; run<64; run++){ int len, code; int alevel= FFABS(level); if (alevel > rl->max_level[0][run]) code= 111; /*rl->n*/ else code= rl->index_run[0][run] + alevel - 1; if (code < 111 /* rl->n */) { /* length of vlc and sign */ len= rl->table_vlc[code][1]+1; } else { len= rl->table_vlc[111/*rl->n*/][1]+6; if (alevel < 128) { len += 8; } else { len += 16; } } uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len; } } }
static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len) { int i; for(i = 0; i < 128; i++) { int level = i - 64; int run; for(run = 0; run < 64; run++) { int len, bits, code; int alevel = FFABS(level); int sign = (level >> 31) & 1; if (alevel > rl->max_level[0][run]) code = 111; /*rl->n*/ else code = rl->index_run[0][run] + alevel - 1; if (code < 111 /* rl->n */) { /* store the vlc & sign at once */ len = rl->table_vlc[code][1] + 1; bits = (rl->table_vlc[code][0] << 1) + sign; } else { len = rl->table_vlc[111/*rl->n*/][1] + 6; bits = rl->table_vlc[111/*rl->n*/][0] << 6; bits |= run; if (alevel < 128) { bits <<= 8; len += 8; bits |= level & 0xff; } else { bits <<= 16; len += 16; bits |= level & 0xff; if (level < 0) { bits |= 0x8001 + level + 255; } else { bits |= level & 0xffff; } } } uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)] = len; } } }
/** * Return the number of bits that encoding the 8x8 block in block would need. * @param[in] block_last_index last index in scantable order that refers to a non zero element in block. */ static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ int last=0; int j; int rate=0; for(j=1; j<=block_last_index; j++){ const int index= scantable[j]; int level= block[index]; if(level){ level+= 64; if((level&(~127)) == 0){ if(j<block_last_index) rate+= s->intra_ac_vlc_length [UNI_AC_ENC_INDEX(j-last-1, level)]; else rate+= s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j-last-1, level)]; }else rate += s->ac_esc_length; last= j; } } return rate; }