int ow, oh;
int x, y;
int mode;
+ int dformat;
int axis;
float opacity;
#define OFFSET(x) offsetof(DatascopeContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+#define FLAGSR AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
static const AVOption datascope_options[] = {
{ "size", "set output size", OFFSET(ow), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS },
{ "color2", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "mode" },
{ "axis", "draw column/row numbers", OFFSET(axis), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
{ "opacity", "set background opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
+ { "format", "set display number format", OFFSET(dformat), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "format" },
+ { "hex", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "format" },
+ { "dec", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "format" },
{ NULL }
};
const int yoff = td->yoff;
const int P = FFMAX(s->nb_planes, s->nb_comps);
const int C = s->chars;
+ const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
const int W = (outlink->w - xoff) / (C * 10);
const int H = (outlink->h - yoff) / (P * 12);
- const char *format[2] = {"%02X\n", "%04X\n"};
+ const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
const int slice_start = (W * jobnr) / nb_jobs;
const int slice_end = (W * (jobnr+1)) / nb_jobs;
int x, y, p;
for (p = 0; p < P; p++) {
char text[256];
- snprintf(text, sizeof(text), format[C>>2], value[p]);
+ snprintf(text, sizeof(text), format[D], value[p]);
draw_text(&s->draw, out, &reverse, xoff + x * C * 10 + 2, yoff + y * P * 12 + p * 10 + 2, text, 0);
}
}
const int yoff = td->yoff;
const int P = FFMAX(s->nb_planes, s->nb_comps);
const int C = s->chars;
+ const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
const int W = (outlink->w - xoff) / (C * 10);
const int H = (outlink->h - yoff) / (P * 12);
- const char *format[2] = {"%02X\n", "%04X\n"};
+ const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
const int slice_start = (W * jobnr) / nb_jobs;
const int slice_end = (W * (jobnr+1)) / nb_jobs;
int x, y, p;
for (p = 0; p < P; p++) {
char text[256];
- snprintf(text, sizeof(text), format[C>>2], value[p]);
+ snprintf(text, sizeof(text), format[D], value[p]);
draw_text(&s->draw, out, &color, xoff + x * C * 10 + 2, yoff + y * P * 12 + p * 10 + 2, text, 0);
}
}
const int yoff = td->yoff;
const int P = FFMAX(s->nb_planes, s->nb_comps);
const int C = s->chars;
+ const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
const int W = (outlink->w - xoff) / (C * 10);
const int H = (outlink->h - yoff) / (P * 12);
- const char *format[2] = {"%02X\n", "%04X\n"};
+ const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
const int slice_start = (W * jobnr) / nb_jobs;
const int slice_end = (W * (jobnr+1)) / nb_jobs;
int x, y, p;
for (p = 0; p < P; p++) {
char text[256];
- snprintf(text, sizeof(text), format[C>>2], value[p]);
+ snprintf(text, sizeof(text), format[D], value[p]);
draw_text(&s->draw, out, &s->white, xoff + x * C * 10 + 2, yoff + y * P * 12 + p * 10 + 2, text, 0);
}
}
ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );
ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} );
ff_draw_color(&s->draw, &s->gray, (uint8_t[]){ 77, 77, 77, 255} );
- s->chars = (s->draw.desc->comp[0].depth + 7) / 8 * 2;
+ s->chars = (s->draw.desc->comp[0].depth + 7) / 8 * 2 + s->dformat;
s->nb_comps = s->draw.desc->nb_components;
switch (s->mode) {
}
s->ww = 300;
- s->wh = 300 * 1.6180;
+ s->wh = 300 * 1.6;
s->x = s->xpos * (inlink->w - 1);
s->y = s->ypos * (inlink->h - 1);
if (s->x + s->w >= inlink->w || s->y + s->h >= inlink->h) {
#define OOFFSET(x) offsetof(OscilloscopeContext, x)
static const AVOption oscilloscope_options[] = {
- { "x", "set scope x position", OOFFSET(xpos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
- { "y", "set scope y position", OOFFSET(ypos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
- { "s", "set scope size", OOFFSET(size), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGS },
- { "t", "set scope tilt", OOFFSET(tilt), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
- { "o", "set trace opacity", OOFFSET(o), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGS },
- { "tx", "set trace x position", OOFFSET(tx), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
- { "ty", "set trace y position", OOFFSET(ty), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGS },
- { "tw", "set trace width", OOFFSET(twidth), AV_OPT_TYPE_FLOAT, {.dbl=0.8},.1, 1, FLAGS },
- { "th", "set trace height", OOFFSET(theight), AV_OPT_TYPE_FLOAT, {.dbl=0.3},.1, 1, FLAGS },
- { "c", "set components to trace", OOFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, FLAGS },
- { "g", "draw trace grid", OOFFSET(grid), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
- { "st", "draw statistics", OOFFSET(statistics), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
- { "sc", "draw scope", OOFFSET(scope), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
+ { "x", "set scope x position", OOFFSET(xpos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
+ { "y", "set scope y position", OOFFSET(ypos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
+ { "s", "set scope size", OOFFSET(size), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGSR },
+ { "t", "set scope tilt", OOFFSET(tilt), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
+ { "o", "set trace opacity", OOFFSET(o), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGSR },
+ { "tx", "set trace x position", OOFFSET(tx), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
+ { "ty", "set trace y position", OOFFSET(ty), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGSR },
+ { "tw", "set trace width", OOFFSET(twidth), AV_OPT_TYPE_FLOAT, {.dbl=0.8},.1, 1, FLAGSR },
+ { "th", "set trace height", OOFFSET(theight), AV_OPT_TYPE_FLOAT, {.dbl=0.3},.1, 1, FLAGSR },
+ { "c", "set components to trace", OOFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, FLAGSR },
+ { "g", "draw trace grid", OOFFSET(grid), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
+ { "st", "draw statistics", OOFFSET(statistics), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
+ { "sc", "draw scope", OOFFSET(scope), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
{ NULL }
};
if ((1 << c) & s->components) {
int x = i * s->width / s->nb_values;
int px = (i - 1) * s->width / s->nb_values;
- int py = s->height - s->values[i-1].p[c] * s->height / 256;
- int y = s->height - s->values[i].p[c] * s->height / 256;
+ int py = s->height - s->values[i-1].p[s->rgba_map[c]] * s->height / 256;
+ int y = s->height - s->values[i].p[s->rgba_map[c]] * s->height / 256;
draw_line(&s->draw, s->ox + x, s->oy + y, s->ox + px, s->oy + py, frame, s->colors[c]);
}
if ((1 << c) & s->components) {
int x = i * s->width / s->nb_values;
int px = (i - 1) * s->width / s->nb_values;
- int py = s->height - s->values[i-1].p[c] * s->height / s->max;
- int y = s->height - s->values[i].p[c] * s->height / s->max;
+ int py = s->height - s->values[i-1].p[s->rgba_map[c]] * s->height / s->max;
+ int y = s->height - s->values[i].p[s->rgba_map[c]] * s->height / s->max;
draw_line(&s->draw, s->ox + x, s->oy + y, s->ox + px, s->oy + py, frame, s->colors[c]);
}
}
}
-static int oscilloscope_config_input(AVFilterLink *inlink)
+static void update_oscilloscope(AVFilterContext *ctx)
{
- OscilloscopeContext *s = inlink->dst->priv;
+ OscilloscopeContext *s = ctx->priv;
+ AVFilterLink *inlink = ctx->inputs[0];
int cx, cy, size;
double tilt;
+ ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
+ s->height = s->theight * inlink->h;
+ s->width = s->twidth * inlink->w;
+ size = hypot(inlink->w, inlink->h);
+ size *= s->size;
+ tilt = (s->tilt - 0.5) * M_PI;
+ cx = s->xpos * (inlink->w - 1);
+ cy = s->ypos * (inlink->h - 1);
+ s->x1 = cx - size / 2.0 * cos(tilt);
+ s->x2 = cx + size / 2.0 * cos(tilt);
+ s->y1 = cy - size / 2.0 * sin(tilt);
+ s->y2 = cy + size / 2.0 * sin(tilt);
+ s->ox = (inlink->w - s->width) * s->tx;
+ s->oy = (inlink->h - s->height) * s->ty;
+}
+
+static int oscilloscope_config_input(AVFilterLink *inlink)
+{
+ OscilloscopeContext *s = inlink->dst->priv;
+ int size;
+
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
ff_draw_init(&s->draw, inlink->format, 0);
- ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} );
}
s->max = (1 << s->draw.desc->comp[0].depth);
- cx = s->xpos * (inlink->w - 1);
- cy = s->ypos * (inlink->h - 1);
- s->height = s->theight * inlink->h;
- s->width = s->twidth * inlink->w;
size = hypot(inlink->w, inlink->h);
s->values = av_calloc(size, sizeof(*s->values));
if (!s->values)
return AVERROR(ENOMEM);
- size *= s->size;
- tilt = (s->tilt - 0.5) * M_PI;
- s->x1 = cx - size / 2.0 * cos(tilt);
- s->x2 = cx + size / 2.0 * cos(tilt);
- s->y1 = cy - size / 2.0 * sin(tilt);
- s->y2 = cy + size / 2.0 * sin(tilt);
- s->ox = (inlink->w - s->width) * s->tx;
- s->oy = (inlink->h - s->height) * s->ty;
+ update_oscilloscope(inlink->dst);
return 0;
}
frame->width, frame->height,
s->ox, s->oy, s->width, s->height + 20 * s->statistics);
- if (s->grid) {
+ if (s->grid && outlink->h >= 10) {
ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
s->ox, s->oy, s->width - 1, 1);
for (i = 0; i < s->nb_values; i++) {
for (c = 0; c < s->nb_comps; c++) {
if ((1 << c) & s->components) {
- max[c] = FFMAX(max[c], s->values[i].p[c]);
- min[c] = FFMIN(min[c], s->values[i].p[c]);
- average[c] += s->values[i].p[c];
+ max[c] = FFMAX(max[c], s->values[i].p[s->rgba_map[c]]);
+ min[c] = FFMIN(min[c], s->values[i].p[s->rgba_map[c]]);
+ average[c] += s->values[i].p[s->rgba_map[c]];
}
}
}
const char yuva[4] = { 'Y', 'U', 'V', 'A' };
char text[128];
- snprintf(text, sizeof(text), "%c avg:%.1f min:%d max:%d\n", s->is_rgb ? rgba[c] : yuva[c], average[s->rgba_map[c]], min[s->rgba_map[c]], max[s->rgba_map[c]]);
+ snprintf(text, sizeof(text), "%c avg:%.1f min:%d max:%d\n", s->is_rgb ? rgba[c] : yuva[c], average[c], min[c], max[c]);
draw_text(&s->draw, frame, &s->white, s->ox + 2 + 280 * i++, s->oy + s->height + 4, text, 0);
}
}
return ff_filter_frame(outlink, frame);
}
+static int oscilloscope_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ int ret;
+
+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+ if (ret < 0)
+ return ret;
+
+ update_oscilloscope(ctx);
+
+ return 0;
+}
+
static const AVFilterPad oscilloscope_inputs[] = {
{
.name = "default",
.inputs = oscilloscope_inputs,
.outputs = oscilloscope_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+ .process_command = oscilloscope_process_command,
};