[FFmpeg-devel,04/11] avcodec/mdec: allow/use permuted IDCTs

Submitted by James Darnley on June 19, 2017, 3:10 p.m.

Details

Message ID 20170619151104.31273-5-jdarnley@obe.tv
State New
Headers show

Commit Message

James Darnley June 19, 2017, 3:10 p.m.
From: "Ronald S. Bultje" <rsbultje@gmail.com>

---
 libavcodec/mdec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer June 19, 2017, 4:39 p.m.
On Mon, Jun 19, 2017 at 05:10:57PM +0200, James Darnley wrote:
> From: "Ronald S. Bultje" <rsbultje@gmail.com>
> 
> ---
>  libavcodec/mdec.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
> index 97bfebbeb7..1e1c8f4c55 100644
> --- a/libavcodec/mdec.c
> +++ b/libavcodec/mdec.c
> @@ -94,7 +94,7 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
>                      return AVERROR_INVALIDDATA;
>                  }
>                  j     = scantable[i];
> -                level = (level * qscale * quant_matrix[j]) >> 3;
> +                level = (level * qscale * quant_matrix[ff_zigzag_direct[i]]) >> 3;
>                  level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1);
>                  LAST_SKIP_BITS(re, &a->gb, 1);
>              } else {
> @@ -111,11 +111,11 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
>                  j = scantable[i];
>                  if (level < 0) {
>                      level = -level;
> -                    level = (level * (unsigned)qscale * quant_matrix[j]) >> 3;
> +                    level = (level * (unsigned)qscale * quant_matrix[ff_zigzag_direct[i]]) >> 3;
>                      level = (level - 1) | 1;
>                      level = -level;
>                  } else {
> -                    level = (level * (unsigned)qscale * quant_matrix[j]) >> 3;
> +                    level = (level * (unsigned)qscale * quant_matrix[ff_zigzag_direct[i]]) >> 3;
>                      level = (level - 1) | 1;
>                  }
>              }

quant_matrix can be permuted during init to avoid the per coef
permutation here
Or it could be done per frame and also include the multiplication with
qscale

thx
[...]
Ronald S. Bultje June 19, 2017, 6:02 p.m.
Hi,

On Mon, Jun 19, 2017 at 12:39 PM, Michael Niedermayer <
michael@niedermayer.cc> wrote:

> On Mon, Jun 19, 2017 at 05:10:57PM +0200, James Darnley wrote:
> > From: "Ronald S. Bultje" <rsbultje@gmail.com>
> >
> > ---
> >  libavcodec/mdec.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
> > index 97bfebbeb7..1e1c8f4c55 100644
> > --- a/libavcodec/mdec.c
> > +++ b/libavcodec/mdec.c
> > @@ -94,7 +94,7 @@ static inline int mdec_decode_block_intra(MDECContext
> *a, int16_t *block, int n)
> >                      return AVERROR_INVALIDDATA;
> >                  }
> >                  j     = scantable[i];
> > -                level = (level * qscale * quant_matrix[j]) >> 3;
> > +                level = (level * qscale * quant_matrix[ff_zigzag_direct[i]])
> >> 3;
> >                  level = (level ^ SHOW_SBITS(re, &a->gb, 1)) -
> SHOW_SBITS(re, &a->gb, 1);
> >                  LAST_SKIP_BITS(re, &a->gb, 1);
> >              } else {
> > @@ -111,11 +111,11 @@ static inline int mdec_decode_block_intra(MDECContext
> *a, int16_t *block, int n)
> >                  j = scantable[i];
> >                  if (level < 0) {
> >                      level = -level;
> > -                    level = (level * (unsigned)qscale *
> quant_matrix[j]) >> 3;
> > +                    level = (level * (unsigned)qscale *
> quant_matrix[ff_zigzag_direct[i]]) >> 3;
> >                      level = (level - 1) | 1;
> >                      level = -level;
> >                  } else {
> > -                    level = (level * (unsigned)qscale *
> quant_matrix[j]) >> 3;
> > +                    level = (level * (unsigned)qscale *
> quant_matrix[ff_zigzag_direct[i]]) >> 3;
> >                      level = (level - 1) | 1;
> >                  }
> >              }
>
> quant_matrix can be permuted during init to avoid the per coef
> permutation here

Or it could be done per frame and also include the multiplication with
> qscale


We're not talking about a complex codec here, so I prefer simplicity over
speed. (I.e. I personally believe per-frame quant table init is overkill.)

Ronald

Patch hide | download patch | download mbox

diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 97bfebbeb7..1e1c8f4c55 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -94,7 +94,7 @@  static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
                     return AVERROR_INVALIDDATA;
                 }
                 j     = scantable[i];
-                level = (level * qscale * quant_matrix[j]) >> 3;
+                level = (level * qscale * quant_matrix[ff_zigzag_direct[i]]) >> 3;
                 level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1);
                 LAST_SKIP_BITS(re, &a->gb, 1);
             } else {
@@ -111,11 +111,11 @@  static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
                 j = scantable[i];
                 if (level < 0) {
                     level = -level;
-                    level = (level * (unsigned)qscale * quant_matrix[j]) >> 3;
+                    level = (level * (unsigned)qscale * quant_matrix[ff_zigzag_direct[i]]) >> 3;
                     level = (level - 1) | 1;
                     level = -level;
                 } else {
-                    level = (level * (unsigned)qscale * quant_matrix[j]) >> 3;
+                    level = (level * (unsigned)qscale * quant_matrix[ff_zigzag_direct[i]]) >> 3;
                     level = (level - 1) | 1;
                 }
             }