History

avfilter/vf_thumbnail: add support for YUV and GBRP formats

Paul B Mahol committed 5 years ago

Commit 3b65c841 parent cc4feff2 files · +41 −8Browse files

Unified · Split

2 files
  1. libavfilter/vf_thumbnail.c +40 −7
  2. tests/ref/fate/filter-thumbnail +1 −1
libavfilter/vf_thumbnail.c+40−7
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 */
2929
3030 #include "libavutil/opt.h"
31+#include "libavutil/pixdesc.h"
3132 #include "avfilter.h"
3233 #include "internal.h"
3334
@@ -44,6 +45,9 @@ typedef struct ThumbContext { · 10 unmodified lines
4445 int n_frames; ///< number of frames for analysis
4546 struct thumb_frame *frames; ///< the n_frames frames
4647 AVRational tb; ///< copy of the input timebase to ease access
48+
49+ int planewidth[4];
50+ int planeheight[4];
4751 } ThumbContext;
4852
4953 #define OFFSET(x) offsetof(ThumbContext, x)
@@ -140,14 +144,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 90 unmodified lines
140144 // keep a reference of each frame
141145 s->frames[s->n].buf = frame;
142146
143− // update current frame RGB histogram
144− for (j = 0; j < inlink->h; j++) {
145− for (i = 0; i < inlink->w; i++) {
146− hist[0*256 + p[i*3 ]]++;
147− hist[1*256 + p[i*3 + 1]]++;
148− hist[2*256 + p[i*3 + 2]]++;
147+ // update current frame histogram
148+ switch (inlink->format) {
149+ case AV_PIX_FMT_RGB24:
150+ case AV_PIX_FMT_BGR24:
151+ for (j = 0; j < inlink->h; j++) {
152+ for (i = 0; i < inlink->w; i++) {
153+ hist[0*256 + p[i*3 ]]++;
154+ hist[1*256 + p[i*3 + 1]]++;
155+ hist[2*256 + p[i*3 + 2]]++;
156+ }
157+ p += frame->linesize[0];
158+ }
159+ break;
160+ default:
161+ for (int plane = 0; plane < 3; plane++) {
162+ const uint8_t *p = frame->data[plane];
163+ for (j = 0; j < s->planeheight[plane]; j++) {
164+ for (i = 0; i < s->planewidth[plane]; i++)
165+ hist[256*plane + p[i]]++;
166+ p += frame->linesize[plane];
167+ }
149168 }
150− p += frame->linesize[0];
169+ break;
151170 }
152171
153172 // no selection until the buffer of N frames is filled up
@@ -188,8 +207,14 @@ static int config_props(AVFilterLink *inlink) · 34 unmodified lines
188207 {
189208 AVFilterContext *ctx = inlink->dst;
190209 ThumbContext *s = ctx->priv;
210+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
191211
192212 s->tb = inlink->time_base;
213+ s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
214+ s->planewidth[0] = s->planewidth[3] = inlink->w;
215+ s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
216+ s->planeheight[0] = s->planeheight[3] = inlink->h;
217+
193218 return 0;
194219 }
195220
@@ -197,6 +222,14 @@ static int query_formats(AVFilterContext *ctx) · 1 unmodified line
197222 {
198223 static const enum AVPixelFormat pix_fmts[] = {
199224 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
225+ AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
226+ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
227+ AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
228+ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
229+ AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
230+ AV_PIX_FMT_YUVJ411P,
231+ AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
232+ AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
200233 AV_PIX_FMT_NONE
201234 };
202235 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
tests/ref/fate/filter-thumbnail+1−1
@@ -1 +1 @@
1−thumbnail cd429b3d92c33bcc257e8e6a3284dbf7
1+thumbnail 8b54dbc891b9cc05742dd0f5b74c0727

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t