This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new a1a7737c4b avcodec/dvbsubdec: compute the clut scores incrementally
a1a7737c4b is described below

commit a1a7737c4bcace8615f70b8f2cc7fc515ca26522
Author:     romainhedouin <[email protected]>
AuthorDate: Mon Nov 2 01:15:39 2026 +0100
Commit:     kierank <[email protected]>
CommitDate: Mon Nov 2 23:38:02 2026 +0000

    avcodec/dvbsubdec: compute the clut scores incrementally
    
    compute_default_clut() recomputed the score of every candidate from
    scratch, summing over all 256 colours, each time a colour was added to
    the list: up to 256 * 256 * 256 multiply-adds per region. Keep the
    scores and add the contribution of the new colour instead. The output
    is unchanged.
    
    Noticed during a review sweep of ffmpeg using an LLM.
    
    Signed-off-by: romainhedouin <[email protected]>
---
 libavcodec/dvbsubdec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 0256e8355d..2426da896d 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -673,6 +673,7 @@ static void compute_default_clut(DVBSubContext *ctx, 
uint8_t *clut, AVSubtitleRe
     uint8_t list[256] = {0};
     uint8_t list_inv[256];
     int counttab[256] = {0};
+    int scoretab[256];
     int (*counttab2)[256] = ctx->clut_count2;
     int count, i, x, y;
     ptrdiff_t stride = rect->linesize[0];
@@ -699,18 +700,15 @@ static void compute_default_clut(DVBSubContext *ctx, 
uint8_t *clut, AVSubtitleRe
     for (i = 0; i<256; i++) {
         counttab2[i+1][i] = 0;
     }
+    memcpy(scoretab, counttab2[0], sizeof(scoretab));
     for (i = 0; i<256; i++) {
         int bestscore = 0;
         int bestv = 0;
 
         for (x = 0; x < 256; x++) {
-            int scorev = 0;
+            int scorev = scoretab[x];
             if (list[x])
                 continue;
-            scorev += counttab2[0][x];
-            for (y = 0; y < 256; y++) {
-                scorev += list[y] * counttab2[y+1][x];
-            }
 
             if (scorev) {
                 int score = 1024LL*scorev / counttab[x];
@@ -724,6 +722,8 @@ static void compute_default_clut(DVBSubContext *ctx, 
uint8_t *clut, AVSubtitleRe
             break;
         list    [ bestv ] = 1;
         list_inv[     i ] = bestv;
+        for (x = 0; x < 256; x++)
+            scoretab[x] += counttab2[bestv+1][x];
     }
 
     count = FFMAX(i - 1, 1);

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to