2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 /* non-GST-specific stuff */
26 #include "gstvideotestsrc.h"
27 #include "videotestsrc.h"
28 #include "gstvideotestsrcorc.h"
30 #include <gst/math-compat.h>
35 #define TO_16(x) (((x)<<8) | (x))
40 static unsigned int state;
44 return (state >> 16) & 0xff;
63 static const struct vts_color_struct vts_colors_bt709_ycbcr_100[] = {
64 {235, 128, 128, 255, 255, 255, 255, (235 << 8)},
65 {219, 16, 138, 255, 255, 255, 0, (219 << 8)},
66 {188, 154, 16, 255, 0, 255, 255, (188 < 8)},
67 {173, 42, 26, 255, 0, 255, 0, (173 << 8)},
68 {78, 214, 230, 255, 255, 0, 255, (78 << 8)},
69 {63, 102, 240, 255, 255, 0, 0, (64 << 8)},
70 {32, 240, 118, 255, 0, 0, 255, (32 << 8)},
71 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
72 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
73 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
74 {0, 128, 128, 255, 0, 0, 0, 0},
75 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
78 static const struct vts_color_struct vts_colors_bt709_ycbcr_75[] = {
79 {180, 128, 128, 255, 191, 191, 191, (180 << 8)},
80 {168, 44, 136, 255, 191, 191, 0, (168 << 8)},
81 {145, 147, 44, 255, 0, 191, 191, (145 << 8)},
82 {133, 63, 52, 255, 0, 191, 0, (133 << 8)},
83 {63, 193, 204, 255, 191, 0, 191, (63 << 8)},
84 {51, 109, 212, 255, 191, 0, 0, (51 << 8)},
85 {28, 212, 120, 255, 0, 0, 191, (28 << 8)},
86 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
87 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
88 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
89 {0, 128, 128, 255, 0, 0, 0, 0},
90 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
93 static const struct vts_color_struct vts_colors_bt601_ycbcr_100[] = {
94 {235, 128, 128, 255, 255, 255, 255, (235 << 8)},
95 {210, 16, 146, 255, 255, 255, 0, (219 << 8)},
96 {170, 166, 16, 255, 0, 255, 255, (188 < 8)},
97 {145, 54, 34, 255, 0, 255, 0, (173 << 8)},
98 {106, 202, 222, 255, 255, 0, 255, (78 << 8)},
99 {81, 90, 240, 255, 255, 0, 0, (64 << 8)},
100 {41, 240, 110, 255, 0, 0, 255, (32 << 8)},
101 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
102 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
103 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
104 {-0, 128, 128, 255, 0, 0, 0, 0},
105 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
108 static const struct vts_color_struct vts_colors_bt601_ycbcr_75[] = {
109 {180, 128, 128, 255, 191, 191, 191, (180 << 8)},
110 {162, 44, 142, 255, 191, 191, 0, (168 << 8)},
111 {131, 156, 44, 255, 0, 191, 191, (145 << 8)},
112 {112, 72, 58, 255, 0, 191, 0, (133 << 8)},
113 {84, 184, 198, 255, 191, 0, 191, (63 << 8)},
114 {65, 100, 212, 255, 191, 0, 0, (51 << 8)},
115 {35, 212, 114, 255, 0, 0, 191, (28 << 8)},
116 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
117 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
118 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
119 {-0, 128, 128, 255, 0, 0, 0, 0},
120 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
124 static void paint_tmpline_ARGB (paintinfo * p, int x, int w);
125 static void paint_tmpline_AYUV (paintinfo * p, int x, int w);
127 static void convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y);
128 static void convert_hline_bayer (paintinfo * p, GstVideoFrame * frame, int y);
131 #define ONE_HALF (1 << (SCALEBITS - 1))
132 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
134 #define RGB_TO_Y(r, g, b) \
135 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
136 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
138 #define RGB_TO_U(r1, g1, b1, shift)\
139 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
140 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
142 #define RGB_TO_V(r1, g1, b1, shift)\
143 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
144 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
146 #define RGB_TO_Y_CCIR(r, g, b) \
147 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
148 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
150 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\
151 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
152 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
154 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\
155 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
156 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
158 #define RGB_TO_Y_CCIR_709(r, g, b) \
159 ((FIX(0.212600*219.0/255.0) * (r) + FIX(0.715200*219.0/255.0) * (g) + \
160 FIX(0.072200*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
162 #define RGB_TO_U_CCIR_709(r1, g1, b1, shift)\
163 (((- FIX(0.114572*224.0/255.0) * r1 - FIX(0.385427*224.0/255.0) * g1 + \
164 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
166 #define RGB_TO_V_CCIR_709(r1, g1, b1, shift)\
167 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.454153*224.0/255.0) * g1 - \
168 FIX(0.045847*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
171 videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h)
175 GstVideoInfo *info = &v->info;
177 width = GST_VIDEO_INFO_WIDTH (info);
179 if (info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
180 p->colors = vts_colors_bt601_ycbcr_100;
182 p->colors = vts_colors_bt709_ycbcr_100;
186 p->paint_tmpline = paint_tmpline_ARGB;
187 p->convert_tmpline = convert_hline_bayer;
189 p->convert_tmpline = convert_hline_generic;
190 if (GST_VIDEO_INFO_IS_RGB (info)) {
191 p->paint_tmpline = paint_tmpline_ARGB;
193 p->paint_tmpline = paint_tmpline_AYUV;
196 p->tmpline = v->tmpline;
197 p->tmpline2 = v->tmpline2;
198 p->tmpline_u8 = v->tmpline_u8;
199 p->tmpline_u16 = v->tmpline_u16;
200 p->x_offset = (v->horizontal_speed * v->n_frames) % width;
202 p->x_offset += width;
203 p->x_invert = v->x_invert;
204 p->y_invert = v->y_invert;
206 a = (v->foreground_color >> 24) & 0xff;
207 r = (v->foreground_color >> 16) & 0xff;
208 g = (v->foreground_color >> 8) & 0xff;
209 b = (v->foreground_color >> 0) & 0xff;
210 p->foreground_color.A = a;
211 p->foreground_color.R = r;
212 p->foreground_color.G = g;
213 p->foreground_color.B = b;
215 if (info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
216 p->foreground_color.Y = RGB_TO_Y_CCIR (r, g, b);
217 p->foreground_color.U = RGB_TO_U_CCIR (r, g, b, 0);
218 p->foreground_color.V = RGB_TO_V_CCIR (r, g, b, 0);
220 p->foreground_color.Y = RGB_TO_Y_CCIR_709 (r, g, b);
221 p->foreground_color.U = RGB_TO_U_CCIR_709 (r, g, b, 0);
222 p->foreground_color.V = RGB_TO_V_CCIR_709 (r, g, b, 0);
224 p->foreground_color.gray = RGB_TO_Y (r, g, b);
226 a = (v->background_color >> 24) & 0xff;
227 r = (v->background_color >> 16) & 0xff;
228 g = (v->background_color >> 8) & 0xff;
229 b = (v->background_color >> 0) & 0xff;
230 p->background_color.A = a;
231 p->background_color.R = r;
232 p->background_color.G = g;
233 p->background_color.B = b;
235 if (info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
236 p->background_color.Y = RGB_TO_Y_CCIR (r, g, b);
237 p->background_color.U = RGB_TO_U_CCIR (r, g, b, 0);
238 p->background_color.V = RGB_TO_V_CCIR (r, g, b, 0);
240 p->background_color.Y = RGB_TO_Y_CCIR_709 (r, g, b);
241 p->background_color.U = RGB_TO_U_CCIR_709 (r, g, b, 0);
242 p->background_color.V = RGB_TO_V_CCIR_709 (r, g, b, 0);
244 p->background_color.gray = RGB_TO_Y (r, g, b);
249 videotestsrc_convert_tmpline (paintinfo * p, GstVideoFrame * frame, int j)
253 int width = frame->info.width;
256 memcpy (p->tmpline2, p->tmpline, width * 4);
257 memcpy (p->tmpline, p->tmpline2 + x * 4, (width - x) * 4);
258 memcpy (p->tmpline + (width - x) * 4, p->tmpline2, x * 4);
261 for (i = width; i < width + 5; i++) {
262 p->tmpline[4 * i + 0] = p->tmpline[4 * (width - 1) + 0];
263 p->tmpline[4 * i + 1] = p->tmpline[4 * (width - 1) + 1];
264 p->tmpline[4 * i + 2] = p->tmpline[4 * (width - 1) + 2];
265 p->tmpline[4 * i + 3] = p->tmpline[4 * (width - 1) + 3];
268 p->convert_tmpline (p, frame, j);
271 #define BLEND1(a,b,x) ((a)*(x) + (b)*(255-(x)))
272 #define DIV255(x) (((x) + (((x)+128)>>8) + 128)>>8)
273 #define BLEND(a,b,x) DIV255(BLEND1(a,b,x))
277 videotestsrc_blend_color (struct vts_color_struct *dest,
278 struct vts_color_struct *a, struct vts_color_struct *b, int x)
280 dest->Y = BLEND (a->Y, b->Y, x);
281 dest->U = BLEND (a->U, b->U, x);
282 dest->V = BLEND (a->V, b->V, x);
283 dest->R = BLEND (a->R, b->R, x);
284 dest->G = BLEND (a->G, b->G, x);
285 dest->B = BLEND (a->B, b->B, x);
286 dest->gray = BLEND (a->gray, b->gray, x);
292 videotestsrc_blend_line (GstVideoTestSrc * v, guint8 * dest, guint8 * src,
293 struct vts_color_struct *a, struct vts_color_struct *b, int n)
296 if (v->bayer || GST_VIDEO_INFO_IS_RGB (&v->info)) {
297 for (i = 0; i < n; i++) {
298 dest[i * 4 + 0] = BLEND (a->A, b->A, src[i]);
299 dest[i * 4 + 1] = BLEND (a->R, b->R, src[i]);
300 dest[i * 4 + 2] = BLEND (a->G, b->G, src[i]);
301 dest[i * 4 + 3] = BLEND (a->B, b->B, src[i]);
304 for (i = 0; i < n; i++) {
305 dest[i * 4 + 0] = BLEND (a->A, b->A, src[i]);
306 dest[i * 4 + 1] = BLEND (a->Y, b->Y, src[i]);
307 dest[i * 4 + 2] = BLEND (a->U, b->U, src[i]);
308 dest[i * 4 + 3] = BLEND (a->V, b->V, src[i]);
315 gst_video_test_src_smpte (GstVideoTestSrc * v, GstVideoFrame * frame)
320 paintinfo pi = PAINT_INFO_INIT;
322 int w = frame->info.width, h = frame->info.height;
324 videotestsrc_setup_paintinfo (v, p, w, h);
330 for (j = 0; j < y1; j++) {
331 for (i = 0; i < 7; i++) {
333 int x2 = (i + 1) * w / 7;
335 p->color = p->colors + i;
336 p->paint_tmpline (p, x1, (x2 - x1));
338 videotestsrc_convert_tmpline (p, frame, j);
341 /* inverse blue bars */
342 for (j = y1; j < y2; j++) {
343 for (i = 0; i < 7; i++) {
345 int x2 = (i + 1) * w / 7;
353 p->color = p->colors + k;
354 p->paint_tmpline (p, x1, (x2 - x1));
356 videotestsrc_convert_tmpline (p, frame, j);
359 for (j = y2; j < h; j++) {
360 /* -I, white, Q regions */
361 for (i = 0; i < 3; i++) {
363 int x2 = (i + 1) * w / 6;
373 p->color = p->colors + k;
374 p->paint_tmpline (p, x1, (x2 - x1));
377 /* superblack, black, dark grey */
378 for (i = 0; i < 3; i++) {
379 int x1 = w / 2 + i * w / 12;
380 int x2 = w / 2 + (i + 1) * w / 12;
384 k = COLOR_SUPER_BLACK;
390 p->color = p->colors + k;
391 p->paint_tmpline (p, x1, (x2 - x1));
396 struct vts_color_struct color;
398 color = p->colors[COLOR_BLACK];
401 for (i = x1; i < w; i++) {
402 int y = random_char ();
403 p->tmpline_u8[i] = y;
405 videotestsrc_blend_line (v, p->tmpline + x1 * 4, p->tmpline_u8 + x1,
406 &p->foreground_color, &p->background_color, w - x1);
409 videotestsrc_convert_tmpline (p, frame, j);
415 gst_video_test_src_smpte75 (GstVideoTestSrc * v, GstVideoFrame * frame)
419 paintinfo pi = PAINT_INFO_INIT;
421 int w = frame->info.width, h = frame->info.height;
423 videotestsrc_setup_paintinfo (v, p, w, h);
424 if (v->info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
425 p->colors = vts_colors_bt601_ycbcr_75;
427 p->colors = vts_colors_bt709_ycbcr_75;
431 for (j = 0; j < h; j++) {
432 for (i = 0; i < 7; i++) {
434 int x2 = (i + 1) * w / 7;
436 p->color = p->colors + i;
437 p->paint_tmpline (p, x1, (x2 - x1));
439 videotestsrc_convert_tmpline (p, frame, j);
444 gst_video_test_src_smpte100 (GstVideoTestSrc * v, GstVideoFrame * frame)
448 paintinfo pi = PAINT_INFO_INIT;
450 int w = frame->info.width, h = frame->info.height;
452 videotestsrc_setup_paintinfo (v, p, w, h);
455 for (j = 0; j < h; j++) {
456 for (i = 0; i < 7; i++) {
458 int x2 = (i + 1) * w / 7;
460 p->color = p->colors + i;
461 p->paint_tmpline (p, x1, (x2 - x1));
463 videotestsrc_convert_tmpline (p, frame, j);
468 gst_video_test_src_bar (GstVideoTestSrc * v, GstVideoFrame * frame)
471 paintinfo pi = PAINT_INFO_INIT;
473 int w = frame->info.width, h = frame->info.height;
475 videotestsrc_setup_paintinfo (v, p, w, h);
477 for (j = 0; j < h; j++) {
478 /* use fixed size for now */
481 p->color = &p->foreground_color;
482 p->paint_tmpline (p, 0, x2);
483 p->color = &p->background_color;
484 p->paint_tmpline (p, x2, (w - x2));
485 videotestsrc_convert_tmpline (p, frame, j);
490 gst_video_test_src_snow (GstVideoTestSrc * v, GstVideoFrame * frame)
494 paintinfo pi = PAINT_INFO_INIT;
496 struct vts_color_struct color;
497 int w = frame->info.width, h = frame->info.height;
499 videotestsrc_setup_paintinfo (v, p, w, h);
501 color = p->colors[COLOR_BLACK];
504 for (j = 0; j < h; j++) {
505 for (i = 0; i < w; i++) {
506 int y = random_char ();
507 p->tmpline_u8[i] = y;
509 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
510 &p->foreground_color, &p->background_color, w);
511 videotestsrc_convert_tmpline (p, frame, j);
516 gst_video_test_src_unicolor (GstVideoTestSrc * v, GstVideoFrame * frame,
520 paintinfo pi = PAINT_INFO_INIT;
522 int w = frame->info.width, h = frame->info.height;
524 videotestsrc_setup_paintinfo (v, p, w, h);
526 p->color = p->colors + color_index;
527 if (color_index == COLOR_BLACK) {
528 p->color = &p->background_color;
530 if (color_index == COLOR_WHITE) {
531 p->color = &p->foreground_color;
534 for (i = 0; i < h; i++) {
535 p->paint_tmpline (p, 0, w);
536 videotestsrc_convert_tmpline (p, frame, i);
541 gst_video_test_src_black (GstVideoTestSrc * v, GstVideoFrame * frame)
543 gst_video_test_src_unicolor (v, frame, COLOR_BLACK);
547 gst_video_test_src_white (GstVideoTestSrc * v, GstVideoFrame * frame)
549 gst_video_test_src_unicolor (v, frame, COLOR_WHITE);
553 gst_video_test_src_red (GstVideoTestSrc * v, GstVideoFrame * frame)
555 gst_video_test_src_unicolor (v, frame, COLOR_RED);
559 gst_video_test_src_green (GstVideoTestSrc * v, GstVideoFrame * frame)
561 gst_video_test_src_unicolor (v, frame, COLOR_GREEN);
565 gst_video_test_src_blue (GstVideoTestSrc * v, GstVideoFrame * frame)
567 gst_video_test_src_unicolor (v, frame, COLOR_BLUE);
571 gst_video_test_src_blink (GstVideoTestSrc * v, GstVideoFrame * frame)
574 paintinfo pi = PAINT_INFO_INIT;
576 int w = frame->info.width, h = frame->info.height;
578 videotestsrc_setup_paintinfo (v, p, w, h);
580 if (v->n_frames & 1) {
581 p->color = &p->foreground_color;
583 p->color = &p->background_color;
586 for (i = 0; i < h; i++) {
587 p->paint_tmpline (p, 0, w);
588 videotestsrc_convert_tmpline (p, frame, i);
593 gst_video_test_src_solid (GstVideoTestSrc * v, GstVideoFrame * frame)
596 paintinfo pi = PAINT_INFO_INIT;
598 int w = frame->info.width, h = frame->info.height;
600 videotestsrc_setup_paintinfo (v, p, w, h);
602 p->color = &p->foreground_color;
604 for (i = 0; i < h; i++) {
605 p->paint_tmpline (p, 0, w);
606 videotestsrc_convert_tmpline (p, frame, i);
611 gst_video_test_src_checkers1 (GstVideoTestSrc * v, GstVideoFrame * frame)
614 paintinfo pi = PAINT_INFO_INIT;
616 int w = frame->info.width, h = frame->info.height;
618 videotestsrc_setup_paintinfo (v, p, w, h);
620 for (y = 0; y < h; y++) {
621 for (x = 0; x < w; x++) {
623 p->color = p->colors + COLOR_GREEN;
625 p->color = p->colors + COLOR_RED;
627 p->paint_tmpline (p, x, 1);
629 videotestsrc_convert_tmpline (p, frame, y);
634 gst_video_test_src_checkers2 (GstVideoTestSrc * v, GstVideoFrame * frame)
637 paintinfo pi = PAINT_INFO_INIT;
639 int w = frame->info.width, h = frame->info.height;
641 videotestsrc_setup_paintinfo (v, p, w, h);
643 for (y = 0; y < h; y++) {
644 for (x = 0; x < w; x += 2) {
645 guint len = MIN (2, w - x);
648 p->color = p->colors + COLOR_GREEN;
650 p->color = p->colors + COLOR_RED;
652 p->paint_tmpline (p, x, len);
654 videotestsrc_convert_tmpline (p, frame, y);
659 gst_video_test_src_checkers4 (GstVideoTestSrc * v, GstVideoFrame * frame)
662 paintinfo pi = PAINT_INFO_INIT;
664 int w = frame->info.width, h = frame->info.height;
666 videotestsrc_setup_paintinfo (v, p, w, h);
668 for (y = 0; y < h; y++) {
669 for (x = 0; x < w; x += 4) {
670 guint len = MIN (4, w - x);
673 p->color = p->colors + COLOR_GREEN;
675 p->color = p->colors + COLOR_RED;
677 p->paint_tmpline (p, x, len);
679 videotestsrc_convert_tmpline (p, frame, y);
684 gst_video_test_src_checkers8 (GstVideoTestSrc * v, GstVideoFrame * frame)
687 paintinfo pi = PAINT_INFO_INIT;
689 int w = frame->info.width, h = frame->info.height;
691 videotestsrc_setup_paintinfo (v, p, w, h);
693 for (y = 0; y < h; y++) {
694 for (x = 0; x < w; x += 8) {
695 guint len = MIN (8, w - x);
698 p->color = p->colors + COLOR_GREEN;
700 p->color = p->colors + COLOR_RED;
702 p->paint_tmpline (p, x, len);
704 videotestsrc_convert_tmpline (p, frame, y);
708 static const guint8 sine_table[256] = {
709 128, 131, 134, 137, 140, 143, 146, 149,
710 152, 156, 159, 162, 165, 168, 171, 174,
711 176, 179, 182, 185, 188, 191, 193, 196,
712 199, 201, 204, 206, 209, 211, 213, 216,
713 218, 220, 222, 224, 226, 228, 230, 232,
714 234, 236, 237, 239, 240, 242, 243, 245,
715 246, 247, 248, 249, 250, 251, 252, 252,
716 253, 254, 254, 255, 255, 255, 255, 255,
717 255, 255, 255, 255, 255, 255, 254, 254,
718 253, 252, 252, 251, 250, 249, 248, 247,
719 246, 245, 243, 242, 240, 239, 237, 236,
720 234, 232, 230, 228, 226, 224, 222, 220,
721 218, 216, 213, 211, 209, 206, 204, 201,
722 199, 196, 193, 191, 188, 185, 182, 179,
723 176, 174, 171, 168, 165, 162, 159, 156,
724 152, 149, 146, 143, 140, 137, 134, 131,
725 128, 124, 121, 118, 115, 112, 109, 106,
726 103, 99, 96, 93, 90, 87, 84, 81,
727 79, 76, 73, 70, 67, 64, 62, 59,
728 56, 54, 51, 49, 46, 44, 42, 39,
729 37, 35, 33, 31, 29, 27, 25, 23,
730 21, 19, 18, 16, 15, 13, 12, 10,
731 9, 8, 7, 6, 5, 4, 3, 3,
732 2, 1, 1, 0, 0, 0, 0, 0,
733 0, 0, 0, 0, 0, 0, 1, 1,
734 2, 3, 3, 4, 5, 6, 7, 8,
735 9, 10, 12, 13, 15, 16, 18, 19,
736 21, 23, 25, 27, 29, 31, 33, 35,
737 37, 39, 42, 44, 46, 49, 51, 54,
738 56, 59, 62, 64, 67, 70, 73, 76,
739 79, 81, 84, 87, 90, 93, 96, 99,
740 103, 106, 109, 112, 115, 118, 121, 124
745 gst_video_test_src_zoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
749 paintinfo pi = PAINT_INFO_INIT;
751 struct vts_color_struct color;
753 int w = frame->info.width, h = frame->info.height;
754 int xreset = -(w / 2) - v->xoffset; /* starting values for x^2 and y^2, centering the ellipse */
755 int yreset = -(h / 2) - v->yoffset;
766 int delta_kxt = v->kxt * t;
768 int scale_kxy = 0xffff / (w / 2);
769 int scale_kx2 = 0xffff / w;
771 videotestsrc_setup_paintinfo (v, p, w, h);
773 color = p->colors[COLOR_BLACK];
776 /* Zoneplate equation:
778 * phase = k0 + kx*x + ky*y + kt*t
779 * + kxt*x*t + kyt*y*t + kxy*x*y
780 * + kx2*x*x + ky2*y*y + Kt2*t*t
784 for (j = 0, y = yreset; j < h; j++, y++) {
785 for (i = 0, x = xreset; i < w; i++, x++) {
791 phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t);
794 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
795 /* phase = phase + (v->kxy * x * y) / (w/2); */
798 /*normalise x/y terms to rate of change of phase at the picture edge */
800 phase + ((v->kx2 * x * x) / w) + ((v->ky2 * y * y) / h) +
801 ((v->kt2 * t * t) >> 1);
803 color.Y = sine_table[phase & 0xff];
808 p->paint_tmpline (p, i, 1);
813 /* optimised version, with original code shown in comments */
817 kt2 = v->kt2 * t * t;
818 for (j = 0, y = yreset; j < h; j++, y++) {
822 accum_kyt += v->kyt * t;
823 delta_kxy = v->kxy * y * scale_kxy;
824 accum_kxy = delta_kxy * xreset;
825 ky2 = (v->ky2 * y * y) / h;
826 for (i = 0, x = xreset; i < w; i++, x++) {
833 /* phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t); */
834 phase = phase + accum_kx + accum_ky + kt;
837 accum_kxt += delta_kxt;
838 accum_kxy += delta_kxy;
839 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
840 phase = phase + accum_kxt + accum_kyt;
842 /* phase = phase + (v->kxy * x * y) / (w/2); */
843 /* phase = phase + accum_kxy / (w/2); */
844 phase = phase + (accum_kxy >> 16);
847 /*normalise x/y terms to rate of change of phase at the picture edge */
848 /*phase = phase + ((v->kx2 * x * x)/w) + ((v->ky2 * y * y)/h) + ((v->kt2 * t * t)>>1); */
849 phase = phase + ((v->kx2 * x * x * scale_kx2) >> 16) + ky2 + (kt2 >> 1);
851 p->tmpline_u8[i] = sine_table[phase & 0xff];
853 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
854 &p->foreground_color, &p->background_color, w);
855 videotestsrc_convert_tmpline (p, frame, j);
860 gst_video_test_src_chromazoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
864 paintinfo pi = PAINT_INFO_INIT;
866 struct vts_color_struct color;
868 int w = frame->info.width, h = frame->info.height;
870 int xreset = -(w / 2) - v->xoffset; /* starting values for x^2 and y^2, centering the ellipse */
871 int yreset = -(h / 2) - v->yoffset;
882 int delta_kxt = v->kxt * t;
884 int scale_kxy = 0xffff / (w / 2);
885 int scale_kx2 = 0xffff / w;
887 videotestsrc_setup_paintinfo (v, p, w, h);
889 color = p->colors[COLOR_BLACK];
892 /* Zoneplate equation:
894 * phase = k0 + kx*x + ky*y + kt*t
895 * + kxt*x*t + kyt*y*t + kxy*x*y
896 * + kx2*x*x + ky2*y*y + Kt2*t*t
899 /* optimised version, with original code shown in comments */
903 kt2 = v->kt2 * t * t;
904 for (j = 0, y = yreset; j < h; j++, y++) {
908 accum_kyt += v->kyt * t;
909 delta_kxy = v->kxy * y * scale_kxy;
910 accum_kxy = delta_kxy * xreset;
911 ky2 = (v->ky2 * y * y) / h;
912 for (i = 0, x = xreset; i < w; i++, x++) {
919 /* phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t); */
920 phase = phase + accum_kx + accum_ky + kt;
923 accum_kxt += delta_kxt;
924 accum_kxy += delta_kxy;
925 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
926 phase = phase + accum_kxt + accum_kyt;
928 /* phase = phase + (v->kxy * x * y) / (w/2); */
929 /* phase = phase + accum_kxy / (w/2); */
930 phase = phase + (accum_kxy >> 16);
933 /*normalise x/y terms to rate of change of phase at the picture edge */
934 /*phase = phase + ((v->kx2 * x * x)/w) + ((v->ky2 * y * y)/h) + ((v->kt2 * t * t)>>1); */
935 phase = phase + ((v->kx2 * x * x * scale_kx2) >> 16) + ky2 + (kt2 >> 1);
938 color.U = sine_table[phase & 0xff];
939 color.V = sine_table[phase & 0xff];
945 color.gray = color.Y << 8;
946 p->paint_tmpline (p, i, 1);
948 videotestsrc_convert_tmpline (p, frame, j);
952 #undef SCALE_AMPLITUDE
954 gst_video_test_src_circular (GstVideoTestSrc * v, GstVideoFrame * frame)
958 paintinfo pi = PAINT_INFO_INIT;
961 int w = frame->info.width, h = frame->info.height;
965 videotestsrc_setup_paintinfo (v, p, w, h);
967 for (i = 1; i < 8; i++) {
968 freq[i] = 200 * pow (2.0, -(i - 1) / 4.0);
971 for (j = 0; j < h; j++) {
972 for (i = 0; i < w; i++) {
977 sqrt ((2 * i - w) * (2 * i - w) + (2 * j - h) * (2 * j -
979 seg = floor (dist * 16);
980 if (seg == 0 || seg >= 8) {
981 p->tmpline_u8[i] = 0;
983 d = floor (256 * dist * freq[seg] + 0.5);
984 p->tmpline_u8[i] = sine_table[d & 0xff];
987 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
988 &p->foreground_color, &p->background_color, w);
989 videotestsrc_convert_tmpline (p, frame, j);
994 gst_video_test_src_gamut (GstVideoTestSrc * v, GstVideoFrame * frame)
997 paintinfo pi = PAINT_INFO_INIT;
999 struct vts_color_struct yuv_primary;
1000 struct vts_color_struct yuv_secondary;
1001 int w = frame->info.width, h = frame->info.height;
1003 videotestsrc_setup_paintinfo (v, p, w, h);
1005 for (y = 0; y < h; y++) {
1006 int region = (y * 4) / h;
1010 yuv_primary = p->colors[COLOR_BLACK];
1011 yuv_secondary = p->colors[COLOR_BLACK];
1012 yuv_secondary.Y = 0;
1015 yuv_primary = p->colors[COLOR_WHITE];
1016 yuv_secondary = p->colors[COLOR_WHITE];
1017 yuv_secondary.Y = 255;
1020 yuv_primary = p->colors[COLOR_RED];
1021 yuv_secondary = p->colors[COLOR_RED];
1022 yuv_secondary.V = 255;
1025 yuv_primary = p->colors[COLOR_BLUE];
1026 yuv_secondary = p->colors[COLOR_BLUE];
1027 yuv_secondary.U = 255;
1031 for (x = 0; x < w; x += 8) {
1032 int len = MIN (8, w - x);
1034 if ((x ^ y) & (1 << 4)) {
1035 p->color = &yuv_primary;
1037 p->color = &yuv_secondary;
1039 p->paint_tmpline (p, x, len);
1041 videotestsrc_convert_tmpline (p, frame, y);
1046 gst_video_test_src_ball (GstVideoTestSrc * v, GstVideoFrame * frame)
1049 paintinfo pi = PAINT_INFO_INIT;
1051 int t = v->n_frames;
1054 int w = frame->info.width, h = frame->info.height;
1056 videotestsrc_setup_paintinfo (v, p, w, h);
1058 x = radius + (0.5 + 0.5 * sin (2 * G_PI * t / 200)) * (w - 2 * radius);
1059 y = radius + (0.5 + 0.5 * sin (2 * G_PI * sqrt (2) * t / 200)) * (h -
1062 for (i = 0; i < h; i++) {
1063 if (i < y - radius || i > y + radius) {
1064 memset (p->tmpline_u8, 0, w);
1066 int r = rint (sqrt (radius * radius - (i - y) * (i - y)));
1071 x2 = MAX (0, x - r);
1072 for (j = x1; j < x2; j++) {
1073 p->tmpline_u8[j] = 0;
1076 x1 = MAX (0, x - r);
1077 x2 = MIN (w, x + r + 1);
1078 for (j = x1; j < x2; j++) {
1079 double rr = radius - sqrt ((j - x) * (j - x) + (i - y) * (i - y));
1082 p->tmpline_u8[j] = CLAMP ((int) floor (256 * rr), 0, 255);
1085 x1 = MIN (w, x + r + 1);
1087 for (j = x1; j < x2; j++) {
1088 p->tmpline_u8[j] = 0;
1091 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1092 &p->foreground_color, &p->background_color, w);
1093 videotestsrc_convert_tmpline (p, frame, i);
1098 paint_tmpline_ARGB (paintinfo * p, int x, int w)
1103 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1104 value = (p->color->A << 0) | (p->color->R << 8) |
1105 (p->color->G << 16) | (p->color->B << 24);
1107 value = (p->color->A << 24) | (p->color->R << 16) |
1108 (p->color->G << 8) | (p->color->B << 0);
1112 video_test_src_orc_splat_u32 (p->tmpline + offset, value, w);
1116 paint_tmpline_AYUV (paintinfo * p, int x, int w)
1121 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1122 value = (p->color->A << 0) | (p->color->Y << 8) |
1123 (p->color->U << 16) | (p->color->V << 24);
1125 value = (p->color->A << 24) | (p->color->Y << 16) |
1126 (p->color->U << 8) | (p->color->V << 0);
1130 video_test_src_orc_splat_u32 (p->tmpline + offset, value, w);
1134 convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y)
1136 const GstVideoFormatInfo *finfo, *uinfo;
1137 gint i, width = GST_VIDEO_FRAME_WIDTH (frame);
1140 finfo = frame->info.finfo;
1141 uinfo = gst_video_format_get_info (finfo->unpack_format);
1143 if (GST_VIDEO_FORMAT_INFO_DEPTH (uinfo, 0) == 16) {
1145 for (i = 0; i < width; i++) {
1146 p->tmpline_u16[i * 4 + 0] = TO_16 (p->tmpline[i * 4 + 0]);
1147 p->tmpline_u16[i * 4 + 1] = TO_16 (p->tmpline[i * 4 + 1]);
1148 p->tmpline_u16[i * 4 + 2] = TO_16 (p->tmpline[i * 4 + 2]);
1149 p->tmpline_u16[i * 4 + 3] = TO_16 (p->tmpline[i * 4 + 3]);
1151 src = p->tmpline_u16;
1155 finfo->pack_func (finfo, GST_VIDEO_PACK_FLAG_NONE,
1156 src, 0, frame->data, frame->info.stride,
1157 frame->info.chroma_site, y, width);
1161 convert_hline_bayer (paintinfo * p, GstVideoFrame * frame, int y)
1164 guint8 *data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
1165 guint8 *R = data + y * GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
1166 guint8 *argb = p->tmpline;
1167 gint width = GST_VIDEO_FRAME_WIDTH (frame);
1168 int x_inv = p->x_invert;
1169 int y_inv = p->y_invert;
1171 if ((y ^ y_inv) & 1) {
1172 for (i = 0; i < width; i++) {
1173 if ((i ^ x_inv) & 1) {
1174 R[i] = argb[4 * i + 1];
1176 R[i] = argb[4 * i + 2];
1180 for (i = 0; i < width; i++) {
1181 if ((i ^ x_inv) & 1) {
1182 R[i] = argb[4 * i + 2];
1184 R[i] = argb[4 * i + 3];