| @@ -28,6 +28,7 @@ · 27 unmodified lines |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | #include "libavutil/opt.h" |
| 31 | +#include "libavutil/pixdesc.h" |
| 31 | 32 | #include "avfilter.h" |
| 32 | 33 | #include "internal.h" |
| 33 | 34 | |
| @@ -44,6 +45,9 @@ typedef struct ThumbContext { · 10 unmodified lines |
| 44 | 45 | int n_frames; ///< number of frames for analysis |
| 45 | 46 | struct thumb_frame *frames; ///< the n_frames frames |
| 46 | 47 | AVRational tb; ///< copy of the input timebase to ease access |
| 48 | + |
| 49 | + int planewidth[4]; |
| 50 | + int planeheight[4]; |
| 47 | 51 | } ThumbContext; |
| 48 | 52 | |
| 49 | 53 | #define OFFSET(x) offsetof(ThumbContext, x) |
| @@ -140,14 +144,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 90 unmodified lines |
| 140 | 144 | // keep a reference of each frame |
| 141 | 145 | s->frames[s->n].buf = frame; |
| 142 | 146 | |
| 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 | + } |
| 149 | 168 | } |
| 150 | | − p += frame->linesize[0]; |
| 169 | + break; |
| 151 | 170 | } |
| 152 | 171 | |
| 153 | 172 | // no selection until the buffer of N frames is filled up |
| @@ -188,8 +207,14 @@ static int config_props(AVFilterLink *inlink) · 34 unmodified lines |
| 188 | 207 | { |
| 189 | 208 | AVFilterContext *ctx = inlink->dst; |
| 190 | 209 | ThumbContext *s = ctx->priv; |
| 210 | + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 191 | 211 | |
| 192 | 212 | 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 | + |
| 193 | 218 | return 0; |
| 194 | 219 | } |
| 195 | 220 | |
| @@ -197,6 +222,14 @@ static int query_formats(AVFilterContext *ctx) · 1 unmodified line |
| 197 | 222 | { |
| 198 | 223 | static const enum AVPixelFormat pix_fmts[] = { |
| 199 | 224 | 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, |
| 200 | 233 | AV_PIX_FMT_NONE |
| 201 | 234 | }; |
| 202 | 235 | AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); |