From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 7A0A64F372 for ; Mon, 16 Jun 2025 11:54:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id A9E1268DC8C; Mon, 16 Jun 2025 14:54:30 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 13BFB68D0AB for ; Mon, 16 Jun 2025 14:54:24 +0300 (EEST) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id C9946402F2 for ; Mon, 16 Jun 2025 13:54:23 +0200 (CEST) Date: Mon, 16 Jun 2025 13:54:23 +0200 Message-ID: <20250616135423.GB31822@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: References: <20250612144730.112089-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_thumbnail: support high bit depth formats X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Sun, 15 Jun 2025 05:44:43 +0200 Andreas Rheinhardt wrote: > Niklas Haas: > > From: Niklas Haas > > > > Implementation is the same as 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 | 54 +++++++++++++++++++++++++++++++++++++- > > 1 file changed, 53 insertions(+), 1 deletion(-) > > > > diff --git a/libavfilter/vf_thumbnail.c b/libavfilter/vf_thumbnail.c > > index 90125a879c..f353f0495c 100644 > > --- a/libavfilter/vf_thumbnail.c > > +++ b/libavfilter/vf_thumbnail.c > > @@ -53,6 +53,7 @@ typedef struct ThumbContext { > > > > int planewidth[4]; > > int planeheight[4]; > > + int bitdepth; > > } ThumbContext; > > > > #define OFFSET(x) offsetof(ThumbContext, x) > > @@ -193,7 +194,23 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) > > p += frame->linesize[0]; > > } > > break; > > - default: > > + > > + case AV_PIX_FMT_YUV410P: > > + case AV_PIX_FMT_YUV411P: > > + case AV_PIX_FMT_YUV420P: > > + case AV_PIX_FMT_YUV422P: > > + case AV_PIX_FMT_YUV440P: > > + case AV_PIX_FMT_YUV444P: > > + case AV_PIX_FMT_YUVJ420P: > > + case AV_PIX_FMT_YUVJ422P: > > + case AV_PIX_FMT_YUVJ440P: > > + case AV_PIX_FMT_YUVJ444P: > > + case AV_PIX_FMT_YUVJ411P: > > + case AV_PIX_FMT_YUVA420P: > > + case AV_PIX_FMT_YUVA422P: > > + case AV_PIX_FMT_YUVA444P: > > + case AV_PIX_FMT_GBRP: > > + case AV_PIX_FMT_GBRAP: > > for (int plane = 0; plane < 3; plane++) { > > const int slice_start = (s->planeheight[plane] * jobnr) / nb_jobs; > > const int slice_end = (s->planeheight[plane] * (jobnr+1)) / nb_jobs; > > @@ -209,6 +226,25 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) > > } > > } > > break; > > + > > + default: > > + for (int plane = 0; plane < 3; plane++) { > > + const int slice_start = (s->planeheight[plane] * jobnr) / nb_jobs; > > + const int slice_end = (s->planeheight[plane] * (jobnr+1)) / nb_jobs; > > + const int slice_offset = slice_start * frame->linesize[plane]; > > + const uint16_t *p = (const uint16_t *) (frame->data[plane] + slice_offset); > > + const ptrdiff_t linesize = frame->linesize[plane] >> 1; > > + const int planewidth = s->planewidth[plane]; > > + const int shift = s->bitdepth - 8; > > + int *hhist = hist + 256 * plane; > > + > > + for (int j = slice_start; j < slice_end; j++) { > > + for (int i = 0; i < planewidth; i++) > > + hhist[(p[i] >> shift) & 0xFF]++; > > + p += linesize; > > + } > > + } > > + break; > > } > > > > return 0; > > @@ -286,6 +322,7 @@ 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->bitdepth = desc->comp[0].depth; > > > > return 0; > > } > > @@ -304,6 +341,21 @@ static const enum AVPixelFormat pix_fmts[] = { > > AV_PIX_FMT_YUVJ411P, > > AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, > > AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, > > + > > + /* High bit depth formats */ > > + AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9, > > + AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, > > + AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, > > + AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14, > > + AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, > > + AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9, > > + AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10, > > + AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12, > > + AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, > > + AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, > > + AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRAP14, > > + AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, > > + > > AV_PIX_FMT_NONE > > }; > > > > Can't you use some AVPixFmtDescriptor magic to replace this huge list > with a query formats function? Sure. I will submit that as a separate commit, I think. > > - Andreas > > _______________________________________________ > 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". _______________________________________________ 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".