diff options
author | Paul B Mahol <onemda@gmail.com> | 2021-02-06 21:59:50 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2021-02-08 12:45:49 +0100 |
commit | 3b65c848a606a86cbdfdc8a2c25c0d21e8e3b032 (patch) | |
tree | 97ab1a5f28f30827a84846fee351436f412481d4 | |
parent | cc4feff861e866550956f39c194001d2628939fa (diff) | |
download | ffmpeg-3b65c848a606a86cbdfdc8a2c25c0d21e8e3b032.tar.gz |
avfilter/vf_thumbnail: add support for YUV and GBRP formats
-rw-r--r-- | libavfilter/vf_thumbnail.c | 47 | ||||
-rw-r--r-- | tests/ref/fate/filter-thumbnail | 2 |
2 files changed, 41 insertions, 8 deletions
diff --git a/libavfilter/vf_thumbnail.c b/libavfilter/vf_thumbnail.c index ac04615bdc..a0561683aa 100644 --- a/libavfilter/vf_thumbnail.c +++ b/libavfilter/vf_thumbnail.c @@ -28,6 +28,7 @@ */ #include "libavutil/opt.h" +#include "libavutil/pixdesc.h" #include "avfilter.h" #include "internal.h" @@ -44,6 +45,9 @@ typedef struct ThumbContext { int n_frames; ///< number of frames for analysis struct thumb_frame *frames; ///< the n_frames frames AVRational tb; ///< copy of the input timebase to ease access + + int planewidth[4]; + int planeheight[4]; } ThumbContext; #define OFFSET(x) offsetof(ThumbContext, x) @@ -140,14 +144,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) // keep a reference of each frame s->frames[s->n].buf = frame; - // update current frame RGB histogram - for (j = 0; j < inlink->h; j++) { - for (i = 0; i < inlink->w; i++) { - hist[0*256 + p[i*3 ]]++; - hist[1*256 + p[i*3 + 1]]++; - hist[2*256 + p[i*3 + 2]]++; + // update current frame histogram + switch (inlink->format) { + case AV_PIX_FMT_RGB24: + case AV_PIX_FMT_BGR24: + for (j = 0; j < inlink->h; j++) { + for (i = 0; i < inlink->w; i++) { + hist[0*256 + p[i*3 ]]++; + hist[1*256 + p[i*3 + 1]]++; + hist[2*256 + p[i*3 + 2]]++; + } + p += frame->linesize[0]; + } + break; + default: + for (int plane = 0; plane < 3; plane++) { + const uint8_t *p = frame->data[plane]; + for (j = 0; j < s->planeheight[plane]; j++) { + for (i = 0; i < s->planewidth[plane]; i++) + hist[256*plane + p[i]]++; + p += frame->linesize[plane]; + } } - p += frame->linesize[0]; + break; } // no selection until the buffer of N frames is filled up @@ -188,8 +207,14 @@ static int config_props(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; ThumbContext *s = ctx->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); s->tb = inlink->time_base; + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); + 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; + return 0; } @@ -197,6 +222,14 @@ static int query_formats(AVFilterContext *ctx) { static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, + AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, + AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, + AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, + AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, + AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, + AV_PIX_FMT_YUVJ411P, + AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, + AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE }; AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); diff --git a/tests/ref/fate/filter-thumbnail b/tests/ref/fate/filter-thumbnail index 36f11f297e..4d8c5011ce 100644 --- a/tests/ref/fate/filter-thumbnail +++ b/tests/ref/fate/filter-thumbnail @@ -1 +1 @@ -thumbnail cd429b3d92c33bcc257e8e6a3284dbf7 +thumbnail 8b54dbc891b9cc05742dd0f5b74c0727 |