diff mbox

[FFmpeg-devel,2/2] avcodec/dvbsubdec: Split best score computation out of loop in compute_default_clut()

Message ID 20171001161036.6133-2-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Oct. 1, 2017, 4:10 p.m. UTC
3% faster

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/dvbsubdec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Clément Bœsch Oct. 1, 2017, 4:26 p.m. UTC | #1
On Sun, Oct 01, 2017 at 06:10:36PM +0200, Michael Niedermayer wrote:
> 3% faster
> 
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/dvbsubdec.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
> index 6a40f2376f..e60bf41936 100644
> --- a/libavcodec/dvbsubdec.c
> +++ b/libavcodec/dvbsubdec.c
> @@ -681,14 +681,17 @@ static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
>                  int l_r = x+1<w ? L(+1, 0) : 1;
>                  int l_t = y     ? L(0, -1) : 1;
>                  int l_b = y+1<h ? L(0, +1) : 1;
> -                int score;
>                  if (l_m)
>                      continue;
>                  scoretab[v] += l_l + l_r + l_t + l_b;
> -                score = 1024LL*scoretab[v] / counttab[v];
> +            }
> +        }
> +        for (x = 0; x < 256; x++) {
> +            if (scoretab[x]) {
> +                int score = 1024LL*scoretab[x] / counttab[x];
>                  if (score > bestscore) {
>                      bestscore = score;
> -                    bestv = v;
> +                    bestv = x;
>                  }
>              }
>          }

OK
Michael Niedermayer Oct. 14, 2017, 4:25 p.m. UTC | #2
On Sun, Oct 01, 2017 at 06:26:53PM +0200, Clément Bœsch wrote:
> On Sun, Oct 01, 2017 at 06:10:36PM +0200, Michael Niedermayer wrote:
> > 3% faster
> > 
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/dvbsubdec.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
> > index 6a40f2376f..e60bf41936 100644
> > --- a/libavcodec/dvbsubdec.c
> > +++ b/libavcodec/dvbsubdec.c
> > @@ -681,14 +681,17 @@ static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
> >                  int l_r = x+1<w ? L(+1, 0) : 1;
> >                  int l_t = y     ? L(0, -1) : 1;
> >                  int l_b = y+1<h ? L(0, +1) : 1;
> > -                int score;
> >                  if (l_m)
> >                      continue;
> >                  scoretab[v] += l_l + l_r + l_t + l_b;
> > -                score = 1024LL*scoretab[v] / counttab[v];
> > +            }
> > +        }
> > +        for (x = 0; x < 256; x++) {
> > +            if (scoretab[x]) {
> > +                int score = 1024LL*scoretab[x] / counttab[x];
> >                  if (score > bestscore) {
> >                      bestscore = score;
> > -                    bestv = v;
> > +                    bestv = x;
> >                  }
> >              }
> >          }
> 
> OK

applied

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 6a40f2376f..e60bf41936 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -681,14 +681,17 @@  static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
                 int l_r = x+1<w ? L(+1, 0) : 1;
                 int l_t = y     ? L(0, -1) : 1;
                 int l_b = y+1<h ? L(0, +1) : 1;
-                int score;
                 if (l_m)
                     continue;
                 scoretab[v] += l_l + l_r + l_t + l_b;
-                score = 1024LL*scoretab[v] / counttab[v];
+            }
+        }
+        for (x = 0; x < 256; x++) {
+            if (scoretab[x]) {
+                int score = 1024LL*scoretab[x] / counttab[x];
                 if (score > bestscore) {
                     bestscore = score;
-                    bestv = v;
+                    bestv = x;
                 }
             }
         }