[FFmpeg-cvslog] vf_lut: avoid rgb component indexing in the inner loop

Michael Niedermayer git at videolan.org
Tue Apr 3 18:44:25 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Apr  3 18:30:07 2012 +0200| [38477e1981a7729b02d9a2f45142c53dc78625fe] | committer: Michael Niedermayer

vf_lut: avoid rgb component indexing in the inner loop

15k->10k cpu cycles

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

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

 libavfilter/vf_lut.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index ee485f3..b3816c6 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -244,6 +244,9 @@ static int config_props(AVFilterLink *inlink)
 
     for (comp = 0; comp < desc->nb_components; comp++) {
         double res;
+        int tcomp;
+        for (tcomp = 0; lut->rgba_map[tcomp] != comp; tcomp++)
+            ;
 
         /* create the parsed expression */
         ret = av_expr_parse(&lut->comp_expr[comp], lut->comp_expr_str[comp],
@@ -273,8 +276,8 @@ static int config_props(AVFilterLink *inlink)
                        lut->comp_expr_str[comp], val, comp);
                 return AVERROR(EINVAL);
             }
-            lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]);
-            av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]);
+            lut->lut[tcomp][val] = av_clip((int)res, min[comp], max[comp]);
+            av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[tcomp][val]);
         }
     }
 
@@ -298,16 +301,17 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 
         for (i = 0; i < h; i ++) {
             int w = inlink->w;
+            const uint8_t (*tab)[256] = lut->lut;
             inrow  = inrow0;
             outrow = outrow0;
             for (j = 0; j < w; j++) {
-                outrow[0] = lut->lut[lut->rgba_map[0]][inrow[0]];
+                outrow[0] = tab[0][inrow[0]];
                 if (lut->step>1) {
-                    outrow[1] = lut->lut[lut->rgba_map[1]][inrow[1]];
+                    outrow[1] = tab[1][inrow[1]];
                     if (lut->step>2) {
-                        outrow[2] = lut->lut[lut->rgba_map[2]][inrow[2]];
+                        outrow[2] = tab[2][inrow[2]];
                         if (lut->step>3) {
-                            outrow[3] = lut->lut[lut->rgba_map[3]][inrow[3]];
+                            outrow[3] = tab[3][inrow[3]];
                         }
                     }
                 }



More information about the ffmpeg-cvslog mailing list