[FFmpeg-cvslog] avcodec: Use av_clip_uintp2() where possible

Michael Niedermayer git at videolan.org
Sat Feb 21 16:05:37 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Feb 21 15:46:38 2015 +0100| [114a2eb272077b68bc8e0f2ee8fd6fc85a8e07c2] | committer: Michael Niedermayer

avcodec: Use av_clip_uintp2() where possible

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=114a2eb272077b68bc8e0f2ee8fd6fc85a8e07c2
---

 libavcodec/adpcmenc.c   |    2 +-
 libavcodec/cngenc.c     |    2 +-
 libavcodec/cook.c       |    4 ++--
 libavcodec/hevc.c       |    4 ++--
 libavcodec/ivi_common.c |    2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index ea6cc23..c3546f9 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -581,7 +581,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         // init the encoder state
         for (i = 0; i < avctx->channels; i++) {
             // clip step so it fits 6 bits
-            c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63);
+            c->status[i].step_index = av_clip_uintp2(c->status[i].step_index, 6);
             put_sbits(&pb, 16, samples[i]);
             put_bits(&pb, 6, c->status[i].step_index);
             c->status[i].prev_sample = samples[i];
diff --git a/libavcodec/cngenc.c b/libavcodec/cngenc.c
index bf5f7bf..58918aa 100644
--- a/libavcodec/cngenc.c
+++ b/libavcodec/cngenc.c
@@ -87,7 +87,7 @@ static int cng_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     energy /= frame->nb_samples;
     if (energy > 0) {
         double dbov = 10 * log10(energy / 1081109975);
-        qdbov = av_clip(-floor(dbov), 0, 127);
+        qdbov = av_clip_uintp2(-floor(dbov), 7);
     } else {
         qdbov = 127;
     }
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 3d3bb94..02ac0e0 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -418,7 +418,7 @@ static void categorize(COOKContext *q, COOKSubpacket *p, const int *quant_index_
         num_bits = 0;
         index    = 0;
         for (j = p->total_subbands; j > 0; j--) {
-            exp_idx = av_clip((i - quant_index_table[index] + bias) / 2, 0, 7);
+            exp_idx = av_clip_uintp2((i - quant_index_table[index] + bias) / 2, 3);
             index++;
             num_bits += expbits_tab[exp_idx];
         }
@@ -429,7 +429,7 @@ static void categorize(COOKContext *q, COOKSubpacket *p, const int *quant_index_
     /* Calculate total number of bits. */
     num_bits = 0;
     for (i = 0; i < p->total_subbands; i++) {
-        exp_idx = av_clip((bias - quant_index_table[i]) / 2, 0, 7);
+        exp_idx = av_clip_uintp2((bias - quant_index_table[i]) / 2, 3);
         num_bits += expbits_tab[exp_idx];
         exp_index1[i] = exp_idx;
         exp_index2[i] = exp_idx;
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index e63088f..fdbaa28 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -148,10 +148,10 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
     luma_log2_weight_denom = get_ue_golomb_long(gb);
     if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7)
         av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
-    s->sh.luma_log2_weight_denom = av_clip(luma_log2_weight_denom, 0, 7);
+    s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
     if (s->sps->chroma_format_idc != 0) {
         int delta = get_se_golomb(gb);
-        s->sh.chroma_log2_weight_denom = av_clip(s->sh.luma_log2_weight_denom + delta, 0, 7);
+        s->sh.chroma_log2_weight_denom = av_clip_uintp2(s->sh.luma_log2_weight_denom + delta, 3);
     }
 
     for (i = 0; i < s->sh.nb_refs[L0]; i++) {
diff --git a/libavcodec/ivi_common.c b/libavcodec/ivi_common.c
index 3795081..d27eff2 100644
--- a/libavcodec/ivi_common.c
+++ b/libavcodec/ivi_common.c
@@ -646,7 +646,7 @@ static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
 
         quant = band->glob_quant + mb->q_delta;
         if (avctx->codec_id == AV_CODEC_ID_INDEO4)
-            quant = av_clip(quant, 0, 31);
+            quant = av_clip_uintp2(quant, 5);
         else
             quant = av_clip(quant, 0, 23);
 



More information about the ffmpeg-cvslog mailing list