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
00174 if (test->duration >= 0 &&
00175 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
00176 return AVERROR_EOF;
00177
00178 if (test->draw_once) {
00179 if (!test->picref) {
00180 test->picref =
00181 ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_PRESERVE|AV_PERM_REUSE,
00182 test->w, test->h);
00183 if (!test->picref)
00184 return AVERROR(ENOMEM);
00185 test->fill_picture_fn(outlink->src, test->picref);
00186 }
00187 outpicref = avfilter_ref_buffer(test->picref, ~AV_PERM_WRITE);
00188 } else
00189 outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
00190
00191 if (!outpicref)
00192 return AVERROR(ENOMEM);
00193 outpicref->pts = test->pts;
00194 outpicref->pos = -1;
00195 outpicref->video->key_frame = 1;
00196 outpicref->video->interlaced = 0;
00197 outpicref->video->pict_type = AV_PICTURE_TYPE_I;
00198 outpicref->video->sample_aspect_ratio = test->sar;
00199 if (!test->draw_once)
00200 test->fill_picture_fn(outlink->src, outpicref);
00201
00202 test->pts++;
00203 test->nb_frame++;
00204
00205 return ff_filter_frame(outlink, outpicref);
00206 }
00207
00208 #if CONFIG_COLOR_FILTER
00209
00210 #define color_options options
00211 AVFILTER_DEFINE_CLASS(color);
00212
00213 static void color_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00214 {
00215 TestSourceContext *test = ctx->priv;
00216 ff_fill_rectangle(&test->draw, &test->color,
00217 picref->data, picref->linesize,
00218 0, 0, test->w, test->h);
00219 }
00220
00221 static av_cold int color_init(AVFilterContext *ctx, const char *args)
00222 {
00223 TestSourceContext *test = ctx->priv;
00224 test->class = &color_class;
00225 test->fill_picture_fn = color_fill_picture;
00226 test->draw_once = 1;
00227 av_opt_set(test, "color", "black", 0);
00228 return init(ctx, args);
00229 }
00230
00231 static int color_query_formats(AVFilterContext *ctx)
00232 {
00233 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
00234 return 0;
00235 }
00236
00237 static int color_config_props(AVFilterLink *inlink)
00238 {
00239 AVFilterContext *ctx = inlink->src;
00240 TestSourceContext *test = ctx->priv;
00241 int ret;
00242
00243 ff_draw_init(&test->draw, inlink->format, 0);
00244 ff_draw_color(&test->draw, &test->color, test->color_rgba);
00245
00246 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
00247 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
00248 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
00249 return AVERROR(EINVAL);
00250
00251 if (ret = config_props(inlink) < 0)
00252 return ret;
00253
00254 av_log(ctx, AV_LOG_VERBOSE, "color:0x%02x%02x%02x%02x\n",
00255 test->color_rgba[0], test->color_rgba[1], test->color_rgba[2], test->color_rgba[3]);
00256 return 0;
00257 }
00258
00259 static const AVFilterPad color_outputs[] = {
00260 {
00261 .name = "default",
00262 .type = AVMEDIA_TYPE_VIDEO,
00263 .request_frame = request_frame,
00264 .config_props = color_config_props,
00265 },
00266 { NULL }
00267 };
00268
00269 AVFilter avfilter_vsrc_color = {
00270 .name = "color",
00271 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
00272
00273 .priv_size = sizeof(TestSourceContext),
00274 .init = color_init,
00275 .uninit = uninit,
00276
00277 .query_formats = color_query_formats,
00278 .inputs = NULL,
00279 .outputs = color_outputs,
00280 .priv_class = &color_class,
00281 };
00282
00283 #endif
00284
00285 #if CONFIG_NULLSRC_FILTER
00286
00287 #define nullsrc_options options
00288 AVFILTER_DEFINE_CLASS(nullsrc);
00289
00290 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
00291
00292 static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
00293 {
00294 TestSourceContext *test = ctx->priv;
00295
00296 test->class = &nullsrc_class;
00297 test->fill_picture_fn = nullsrc_fill_picture;
00298 return init(ctx, args);
00299 }
00300
00301 static const AVFilterPad nullsrc_outputs[] = {
00302 {
00303 .name = "default",
00304 .type = AVMEDIA_TYPE_VIDEO,
00305 .request_frame = request_frame,
00306 .config_props = config_props,
00307 },
00308 { NULL },
00309 };
00310
00311 AVFilter avfilter_vsrc_nullsrc = {
00312 .name = "nullsrc",
00313 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
00314 .init = nullsrc_init,
00315 .uninit = uninit,
00316 .priv_size = sizeof(TestSourceContext),
00317 .inputs = NULL,
00318 .outputs = nullsrc_outputs,
00319 .priv_class = &nullsrc_class,
00320 };
00321
00322 #endif
00323
00324 #if CONFIG_TESTSRC_FILTER
00325
00326 #define testsrc_options options
00327 AVFILTER_DEFINE_CLASS(testsrc);
00328
00341 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
00342 unsigned x, unsigned y, unsigned w, unsigned h)
00343 {
00344 int i;
00345 int step = 3;
00346
00347 dst += segment_width * (step * x + y * dst_linesize);
00348 w *= segment_width * step;
00349 h *= segment_width;
00350 for (i = 0; i < h; i++) {
00351 memset(dst, val, w);
00352 dst += dst_linesize;
00353 }
00354 }
00355
00356 static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
00357 unsigned segment_width)
00358 {
00359 #define TOP_HBAR 1
00360 #define MID_HBAR 2
00361 #define BOT_HBAR 4
00362 #define LEFT_TOP_VBAR 8
00363 #define LEFT_BOT_VBAR 16
00364 #define RIGHT_TOP_VBAR 32
00365 #define RIGHT_BOT_VBAR 64
00366 struct {
00367 int x, y, w, h;
00368 } segments[] = {
00369 { 1, 0, 5, 1 },
00370 { 1, 6, 5, 1 },
00371 { 1, 12, 5, 1 },
00372 { 0, 1, 1, 5 },
00373 { 0, 7, 1, 5 },
00374 { 6, 1, 1, 5 },
00375 { 6, 7, 1, 5 }
00376 };
00377 static const unsigned char masks[10] = {
00378 TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00379 RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00380 TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
00381 TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00382 MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00383 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
00384 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
00385 TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00386 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00387 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
00388 };
00389 unsigned mask = masks[digit];
00390 int i;
00391
00392 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
00393 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
00394 if (mask & (1<<i))
00395 draw_rectangle(255, dst, dst_linesize, segment_width,
00396 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
00397 }
00398
00399 #define GRADIENT_SIZE (6 * 256)
00400
00401 static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00402 {
00403 TestSourceContext *test = ctx->priv;
00404 uint8_t *p, *p0;
00405 int x, y;
00406 int color, color_rest;
00407 int icolor;
00408 int radius;
00409 int quad0, quad;
00410 int dquad_x, dquad_y;
00411 int grad, dgrad, rgrad, drgrad;
00412 int seg_size;
00413 int second;
00414 int i;
00415 uint8_t *data = picref->data[0];
00416 int width = picref->video->w;
00417 int height = picref->video->h;
00418
00419
00420 radius = (width + height) / 4;
00421 quad0 = width * width / 4 + height * height / 4 - radius * radius;
00422 dquad_y = 1 - height;
00423 p0 = data;
00424 for (y = 0; y < height; y++) {
00425 p = p0;
00426 color = 0;
00427 color_rest = 0;
00428 quad = quad0;
00429 dquad_x = 1 - width;
00430 for (x = 0; x < width; x++) {
00431 icolor = color;
00432 if (quad < 0)
00433 icolor ^= 7;
00434 quad += dquad_x;
00435 dquad_x += 2;
00436 *(p++) = icolor & 1 ? 255 : 0;
00437 *(p++) = icolor & 2 ? 255 : 0;
00438 *(p++) = icolor & 4 ? 255 : 0;
00439 color_rest += 8;
00440 if (color_rest >= width) {
00441 color_rest -= width;
00442 color++;
00443 }
00444 }
00445 quad0 += dquad_y;
00446 dquad_y += 2;
00447 p0 += picref->linesize[0];
00448 }
00449
00450
00451 p0 = p = data + picref->linesize[0] * height * 3/4;
00452 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
00453 GRADIENT_SIZE;
00454 rgrad = 0;
00455 dgrad = GRADIENT_SIZE / width;
00456 drgrad = GRADIENT_SIZE % width;
00457 for (x = 0; x < width; x++) {
00458 *(p++) =
00459 grad < 256 || grad >= 5 * 256 ? 255 :
00460 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
00461 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
00462 *(p++) =
00463 grad >= 4 * 256 ? 0 :
00464 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
00465 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
00466 *(p++) =
00467 grad < 2 * 256 ? 0 :
00468 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
00469 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
00470 grad += dgrad;
00471 rgrad += drgrad;
00472 if (rgrad >= GRADIENT_SIZE) {
00473 grad++;
00474 rgrad -= GRADIENT_SIZE;
00475 }
00476 if (grad >= GRADIENT_SIZE)
00477 grad -= GRADIENT_SIZE;
00478 }
00479 p = p0;
00480 for (y = height / 8; y > 0; y--) {
00481 memcpy(p+picref->linesize[0], p, 3 * width);
00482 p += picref->linesize[0];
00483 }
00484
00485
00486 seg_size = width / 80;
00487 if (seg_size >= 1 && height >= 13 * seg_size) {
00488 double time = av_q2d(test->time_base) * test->nb_frame *
00489 pow(10, test->nb_decimals);
00490 if (time > INT_MAX)
00491 return;
00492 second = (int)time;
00493 x = width - (width - seg_size * 64) / 2;
00494 y = (height - seg_size * 13) / 2;
00495 p = data + (x*3 + y * picref->linesize[0]);
00496 for (i = 0; i < 8; i++) {
00497 p -= 3 * 8 * seg_size;
00498 draw_digit(second % 10, p, picref->linesize[0], seg_size);
00499 second /= 10;
00500 if (second == 0)
00501 break;
00502 }
00503 }
00504 }
00505
00506 static av_cold int test_init(AVFilterContext *ctx, const char *args)
00507 {
00508 TestSourceContext *test = ctx->priv;
00509
00510 test->class = &testsrc_class;
00511 test->fill_picture_fn = test_fill_picture;
00512 return init(ctx, args);
00513 }
00514
00515 static int test_query_formats(AVFilterContext *ctx)
00516 {
00517 static const enum AVPixelFormat pix_fmts[] = {
00518 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
00519 };
00520 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
00521 return 0;
00522 }
00523
00524 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
00525 {
00526 .name = "default",
00527 .type = AVMEDIA_TYPE_VIDEO,
00528 .request_frame = request_frame,
00529 .config_props = config_props,
00530 },
00531 { NULL }
00532 };
00533
00534 AVFilter avfilter_vsrc_testsrc = {
00535 .name = "testsrc",
00536 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
00537 .priv_size = sizeof(TestSourceContext),
00538 .init = test_init,
00539 .uninit = uninit,
00540
00541 .query_formats = test_query_formats,
00542
00543 .inputs = NULL,
00544 .outputs = avfilter_vsrc_testsrc_outputs,
00545 .priv_class = &testsrc_class,
00546 };
00547
00548 #endif
00549
00550 #if CONFIG_RGBTESTSRC_FILTER
00551
00552 #define rgbtestsrc_options options
00553 AVFILTER_DEFINE_CLASS(rgbtestsrc);
00554
00555 #define R 0
00556 #define G 1
00557 #define B 2
00558 #define A 3
00559
00560 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
00561 int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
00562 uint8_t rgba_map[4])
00563 {
00564 int32_t v;
00565 uint8_t *p;
00566
00567 switch (fmt) {
00568 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
00569 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
00570 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
00571 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
00572 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
00573 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
00574 case AV_PIX_FMT_RGB24:
00575 case AV_PIX_FMT_BGR24:
00576 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
00577 p = dst + 3*x + y*dst_linesize;
00578 AV_WL24(p, v);
00579 break;
00580 case AV_PIX_FMT_RGBA:
00581 case AV_PIX_FMT_BGRA:
00582 case AV_PIX_FMT_ARGB:
00583 case AV_PIX_FMT_ABGR:
00584 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
00585 p = dst + 4*x + y*dst_linesize;
00586 AV_WL32(p, v);
00587 break;
00588 }
00589 }
00590
00591 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00592 {
00593 TestSourceContext *test = ctx->priv;
00594 int x, y, w = picref->video->w, h = picref->video->h;
00595
00596 for (y = 0; y < h; y++) {
00597 for (x = 0; x < picref->video->w; x++) {
00598 int c = 256*x/w;
00599 int r = 0, g = 0, b = 0;
00600
00601 if (3*y < h ) r = c;
00602 else if (3*y < 2*h) g = c;
00603 else b = c;
00604
00605 rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b,
00606 ctx->outputs[0]->format, test->rgba_map);
00607 }
00608 }
00609 }
00610
00611 static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
00612 {
00613 TestSourceContext *test = ctx->priv;
00614
00615 test->draw_once = 1;
00616 test->class = &rgbtestsrc_class;
00617 test->fill_picture_fn = rgbtest_fill_picture;
00618 return init(ctx, args);
00619 }
00620
00621 static int rgbtest_query_formats(AVFilterContext *ctx)
00622 {
00623 static const enum AVPixelFormat pix_fmts[] = {
00624 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
00625 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
00626 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
00627 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
00628 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
00629 AV_PIX_FMT_NONE
00630 };
00631 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
00632 return 0;
00633 }
00634
00635 static int rgbtest_config_props(AVFilterLink *outlink)
00636 {
00637 TestSourceContext *test = outlink->src->priv;
00638
00639 ff_fill_rgba_map(test->rgba_map, outlink->format);
00640 return config_props(outlink);
00641 }
00642
00643 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
00644 {
00645 .name = "default",
00646 .type = AVMEDIA_TYPE_VIDEO,
00647 .request_frame = request_frame,
00648 .config_props = rgbtest_config_props,
00649 },
00650 { NULL }
00651 };
00652
00653 AVFilter avfilter_vsrc_rgbtestsrc = {
00654 .name = "rgbtestsrc",
00655 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
00656 .priv_size = sizeof(TestSourceContext),
00657 .init = rgbtest_init,
00658 .uninit = uninit,
00659
00660 .query_formats = rgbtest_query_formats,
00661
00662 .inputs = NULL,
00663
00664 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
00665 .priv_class = &rgbtestsrc_class,
00666 };
00667
00668 #endif
00669
00670 #if CONFIG_SMPTEBARS_FILTER
00671
00672 #define smptebars_options options
00673 AVFILTER_DEFINE_CLASS(smptebars);
00674
00675 static const uint8_t rainbow[7][4] = {
00676 { 191, 191, 191, 255 },
00677 { 191, 191, 0, 255 },
00678 { 0, 191, 191, 255 },
00679 { 0, 191, 0, 255 },
00680 { 191, 0, 191, 255 },
00681 { 191, 0, 0, 255 },
00682 { 0, 0, 191, 255 },
00683 };
00684
00685 static const uint8_t wobnair[7][4] = {
00686 { 0, 0, 191, 255 },
00687 { 19, 19, 19, 255 },
00688 { 191, 0, 191, 255 },
00689 { 19, 19, 19, 255 },
00690 { 0, 191, 191, 255 },
00691 { 19, 19, 19, 255 },
00692 { 191, 191, 191, 255 },
00693 };
00694
00695 static const uint8_t white[4] = { 255, 255, 255, 255 };
00696 static const uint8_t black[4] = { 19, 19, 19, 255 };
00697
00698
00699 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 };
00700 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 };
00701
00702
00703 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
00704 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
00705
00706 static void smptebars_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
00707 {
00708 TestSourceContext *test = ctx->priv;
00709 FFDrawColor color;
00710 int r_w, r_h, w_h, p_w, p_h, i, x = 0;
00711
00712 r_w = (test->w + 6) / 7;
00713 r_h = test->h * 2 / 3;
00714 w_h = test->h * 3 / 4 - r_h;
00715 p_w = r_w * 5 / 4;
00716 p_h = test->h - w_h - r_h;
00717
00718 #define DRAW_COLOR(rgba, x, y, w, h) \
00719 ff_draw_color(&test->draw, &color, rgba); \
00720 ff_fill_rectangle(&test->draw, &color, \
00721 picref->data, picref->linesize, x, y, w, h) \
00722
00723 for (i = 0; i < 7; i++) {
00724 DRAW_COLOR(rainbow[i], x, 0, FFMIN(r_w, test->w - x), r_h);
00725 DRAW_COLOR(wobnair[i], x, r_h, FFMIN(r_w, test->w - x), w_h);
00726 x += r_w;
00727 }
00728 x = 0;
00729 DRAW_COLOR(i_pixel, x, r_h + w_h, p_w, p_h);
00730 x += p_w;
00731 DRAW_COLOR(white, x, r_h + w_h, p_w, p_h);
00732 x += p_w;
00733 DRAW_COLOR(q_pixel, x, r_h + w_h, p_w, p_h);
00734 x += p_w;
00735 DRAW_COLOR(black, x, r_h + w_h, 5 * r_w - x, p_h);
00736 x += 5 * r_w - x;
00737 DRAW_COLOR(neg4ire, x, r_h + w_h, r_w / 3, p_h);
00738 x += r_w / 3;
00739 DRAW_COLOR(black, x, r_h + w_h, r_w / 3, p_h);
00740 x += r_w / 3;
00741 DRAW_COLOR(pos4ire, x, r_h + w_h, r_w / 3, p_h);
00742 x += r_w / 3;
00743 DRAW_COLOR(black, x, r_h + w_h, test->w - x, p_h);
00744 }
00745
00746 static av_cold int smptebars_init(AVFilterContext *ctx, const char *args)
00747 {
00748 TestSourceContext *test = ctx->priv;
00749
00750 test->class = &smptebars_class;
00751 test->fill_picture_fn = smptebars_fill_picture;
00752 test->draw_once = 1;
00753 return init(ctx, args);
00754 }
00755
00756 static int smptebars_query_formats(AVFilterContext *ctx)
00757 {
00758 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
00759 return 0;
00760 }
00761
00762 static int smptebars_config_props(AVFilterLink *outlink)
00763 {
00764 AVFilterContext *ctx = outlink->src;
00765 TestSourceContext *test = ctx->priv;
00766
00767 ff_draw_init(&test->draw, outlink->format, 0);
00768
00769 return config_props(outlink);
00770 }
00771
00772 static const AVFilterPad smptebars_outputs[] = {
00773 {
00774 .name = "default",
00775 .type = AVMEDIA_TYPE_VIDEO,
00776 .request_frame = request_frame,
00777 .config_props = smptebars_config_props,
00778 },
00779 { NULL }
00780 };
00781
00782 AVFilter avfilter_vsrc_smptebars = {
00783 .name = "smptebars",
00784 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
00785 .priv_size = sizeof(TestSourceContext),
00786 .init = smptebars_init,
00787 .uninit = uninit,
00788
00789 .query_formats = smptebars_query_formats,
00790 .inputs = NULL,
00791 .outputs = smptebars_outputs,
00792 .priv_class = &smptebars_class,
00793 };
00794
00795 #endif