mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avfilter/vf_histogram: levels: support more input pixel formats
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
b4d68e7cdb
commit
6be5b05fb1
@ -49,8 +49,10 @@ typedef struct HistogramContext {
|
||||
int waveform_mirror;
|
||||
int display_mode;
|
||||
int levels_mode;
|
||||
const AVPixFmtDescriptor *desc;
|
||||
const AVPixFmtDescriptor *desc, *odesc;
|
||||
int components;
|
||||
int planewidth[4];
|
||||
int planeheight[4];
|
||||
} HistogramContext;
|
||||
|
||||
#define OFFSET(x) offsetof(HistogramContext, x)
|
||||
@ -86,9 +88,25 @@ static const enum AVPixelFormat color_pix_fmts[] = {
|
||||
AV_PIX_FMT_NONE
|
||||
};
|
||||
|
||||
static const enum AVPixelFormat levels_pix_fmts[] = {
|
||||
AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVJ444P,
|
||||
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE
|
||||
static const enum AVPixelFormat levels_in_pix_fmts[] = {
|
||||
AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P,
|
||||
AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
|
||||
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUVJ411P,
|
||||
AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV410P,
|
||||
AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
|
||||
AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRP,
|
||||
AV_PIX_FMT_GRAY8,
|
||||
AV_PIX_FMT_NONE
|
||||
};
|
||||
|
||||
static const enum AVPixelFormat levels_out_yuv_pix_fmts[] = {
|
||||
AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P,
|
||||
AV_PIX_FMT_NONE
|
||||
};
|
||||
|
||||
static const enum AVPixelFormat levels_out_rgb_pix_fmts[] = {
|
||||
AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRP,
|
||||
AV_PIX_FMT_NONE
|
||||
};
|
||||
|
||||
static const enum AVPixelFormat waveform_pix_fmts[] = {
|
||||
@ -114,7 +132,36 @@ static int query_formats(AVFilterContext *ctx)
|
||||
pix_fmts = waveform_pix_fmts;
|
||||
break;
|
||||
case MODE_LEVELS:
|
||||
pix_fmts = levels_pix_fmts;
|
||||
{
|
||||
AVFilterFormats *avff;
|
||||
const AVPixFmtDescriptor *desc;
|
||||
const enum AVPixelFormat *out_pix_fmts;
|
||||
int rgb, i;
|
||||
|
||||
if (!ctx->inputs[0]->in_formats ||
|
||||
!ctx->inputs[0]->in_formats->nb_formats) {
|
||||
return AVERROR(EAGAIN);
|
||||
}
|
||||
|
||||
if (!ctx->inputs[0]->out_formats)
|
||||
ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->out_formats);
|
||||
avff = ctx->inputs[0]->in_formats;
|
||||
desc = av_pix_fmt_desc_get(avff->formats[0]);
|
||||
rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
|
||||
for (i = 1; i < avff->nb_formats; i++) {
|
||||
desc = av_pix_fmt_desc_get(avff->formats[i]);
|
||||
if (rgb != desc->flags & AV_PIX_FMT_FLAG_RGB)
|
||||
return AVERROR(EAGAIN);
|
||||
}
|
||||
|
||||
if (rgb)
|
||||
out_pix_fmts = levels_out_rgb_pix_fmts;
|
||||
else
|
||||
out_pix_fmts = levels_out_yuv_pix_fmts;
|
||||
ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats);
|
||||
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case MODE_COLOR:
|
||||
case MODE_COLOR2:
|
||||
@ -153,6 +200,11 @@ static int config_input(AVFilterLink *inlink)
|
||||
h->fg_color = white_yuva_color;
|
||||
}
|
||||
|
||||
h->planeheight[1] = h->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, h->desc->log2_chroma_h);
|
||||
h->planeheight[0] = h->planeheight[3] = inlink->h;
|
||||
h->planewidth[1] = h->planewidth[2] = FF_CEIL_RSHIFT(inlink->w, h->desc->log2_chroma_w);
|
||||
h->planewidth[0] = h->planewidth[3] = inlink->w;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -187,6 +239,7 @@ static int config_output(AVFilterLink *outlink)
|
||||
av_assert0(0);
|
||||
}
|
||||
|
||||
h->odesc = av_pix_fmt_desc_get(outlink->format);
|
||||
outlink->sample_aspect_ratio = (AVRational){1,1};
|
||||
|
||||
return 0;
|
||||
@ -257,13 +310,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
|
||||
out->pts = in->pts;
|
||||
|
||||
for (k = 0; k < h->ncomp; k++) {
|
||||
for (k = 0; k < 4 && out->data[k]; k++) {
|
||||
const int is_chroma = (k == 1 || k == 2);
|
||||
const int dst_h = FF_CEIL_RSHIFT(outlink->h, (is_chroma ? h->desc->log2_chroma_h : 0));
|
||||
const int dst_w = FF_CEIL_RSHIFT(outlink->w, (is_chroma ? h->desc->log2_chroma_w : 0));
|
||||
const int dst_h = FF_CEIL_RSHIFT(outlink->h, (is_chroma ? h->odesc->log2_chroma_h : 0));
|
||||
const int dst_w = FF_CEIL_RSHIFT(outlink->w, (is_chroma ? h->odesc->log2_chroma_w : 0));
|
||||
for (i = 0; i < dst_h ; i++)
|
||||
memset(out->data[h->desc->comp[k].plane] +
|
||||
i * out->linesize[h->desc->comp[k].plane],
|
||||
memset(out->data[h->odesc->comp[k].plane] +
|
||||
i * out->linesize[h->odesc->comp[k].plane],
|
||||
h->bg_color[k], dst_w);
|
||||
}
|
||||
|
||||
@ -271,6 +324,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
case MODE_LEVELS:
|
||||
for (m = 0, k = 0; k < h->ncomp; k++) {
|
||||
const int p = h->desc->comp[k].plane;
|
||||
const int height = h->planeheight[p];
|
||||
const int width = h->planewidth[p];
|
||||
int start;
|
||||
double max_hval_log;
|
||||
unsigned max_hval = 0;
|
||||
@ -279,9 +334,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
continue;
|
||||
start = m++ * (h->level_height + h->scale_height) * h->display_mode;
|
||||
|
||||
for (i = 0; i < in->height; i++) {
|
||||
for (i = 0; i < height; i++) {
|
||||
src = in->data[p] + i * in->linesize[p];
|
||||
for (j = 0; j < in->width; j++)
|
||||
for (j = 0; j < width; j++)
|
||||
h->histogram[src[j]]++;
|
||||
}
|
||||
|
||||
|
@ -1,51 +1,51 @@
|
||||
#tb 0: 1/25
|
||||
0, 0, 0, 1, 488448, 0x0d7343b9
|
||||
0, 1, 1, 1, 488448, 0x118e3ade
|
||||
0, 2, 2, 1, 488448, 0x778f1ba9
|
||||
0, 3, 3, 1, 488448, 0x153bf44e
|
||||
0, 4, 4, 1, 488448, 0x2d83c1ab
|
||||
0, 5, 5, 1, 488448, 0xa3e95f8f
|
||||
0, 6, 6, 1, 488448, 0x91aad31b
|
||||
0, 7, 7, 1, 488448, 0x90b92c09
|
||||
0, 8, 8, 1, 488448, 0x1e4c9f41
|
||||
0, 9, 9, 1, 488448, 0xa88c1882
|
||||
0, 10, 10, 1, 488448, 0x1aa04274
|
||||
0, 11, 11, 1, 488448, 0x49c45de8
|
||||
0, 12, 12, 1, 488448, 0xe799c29f
|
||||
0, 13, 13, 1, 488448, 0x789e233f
|
||||
0, 14, 14, 1, 488448, 0x9f753404
|
||||
0, 15, 15, 1, 488448, 0x83050c2c
|
||||
0, 16, 16, 1, 488448, 0xddf7ccbf
|
||||
0, 17, 17, 1, 488448, 0xe3128531
|
||||
0, 18, 18, 1, 488448, 0xcc6596af
|
||||
0, 19, 19, 1, 488448, 0x6e19754f
|
||||
0, 20, 20, 1, 488448, 0xc3b32c7c
|
||||
0, 21, 21, 1, 488448, 0x40b4853f
|
||||
0, 22, 22, 1, 488448, 0x6e492674
|
||||
0, 23, 23, 1, 488448, 0x7f867236
|
||||
0, 24, 24, 1, 488448, 0x22094365
|
||||
0, 25, 25, 1, 488448, 0x45f30fc3
|
||||
0, 26, 26, 1, 488448, 0xe6cbad09
|
||||
0, 27, 27, 1, 488448, 0x0c44836b
|
||||
0, 28, 28, 1, 488448, 0xa7f04271
|
||||
0, 29, 29, 1, 488448, 0xd222ba88
|
||||
0, 30, 30, 1, 488448, 0xc96a9749
|
||||
0, 31, 31, 1, 488448, 0x82e25bbd
|
||||
0, 32, 32, 1, 488448, 0xf79d1882
|
||||
0, 33, 33, 1, 488448, 0x6d7fdd68
|
||||
0, 34, 34, 1, 488448, 0xeb5c9b1b
|
||||
0, 35, 35, 1, 488448, 0x9014f9f4
|
||||
0, 36, 36, 1, 488448, 0x96c6ab5f
|
||||
0, 37, 37, 1, 488448, 0x03911af0
|
||||
0, 38, 38, 1, 488448, 0xbf9dd8eb
|
||||
0, 39, 39, 1, 488448, 0x73509963
|
||||
0, 40, 40, 1, 488448, 0xf2ecb068
|
||||
0, 41, 41, 1, 488448, 0xec2fb311
|
||||
0, 42, 42, 1, 488448, 0xf4c7ba26
|
||||
0, 43, 43, 1, 488448, 0x23f56543
|
||||
0, 44, 44, 1, 488448, 0x25f8c48c
|
||||
0, 45, 45, 1, 488448, 0xf1ccd38b
|
||||
0, 46, 46, 1, 488448, 0x10780667
|
||||
0, 47, 47, 1, 488448, 0xbeb70431
|
||||
0, 48, 48, 1, 488448, 0xbc950678
|
||||
0, 49, 49, 1, 488448, 0xfedf5d83
|
||||
0, 0, 0, 1, 488448, 0xc27a6cac
|
||||
0, 1, 1, 1, 488448, 0xf00a152e
|
||||
0, 2, 2, 1, 488448, 0x060b8c70
|
||||
0, 3, 3, 1, 488448, 0xf75d6ee2
|
||||
0, 4, 4, 1, 488448, 0xd7a7f06e
|
||||
0, 5, 5, 1, 488448, 0x585281a5
|
||||
0, 6, 6, 1, 488448, 0xb06e3ee8
|
||||
0, 7, 7, 1, 488448, 0x201d0b8c
|
||||
0, 8, 8, 1, 488448, 0x4e14e319
|
||||
0, 9, 9, 1, 488448, 0x5aef5cca
|
||||
0, 10, 10, 1, 488448, 0x57018668
|
||||
0, 11, 11, 1, 488448, 0x2ad45b3f
|
||||
0, 12, 12, 1, 488448, 0x62cc36b8
|
||||
0, 13, 13, 1, 488448, 0x9e84585e
|
||||
0, 14, 14, 1, 488448, 0xe6552e42
|
||||
0, 15, 15, 1, 488448, 0x13b90c2c
|
||||
0, 16, 16, 1, 488448, 0xf9557145
|
||||
0, 17, 17, 1, 488448, 0x818340bc
|
||||
0, 18, 18, 1, 488448, 0x5112c6e1
|
||||
0, 19, 19, 1, 488448, 0x5d5b8f43
|
||||
0, 20, 20, 1, 488448, 0xf2101ea6
|
||||
0, 21, 21, 1, 488448, 0x4266af4d
|
||||
0, 22, 22, 1, 488448, 0xb358806e
|
||||
0, 23, 23, 1, 488448, 0xe336aa60
|
||||
0, 24, 24, 1, 488448, 0x64fcc339
|
||||
0, 25, 25, 1, 488448, 0x86e4b729
|
||||
0, 26, 26, 1, 488448, 0x48c380d0
|
||||
0, 27, 27, 1, 488448, 0xaee36fd3
|
||||
0, 28, 28, 1, 488448, 0x20b84429
|
||||
0, 29, 29, 1, 488448, 0x84d85542
|
||||
0, 30, 30, 1, 488448, 0x94aea169
|
||||
0, 31, 31, 1, 488448, 0x6278fa2c
|
||||
0, 32, 32, 1, 488448, 0xaadf998d
|
||||
0, 33, 33, 1, 488448, 0x29bba90d
|
||||
0, 34, 34, 1, 488448, 0xef1117ad
|
||||
0, 35, 35, 1, 488448, 0xd961e36d
|
||||
0, 36, 36, 1, 488448, 0xff53296e
|
||||
0, 37, 37, 1, 488448, 0x41f381f9
|
||||
0, 38, 38, 1, 488448, 0x66fcfc2a
|
||||
0, 39, 39, 1, 488448, 0x758bb472
|
||||
0, 40, 40, 1, 488448, 0xefc6dc9e
|
||||
0, 41, 41, 1, 488448, 0x77fccb69
|
||||
0, 42, 42, 1, 488448, 0x7a1d82a4
|
||||
0, 43, 43, 1, 488448, 0xc9d61a1b
|
||||
0, 44, 44, 1, 488448, 0x8e689deb
|
||||
0, 45, 45, 1, 488448, 0x52133e75
|
||||
0, 46, 46, 1, 488448, 0xcc0a098e
|
||||
0, 47, 47, 1, 488448, 0x045cd17f
|
||||
0, 48, 48, 1, 488448, 0x97f89963
|
||||
0, 49, 49, 1, 488448, 0xa1f835ff
|
||||
|
Loading…
Reference in New Issue
Block a user