Skip to content

Commit 1c78db8

Browse files
committed
avcodec/vc2enc: Use LUT to avoid repeated av_log2()
Signed-off-by: Andreas Rheinhardt <[email protected]>
1 parent a6bcc77 commit 1c78db8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libavcodec/vc2enc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ static uint16_t interleaved_ue_golomb_tab[256];
193193
static uint16_t top_interleaved_ue_golomb_tab[256];
194194
/// 1 x_{k-1} ... x_0 -> 2 * k
195195
static uint8_t golomb_len_tab[256];
196+
/// quant -> av_log2(ff_dirac_qscale_tab[quant]) + 32
197+
static uint8_t qscale_len_tab[FF_ARRAY_ELEMS(ff_dirac_qscale_tab)];
196198

197199
static av_cold void vc2_init_static_data(void)
198200
{
@@ -202,6 +204,8 @@ static av_cold void vc2_init_static_data(void)
202204
interleaved_ue_golomb_tab[i] = (interleaved_ue_golomb_tab[i >> 1] << 2) | (i & 1);
203205
top_interleaved_ue_golomb_tab[i] = interleaved_ue_golomb_tab[i] ^ (1 << golomb_len_tab[i]);
204206
}
207+
for (size_t i = 0; i < FF_ARRAY_ELEMS(qscale_len_tab); ++i)
208+
qscale_len_tab[i] = av_log2(ff_dirac_qscale_tab[i]) + 32;
205209
}
206210

207211
static av_always_inline void put_vc2_ue_uint_inline(PutBitContext *pb, uint32_t val)
@@ -545,7 +549,7 @@ static void encode_subband(const VC2EncContext *s, PutBitContext *pb,
545549
dwtcoef *coeff = b->buf + top * b->stride;
546550
const uint64_t q_m = ((uint64_t)(s->qmagic_lut[quant][0])) << 2;
547551
const uint64_t q_a = s->qmagic_lut[quant][1];
548-
const int q_s = av_log2(ff_dirac_qscale_tab[quant]) + 32;
552+
const int q_s = qscale_len_tab[quant];
549553

550554
for (y = top; y < bottom; y++) {
551555
for (x = left; x < right; x++) {
@@ -586,7 +590,7 @@ static int count_hq_slice(SliceArgs *slice, int quant_idx)
586590
const int q_idx = quants[level][orientation];
587591
const uint64_t q_m = ((uint64_t)s->qmagic_lut[q_idx][0]) << 2;
588592
const uint64_t q_a = s->qmagic_lut[q_idx][1];
589-
const int q_s = av_log2(ff_dirac_qscale_tab[q_idx]) + 32;
593+
const int q_s = qscale_len_tab[q_idx];
590594

591595
const int left = b->width * slice->x / s->num_x;
592596
const int right = b->width *(slice->x+1) / s->num_x;

0 commit comments

Comments
 (0)