76 #define OFFSET(x) offsetof(TestSourceContext, x)
77 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
79 #define COMMON_OPTIONS \
80 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
81 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
82 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
83 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
84 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
85 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
86 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
120 outlink->
w = test->
w;
121 outlink->
h = test->
h;
170 #if CONFIG_COLOR_FILTER
172 static const AVOption color_options[] = {
186 0, 0, test->
w, test->
h);
229 if (!strcmp(cmd,
"color") || !strcmp(cmd,
"c")) {
236 memcpy(test->
color_rgba, color_rgba,
sizeof(color_rgba));
250 .config_props = color_config_props,
259 .priv_class = &color_class,
272 #if CONFIG_NULLSRC_FILTER
274 #define nullsrc_options options
300 .init = nullsrc_init,
303 .priv_class = &nullsrc_class,
310 #if CONFIG_TESTSRC_FILTER
312 static const AVOption testsrc_options[] = {
333 static void draw_rectangle(
unsigned val,
uint8_t *
dst,
int dst_linesize,
int segment_width,
334 int x,
int y,
int w,
int h)
339 dst += segment_width * (step * x + y * dst_linesize);
340 w *= segment_width * step;
342 for (i = 0; i < h; i++) {
348 static void draw_digit(
int digit,
uint8_t *dst,
int dst_linesize,
354 #define LEFT_TOP_VBAR 8
355 #define LEFT_BOT_VBAR 16
356 #define RIGHT_TOP_VBAR 32
357 #define RIGHT_BOT_VBAR 64
369 static const unsigned char masks[10] = {
370 TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
371 RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
372 TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
373 TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
374 MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
375 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
376 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
377 TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
378 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
379 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
381 unsigned mask = masks[digit];
384 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
387 draw_rectangle(255, dst, dst_linesize, segment_width,
388 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
391 #define GRADIENT_SIZE (6 * 256)
398 int color, color_rest;
402 int dquad_x, dquad_y;
403 int grad, dgrad, rgrad, drgrad;
412 radius = (width +
height) / 4;
413 quad0 = width * width / 4 + height * height / 4 - radius * radius;
416 for (y = 0; y <
height; y++) {
422 for (x = 0; x <
width; x++) {
428 *(p++) = icolor & 1 ? 255 : 0;
429 *(p++) = icolor & 2 ? 255 : 0;
430 *(p++) = icolor & 4 ? 255 : 0;
432 if (color_rest >= width) {
443 p0 = p = data + frame->
linesize[0] * height * 3/4;
447 dgrad = GRADIENT_SIZE /
width;
448 drgrad = GRADIENT_SIZE %
width;
449 for (x = 0; x <
width; x++) {
451 grad < 256 || grad >= 5 * 256 ? 255 :
452 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
453 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
455 grad >= 4 * 256 ? 0 :
456 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
457 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
460 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
461 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
464 if (rgrad >= GRADIENT_SIZE) {
466 rgrad -= GRADIENT_SIZE;
468 if (grad >= GRADIENT_SIZE)
469 grad -= GRADIENT_SIZE;
472 for (y = height / 8; y > 0; y--) {
473 memcpy(p+frame->
linesize[0], p, 3 * width);
478 seg_size = width / 80;
479 if (seg_size >= 1 && height >= 13 * seg_size) {
480 int64_t p10decimals = 1;
490 x = width - (width - seg_size * 64) / 2;
491 y = (height - seg_size * 13) / 2;
492 p = data + (x*3 + y * frame->
linesize[0]);
493 for (i = 0; i < 8; i++) {
494 p -= 3 * 8 * seg_size;
495 draw_digit(second % 10, p, frame->
linesize[0], seg_size);
520 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
534 .priv_class = &testsrc_class,
541 .
outputs = avfilter_vsrc_testsrc_outputs,
546 #if CONFIG_RGBTESTSRC_FILTER
548 #define rgbtestsrc_options options
556 static void rgbtest_put_pixel(
uint8_t *dst,
int dst_linesize,
564 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
break;
565 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4);
break;
566 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
break;
567 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
break;
568 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
break;
569 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
break;
572 v = (r << (rgba_map[
R]*8)) + (g << (rgba_map[
G]*8)) + (b << (rgba_map[
B]*8));
573 p = dst + 3*x + y*dst_linesize;
580 v = (r << (rgba_map[
R]*8)) + (g << (rgba_map[
G]*8)) + (b << (rgba_map[
B]*8)) + (255 << (rgba_map[
A]*8));
581 p = dst + 4*x + y*dst_linesize;
592 for (y = 0; y < h; y++) {
593 for (x = 0; x < w; x++) {
595 int r = 0, g = 0, b = 0;
598 else if (3*y < 2*h) g =
c;
601 rgbtest_put_pixel(frame->
data[0], frame->
linesize[0], x, y, r, g, b,
638 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
643 .config_props = rgbtest_config_props,
648 AVFilter avfilter_vsrc_rgbtestsrc = {
649 .
name =
"rgbtestsrc",
652 .priv_class = &rgbtestsrc_class,
653 .
init = rgbtest_init,
660 .
outputs = avfilter_vsrc_rgbtestsrc_outputs,
665 #if CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
667 static const uint8_t rainbow[7][4] = {
668 { 191, 191, 191, 255 },
669 { 191, 191, 0, 255 },
670 { 0, 191, 191, 255 },
672 { 191, 0, 191, 255 },
677 static const uint8_t wobnair[7][4] = {
680 { 191, 0, 191, 255 },
682 { 0, 191, 191, 255 },
684 { 191, 191, 191, 255 },
687 static const uint8_t white[4] = { 255, 255, 255, 255 };
688 static const uint8_t black[4] = { 19, 19, 19, 255 };
691 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 };
692 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 };
695 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
696 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
698 static const uint8_t gray40[4] = { 102, 102, 102, 255 };
699 static const uint8_t gray15[4] = { 38, 38, 38, 255 };
700 static const uint8_t cyan[4] = { 0, 255, 255, 255 };
701 static const uint8_t yellow[4] = { 255, 255, 0, 255 };
702 static const uint8_t blue[4] = { 0, 0, 255, 255 };
703 static const uint8_t red[4] = { 255, 0, 0, 255 };
704 static const uint8_t black0[4] = { 5, 5, 5, 255 };
705 static const uint8_t black2[4] = { 10, 10, 10, 255 };
706 static const uint8_t black4[4] = { 15, 15, 15, 255 };
707 static const uint8_t neg2[4] = { 0, 0, 0, 255 };
710 unsigned x,
unsigned y,
unsigned w,
unsigned h,
715 x =
FFMIN(x, test->
w - 1);
716 y =
FFMIN(y, test->
h - 1);
717 w =
FFMIN(w, test->
w - x);
718 h =
FFMIN(h, test->
h - y);
734 static int smptebars_config_props(
AVFilterLink *outlink)
749 .config_props = smptebars_config_props,
754 #if CONFIG_SMPTEBARS_FILTER
756 #define smptebars_options options
762 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
769 p_h = test->
h - w_h - r_h;
771 for (i = 0; i < 7; i++) {
772 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
773 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
777 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
779 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
781 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
784 draw_bar(test, black, x, r_h + w_h, tmp, p_h, picref);
787 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
789 draw_bar(test, black, x, r_h + w_h, tmp, p_h, picref);
791 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
793 draw_bar(test, black, x, r_h + w_h, test->
w - x, p_h, picref);
805 AVFilter avfilter_vsrc_smptebars = {
809 .
init = smptebars_init,
815 .priv_class = &smptebars_class,
820 #if CONFIG_SMPTEHDBARS_FILTER
822 #define smptehdbars_options options
828 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
833 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
837 for (i = 0; i < 7; i++) {
838 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
841 draw_bar(test, gray40, x, 0, test->
w - x, r_h, picref);
844 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
846 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
849 draw_bar(test, rainbow[0], x, y, tmp, r_h, picref);
852 draw_bar(test, blue, x, y, test->
w - x, r_h, picref);
854 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
856 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
864 yramp[2] = i * 255 / tmp;
867 draw_bar(test, yramp, x, y, 1 << pixdesc->
log2_chroma_w, r_h, picref);
870 draw_bar(test, red, x, y, test->
w - x, r_h, picref);
872 draw_bar(test, gray15, 0, y, d_w, test->
h - y, picref);
875 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
878 draw_bar(test, white, x, y, tmp, test->
h - y, picref);
881 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
884 draw_bar(test, neg2, x, y, tmp, test->
h - y, picref);
886 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
888 draw_bar(test, black2, x, y, tmp, test->
h - y, picref);
890 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
892 draw_bar(test, black4, x, y, tmp, test->
h - y, picref);
895 draw_bar(test, black0, x, y, r_w, test->
h - y, picref);
897 draw_bar(test, gray15, x, y, test->
w - x, test->
h - y, picref);
909 AVFilter avfilter_vsrc_smptehdbars = {
910 .
name =
"smptehdbars",
913 .
init = smptehdbars_init,
919 .priv_class = &smptehdbars_class,