X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fffv1.h;h=f0bb19350a8992a928e98b68c9e4acf5a5fc7d57;hb=24424a6516f8adc4c73a2fe00fa106b0e49abafd;hp=653138b0702196f186b930df4eb940da774b573c;hpb=8e789d244cc946bc350672eeb02453918b21a09f;p=ffmpeg diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 653138b0702..f0bb19350a8 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -153,9 +153,7 @@ static av_always_inline int fold(int diff, int bits) if (bits == 8) diff = (int8_t)diff; else { - diff += 1 << (bits - 1); - diff = av_mod_uintp2(diff, bits); - diff -= 1 << (bits - 1); + diff = sign_extend(diff, bits); } return diff; @@ -176,19 +174,13 @@ static inline void update_vlc_state(VlcState *const state, const int v) count++; if (drift <= -count) { - if (state->bias > -128) - state->bias--; + state->bias = FFMAX(state->bias - 1, -128); - drift += count; - if (drift <= -count) - drift = -count + 1; + drift = FFMAX(drift + count, -count + 1); } else if (drift > 0) { - if (state->bias < 127) - state->bias++; + state->bias = FFMIN(state->bias + 1, 127); - drift -= count; - if (drift > 0) - drift = 0; + drift = FFMIN(drift - count, 0); } state->drift = drift;