avcodec: use av_mod_uintp2() where useful

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: James Almer <jamrial@gmail.com>
pull/89/merge
James Almer 10 years ago
parent 4f287a3c50
commit ba625dd8a1
  1. 2
      libavcodec/adpcm.c
  2. 4
      libavcodec/atrac3plus.c
  3. 2
      libavcodec/dnxhdenc.c
  4. 2
      libavcodec/dvenc.c
  5. 2
      libavcodec/ffv1.h
  6. 3
      libavcodec/ffv1dec.c
  7. 2
      libavcodec/g726.c
  8. 2
      libavcodec/g729dec.c
  9. 2
      libavcodec/golomb.h
  10. 5
      libavcodec/h264.c
  11. 2
      libavcodec/h264_refs.c
  12. 16
      libavcodec/hevc.c
  13. 8
      libavcodec/hevc_cabac.c
  14. 4
      libavcodec/hevc_mvs.c
  15. 4
      libavcodec/hevc_ps.c
  16. 4
      libavcodec/hevcpred_template.c
  17. 8
      libavcodec/mpeg12enc.c
  18. 2
      libavcodec/opus.h
  19. 4
      libavcodec/opus_celt.c
  20. 6
      libavcodec/proresenc_kostya.c
  21. 2
      libavcodec/put_bits.h

@ -197,7 +197,7 @@ static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitC
step_index = av_clip(step_index, 0, 88);
sign = nibble & (1 << shift);
delta = nibble & ((1 << shift) - 1);
delta = av_mod_uintp2(nibble, shift);
diff = ((2 * delta + 1) * step) >> shift;
predictor = c->predictor;
if (sign) predictor -= diff;

@ -820,7 +820,7 @@ static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab,
int num_coeffs = tab->num_coeffs;
int bits = tab->bits;
int is_signed = tab->is_signed;
unsigned val, mask = (1 << bits) - 1;
unsigned val;
for (pos = 0; pos < num_specs;) {
if (group_size == 1 || get_bits1(gb)) {
@ -828,7 +828,7 @@ static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab,
val = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
for (i = 0; i < num_coeffs; i++) {
cf = val & mask;
cf = av_mod_uintp2(val, bits);
if (is_signed)
cf = sign_extend(cf, bits);
else if (cf && get_bits1(gb))

@ -450,7 +450,7 @@ static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
}
put_bits(&ctx->m.pb, ctx->cid_table->dc_bits[nbits] + nbits,
(ctx->cid_table->dc_codes[nbits] << nbits) +
(diff & ((1 << nbits) - 1)));
av_mod_uintp2(diff, nbits));
}
static av_always_inline

@ -176,7 +176,7 @@ static av_always_inline PutBitContext *dv_encode_ac(EncBlockInfo *bi,
if (bits_left) {
size -= bits_left;
put_bits(pb, bits_left, vlc >> size);
vlc = vlc & ((1 << size) - 1);
vlc = av_mod_uintp2(vlc, size);
}
if (pb + 1 >= pb_end) {
bi->partial_bit_count = size;

@ -143,7 +143,7 @@ static av_always_inline int fold(int diff, int bits)
diff = (int8_t)diff;
else {
diff += 1 << (bits - 1);
diff &= (1 << bits) - 1;
diff = av_mod_uintp2(diff, bits);
diff -= 1 << (bits - 1);
}

@ -172,8 +172,7 @@ static av_always_inline void decode_line(FFV1Context *s, int w,
if (sign)
diff = -diff;
sample[1][x] = (predict(sample[1] + x, sample[0] + x) + diff) &
((1 << bits) - 1);
sample[1][x] = av_mod_uintp2(predict(sample[1] + x, sample[0] + x) + diff, bits);
}
s->run_index = run_index;
}

@ -298,7 +298,7 @@ static int16_t g726_encode(G726Context* c, int16_t sig)
{
uint8_t i;
i = quant(c, sig/4 - c->se) & ((1<<c->code_size) - 1);
i = av_mod_uintp2(quant(c, sig/4 - c->se), c->code_size);
g726_decode(c, i);
return i;
}

@ -512,7 +512,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
if (frame_erasure) {
ctx->rand_value = g729_prng(ctx->rand_value);
fc_indexes = ctx->rand_value & ((1 << format->fc_indexes_bits) - 1);
fc_indexes = av_mod_uintp2(ctx->rand_value, format->fc_indexes_bits);
ctx->rand_value = g729_prng(ctx->rand_value);
pulses_signs = ctx->rand_value;

@ -518,7 +518,7 @@ static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit,
e = i >> k;
if (e < limit)
put_bits(pb, e + k + 1, (1 << k) + (i & ((1 << k) - 1)));
put_bits(pb, e + k + 1, (1 << k) + av_mod_uintp2(i, k));
else
put_bits(pb, limit + esc_len, i - limit + 1);
}

@ -1559,9 +1559,8 @@ again:
h->valid_recovery_point = 1;
if ( h->recovery_frame < 0
|| ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt) {
h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) &
((1 << h->sps.log2_max_frame_num) - 1);
|| av_mod_uintp2(h->recovery_frame - h->frame_num, h->sps.log2_max_frame_num) > h->sei_recovery_frame_cnt) {
h->recovery_frame = av_mod_uintp2(h->frame_num + h->sei_recovery_frame_cnt, h->sps.log2_max_frame_num);
if (!h->valid_recovery_point)
h->recovery_frame = h->frame_num;

@ -772,7 +772,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count)
for (i = 0; i<h->short_ref_count; i++) {
pic = h->short_ref[i];
if (pic->invalid_gap) {
int d = (h->cur_pic_ptr->frame_num - pic->frame_num) & ((1 << h->sps.log2_max_frame_num)-1);
int d = av_mod_uintp2(h->cur_pic_ptr->frame_num - pic->frame_num, h->sps.log2_max_frame_num);
if (d > h->sps.ref_frame_count)
remove_short(h, pic->frame_num, 0);
}

@ -1461,8 +1461,8 @@ static void chroma_mc_uni(HEVCContext *s, uint8_t *dst0,
int idx = ff_hevc_pel_weight[block_w];
int hshift = s->sps->hshift[1];
int vshift = s->sps->vshift[1];
intptr_t mx = mv->x & ((1 << (2 + hshift)) - 1);
intptr_t my = mv->y & ((1 << (2 + vshift)) - 1);
intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift);
intptr_t my = av_mod_uintp2(mv->y, 2 + vshift);
intptr_t _mx = mx << (1 - hshift);
intptr_t _my = my << (1 - vshift);
@ -1530,10 +1530,10 @@ static void chroma_mc_bi(HEVCContext *s, uint8_t *dst0, ptrdiff_t dststride, AVF
int hshift = s->sps->hshift[1];
int vshift = s->sps->vshift[1];
intptr_t mx0 = mv0->x & ((1 << (2 + hshift)) - 1);
intptr_t my0 = mv0->y & ((1 << (2 + vshift)) - 1);
intptr_t mx1 = mv1->x & ((1 << (2 + hshift)) - 1);
intptr_t my1 = mv1->y & ((1 << (2 + vshift)) - 1);
intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift);
intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift);
intptr_t mx1 = av_mod_uintp2(mv1->x, 2 + hshift);
intptr_t my1 = av_mod_uintp2(mv1->y, 2 + vshift);
intptr_t _mx0 = mx0 << (1 - hshift);
intptr_t _my0 = my0 << (1 - vshift);
intptr_t _mx1 = mx1 << (1 - hshift);
@ -1791,8 +1791,8 @@ static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
int y_pu = y0 >> s->sps->log2_min_pu_size;
int min_pu_width = s->sps->min_pu_width;
int size_in_pus = pu_size >> s->sps->log2_min_pu_size;
int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
int cand_up = (lc->ctb_up_flag || y0b) ?
s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;

@ -658,8 +658,8 @@ int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0, int x_cb, int y_cb)
{
int min_cb_width = s->sps->min_cb_width;
int inc = 0;
int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
if (s->HEVClc->ctb_left_flag || x0b)
inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb);
@ -723,8 +723,8 @@ int ff_hevc_pred_mode_decode(HEVCContext *s)
int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth, int x0, int y0)
{
int inc = 0, depth_left = 0, depth_top = 0;
int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
int x_cb = x0 >> s->sps->log2_min_cb_size;
int y_cb = y0 >> s->sps->log2_min_cb_size;

@ -42,8 +42,8 @@ void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0,
int nPbW, int nPbH)
{
HEVCLocalContext *lc = s->HEVClc;
int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
lc->na.cand_up = (lc->ctb_up_flag || y0b);
lc->na.cand_left = (lc->ctb_left_flag || x0b);

@ -1123,8 +1123,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
if (sps->width & ((1 << sps->log2_min_cb_size) - 1) ||
sps->height & ((1 << sps->log2_min_cb_size) - 1)) {
if (av_mod_uintp2(sps->width, sps->log2_min_cb_size) ||
av_mod_uintp2(sps->height, sps->log2_min_cb_size)) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n");
goto err;
}

@ -117,8 +117,8 @@ do { \
if (s->pps->constrained_intra_pred_flag == 1) {
int size_in_luma_pu_v = PU(size_in_luma_v);
int size_in_luma_pu_h = PU(size_in_luma_h);
int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
int on_pu_edge_x = !av_mod_uintp2(x0, s->sps->log2_min_pu_size);
int on_pu_edge_y = !av_mod_uintp2(y0, s->sps->log2_min_pu_size);
if (!size_in_luma_pu_h)
size_in_luma_pu_h++;
if (cand_bottom_left == 1 && on_pu_edge_x) {

@ -620,12 +620,12 @@ static inline void encode_dc(MpegEncContext *s, int diff, int component)
put_bits(&s->pb,
ff_mpeg12_vlc_dc_lum_bits[index] + index,
(ff_mpeg12_vlc_dc_lum_code[index] << index) +
(diff & ((1 << index) - 1)));
av_mod_uintp2(diff, index));
else
put_bits(&s->pb,
ff_mpeg12_vlc_dc_chroma_bits[index] + index,
(ff_mpeg12_vlc_dc_chroma_code[index] << index) +
(diff & ((1 << index) - 1)));
av_mod_uintp2(diff, index));
} else {
if (component == 0)
put_bits(&s->pb,
@ -1041,12 +1041,12 @@ av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
bits = ff_mpeg12_vlc_dc_lum_bits[index] + index;
code = (ff_mpeg12_vlc_dc_lum_code[index] << index) +
(diff & ((1 << index) - 1));
av_mod_uintp2(diff, index);
mpeg1_lum_dc_uni[i + 255] = bits + (code << 8);
bits = ff_mpeg12_vlc_dc_chroma_bits[index] + index;
code = (ff_mpeg12_vlc_dc_chroma_code[index] << index) +
(diff & ((1 << index) - 1));
av_mod_uintp2(diff, index);
mpeg1_chr_dc_uni[i + 255] = bits + (code << 8);
}

@ -279,7 +279,7 @@ static av_always_inline unsigned int opus_getrawbits(OpusRangeCoder *rc, unsigne
rc->rb.bytes--;
}
value = rc->rb.cacheval & ((1<<count)-1);
value = av_mod_uintp2(rc->rb.cacheval, count);
rc->rb.cacheval >>= count;
rc->rb.cachelen -= count;
rc->total_read_bits += count;

@ -1454,7 +1454,7 @@ static unsigned int celt_decode_band(CeltContext *s, OpusRangeCoder *rc,
if (itheta == 0) {
imid = 32767;
iside = 0;
fill &= (1 << blocks) - 1;
fill = av_mod_uintp2(fill, blocks);
delta = -16384;
} else if (itheta == 16384) {
imid = 0;
@ -1666,7 +1666,7 @@ static unsigned int celt_decode_band(CeltContext *s, OpusRangeCoder *rc,
for (j = 0; j < N0; j++)
lowband_out[j] = n * X[j];
}
cm &= (1 << blocks) - 1;
cm = av_mod_uintp2(cm, blocks);
}
return cm;
}

@ -440,12 +440,11 @@ static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb,
static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits)
{
const int mask = (1 << abits) - 1;
const int dbits = (abits == 8) ? 4 : 7;
const int dsize = 1 << dbits - 1;
int diff = cur - prev;
diff &= mask;
diff = av_mod_uintp2(diff, abits);
if (diff >= (1 << abits) - dsize)
diff -= 1 << abits;
if (diff < -dsize || diff > dsize || !diff) {
@ -689,12 +688,11 @@ static int estimate_slice_plane(ProresContext *ctx, int *error, int plane,
static int est_alpha_diff(int cur, int prev, int abits)
{
const int mask = (1 << abits) - 1;
const int dbits = (abits == 8) ? 4 : 7;
const int dsize = 1 << dbits - 1;
int diff = cur - prev;
diff &= mask;
diff = av_mod_uintp2(diff, abits);
if (diff >= (1 << abits) - dsize)
diff -= 1 << abits;
if (diff < -dsize || diff > dsize || !diff)

@ -193,7 +193,7 @@ static inline void put_sbits(PutBitContext *pb, int n, int32_t value)
{
av_assert2(n >= 0 && n <= 31);
put_bits(pb, n, value & ((1 << n) - 1));
put_bits(pb, n, av_mod_uintp2(value, n));
}
/**

Loading…
Cancel
Save