00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00036 #include <float.h>
00037
00038 #include "libavutil/common.h"
00039 #include "libavutil/opt.h"
00040 #include "libavutil/imgutils.h"
00041 #include "libavutil/intreadwrite.h"
00042 #include "libavutil/parseutils.h"
00043 #include "avfilter.h"
00044 #include "drawutils.h"
00045 #include "formats.h"
00046 #include "internal.h"
00047 #include "video.h"
00048
00049 typedef struct {
00050 const AVClass *class;
00051 int w, h;
00052 unsigned int nb_frame;
00053 AVRational time_base, frame_rate;
00054 int64_t pts;
00055 char *frame_rate_str;
00056 char *duration_str;
00057 int64_t duration;
00058 AVRational sar;
00059 int nb_decimals;
00060 int draw_once;
00061 AVFilterBufferRef *picref;
00062
00063 void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref);
00064
00065
00066 char *color_str;
00067 FFDrawContext draw;
00068 FFDrawColor color;
00069 uint8_t color_rgba[4];
00070
00071
00072 uint8_t rgba_map[4];
00073 } TestSourceContext;
00074
00075 #define OFFSET(x) offsetof(TestSourceContext, x)
00076 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
00077
00078 static const AVOption options[] = {
00079 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },
00080 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },
00081 { "rate", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
00082 { "r", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
00083 { "duration", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
00084 { "d", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
00085 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
00086
00087
00088 { "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
00089 { "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
00090
00091
00092 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
00093 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
00094 { NULL },
00095 };
00096
00097 static av_cold int init(AVFilterContext *ctx, const char *args)
00098 {
00099 TestSourceContext *test = ctx->priv;
00100 int ret = 0;
00101
00102 av_opt_set_defaults(test);
00103
00104 if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0)
00105 return ret;
00106
00107 if ((ret = av_parse_video_rate(&test->frame_rate, test->frame_rate_str)) < 0) {
00108 av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->frame_rate_str);
00109 return ret;
00110 }
00111
00112 test->duration = -1;
00113 if (test->duration_str &&
00114 (ret = av_parse_time(&test->duration, test->duration_str, 1)) < 0) {
00115 av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration_str);
00116 return ret;
00117 }
00118
00119 if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) {
00120 av_log(ctx, AV_LOG_WARNING,
00121 "Option 'decimals' is ignored with source '%s'\n",
00122 ctx->filter->name);
00123 }
00124
00125 if (test->color_str) {
00126 if (!strcmp(ctx->filter->name, "color")) {
00127 ret = av_parse_color(test->color_rgba, test->color_str, -1, ctx);
00128 if (ret < 0)
00129 return ret;
00130 } else {
00131 av_log(ctx, AV_LOG_WARNING,
00132 "Option 'color' is ignored with source '%s'\n",
00133 ctx->filter->name);
00134 }
00135 }
00136
00137 test->time_base = av_inv_q(test->frame_rate);
00138 test->nb_frame = 0;
00139 test->pts = 0;
00140
00141 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
00142 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
00143 test->duration < 0 ? -1 : (double)test->duration/1000000,
00144 test->sar.num, test->sar.den);
00145 return 0;
00146 }
00147
00148 static av_cold void uninit(AVFilterContext *ctx)
00149 {
00150 TestSourceContext *test = ctx->priv;
00151
00152 av_opt_free(test);
00153 avfilter_unref_bufferp(&test->picref);
00154 }
00155
00156 static int config_props(AVFilterLink *outlink)
00157 {
00158 TestSourceContext *test = outlink->src->priv;
00159
00160 outlink->w = test->w;
00161 outlink->h = test->h;
00162 outlink->sample_aspect_ratio = test->sar;
00163 outlink->frame_rate = test->frame_rate;
00164 outlink->time_base = test->time_base;
00165
00166 return 0;
00167 }
00168
00169 static int request_frame(AVFilterLink *outlink)
00170 {
00171 TestSourceContext *test = outlink->src->priv;
00172 AVFilterBufferRef *outpicref;
00173 int ret = 0;
00174
00175 if (test->duration >= 0 &&
00176 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
00177 return AVERROR_EOF;
00178
00179 if (test->draw_once) {
00180 if (!test->picref) {
00181 test->picref =
00182 ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_PRESERVE|AV_PERM_REUSE,
00183 test->w, test->h);
00184 if (!test->picref)
00185 return AVERROR(ENOMEM);
00186 test->fill_picture_fn(outlink->src, test->picref);
00187 }
00188 outpicref = avfilter_ref_buffer(test->picref, ~AV_PERM_WRITE);
00189 } else
00190 outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
00191
00192 if (!outpicref)
00193 return AVERROR(ENOMEM);
00194 outpicref->pts = test->pts;
00195 outpicref->pos = -1;
00196 outpicref->video->key_frame = 1;
00197 outpicref->video->interlaced = 0;
00198 outpicref->video->pict_type = AV_PICTURE_TYPE_I;
00199 outpicref->video->sample_aspect_ratio = test->sar;
00200 if (!test->draw_once)
00201 test->fill_picture_fn(outlink->src, outpicref);
00202
00203 test->pts++;
00204 test->nb_frame++;
00205
00206 if ((ret = ff_start_frame(outlink, outpicref)) < 0 ||
00207 (ret = ff_draw_slice(outlink, 0, test->h, 1)) < 0 ||
00208 (ret = ff_end_frame(outlink)) < 0)
00209 return ret;
00210
00211 return 0;
00212 }
00213
00214 #if CONFIG_COLOR_FILTER
00215
00216 #define color_options options
00217 AVFILTER_DEFINE_CLASS(color);
00218
00219 static void color_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00220 {
00221 TestSourceContext *test = ctx->priv;
00222 ff_fill_rectangle(&test->draw, &test->color,
00223 picref->data, picref->linesize,
00224 0, 0, test->w, test->h);
00225 }
00226
00227 static av_cold int color_init(AVFilterContext *ctx, const char *args)
00228 {
00229 TestSourceContext *test = ctx->priv;
00230 test->class = &color_class;
00231 test->fill_picture_fn = color_fill_picture;
00232 test->draw_once = 1;
00233 av_opt_set(test, "color", "black", 0);
00234 return init(ctx, args);
00235 }
00236
00237 static int color_query_formats(AVFilterContext *ctx)
00238 {
00239 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
00240 return 0;
00241 }
00242
00243 static int color_config_props(AVFilterLink *inlink)
00244 {
00245 AVFilterContext *ctx = inlink->src;
00246 TestSourceContext *test = ctx->priv;
00247 int ret;
00248
00249 ff_draw_init(&test->draw, inlink->format, 0);
00250 ff_draw_color(&test->draw, &test->color, test->color_rgba);
00251
00252 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
00253 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
00254 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
00255 return AVERROR(EINVAL);
00256
00257 if (ret = config_props(inlink) < 0)
00258 return ret;
00259
00260 av_log(ctx, AV_LOG_VERBOSE, "color:0x%02x%02x%02x%02x\n",
00261 test->color_rgba[0], test->color_rgba[1], test->color_rgba[2], test->color_rgba[3]);
00262 return 0;
00263 }
00264
00265 AVFilter avfilter_vsrc_color = {
00266 .name = "color",
00267 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
00268
00269 .priv_size = sizeof(TestSourceContext),
00270 .init = color_init,
00271 .uninit = uninit,
00272
00273 .query_formats = color_query_formats,
00274
00275 .inputs = (const AVFilterPad[]) {
00276 { .name = NULL }
00277 },
00278
00279 .outputs = (const AVFilterPad[]) {
00280 {
00281 .name = "default",
00282 .type = AVMEDIA_TYPE_VIDEO,
00283 .request_frame = request_frame,
00284 .config_props = color_config_props,
00285 },
00286 { .name = NULL }
00287 },
00288
00289 .priv_class = &color_class,
00290 };
00291
00292 #endif
00293
00294 #if CONFIG_NULLSRC_FILTER
00295
00296 #define nullsrc_options options
00297 AVFILTER_DEFINE_CLASS(nullsrc);
00298
00299 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
00300
00301 static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
00302 {
00303 TestSourceContext *test = ctx->priv;
00304
00305 test->class = &nullsrc_class;
00306 test->fill_picture_fn = nullsrc_fill_picture;
00307 return init(ctx, args);
00308 }
00309
00310 AVFilter avfilter_vsrc_nullsrc = {
00311 .name = "nullsrc",
00312 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
00313 .init = nullsrc_init,
00314 .uninit = uninit,
00315 .priv_size = sizeof(TestSourceContext),
00316
00317 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
00318 .outputs = (const AVFilterPad[]) {{ .name = "default",
00319 .type = AVMEDIA_TYPE_VIDEO,
00320 .request_frame = request_frame,
00321 .config_props = config_props, },
00322 { .name = NULL}},
00323 .priv_class = &nullsrc_class,
00324 };
00325
00326 #endif
00327
00328 #if CONFIG_TESTSRC_FILTER
00329
00330 #define testsrc_options options
00331 AVFILTER_DEFINE_CLASS(testsrc);
00332
00345 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
00346 unsigned x, unsigned y, unsigned w, unsigned h)
00347 {
00348 int i;
00349 int step = 3;
00350
00351 dst += segment_width * (step * x + y * dst_linesize);
00352 w *= segment_width * step;
00353 h *= segment_width;
00354 for (i = 0; i < h; i++) {
00355 memset(dst, val, w);
00356 dst += dst_linesize;
00357 }
00358 }
00359
00360 static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
00361 unsigned segment_width)
00362 {
00363 #define TOP_HBAR 1
00364 #define MID_HBAR 2
00365 #define BOT_HBAR 4
00366 #define LEFT_TOP_VBAR 8
00367 #define LEFT_BOT_VBAR 16
00368 #define RIGHT_TOP_VBAR 32
00369 #define RIGHT_BOT_VBAR 64
00370 struct {
00371 int x, y, w, h;
00372 } segments[] = {
00373 { 1, 0, 5, 1 },
00374 { 1, 6, 5, 1 },
00375 { 1, 12, 5, 1 },
00376 { 0, 1, 1, 5 },
00377 { 0, 7, 1, 5 },
00378 { 6, 1, 1, 5 },
00379 { 6, 7, 1, 5 }
00380 };
00381 static const unsigned char masks[10] = {
00382 TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00383 RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00384 TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
00385 TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00386 MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00387 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
00388 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
00389 TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00390 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00391 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00392 };
00393 unsigned mask = masks[digit];
00394 int i;
00395
00396 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
00397 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
00398 if (mask & (1<<i))
00399 draw_rectangle(255, dst, dst_linesize, segment_width,
00400 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
00401 }
00402
00403 #define GRADIENT_SIZE (6 * 256)
00404
00405 static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00406 {
00407 TestSourceContext *test = ctx->priv;
00408 uint8_t *p, *p0;
00409 int x, y;
00410 int color, color_rest;
00411 int icolor;
00412 int radius;
00413 int quad0, quad;
00414 int dquad_x, dquad_y;
00415 int grad, dgrad, rgrad, drgrad;
00416 int seg_size;
00417 int second;
00418 int i;
00419 uint8_t *data = picref->data[0];
00420 int width = picref->video->w;
00421 int height = picref->video->h;
00422
00423
00424 radius = (width + height) / 4;
00425 quad0 = width * width / 4 + height * height / 4 - radius * radius;
00426 dquad_y = 1 - height;
00427 p0 = data;
00428 for (y = 0; y < height; y++) {
00429 p = p0;
00430 color = 0;
00431 color_rest = 0;
00432 quad = quad0;
00433 dquad_x = 1 - width;
00434 for (x = 0; x < width; x++) {
00435 icolor = color;
00436 if (quad < 0)
00437 icolor ^= 7;
00438 quad += dquad_x;
00439 dquad_x += 2;
00440 *(p++) = icolor & 1 ? 255 : 0;
00441 *(p++) = icolor & 2 ? 255 : 0;
00442 *(p++) = icolor & 4 ? 255 : 0;
00443 color_rest += 8;
00444 if (color_rest >= width) {
00445 color_rest -= width;
00446 color++;
00447 }
00448 }
00449 quad0 += dquad_y;
00450 dquad_y += 2;
00451 p0 += picref->linesize[0];
00452 }
00453
00454
00455 p0 = p = data + picref->linesize[0] * height * 3/4;
00456 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
00457 GRADIENT_SIZE;
00458 rgrad = 0;
00459 dgrad = GRADIENT_SIZE / width;
00460 drgrad = GRADIENT_SIZE % width;
00461 for (x = 0; x < width; x++) {
00462 *(p++) =
00463 grad < 256 || grad >= 5 * 256 ? 255 :
00464 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
00465 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
00466 *(p++) =
00467 grad >= 4 * 256 ? 0 :
00468 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
00469 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
00470 *(p++) =
00471 grad < 2 * 256 ? 0 :
00472 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
00473 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
00474 grad += dgrad;
00475 rgrad += drgrad;
00476 if (rgrad >= GRADIENT_SIZE) {
00477 grad++;
00478 rgrad -= GRADIENT_SIZE;
00479 }
00480 if (grad >= GRADIENT_SIZE)
00481 grad -= GRADIENT_SIZE;
00482 }
00483 p = p0;
00484 for (y = height / 8; y > 0; y--) {
00485 memcpy(p+picref->linesize[0], p, 3 * width);
00486 p += picref->linesize[0];
00487 }
00488
00489
00490 seg_size = width / 80;
00491 if (seg_size >= 1 && height >= 13 * seg_size) {
00492 double time = av_q2d(test->time_base) * test->nb_frame *
00493 pow(10, test->nb_decimals);
00494 if (time > INT_MAX)
00495 return;
00496 second = (int)time;
00497 x = width - (width - seg_size * 64) / 2;
00498 y = (height - seg_size * 13) / 2;
00499 p = data + (x*3 + y * picref->linesize[0]);
00500 for (i = 0; i < 8; i++) {
00501 p -= 3 * 8 * seg_size;
00502 draw_digit(second % 10, p, picref->linesize[0], seg_size);
00503 second /= 10;
00504 if (second == 0)
00505 break;
00506 }
00507 }
00508 }
00509
00510 static av_cold int test_init(AVFilterContext *ctx, const char *args)
00511 {
00512 TestSourceContext *test = ctx->priv;
00513
00514 test->class = &testsrc_class;
00515 test->fill_picture_fn = test_fill_picture;
00516 return init(ctx, args);
00517 }
00518
00519 static int test_query_formats(AVFilterContext *ctx)
00520 {
00521 static const enum PixelFormat pix_fmts[] = {
00522 PIX_FMT_RGB24, PIX_FMT_NONE
00523 };
00524 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
00525 return 0;
00526 }
00527
00528 AVFilter avfilter_vsrc_testsrc = {
00529 .name = "testsrc",
00530 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
00531 .priv_size = sizeof(TestSourceContext),
00532 .init = test_init,
00533 .uninit = uninit,
00534
00535 .query_formats = test_query_formats,
00536
00537 .inputs = NULL,
00538
00539 .outputs = (const AVFilterPad[]) {{ .name = "default",
00540 .type = AVMEDIA_TYPE_VIDEO,
00541 .request_frame = request_frame,
00542 .config_props = config_props, },
00543 { .name = NULL }},
00544 .priv_class = &testsrc_class,
00545 };
00546
00547 #endif
00548
00549 #if CONFIG_RGBTESTSRC_FILTER
00550
00551 #define rgbtestsrc_options options
00552 AVFILTER_DEFINE_CLASS(rgbtestsrc);
00553
00554 #define R 0
00555 #define G 1
00556 #define B 2
00557 #define A 3
00558
00559 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
00560 int x, int y, int r, int g, int b, enum PixelFormat fmt,
00561 uint8_t rgba_map[4])
00562 {
00563 int32_t v;
00564 uint8_t *p;
00565
00566 switch (fmt) {
00567 case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
00568 case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
00569 case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
00570 case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
00571 case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
00572 case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
00573 case PIX_FMT_RGB24:
00574 case PIX_FMT_BGR24:
00575 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
00576 p = dst + 3*x + y*dst_linesize;
00577 AV_WL24(p, v);
00578 break;
00579 case PIX_FMT_RGBA:
00580 case PIX_FMT_BGRA:
00581 case PIX_FMT_ARGB:
00582 case PIX_FMT_ABGR:
00583 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
00584 p = dst + 4*x + y*dst_linesize;
00585 AV_WL32(p, v);
00586 break;
00587 }
00588 }
00589
00590 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00591 {
00592 TestSourceContext *test = ctx->priv;
00593 int x, y, w = picref->video->w, h = picref->video->h;
00594
00595 for (y = 0; y < h; y++) {
00596 for (x = 0; x < picref->video->w; x++) {
00597 int c = 256*x/w;
00598 int r = 0, g = 0, b = 0;
00599
00600 if (3*y < h ) r = c;
00601 else if (3*y < 2*h) g = c;
00602 else b = c;
00603
00604 rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b,
00605 ctx->outputs[0]->format, test->rgba_map);
00606 }
00607 }
00608 }
00609
00610 static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
00611 {
00612 TestSourceContext *test = ctx->priv;
00613
00614 test->draw_once = 1;
00615 test->class = &rgbtestsrc_class;
00616 test->fill_picture_fn = rgbtest_fill_picture;
00617 return init(ctx, args);
00618 }
00619
00620 static int rgbtest_query_formats(AVFilterContext *ctx)
00621 {
00622 static const enum PixelFormat pix_fmts[] = {
00623 PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR,
00624 PIX_FMT_BGR24, PIX_FMT_RGB24,
00625 PIX_FMT_RGB444, PIX_FMT_BGR444,
00626 PIX_FMT_RGB565, PIX_FMT_BGR565,
00627 PIX_FMT_RGB555, PIX_FMT_BGR555,
00628 PIX_FMT_NONE
00629 };
00630 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
00631 return 0;
00632 }
00633
00634 static int rgbtest_config_props(AVFilterLink *outlink)
00635 {
00636 TestSourceContext *test = outlink->src->priv;
00637
00638 ff_fill_rgba_map(test->rgba_map, outlink->format);
00639 return config_props(outlink);
00640 }
00641
00642 AVFilter avfilter_vsrc_rgbtestsrc = {
00643 .name = "rgbtestsrc",
00644 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
00645 .priv_size = sizeof(TestSourceContext),
00646 .init = rgbtest_init,
00647 .uninit = uninit,
00648
00649 .query_formats = rgbtest_query_formats,
00650
00651 .inputs = NULL,
00652
00653 .outputs = (const AVFilterPad[]) {{ .name = "default",
00654 .type = AVMEDIA_TYPE_VIDEO,
00655 .request_frame = request_frame,
00656 .config_props = rgbtest_config_props, },
00657 { .name = NULL }},
00658 .priv_class = &rgbtestsrc_class,
00659 };
00660
00661 #endif
00662
00663 #if CONFIG_SMPTEBARS_FILTER
00664
00665 #define smptebars_options options
00666 AVFILTER_DEFINE_CLASS(smptebars);
00667
00668 static const uint8_t rainbow[7][4] = {
00669 { 191, 191, 191, 255 },
00670 { 191, 191, 0, 255 },
00671 { 0, 191, 191, 255 },
00672 { 0, 191, 0, 255 },
00673 { 191, 0, 191, 255 },
00674 { 191, 0, 0, 255 },
00675 { 0, 0, 191, 255 },
00676 };
00677
00678 static const uint8_t wobnair[7][4] = {
00679 { 0, 0, 191, 255 },
00680 { 19, 19, 19, 255 },
00681 { 191, 0, 191, 255 },
00682 { 19, 19, 19, 255 },
00683 { 0, 191, 191, 255 },
00684 { 19, 19, 19, 255 },
00685 { 191, 191, 191, 255 },
00686 };
00687
00688 static const uint8_t white[4] = { 255, 255, 255, 255 };
00689 static const uint8_t black[4] = { 19, 19, 19, 255 };
00690
00691
00692 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 };
00693 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 };
00694
00695
00696 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
00697 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
00698
00699 static void smptebars_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00700 {
00701 TestSourceContext *test = ctx->priv;
00702 FFDrawColor color;
00703 int r_w, r_h, w_h, p_w, p_h, i, x = 0;
00704
00705 r_w = (test->w + 6) / 7;
00706 r_h = test->h * 2 / 3;
00707 w_h = test->h * 3 / 4 - r_h;
00708 p_w = r_w * 5 / 4;
00709 p_h = test->h - w_h - r_h;
00710
00711 #define DRAW_COLOR(rgba, x, y, w, h) \
00712 ff_draw_color(&test->draw, &color, rgba); \
00713 ff_fill_rectangle(&test->draw, &color, \
00714 picref->data, picref->linesize, x, y, w, h) \
00715
00716 for (i = 0; i < 7; i++) {
00717 DRAW_COLOR(rainbow[i], x, 0, FFMIN(r_w, test->w - x), r_h);
00718 DRAW_COLOR(wobnair[i], x, r_h, FFMIN(r_w, test->w - x), w_h);
00719 x += r_w;
00720 }
00721 x = 0;
00722 DRAW_COLOR(i_pixel, x, r_h + w_h, p_w, p_h);
00723 x += p_w;
00724 DRAW_COLOR(white, x, r_h + w_h, p_w, p_h);
00725 x += p_w;
00726 DRAW_COLOR(q_pixel, x, r_h + w_h, p_w, p_h);
00727 x += p_w;
00728 DRAW_COLOR(black, x, r_h + w_h, 5 * r_w - x, p_h);
00729 x += 5 * r_w - x;
00730 DRAW_COLOR(neg4ire, x, r_h + w_h, r_w / 3, p_h);
00731 x += r_w / 3;
00732 DRAW_COLOR(black, x, r_h + w_h, r_w / 3, p_h);
00733 x += r_w / 3;
00734 DRAW_COLOR(pos4ire, x, r_h + w_h, r_w / 3, p_h);
00735 x += r_w / 3;
00736 DRAW_COLOR(black, x, r_h + w_h, test->w - x, p_h);
00737 }
00738
00739 static av_cold int smptebars_init(AVFilterContext *ctx, const char *args)
00740 {
00741 TestSourceContext *test = ctx->priv;
00742
00743 test->class = &smptebars_class;
00744 test->fill_picture_fn = smptebars_fill_picture;
00745 test->draw_once = 1;
00746 return init(ctx, args);
00747 }
00748
00749 static int smptebars_query_formats(AVFilterContext *ctx)
00750 {
00751 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
00752 return 0;
00753 }
00754
00755 static int smptebars_config_props(AVFilterLink *outlink)
00756 {
00757 AVFilterContext *ctx = outlink->src;
00758 TestSourceContext *test = ctx->priv;
00759
00760 ff_draw_init(&test->draw, outlink->format, 0);
00761
00762 return config_props(outlink);
00763 }
00764
00765 AVFilter avfilter_vsrc_smptebars = {
00766 .name = "smptebars",
00767 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
00768 .priv_size = sizeof(TestSourceContext),
00769 .init = smptebars_init,
00770 .uninit = uninit,
00771
00772 .query_formats = smptebars_query_formats,
00773
00774 .inputs = (const AVFilterPad[]) {
00775 { .name = NULL }
00776 },
00777
00778 .outputs = (const AVFilterPad[]) {
00779 {
00780 .name = "default",
00781 .type = AVMEDIA_TYPE_VIDEO,
00782 .request_frame = request_frame,
00783 .config_props = smptebars_config_props,
00784 },
00785 { .name = NULL }
00786 },
00787
00788 .priv_class = &smptebars_class,
00789 };
00790
00791 #endif