79 #define OFFSET(x) offsetof(TestSourceContext, x)
80 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
82 #define SIZE_OPTIONS \
83 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
84 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
86 #define COMMON_OPTIONS_NOSIZE \
87 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
88 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
89 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
90 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
91 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
93 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
126 outlink->
w = test->
w;
127 outlink->
h = test->
h;
176 #if CONFIG_COLOR_FILTER
178 static const AVOption color_options[] = {
192 0, 0, test->
w, test->
h);
235 if (!strcmp(cmd,
"color") || !strcmp(cmd,
"c")) {
242 memcpy(test->
color_rgba, color_rgba,
sizeof(color_rgba));
256 .config_props = color_config_props,
265 .priv_class = &color_class,
278 #if CONFIG_HALDCLUTSRC_FILTER
280 static const AVOption haldclutsrc_options[] = {
290 int i, j, k, x = 0,
y = 0, is16bit = 0, step;
295 const int w = frame->
width;
296 const int h = frame->
height;
298 const int linesize = frame->
linesize[0];
323 scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
325 #define LOAD_CLUT(nbits) do { \
326 uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
327 dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
328 dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
329 dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
331 dst[rgba_map[3]] = alpha; \
335 for (k = 0; k <
level; k++) {
336 for (j = 0; j <
level; j++) {
337 for (i = 0; i <
level; i++) {
375 static int haldclutsrc_config_props(
AVFilterLink *outlink)
389 .config_props = haldclutsrc_config_props,
394 AVFilter avfilter_vsrc_haldclutsrc = {
395 .
name =
"haldclutsrc",
397 .priv_class = &haldclutsrc_class,
399 .
init = haldclutsrc_init,
403 .
outputs = haldclutsrc_outputs,
407 #if CONFIG_NULLSRC_FILTER
409 #define nullsrc_options options
435 .init = nullsrc_init,
438 .priv_class = &nullsrc_class,
445 #if CONFIG_TESTSRC_FILTER
447 static const AVOption testsrc_options[] = {
468 static void draw_rectangle(
unsigned val,
uint8_t *dst,
int dst_linesize,
int segment_width,
469 int x,
int y,
int w,
int h)
474 dst += segment_width * (step * x + y * dst_linesize);
475 w *= segment_width * step;
477 for (i = 0; i < h; i++) {
483 static void draw_digit(
int digit,
uint8_t *dst,
int dst_linesize,
489 #define LEFT_TOP_VBAR 8
490 #define LEFT_BOT_VBAR 16
491 #define RIGHT_TOP_VBAR 32
492 #define RIGHT_BOT_VBAR 64
504 static const unsigned char masks[10] = {
505 TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
506 RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
507 TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
508 TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
509 MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
510 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
511 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
512 TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
513 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
514 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
516 unsigned mask = masks[digit];
519 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
522 draw_rectangle(255, dst, dst_linesize, segment_width,
523 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
526 #define GRADIENT_SIZE (6 * 256)
533 int color, color_rest;
537 int dquad_x, dquad_y;
538 int grad, dgrad, rgrad, drgrad;
547 radius = (width +
height) / 4;
548 quad0 = width * width / 4 + height * height / 4 - radius * radius;
551 for (y = 0; y <
height; y++) {
557 for (x = 0; x <
width; x++) {
563 *(p++) = icolor & 1 ? 255 : 0;
564 *(p++) = icolor & 2 ? 255 : 0;
565 *(p++) = icolor & 4 ? 255 : 0;
567 if (color_rest >= width) {
578 p0 = p = data + frame->
linesize[0] * (height * 3/4);
582 dgrad = GRADIENT_SIZE /
width;
583 drgrad = GRADIENT_SIZE %
width;
584 for (x = 0; x <
width; x++) {
586 grad < 256 || grad >= 5 * 256 ? 255 :
587 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
588 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
590 grad >= 4 * 256 ? 0 :
591 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
592 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
595 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
596 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
599 if (rgrad >= GRADIENT_SIZE) {
601 rgrad -= GRADIENT_SIZE;
603 if (grad >= GRADIENT_SIZE)
604 grad -= GRADIENT_SIZE;
607 for (y = height / 8; y > 0; y--) {
608 memcpy(p+frame->
linesize[0], p, 3 * width);
613 seg_size = width / 80;
614 if (seg_size >= 1 && height >= 13 * seg_size) {
615 int64_t p10decimals = 1;
625 x = width - (width - seg_size * 64) / 2;
626 y = (height - seg_size * 13) / 2;
627 p = data + (x*3 + y * frame->
linesize[0]);
628 for (i = 0; i < 8; i++) {
629 p -= 3 * 8 * seg_size;
630 draw_digit(second % 10, p, frame->
linesize[0], seg_size);
655 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
669 .priv_class = &testsrc_class,
676 .
outputs = avfilter_vsrc_testsrc_outputs,
681 #if CONFIG_RGBTESTSRC_FILTER
683 #define rgbtestsrc_options options
691 static void rgbtest_put_pixel(
uint8_t *dst,
int dst_linesize,
699 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
break;
700 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4);
break;
701 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
break;
702 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
break;
703 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
break;
704 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
break;
707 v = (r << (rgba_map[
R]*8)) + (g << (rgba_map[
G]*8)) + (b << (rgba_map[
B]*8));
708 p = dst + 3*x + y*dst_linesize;
715 v = (r << (rgba_map[
R]*8)) + (g << (rgba_map[
G]*8)) + (b << (rgba_map[
B]*8)) + (255 << (rgba_map[
A]*8));
716 p = dst + 4*x + y*dst_linesize;
727 for (y = 0; y < h; y++) {
728 for (x = 0; x < w; x++) {
730 int r = 0, g = 0, b = 0;
733 else if (3*y < 2*h) g =
c;
736 rgbtest_put_pixel(frame->
data[0], frame->
linesize[0], x, y, r, g, b,
773 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
778 .config_props = rgbtest_config_props,
783 AVFilter avfilter_vsrc_rgbtestsrc = {
784 .
name =
"rgbtestsrc",
787 .priv_class = &rgbtestsrc_class,
788 .
init = rgbtest_init,
795 .
outputs = avfilter_vsrc_rgbtestsrc_outputs,
800 #if CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
802 static const uint8_t rainbow[7][4] = {
803 { 191, 191, 191, 255 },
804 { 191, 191, 0, 255 },
805 { 0, 191, 191, 255 },
807 { 191, 0, 191, 255 },
812 static const uint8_t wobnair[7][4] = {
815 { 191, 0, 191, 255 },
817 { 0, 191, 191, 255 },
819 { 191, 191, 191, 255 },
822 static const uint8_t white[4] = { 255, 255, 255, 255 };
823 static const uint8_t black[4] = { 19, 19, 19, 255 };
826 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 };
827 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 };
830 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
831 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
833 static const uint8_t gray40[4] = { 102, 102, 102, 255 };
834 static const uint8_t gray15[4] = { 38, 38, 38, 255 };
835 static const uint8_t cyan[4] = { 0, 255, 255, 255 };
836 static const uint8_t yellow[4] = { 255, 255, 0, 255 };
837 static const uint8_t blue[4] = { 0, 0, 255, 255 };
838 static const uint8_t red[4] = { 255, 0, 0, 255 };
839 static const uint8_t black0[4] = { 5, 5, 5, 255 };
840 static const uint8_t black2[4] = { 10, 10, 10, 255 };
841 static const uint8_t black4[4] = { 15, 15, 15, 255 };
842 static const uint8_t neg2[4] = { 0, 0, 0, 255 };
845 unsigned x,
unsigned y,
unsigned w,
unsigned h,
850 x =
FFMIN(x, test->
w - 1);
851 y =
FFMIN(y, test->
h - 1);
852 w =
FFMIN(w, test->
w - x);
853 h =
FFMIN(h, test->
h - y);
869 static int smptebars_config_props(
AVFilterLink *outlink)
884 .config_props = smptebars_config_props,
889 #if CONFIG_SMPTEBARS_FILTER
891 #define smptebars_options options
897 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
904 p_h = test->
h - w_h - r_h;
906 for (i = 0; i < 7; i++) {
907 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
908 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
912 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
914 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
916 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
919 draw_bar(test, black, x, r_h + w_h, tmp, p_h, picref);
922 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
924 draw_bar(test, black, x, r_h + w_h, tmp, p_h, picref);
926 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
928 draw_bar(test, black, x, r_h + w_h, test->
w - x, p_h, picref);
940 AVFilter avfilter_vsrc_smptebars = {
944 .
init = smptebars_init,
950 .priv_class = &smptebars_class,
955 #if CONFIG_SMPTEHDBARS_FILTER
957 #define smptehdbars_options options
963 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
968 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
972 for (i = 0; i < 7; i++) {
973 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
976 draw_bar(test, gray40, x, 0, test->
w - x, r_h, picref);
979 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
981 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
984 draw_bar(test, rainbow[0], x, y, tmp, r_h, picref);
987 draw_bar(test, blue, x, y, test->
w - x, r_h, picref);
989 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
991 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
999 yramp[2] = i * 255 / tmp;
1002 draw_bar(test, yramp, x, y, 1 << pixdesc->
log2_chroma_w, r_h, picref);
1005 draw_bar(test, red, x, y, test->
w - x, r_h, picref);
1007 draw_bar(test, gray15, 0, y, d_w, test->
h - y, picref);
1010 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
1013 draw_bar(test, white, x, y, tmp, test->
h - y, picref);
1016 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
1019 draw_bar(test, neg2, x, y, tmp, test->
h - y, picref);
1021 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
1023 draw_bar(test, black2, x, y, tmp, test->
h - y, picref);
1025 draw_bar(test, black0, x, y, tmp, test->
h - y, picref);
1027 draw_bar(test, black4, x, y, tmp, test->
h - y, picref);
1030 draw_bar(test, black0, x, y, r_w, test->
h - y, picref);
1032 draw_bar(test, gray15, x, y, test->
w - x, test->
h - y, picref);
1044 AVFilter avfilter_vsrc_smptehdbars = {
1045 .
name =
"smptehdbars",
1048 .
init = smptehdbars_init,
1054 .priv_class = &smptehdbars_class,