Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH v2 1/2] avfilter/vf_thumbnail: support more planar formats
Date: Fri, 20 Jun 2025 16:13:33 +0200
Message-ID: <20250620141524.2459797-2-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20250620141524.2459797-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

This adds support for high bit depth formats, as well as formats with fewer
than 3 planes. The implementation for HBD is the same as for 8 bit formats,
just right shifted to 8 bits.

It's worth pointing out that this also works for HDR formats (and even DV),
because the underlying implementation is just trying to minimize the histogram
difference. If anything, using a HDR format will result in a *more* accurate
detection, because HDR formats tend to be more perceptually uniform.
---
 libavfilter/vf_thumbnail.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_thumbnail.c b/libavfilter/vf_thumbnail.c
index 90125a879c..55a0598e50 100644
--- a/libavfilter/vf_thumbnail.c
+++ b/libavfilter/vf_thumbnail.c
@@ -53,6 +53,8 @@ typedef struct ThumbContext {
 
     int planewidth[4];
     int planeheight[4];
+    int planes;
+    int bitdepth;
 } ThumbContext;
 
 #define OFFSET(x) offsetof(ThumbContext, x)
@@ -194,7 +196,7 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
         }
         break;
     default:
-        for (int plane = 0; plane < 3; plane++) {
+        for (int plane = 0; plane < s->planes; plane++) {
             const int slice_start = (s->planeheight[plane] * jobnr) / nb_jobs;
             const int slice_end = (s->planeheight[plane] * (jobnr+1)) / nb_jobs;
             const uint8_t *p = frame->data[plane] + slice_start * frame->linesize[plane];
@@ -202,10 +204,21 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
             const int planewidth = s->planewidth[plane];
             int *hhist = hist + 256 * plane;
 
-            for (int j = slice_start; j < slice_end; j++) {
-                for (int i = 0; i < planewidth; i++)
-                    hhist[p[i]]++;
-                p += linesize;
+            if (s->bitdepth > 8) {
+                const uint16_t *p16 = (const uint16_t *) p;
+                const int shift = s->bitdepth - 8;
+
+                for (int j = slice_start; j < slice_end; j++) {
+                    for (int i = 0; i < planewidth; i++)
+                        hhist[(p16[i] >> shift) & 0xFF]++;
+                    p16 += linesize >> 1;
+                }
+            } else {
+                for (int j = slice_start; j < slice_end; j++) {
+                    for (int i = 0; i < planewidth; i++)
+                        hhist[p[i]]++;
+                    p += linesize;
+                }
             }
         }
         break;
@@ -286,6 +299,8 @@ static int config_props(AVFilterLink *inlink)
     s->planewidth[0]  = s->planewidth[3]  = inlink->w;
     s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
     s->planeheight[0] = s->planeheight[3] = inlink->h;
+    s->planes         = av_pix_fmt_count_planes(inlink->format) - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
+    s->bitdepth       = desc->comp[0].depth;
 
     return 0;
 }
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2025-06-20 14:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 14:13 [FFmpeg-devel] [PATCH v2 0/2] avfilter/vf_thumbnail: support more formats Niklas Haas
2025-06-20 14:13 ` Niklas Haas [this message]
2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 Niklas Haas
2025-06-20 14:16   ` Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250620141524.2459797-2-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git