62 #define OFFSET(x) offsetof(TestSourceContext, x)
63 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
88 frame_rate_q.
den <= 0 || frame_rate_q.
num <= 0) {
100 test->
max_pts = duration >= 0 ?
106 test->
w, test->
h, frame_rate_q.
num, frame_rate_q.
den,
116 outlink->
w = test->
w;
117 outlink->
h = test->
h;
146 #if CONFIG_TESTSRC_FILTER
148 static const char *testsrc_get_name(
void *ctx)
153 static const AVClass testsrc_class = {
155 .item_name = testsrc_get_name,
171 static void draw_rectangle(
unsigned val,
uint8_t *dst,
int dst_linesize,
unsigned segment_width,
172 unsigned x,
unsigned y,
unsigned w,
unsigned h)
177 dst += segment_width * (step * x + y * dst_linesize);
178 w *= segment_width *
step;
180 for (i = 0; i < h; i++) {
186 static void draw_digit(
int digit,
uint8_t *dst,
unsigned dst_linesize,
187 unsigned segment_width)
192 #define LEFT_TOP_VBAR 8
193 #define LEFT_BOT_VBAR 16
194 #define RIGHT_TOP_VBAR 32
195 #define RIGHT_BOT_VBAR 64
207 static const unsigned char masks[10] = {
208 TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
209 RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
210 TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
211 TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
212 MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
213 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
214 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
215 TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
216 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
217 TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
219 unsigned mask = masks[digit];
222 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
225 draw_rectangle(255, dst, dst_linesize, segment_width,
226 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
229 #define GRADIENT_SIZE (6 * 256)
236 int color, color_rest;
240 int dquad_x, dquad_y;
241 int grad, dgrad, rgrad, drgrad;
250 radius = (width +
height) / 4;
251 quad0 = width * width / 4 + height * height / 4 - radius * radius;
254 for (y = 0; y <
height; y++) {
260 for (x = 0; x <
width; x++) {
266 *(p++) = icolor & 1 ? 255 : 0;
267 *(p++) = icolor & 2 ? 255 : 0;
268 *(p++) = icolor & 4 ? 255 : 0;
270 if (color_rest >= width) {
281 p = data + frame->
linesize[0] * height * 3/4;
285 dgrad = GRADIENT_SIZE /
width;
286 drgrad = GRADIENT_SIZE %
width;
287 for (x = 0; x <
width; x++) {
289 grad < 256 || grad >= 5 * 256 ? 255 :
290 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
291 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
293 grad >= 4 * 256 ? 0 :
294 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
295 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
298 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
299 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
302 if (rgrad >= GRADIENT_SIZE) {
304 rgrad -= GRADIENT_SIZE;
306 if (grad >= GRADIENT_SIZE)
307 grad -= GRADIENT_SIZE;
309 for (y = height / 8; y > 0; y--) {
310 memcpy(p, p - frame->
linesize[0], 3 * width);
315 seg_size = width / 80;
316 if (seg_size >= 1 && height >= 13 * seg_size) {
318 x = width - (width - seg_size * 64) / 2;
319 y = (height - seg_size * 13) / 2;
320 p = data + (x*3 + y * frame->
linesize[0]);
321 for (i = 0; i < 8; i++) {
322 p -= 3 * 8 * seg_size;
323 draw_digit(second % 10, p, frame->
linesize[0], seg_size);
348 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
362 .priv_class = &testsrc_class,
369 .
outputs = avfilter_vsrc_testsrc_outputs,
374 #if CONFIG_RGBTESTSRC_FILTER
376 static const char *rgbtestsrc_get_name(
void *ctx)
381 static const AVClass rgbtestsrc_class = {
383 .item_name = rgbtestsrc_get_name,
392 static void rgbtest_put_pixel(
uint8_t *dst,
int dst_linesize,
400 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
break;
401 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4);
break;
402 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
break;
403 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
break;
404 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
break;
405 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
break;
408 v = (r << (rgba_map[
R]*8)) + (g << (rgba_map[
G]*8)) + (b << (rgba_map[
B]*8));
409 p = dst + 3*x + y*dst_linesize;
416 v = (r << (rgba_map[
R]*8)) + (g << (rgba_map[
G]*8)) + (b << (rgba_map[
B]*8));
417 p = dst + 4*x + y*dst_linesize;
428 for (y = 0; y < h; y++) {
429 for (x = 0; x < w; x++) {
431 int r = 0, g = 0, b = 0;
434 else if (3*y < 2*h) g = c;
437 rgbtest_put_pixel(frame->
data[0], frame->
linesize[0], x, y, r, g, b,
469 switch (outlink->
format) {
481 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
486 .config_props = rgbtest_config_props,
492 .
name =
"rgbtestsrc",
495 .priv_class = &rgbtestsrc_class,
496 .
init = rgbtest_init,
502 .
outputs = avfilter_vsrc_rgbtestsrc_outputs,