[FFmpeg-cvslog] avfilter/vf_hqx: optimize table init

Michael Niedermayer git at videolan.org
Tue Jun 24 03:17:36 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Jun 24 03:09:08 2014 +0200| [723550d3cadbf671e0990997b969c6722c051543] | committer: Michael Niedermayer

avfilter/vf_hqx: optimize table init

5389024880 -> 1389386610 dezicycles

This surely can be optimized more, i just didnt want to cause a slowdown
when trying to make the fate test bitexact.
Further optimization left to ubitux

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

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

 libavfilter/vf_hqx.c |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_hqx.c b/libavfilter/vf_hqx.c
index e7ed9cf..4783381 100644
--- a/libavfilter/vf_hqx.c
+++ b/libavfilter/vf_hqx.c
@@ -510,14 +510,21 @@ static av_cold int init(AVFilterContext *ctx)
     static const hqxfunc_t hqxfuncs[] = {hq2x, hq3x, hq4x};
 
     uint32_t c;
-    for (c = 0; c < FF_ARRAY_ELEMS(hqx->rgbtoyuv); c++) {
-        const int r = c >> 16 & 0xff;
-        const int g = c >>  8 & 0xff;
-        const int b = c       & 0xff;
-        const uint32_t y = (uint32_t)(( 299*r + 587*g + 114*b)/1000);
-        const uint32_t u = (uint32_t)((-169*r - 331*g + 500*b)/1000) + 128;
-        const uint32_t v = (uint32_t)(( 500*r - 419*g -  81*b)/1000) + 128;
-        hqx->rgbtoyuv[c] = (y << 16) + (u << 8) + v;
+    int bg, rg, g;
+
+    for (bg=-255; bg<256; bg++) {
+        for (rg=-255; rg<256; rg++) {
+            const uint32_t u = (uint32_t)((-169*rg + 500*bg)/1000) + 128;
+            const uint32_t v = (uint32_t)(( 500*rg -  81*bg)/1000) + 128;
+            int startg = FFMAX3(-bg, -rg, 0);
+            int endg = FFMIN3(255-bg, 255-rg, 255);
+            uint32_t y = (uint32_t)(( 299*rg + 1000*startg + 114*bg)/1000);
+            c = bg + (rg<<16) + 0x010101 * startg;
+            for (g = startg; g <= endg; g++) {
+                hqx->rgbtoyuv[c] = ((y++) << 16) + (u << 8) + v;
+                c+= 0x010101;
+            }
+        }
     }
 
     hqx->func = hqxfuncs[hqx->n - 2];



More information about the ffmpeg-cvslog mailing list