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))
36 #define TO_10(x) (((x)<<2) | ((x)>>6))
38 static void paint_tmpline_ARGB (paintinfo * p, int x, int w);
39 static void paint_tmpline_AYUV (paintinfo * p, int x, int w);
44 static unsigned int state;
48 return (state >> 16) & 0xff;
67 static const struct vts_color_struct vts_colors_bt709_ycbcr_100[] = {
68 {235, 128, 128, 255, 255, 255, 255, (235 << 8)},
69 {219, 16, 138, 255, 255, 255, 0, (219 << 8)},
70 {188, 154, 16, 255, 0, 255, 255, (188 < 8)},
71 {173, 42, 26, 255, 0, 255, 0, (173 << 8)},
72 {78, 214, 230, 255, 255, 0, 255, (78 << 8)},
73 {63, 102, 240, 255, 255, 0, 0, (64 << 8)},
74 {32, 240, 118, 255, 0, 0, 255, (32 << 8)},
75 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
76 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
77 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
78 {0, 128, 128, 255, 0, 0, 0, 0},
79 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
82 static const struct vts_color_struct vts_colors_bt709_ycbcr_75[] = {
83 {180, 128, 128, 255, 191, 191, 191, (180 << 8)},
84 {168, 44, 136, 255, 191, 191, 0, (168 << 8)},
85 {145, 147, 44, 255, 0, 191, 191, (145 << 8)},
86 {133, 63, 52, 255, 0, 191, 0, (133 << 8)},
87 {63, 193, 204, 255, 191, 0, 191, (63 << 8)},
88 {51, 109, 212, 255, 191, 0, 0, (51 << 8)},
89 {28, 212, 120, 255, 0, 0, 191, (28 << 8)},
90 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
91 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
92 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
93 {0, 128, 128, 255, 0, 0, 0, 0},
94 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
97 static const struct vts_color_struct vts_colors_bt601_ycbcr_100[] = {
98 {235, 128, 128, 255, 255, 255, 255, (235 << 8)},
99 {210, 16, 146, 255, 255, 255, 0, (219 << 8)},
100 {170, 166, 16, 255, 0, 255, 255, (188 < 8)},
101 {145, 54, 34, 255, 0, 255, 0, (173 << 8)},
102 {106, 202, 222, 255, 255, 0, 255, (78 << 8)},
103 {81, 90, 240, 255, 255, 0, 0, (64 << 8)},
104 {41, 240, 110, 255, 0, 0, 255, (32 << 8)},
105 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
106 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
107 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
108 {-0, 128, 128, 255, 0, 0, 0, 0},
109 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
112 static const struct vts_color_struct vts_colors_bt601_ycbcr_75[] = {
113 {180, 128, 128, 255, 191, 191, 191, (180 << 8)},
114 {162, 44, 142, 255, 191, 191, 0, (168 << 8)},
115 {131, 156, 44, 255, 0, 191, 191, (145 << 8)},
116 {112, 72, 58, 255, 0, 191, 0, (133 << 8)},
117 {84, 184, 198, 255, 191, 0, 191, (63 << 8)},
118 {65, 100, 212, 255, 191, 0, 0, (51 << 8)},
119 {35, 212, 114, 255, 0, 0, 191, (28 << 8)},
120 {16, 128, 128, 255, 0, 0, 0, (16 << 8)},
121 {16, 198, 21, 255, 0, 0, 128, (16 << 8)}, /* -I ? */
122 {16, 235, 198, 255, 0, 128, 255, (16 << 8)}, /* +Q ? */
123 {-0, 128, 128, 255, 0, 0, 0, 0},
124 {32, 128, 128, 255, 19, 19, 19, (32 << 8)},
128 static void paint_setup_I420 (paintinfo * p, GstVideoFrame * frame);
129 static void paint_setup_YV12 (paintinfo * p, GstVideoFrame * frame);
130 static void paint_setup_YUY2 (paintinfo * p, GstVideoFrame * frame);
131 static void paint_setup_UYVY (paintinfo * p, GstVideoFrame * frame);
132 static void paint_setup_YVYU (paintinfo * p, GstVideoFrame * frame);
134 static void paint_setup_IYU2 (paintinfo * p, GstVideoFrame * frame);
136 static void paint_setup_Y41B (paintinfo * p, GstVideoFrame * frame);
137 static void paint_setup_Y42B (paintinfo * p, GstVideoFrame * frame);
138 static void paint_setup_Y444 (paintinfo * p, GstVideoFrame * frame);
139 static void paint_setup_Y800 (paintinfo * p, GstVideoFrame * frame);
140 static void paint_setup_AYUV (paintinfo * p, GstVideoFrame * frame);
141 static void paint_setup_v308 (paintinfo * p, GstVideoFrame * frame);
142 static void paint_setup_NV12 (paintinfo * p, GstVideoFrame * frame);
143 static void paint_setup_NV21 (paintinfo * p, GstVideoFrame * frame);
145 static void paint_setup_v410 (paintinfo * p, GstVideoFrame * frame);
147 static void paint_setup_v216 (paintinfo * p, GstVideoFrame * frame);
148 static void paint_setup_v210 (paintinfo * p, GstVideoFrame * frame);
149 static void paint_setup_UYVP (paintinfo * p, GstVideoFrame * frame);
150 static void paint_setup_AY64 (paintinfo * p, GstVideoFrame * frame);
152 static void paint_setup_YUV9 (paintinfo * p, GstVideoFrame * frame);
153 static void paint_setup_YVU9 (paintinfo * p, GstVideoFrame * frame);
154 static void paint_setup_ARGB8888 (paintinfo * p, GstVideoFrame * frame);
155 static void paint_setup_ABGR8888 (paintinfo * p, GstVideoFrame * frame);
156 static void paint_setup_RGBA8888 (paintinfo * p, GstVideoFrame * frame);
157 static void paint_setup_BGRA8888 (paintinfo * p, GstVideoFrame * frame);
158 static void paint_setup_xRGB8888 (paintinfo * p, GstVideoFrame * frame);
159 static void paint_setup_xBGR8888 (paintinfo * p, GstVideoFrame * frame);
160 static void paint_setup_RGBx8888 (paintinfo * p, GstVideoFrame * frame);
161 static void paint_setup_BGRx8888 (paintinfo * p, GstVideoFrame * frame);
162 static void paint_setup_RGB888 (paintinfo * p, GstVideoFrame * frame);
163 static void paint_setup_BGR888 (paintinfo * p, GstVideoFrame * frame);
164 static void paint_setup_RGB565 (paintinfo * p, GstVideoFrame * frame);
165 static void paint_setup_xRGB1555 (paintinfo * p, GstVideoFrame * frame);
166 static void paint_setup_ARGB64 (paintinfo * p, GstVideoFrame * frame);
168 static void paint_setup_bayer_bggr (paintinfo * p, GstVideoFrame * frame);
169 static void paint_setup_bayer_rggb (paintinfo * p, GstVideoFrame * frame);
170 static void paint_setup_bayer_gbrg (paintinfo * p, GstVideoFrame * frame);
171 static void paint_setup_bayer_grbg (paintinfo * p, GstVideoFrame * frame);
173 static void convert_hline_I420 (paintinfo * p, int y);
174 static void convert_hline_NV12 (paintinfo * p, int y);
175 static void convert_hline_NV21 (paintinfo * p, int y);
176 static void convert_hline_YUY2 (paintinfo * p, int y);
178 static void convert_hline_IYU2 (paintinfo * p, int y);
180 static void convert_hline_Y41B (paintinfo * p, int y);
181 static void convert_hline_Y42B (paintinfo * p, int y);
182 static void convert_hline_Y444 (paintinfo * p, int y);
183 static void convert_hline_Y800 (paintinfo * p, int y);
184 static void convert_hline_v308 (paintinfo * p, int y);
185 static void convert_hline_AYUV (paintinfo * p, int y);
187 static void convert_hline_v410 (paintinfo * p, int y);
189 static void convert_hline_v216 (paintinfo * p, int y);
190 static void convert_hline_v210 (paintinfo * p, int y);
191 static void convert_hline_UYVP (paintinfo * p, int y);
192 static void convert_hline_AY64 (paintinfo * p, int y);
194 static void convert_hline_YUV9 (paintinfo * p, int y);
195 static void convert_hline_astr4 (paintinfo * p, int y);
196 static void convert_hline_astr8 (paintinfo * p, int y);
197 static void convert_hline_str4 (paintinfo * p, int y);
198 static void convert_hline_str3 (paintinfo * p, int y);
199 static void convert_hline_RGB565 (paintinfo * p, int y);
200 static void convert_hline_xRGB1555 (paintinfo * p, int y);
202 static void convert_hline_bayer (paintinfo * p, int y);
204 static void paint_setup_GRAY8 (paintinfo * p, GstVideoFrame * frame);
205 static void paint_setup_GRAY16 (paintinfo * p, GstVideoFrame * frame);
206 static void convert_hline_GRAY8 (paintinfo * p, int y);
207 static void convert_hline_GRAY16 (paintinfo * p, int y);
209 struct format_list_struct format_list[] = {
211 {VTS_YUV, "YUY2", "YUY2", 16, paint_setup_YUY2, convert_hline_YUY2},
212 {VTS_YUV, "UYVY", "UYVY", 16, paint_setup_UYVY, convert_hline_YUY2},
214 {VTS_YUV, "Y422", "Y422", 16, paint_setup_UYVY, convert_hline_YUY2},
215 {VTS_YUV, "UYNV", "UYNV", 16, paint_setup_UYVY, convert_hline_YUY2}, /* FIXME: UYNV? */
217 {VTS_YUV, "YVYU", "YVYU", 16, paint_setup_YVYU, convert_hline_YUY2},
218 {VTS_YUV, "v308", "v308", 24, paint_setup_v308, convert_hline_v308},
219 {VTS_YUV, "AYUV", "AYUV", 32, paint_setup_AYUV, convert_hline_AYUV},
221 {VTS_YUV, "v410", "v410", 32, paint_setup_v410, convert_hline_v410},
223 {VTS_YUV, "v210", "v210", 21, paint_setup_v210, convert_hline_v210},
224 {VTS_YUV, "v216", "v216", 32, paint_setup_v216, convert_hline_v216},
225 {VTS_YUV, "UYVP", "UYVP", 20, paint_setup_UYVP, convert_hline_UYVP},
226 {VTS_YUV, "AY64", "AY64", 64, paint_setup_AY64, convert_hline_AY64},
229 {VTS_YUV, "IYU2", "IYU2", 24, paint_setup_IYU2, convert_hline_IYU2},
234 {VTS_YUV, "YVU9", "YVU9", 9, paint_setup_YVU9, convert_hline_YUV9},
236 {VTS_YUV, "YUV9", "YUV9", 9, paint_setup_YUV9, convert_hline_YUV9},
239 {VTS_YUV, "YV12", "YV12", 12, paint_setup_YV12, convert_hline_I420},
241 {VTS_YUV, "I420", "I420", 12, paint_setup_I420, convert_hline_I420},
243 {VTS_YUV, "NV12", "NV12", 12, paint_setup_NV12, convert_hline_NV12},
245 {VTS_YUV, "NV21", "NV21", 12, paint_setup_NV21, convert_hline_NV21},
248 {VTS_YUV, "Y41B", "Y41B", 12, paint_setup_Y41B, convert_hline_Y41B},
250 {VTS_YUV, "Y42B", "Y42B", 16, paint_setup_Y42B, convert_hline_Y42B},
252 {VTS_YUV, "Y444", "Y444", 24, paint_setup_Y444, convert_hline_Y444},
254 {VTS_YUV, "Y800", "Y800", 8, paint_setup_Y800, convert_hline_Y800},
256 /* Not exactly YUV but it's the same as above */
257 {VTS_GRAY, "GRAY8", "GRAY8", 8, paint_setup_GRAY8, convert_hline_GRAY8},
258 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
259 {VTS_GRAY, "GRAY16_LE", "GRAY16", 16, paint_setup_GRAY16,
260 convert_hline_GRAY16},
262 {VTS_GRAY, "GRAY16_BE", "GRAY16", 16, paint_setup_GRAY16,
263 convert_hline_GRAY16},
266 {VTS_RGB, "xRGB", "xRGB8888", 32, paint_setup_xRGB8888, convert_hline_str4,
268 0x00ff0000, 0x0000ff00, 0x000000ff},
269 {VTS_RGB, "xBGR", "xBGR8888", 32, paint_setup_xBGR8888, convert_hline_str4,
271 0x000000ff, 0x0000ff00, 0x00ff0000},
272 {VTS_RGB, "RGBx", "RGBx8888", 32, paint_setup_RGBx8888, convert_hline_str4,
274 0xff000000, 0x00ff0000, 0x0000ff00},
275 {VTS_RGB, "BGRx", "BGRx8888", 32, paint_setup_BGRx8888, convert_hline_str4,
277 0x0000ff00, 0x00ff0000, 0xff000000},
278 {VTS_RGB, "ARGB", "ARGB8888", 32, paint_setup_ARGB8888, convert_hline_astr4,
280 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
281 {VTS_RGB, "ABGR", "ABGR8888", 32, paint_setup_ABGR8888, convert_hline_astr4,
283 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000},
284 {VTS_RGB, "RGBA", "RGBA8888", 32, paint_setup_RGBA8888, convert_hline_astr4,
286 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff},
287 {VTS_RGB, "BGRA", "BGRA8888", 32, paint_setup_BGRA8888, convert_hline_astr4,
289 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff},
290 {VTS_RGB, "RGB", "RGB888", 24, paint_setup_RGB888, convert_hline_str3, 24,
291 0x00ff0000, 0x0000ff00, 0x000000ff},
292 {VTS_RGB, "BGR", "BGR888", 24, paint_setup_BGR888, convert_hline_str3, 24,
293 0x000000ff, 0x0000ff00, 0x00ff0000},
294 {VTS_RGB, "RGB16", "RGB565", 16, paint_setup_RGB565, convert_hline_RGB565, 16,
295 0x0000f800, 0x000007e0, 0x0000001f},
296 {VTS_RGB, "RGB15", "xRGB1555", 16, paint_setup_xRGB1555,
297 convert_hline_xRGB1555,
299 0x00007c00, 0x000003e0, 0x0000001f},
300 {VTS_RGB, "ARGB64", "ARGB8888", 64, paint_setup_ARGB64, convert_hline_astr8,
302 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
304 {VTS_BAYER, "bggr", "Bayer", 8, paint_setup_bayer_bggr, convert_hline_bayer},
305 {VTS_BAYER, "rggb", "Bayer", 8, paint_setup_bayer_rggb, convert_hline_bayer},
306 {VTS_BAYER, "grbg", "Bayer", 8, paint_setup_bayer_grbg, convert_hline_bayer},
307 {VTS_BAYER, "gbrg", "Bayer", 8, paint_setup_bayer_gbrg, convert_hline_bayer}
310 int n_formats = G_N_ELEMENTS (format_list);
312 struct format_list_struct *
313 paintinfo_find_by_structure (const GstStructure * structure)
316 const char *media_type = gst_structure_get_name (structure);
318 g_return_val_if_fail (structure, NULL);
320 if (strcmp (media_type, "video/x-raw") == 0) {
323 format = gst_structure_get_string (structure, "format");
325 GST_WARNING ("incomplete caps structure: %" GST_PTR_FORMAT, structure);
329 for (i = 0; i < n_formats; i++) {
330 if (g_str_equal (format, format_list[i].format)) {
331 return format_list + i;
335 } else if (strcmp (media_type, "video/x-raw-bayer") == 0) {
338 format = gst_structure_get_string (structure, "format");
340 GST_WARNING ("incomplete caps structure: %" GST_PTR_FORMAT, structure);
344 for (i = 0; i < n_formats; i++) {
345 if (format_list[i].type == VTS_BAYER &&
346 g_str_equal (format, format_list[i].format)) {
347 return format_list + i;
353 g_critical ("format not found for media type %s", media_type);
358 struct format_list_struct *
359 paintrect_find_format (const gchar * find_format)
363 for (i = 0; i < n_formats; i++) {
364 if (g_str_equal (find_format, format_list[i].format)) {
365 return format_list + i;
371 struct format_list_struct *
372 paintrect_find_name (const char *name)
376 for (i = 0; i < n_formats; i++) {
377 if (g_str_equal (name, format_list[i].name)) {
378 return format_list + i;
386 paint_get_structure (struct format_list_struct * format)
388 GstStructure *structure = NULL;
390 g_return_val_if_fail (format, NULL);
392 switch (format->type) {
395 structure = gst_structure_new ("video/x-raw",
396 "format", G_TYPE_STRING, format->format, NULL);
400 GValue value_list = { 0 };
401 GValue value = { 0 };
403 structure = gst_structure_new ("video/x-raw",
404 "format", G_TYPE_STRING, format->format, NULL);
406 if (strcmp (format->format, "Y800") != 0) {
407 g_value_init (&value_list, GST_TYPE_LIST);
409 g_value_init (&value, G_TYPE_STRING);
410 g_value_set_static_string (&value, "sdtv");
411 gst_value_list_append_value (&value_list, &value);
413 g_value_set_static_string (&value, "hdtv");
414 gst_value_list_append_value (&value_list, &value);
416 gst_structure_set_value (structure, "color-matrix", &value_list);
417 g_value_reset (&value_list);
419 if (strcmp (format->format, "AYUV") &&
420 strcmp (format->format, "v308") &&
421 strcmp (format->format, "v410") &&
422 strcmp (format->format, "Y444")) {
423 g_value_set_static_string (&value, "mpeg2");
424 gst_value_list_append_value (&value_list, &value);
426 g_value_set_static_string (&value, "jpeg");
427 gst_value_list_append_value (&value_list, &value);
429 gst_structure_set_value (structure, "chroma-site", &value_list);
431 g_value_unset (&value_list);
436 structure = gst_structure_new ("video/x-raw-bayer",
437 "format", G_TYPE_STRING, format->format, NULL);
440 g_assert_not_reached ();
446 /* returns the size in bytes for one video frame of the given dimensions
447 * given the format in GstVideoTestSrc */
449 gst_video_test_src_get_size (GstVideoTestSrc * v, int w, int h)
451 paintinfo pi = { NULL, };
453 struct format_list_struct *format;
461 format->paint_setup (p, NULL);
467 #define ONE_HALF (1 << (SCALEBITS - 1))
468 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
470 #define RGB_TO_Y(r, g, b) \
471 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
472 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
474 #define RGB_TO_U(r1, g1, b1, shift)\
475 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
476 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
478 #define RGB_TO_V(r1, g1, b1, shift)\
479 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
480 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
482 #define RGB_TO_Y_CCIR(r, g, b) \
483 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
484 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
486 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\
487 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
488 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
490 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\
491 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
492 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
494 #define RGB_TO_Y_CCIR_709(r, g, b) \
495 ((FIX(0.212600*219.0/255.0) * (r) + FIX(0.715200*219.0/255.0) * (g) + \
496 FIX(0.072200*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
498 #define RGB_TO_U_CCIR_709(r1, g1, b1, shift)\
499 (((- FIX(0.114572*224.0/255.0) * r1 - FIX(0.385427*224.0/255.0) * g1 + \
500 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
502 #define RGB_TO_V_CCIR_709(r1, g1, b1, shift)\
503 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.454153*224.0/255.0) * g1 - \
504 FIX(0.045847*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
507 videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h)
511 if (v->color_spec == GST_VIDEO_TEST_SRC_BT601) {
512 p->colors = vts_colors_bt601_ycbcr_100;
514 p->colors = vts_colors_bt709_ycbcr_100;
519 p->convert_tmpline = v->format->convert_hline;
520 if (v->format->type == VTS_RGB || v->format->type == VTS_BAYER) {
521 p->paint_tmpline = paint_tmpline_ARGB;
523 p->paint_tmpline = paint_tmpline_AYUV;
525 p->tmpline = v->tmpline;
526 p->tmpline2 = v->tmpline2;
527 p->tmpline_u8 = v->tmpline_u8;
528 p->x_offset = (v->horizontal_speed * v->n_frames) % p->width;
530 p->x_offset += p->width;
532 a = (v->foreground_color >> 24) & 0xff;
533 r = (v->foreground_color >> 16) & 0xff;
534 g = (v->foreground_color >> 8) & 0xff;
535 b = (v->foreground_color >> 0) & 0xff;
536 p->foreground_color.A = a;
537 p->foreground_color.R = r;
538 p->foreground_color.G = g;
539 p->foreground_color.B = b;
540 if (v->color_spec == GST_VIDEO_TEST_SRC_BT601) {
541 p->foreground_color.Y = RGB_TO_Y_CCIR (r, g, b);
542 p->foreground_color.U = RGB_TO_U_CCIR (r, g, b, 0);
543 p->foreground_color.V = RGB_TO_V_CCIR (r, g, b, 0);
545 p->foreground_color.Y = RGB_TO_Y_CCIR_709 (r, g, b);
546 p->foreground_color.U = RGB_TO_U_CCIR_709 (r, g, b, 0);
547 p->foreground_color.V = RGB_TO_V_CCIR_709 (r, g, b, 0);
549 p->foreground_color.gray = RGB_TO_Y (r, g, b);
551 a = (v->background_color >> 24) & 0xff;
552 r = (v->background_color >> 16) & 0xff;
553 g = (v->background_color >> 8) & 0xff;
554 b = (v->background_color >> 0) & 0xff;
555 p->background_color.A = a;
556 p->background_color.R = r;
557 p->background_color.G = g;
558 p->background_color.B = b;
559 if (v->color_spec == GST_VIDEO_TEST_SRC_BT601) {
560 p->background_color.Y = RGB_TO_Y_CCIR (r, g, b);
561 p->background_color.U = RGB_TO_U_CCIR (r, g, b, 0);
562 p->background_color.V = RGB_TO_V_CCIR (r, g, b, 0);
564 p->background_color.Y = RGB_TO_Y_CCIR_709 (r, g, b);
565 p->background_color.U = RGB_TO_U_CCIR_709 (r, g, b, 0);
566 p->background_color.V = RGB_TO_V_CCIR_709 (r, g, b, 0);
568 p->background_color.gray = RGB_TO_Y (r, g, b);
573 videotestsrc_convert_tmpline (paintinfo * p, int j)
579 memcpy (p->tmpline2, p->tmpline, p->width * 4);
580 memcpy (p->tmpline, p->tmpline2 + x * 4, (p->width - x) * 4);
581 memcpy (p->tmpline + (p->width - x) * 4, p->tmpline2, x * 4);
584 for (i = p->width; i < p->width + 5; i++) {
585 p->tmpline[4 * i + 0] = p->tmpline[4 * (p->width - 1) + 0];
586 p->tmpline[4 * i + 1] = p->tmpline[4 * (p->width - 1) + 1];
587 p->tmpline[4 * i + 2] = p->tmpline[4 * (p->width - 1) + 2];
588 p->tmpline[4 * i + 3] = p->tmpline[4 * (p->width - 1) + 3];
591 p->convert_tmpline (p, j);
594 #define BLEND1(a,b,x) ((a)*(x) + (b)*(255-(x)))
595 #define DIV255(x) (((x) + (((x)+128)>>8) + 128)>>8)
596 #define BLEND(a,b,x) DIV255(BLEND1(a,b,x))
600 videotestsrc_blend_color (struct vts_color_struct *dest,
601 struct vts_color_struct *a, struct vts_color_struct *b, int x)
603 dest->Y = BLEND (a->Y, b->Y, x);
604 dest->U = BLEND (a->U, b->U, x);
605 dest->V = BLEND (a->V, b->V, x);
606 dest->R = BLEND (a->R, b->R, x);
607 dest->G = BLEND (a->G, b->G, x);
608 dest->B = BLEND (a->B, b->B, x);
609 dest->gray = BLEND (a->gray, b->gray, x);
615 videotestsrc_blend_line (GstVideoTestSrc * v, guint8 * dest, guint8 * src,
616 struct vts_color_struct *a, struct vts_color_struct *b, int n)
619 if (v->format->type == VTS_RGB || v->format->type == VTS_BAYER) {
620 for (i = 0; i < n; i++) {
621 dest[i * 4 + 0] = BLEND (a->A, b->A, src[i]);
622 dest[i * 4 + 1] = BLEND (a->R, b->R, src[i]);
623 dest[i * 4 + 2] = BLEND (a->G, b->G, src[i]);
624 dest[i * 4 + 3] = BLEND (a->B, b->B, src[i]);
627 for (i = 0; i < n; i++) {
628 dest[i * 4 + 0] = BLEND (a->A, b->A, src[i]);
629 dest[i * 4 + 1] = BLEND (a->Y, b->Y, src[i]);
630 dest[i * 4 + 2] = BLEND (a->U, b->U, src[i]);
631 dest[i * 4 + 3] = BLEND (a->V, b->V, src[i]);
638 gst_video_test_src_smpte (GstVideoTestSrc * v, GstVideoFrame * frame)
643 paintinfo pi = { NULL, };
645 struct format_list_struct *format;
646 int w = frame->info.width, h = frame->info.height;
648 videotestsrc_setup_paintinfo (v, p, frame->info.width, frame->info.height);
653 format->paint_setup (p, frame);
659 for (j = 0; j < y1; j++) {
660 for (i = 0; i < 7; i++) {
662 int x2 = (i + 1) * w / 7;
664 p->color = p->colors + i;
665 p->paint_tmpline (p, x1, (x2 - x1));
667 videotestsrc_convert_tmpline (p, j);
670 /* inverse blue bars */
671 for (j = y1; j < y2; j++) {
672 for (i = 0; i < 7; i++) {
674 int x2 = (i + 1) * w / 7;
682 p->color = p->colors + k;
683 p->paint_tmpline (p, x1, (x2 - x1));
685 videotestsrc_convert_tmpline (p, j);
688 for (j = y2; j < h; j++) {
689 /* -I, white, Q regions */
690 for (i = 0; i < 3; i++) {
692 int x2 = (i + 1) * w / 6;
702 p->color = p->colors + k;
703 p->paint_tmpline (p, x1, (x2 - x1));
706 /* superblack, black, dark grey */
707 for (i = 0; i < 3; i++) {
708 int x1 = w / 2 + i * w / 12;
709 int x2 = w / 2 + (i + 1) * w / 12;
713 k = COLOR_SUPER_BLACK;
719 p->color = p->colors + k;
720 p->paint_tmpline (p, x1, (x2 - x1));
725 struct vts_color_struct color;
727 color = p->colors[COLOR_BLACK];
730 for (i = x1; i < w; i++) {
731 int y = random_char ();
732 p->tmpline_u8[i] = y;
734 videotestsrc_blend_line (v, p->tmpline + x1 * 4, p->tmpline_u8 + x1,
735 &p->foreground_color, &p->background_color, w - x1);
738 videotestsrc_convert_tmpline (p, j);
744 gst_video_test_src_smpte75 (GstVideoTestSrc * v, GstVideoFrame * frame)
748 paintinfo pi = { NULL, };
750 struct format_list_struct *format;
751 int w = frame->info.width, h = frame->info.height;
753 videotestsrc_setup_paintinfo (v, p, w, h);
754 if (v->color_spec == GST_VIDEO_TEST_SRC_BT601) {
755 p->colors = vts_colors_bt601_ycbcr_75;
757 p->colors = vts_colors_bt709_ycbcr_75;
763 format->paint_setup (p, frame);
766 for (j = 0; j < h; j++) {
767 for (i = 0; i < 7; i++) {
769 int x2 = (i + 1) * w / 7;
771 p->color = p->colors + i;
772 p->paint_tmpline (p, x1, (x2 - x1));
774 videotestsrc_convert_tmpline (p, j);
779 gst_video_test_src_smpte100 (GstVideoTestSrc * v, GstVideoFrame * frame)
783 paintinfo pi = { NULL, };
785 struct format_list_struct *format;
786 int w = frame->info.width, h = frame->info.height;
788 videotestsrc_setup_paintinfo (v, p, w, h);
793 format->paint_setup (p, frame);
796 for (j = 0; j < h; j++) {
797 for (i = 0; i < 7; i++) {
799 int x2 = (i + 1) * w / 7;
801 p->color = p->colors + i;
802 p->paint_tmpline (p, x1, (x2 - x1));
804 videotestsrc_convert_tmpline (p, j);
809 gst_video_test_src_bar (GstVideoTestSrc * v, GstVideoFrame * frame)
812 paintinfo pi = { NULL, };
814 struct format_list_struct *format;
815 int w = frame->info.width, h = frame->info.height;
817 videotestsrc_setup_paintinfo (v, p, w, h);
822 format->paint_setup (p, frame);
824 for (j = 0; j < h; j++) {
825 /* use fixed size for now */
828 p->color = &p->foreground_color;
829 p->paint_tmpline (p, 0, x2);
830 p->color = &p->background_color;
831 p->paint_tmpline (p, x2, (w - x2));
832 videotestsrc_convert_tmpline (p, j);
837 gst_video_test_src_snow (GstVideoTestSrc * v, GstVideoFrame * frame)
841 paintinfo pi = { NULL, };
843 struct format_list_struct *format;
844 struct vts_color_struct color;
845 int w = frame->info.width, h = frame->info.height;
847 videotestsrc_setup_paintinfo (v, p, w, h);
852 format->paint_setup (p, frame);
854 color = p->colors[COLOR_BLACK];
857 for (j = 0; j < h; j++) {
858 for (i = 0; i < w; i++) {
859 int y = random_char ();
860 p->tmpline_u8[i] = y;
862 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
863 &p->foreground_color, &p->background_color, p->width);
864 videotestsrc_convert_tmpline (p, j);
869 gst_video_test_src_unicolor (GstVideoTestSrc * v, GstVideoFrame * frame,
873 paintinfo pi = { NULL, };
875 struct format_list_struct *format;
876 int w = frame->info.width, h = frame->info.height;
878 videotestsrc_setup_paintinfo (v, p, w, h);
883 format->paint_setup (p, frame);
885 p->color = p->colors + color_index;
886 if (color_index == COLOR_BLACK) {
887 p->color = &p->background_color;
889 if (color_index == COLOR_WHITE) {
890 p->color = &p->foreground_color;
893 for (i = 0; i < h; i++) {
894 p->paint_tmpline (p, 0, w);
895 videotestsrc_convert_tmpline (p, i);
900 gst_video_test_src_black (GstVideoTestSrc * v, GstVideoFrame * frame)
902 gst_video_test_src_unicolor (v, frame, COLOR_BLACK);
906 gst_video_test_src_white (GstVideoTestSrc * v, GstVideoFrame * frame)
908 gst_video_test_src_unicolor (v, frame, COLOR_WHITE);
912 gst_video_test_src_red (GstVideoTestSrc * v, GstVideoFrame * frame)
914 gst_video_test_src_unicolor (v, frame, COLOR_RED);
918 gst_video_test_src_green (GstVideoTestSrc * v, GstVideoFrame * frame)
920 gst_video_test_src_unicolor (v, frame, COLOR_GREEN);
924 gst_video_test_src_blue (GstVideoTestSrc * v, GstVideoFrame * frame)
926 gst_video_test_src_unicolor (v, frame, COLOR_BLUE);
930 gst_video_test_src_blink (GstVideoTestSrc * v, GstVideoFrame * frame)
933 paintinfo pi = { NULL, };
935 struct format_list_struct *format;
936 int w = frame->info.width, h = frame->info.height;
938 videotestsrc_setup_paintinfo (v, p, w, h);
944 format->paint_setup (p, frame);
946 if (v->n_frames & 1) {
947 p->color = &p->foreground_color;
949 p->color = &p->background_color;
952 for (i = 0; i < h; i++) {
953 p->paint_tmpline (p, 0, w);
954 videotestsrc_convert_tmpline (p, i);
959 gst_video_test_src_solid (GstVideoTestSrc * v, GstVideoFrame * frame)
962 paintinfo pi = { NULL, };
964 struct format_list_struct *format;
965 int w = frame->info.width, h = frame->info.height;
967 videotestsrc_setup_paintinfo (v, p, w, h);
973 format->paint_setup (p, frame);
975 p->color = &p->foreground_color;
977 for (i = 0; i < h; i++) {
978 p->paint_tmpline (p, 0, w);
979 videotestsrc_convert_tmpline (p, i);
984 gst_video_test_src_checkers1 (GstVideoTestSrc * v, GstVideoFrame * frame)
987 paintinfo pi = { NULL, };
989 struct format_list_struct *format;
990 int w = frame->info.width, h = frame->info.height;
992 videotestsrc_setup_paintinfo (v, p, w, h);
998 format->paint_setup (p, frame);
1000 for (y = 0; y < h; y++) {
1001 for (x = 0; x < w; x++) {
1003 p->color = p->colors + COLOR_GREEN;
1005 p->color = p->colors + COLOR_RED;
1007 p->paint_tmpline (p, x, 1);
1009 videotestsrc_convert_tmpline (p, y);
1014 gst_video_test_src_checkers2 (GstVideoTestSrc * v, GstVideoFrame * frame)
1017 paintinfo pi = { NULL, };
1019 struct format_list_struct *format;
1020 int w = frame->info.width, h = frame->info.height;
1022 videotestsrc_setup_paintinfo (v, p, w, h);
1027 format->paint_setup (p, frame);
1029 for (y = 0; y < h; y++) {
1030 for (x = 0; x < w; x += 2) {
1031 guint len = MIN (2, w - x);
1034 p->color = p->colors + COLOR_GREEN;
1036 p->color = p->colors + COLOR_RED;
1038 p->paint_tmpline (p, x, len);
1040 videotestsrc_convert_tmpline (p, y);
1045 gst_video_test_src_checkers4 (GstVideoTestSrc * v, GstVideoFrame * frame)
1048 paintinfo pi = { NULL, };
1050 struct format_list_struct *format;
1051 int w = frame->info.width, h = frame->info.height;
1053 videotestsrc_setup_paintinfo (v, p, w, h);
1058 format->paint_setup (p, frame);
1060 for (y = 0; y < h; y++) {
1061 for (x = 0; x < w; x += 4) {
1062 guint len = MIN (4, w - x);
1065 p->color = p->colors + COLOR_GREEN;
1067 p->color = p->colors + COLOR_RED;
1069 p->paint_tmpline (p, x, len);
1071 videotestsrc_convert_tmpline (p, y);
1076 gst_video_test_src_checkers8 (GstVideoTestSrc * v, GstVideoFrame * frame)
1079 paintinfo pi = { NULL, };
1081 struct format_list_struct *format;
1082 int w = frame->info.width, h = frame->info.height;
1084 videotestsrc_setup_paintinfo (v, p, w, h);
1089 format->paint_setup (p, frame);
1091 for (y = 0; y < h; y++) {
1092 for (x = 0; x < w; x += 8) {
1093 guint len = MIN (8, w - x);
1096 p->color = p->colors + COLOR_GREEN;
1098 p->color = p->colors + COLOR_RED;
1100 p->paint_tmpline (p, x, len);
1102 videotestsrc_convert_tmpline (p, y);
1106 static const guint8 sine_table[256] = {
1107 128, 131, 134, 137, 140, 143, 146, 149,
1108 152, 156, 159, 162, 165, 168, 171, 174,
1109 176, 179, 182, 185, 188, 191, 193, 196,
1110 199, 201, 204, 206, 209, 211, 213, 216,
1111 218, 220, 222, 224, 226, 228, 230, 232,
1112 234, 236, 237, 239, 240, 242, 243, 245,
1113 246, 247, 248, 249, 250, 251, 252, 252,
1114 253, 254, 254, 255, 255, 255, 255, 255,
1115 255, 255, 255, 255, 255, 255, 254, 254,
1116 253, 252, 252, 251, 250, 249, 248, 247,
1117 246, 245, 243, 242, 240, 239, 237, 236,
1118 234, 232, 230, 228, 226, 224, 222, 220,
1119 218, 216, 213, 211, 209, 206, 204, 201,
1120 199, 196, 193, 191, 188, 185, 182, 179,
1121 176, 174, 171, 168, 165, 162, 159, 156,
1122 152, 149, 146, 143, 140, 137, 134, 131,
1123 128, 124, 121, 118, 115, 112, 109, 106,
1124 103, 99, 96, 93, 90, 87, 84, 81,
1125 79, 76, 73, 70, 67, 64, 62, 59,
1126 56, 54, 51, 49, 46, 44, 42, 39,
1127 37, 35, 33, 31, 29, 27, 25, 23,
1128 21, 19, 18, 16, 15, 13, 12, 10,
1129 9, 8, 7, 6, 5, 4, 3, 3,
1130 2, 1, 1, 0, 0, 0, 0, 0,
1131 0, 0, 0, 0, 0, 0, 1, 1,
1132 2, 3, 3, 4, 5, 6, 7, 8,
1133 9, 10, 12, 13, 15, 16, 18, 19,
1134 21, 23, 25, 27, 29, 31, 33, 35,
1135 37, 39, 42, 44, 46, 49, 51, 54,
1136 56, 59, 62, 64, 67, 70, 73, 76,
1137 79, 81, 84, 87, 90, 93, 96, 99,
1138 103, 106, 109, 112, 115, 118, 121, 124
1143 gst_video_test_src_zoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
1147 paintinfo pi = { NULL, };
1149 struct format_list_struct *format;
1150 struct vts_color_struct color;
1151 int t = v->n_frames;
1152 int w = frame->info.width, h = frame->info.height;
1153 int xreset = -(w / 2) - v->xoffset; /* starting values for x^2 and y^2, centering the ellipse */
1154 int yreset = -(h / 2) - v->yoffset;
1165 int delta_kxt = v->kxt * t;
1167 int scale_kxy = 0xffff / (w / 2);
1168 int scale_kx2 = 0xffff / w;
1170 videotestsrc_setup_paintinfo (v, p, w, h);
1175 format->paint_setup (p, frame);
1177 color = p->colors[COLOR_BLACK];
1180 /* Zoneplate equation:
1182 * phase = k0 + kx*x + ky*y + kt*t
1183 * + kxt*x*t + kyt*y*t + kxy*x*y
1184 * + kx2*x*x + ky2*y*y + Kt2*t*t
1188 for (j = 0, y = yreset; j < h; j++, y++) {
1189 for (i = 0, x = xreset; i < w; i++, x++) {
1195 phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t);
1198 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
1199 /* phase = phase + (v->kxy * x * y) / (w/2); */
1202 /*normalise x/y terms to rate of change of phase at the picture edge */
1204 phase + ((v->kx2 * x * x) / w) + ((v->ky2 * y * y) / h) +
1205 ((v->kt2 * t * t) >> 1);
1207 color.Y = sine_table[phase & 0xff];
1212 p->paint_tmpline (p, i, 1);
1217 /* optimised version, with original code shown in comments */
1221 kt2 = v->kt2 * t * t;
1222 for (j = 0, y = yreset; j < h; j++, y++) {
1226 accum_kyt += v->kyt * t;
1227 delta_kxy = v->kxy * y * scale_kxy;
1228 accum_kxy = delta_kxy * xreset;
1229 ky2 = (v->ky2 * y * y) / h;
1230 for (i = 0, x = xreset; i < w; i++, x++) {
1237 /* phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t); */
1238 phase = phase + accum_kx + accum_ky + kt;
1241 accum_kxt += delta_kxt;
1242 accum_kxy += delta_kxy;
1243 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
1244 phase = phase + accum_kxt + accum_kyt;
1246 /* phase = phase + (v->kxy * x * y) / (w/2); */
1247 /* phase = phase + accum_kxy / (w/2); */
1248 phase = phase + (accum_kxy >> 16);
1251 /*normalise x/y terms to rate of change of phase at the picture edge */
1252 /*phase = phase + ((v->kx2 * x * x)/w) + ((v->ky2 * y * y)/h) + ((v->kt2 * t * t)>>1); */
1253 phase = phase + ((v->kx2 * x * x * scale_kx2) >> 16) + ky2 + (kt2 >> 1);
1255 p->tmpline_u8[i] = sine_table[phase & 0xff];
1257 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1258 &p->foreground_color, &p->background_color, p->width);
1259 videotestsrc_convert_tmpline (p, j);
1264 gst_video_test_src_chromazoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
1268 paintinfo pi = { NULL, };
1270 struct format_list_struct *format;
1271 struct vts_color_struct color;
1272 int t = v->n_frames;
1273 int w = frame->info.width, h = frame->info.height;
1275 int xreset = -(w / 2) - v->xoffset; /* starting values for x^2 and y^2, centering the ellipse */
1276 int yreset = -(h / 2) - v->yoffset;
1287 int delta_kxt = v->kxt * t;
1289 int scale_kxy = 0xffff / (w / 2);
1290 int scale_kx2 = 0xffff / w;
1292 videotestsrc_setup_paintinfo (v, p, w, h);
1297 format->paint_setup (p, frame);
1299 color = p->colors[COLOR_BLACK];
1302 /* Zoneplate equation:
1304 * phase = k0 + kx*x + ky*y + kt*t
1305 * + kxt*x*t + kyt*y*t + kxy*x*y
1306 * + kx2*x*x + ky2*y*y + Kt2*t*t
1309 /* optimised version, with original code shown in comments */
1313 kt2 = v->kt2 * t * t;
1314 for (j = 0, y = yreset; j < h; j++, y++) {
1318 accum_kyt += v->kyt * t;
1319 delta_kxy = v->kxy * y * scale_kxy;
1320 accum_kxy = delta_kxy * xreset;
1321 ky2 = (v->ky2 * y * y) / h;
1322 for (i = 0, x = xreset; i < w; i++, x++) {
1329 /* phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t); */
1330 phase = phase + accum_kx + accum_ky + kt;
1333 accum_kxt += delta_kxt;
1334 accum_kxy += delta_kxy;
1335 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
1336 phase = phase + accum_kxt + accum_kyt;
1338 /* phase = phase + (v->kxy * x * y) / (w/2); */
1339 /* phase = phase + accum_kxy / (w/2); */
1340 phase = phase + (accum_kxy >> 16);
1343 /*normalise x/y terms to rate of change of phase at the picture edge */
1344 /*phase = phase + ((v->kx2 * x * x)/w) + ((v->ky2 * y * y)/h) + ((v->kt2 * t * t)>>1); */
1345 phase = phase + ((v->kx2 * x * x * scale_kx2) >> 16) + ky2 + (kt2 >> 1);
1348 color.U = sine_table[phase & 0xff];
1349 color.V = sine_table[phase & 0xff];
1355 color.gray = color.Y << 8;
1356 p->paint_tmpline (p, i, 1);
1358 videotestsrc_convert_tmpline (p, j);
1362 #undef SCALE_AMPLITUDE
1364 gst_video_test_src_circular (GstVideoTestSrc * v, GstVideoFrame * frame)
1368 paintinfo pi = { NULL, };
1370 struct format_list_struct *format;
1372 int w = frame->info.width, h = frame->info.height;
1376 videotestsrc_setup_paintinfo (v, p, w, h);
1381 format->paint_setup (p, frame);
1383 for (i = 1; i < 8; i++) {
1384 freq[i] = 200 * pow (2.0, -(i - 1) / 4.0);
1387 for (j = 0; j < h; j++) {
1388 for (i = 0; i < w; i++) {
1393 sqrt ((2 * i - w) * (2 * i - w) + (2 * j - h) * (2 * j -
1395 seg = floor (dist * 16);
1396 if (seg == 0 || seg >= 8) {
1397 p->tmpline_u8[i] = 0;
1399 d = floor (256 * dist * freq[seg] + 0.5);
1400 p->tmpline_u8[i] = sine_table[d & 0xff];
1403 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1404 &p->foreground_color, &p->background_color, p->width);
1405 videotestsrc_convert_tmpline (p, j);
1410 gst_video_test_src_gamut (GstVideoTestSrc * v, GstVideoFrame * frame)
1413 paintinfo pi = { NULL, };
1415 struct format_list_struct *format;
1416 struct vts_color_struct yuv_primary;
1417 struct vts_color_struct yuv_secondary;
1418 int w = frame->info.width, h = frame->info.height;
1420 videotestsrc_setup_paintinfo (v, p, w, h);
1425 format->paint_setup (p, frame);
1427 for (y = 0; y < h; y++) {
1428 int region = (y * 4) / h;
1432 yuv_primary = p->colors[COLOR_BLACK];
1433 yuv_secondary = p->colors[COLOR_BLACK];
1434 yuv_secondary.Y = 0;
1437 yuv_primary = p->colors[COLOR_WHITE];
1438 yuv_secondary = p->colors[COLOR_WHITE];
1439 yuv_secondary.Y = 255;
1442 yuv_primary = p->colors[COLOR_RED];
1443 yuv_secondary = p->colors[COLOR_RED];
1444 yuv_secondary.V = 255;
1447 yuv_primary = p->colors[COLOR_BLUE];
1448 yuv_secondary = p->colors[COLOR_BLUE];
1449 yuv_secondary.U = 255;
1453 for (x = 0; x < w; x += 8) {
1454 int len = MIN (8, w - x);
1456 if ((x ^ y) & (1 << 4)) {
1457 p->color = &yuv_primary;
1459 p->color = &yuv_secondary;
1461 p->paint_tmpline (p, x, len);
1463 videotestsrc_convert_tmpline (p, y);
1468 gst_video_test_src_ball (GstVideoTestSrc * v, GstVideoFrame * frame)
1471 paintinfo pi = { NULL, };
1473 struct format_list_struct *format;
1474 int t = v->n_frames;
1477 int w = frame->info.width, h = frame->info.height;
1479 videotestsrc_setup_paintinfo (v, p, w, h);
1484 format->paint_setup (p, frame);
1486 x = radius + (0.5 + 0.5 * sin (2 * G_PI * t / 200)) * (w - 2 * radius);
1487 y = radius + (0.5 + 0.5 * sin (2 * G_PI * sqrt (2) * t / 200)) * (h -
1490 for (i = 0; i < h; i++) {
1491 if (i < y - radius || i > y + radius) {
1492 memset (p->tmpline_u8, 0, w);
1494 int r = rint (sqrt (radius * radius - (i - y) * (i - y)));
1499 x2 = MAX (0, x - r);
1500 for (j = x1; j < x2; j++) {
1501 p->tmpline_u8[j] = 0;
1504 x1 = MAX (0, x - r);
1505 x2 = MIN (w, x + r + 1);
1506 for (j = x1; j < x2; j++) {
1507 double rr = radius - sqrt ((j - x) * (j - x) + (i - y) * (i - y));
1510 p->tmpline_u8[j] = CLAMP ((int) floor (256 * rr), 0, 255);
1513 x1 = MIN (w, x + r + 1);
1515 for (j = x1; j < x2; j++) {
1516 p->tmpline_u8[j] = 0;
1519 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1520 &p->foreground_color, &p->background_color, p->width);
1521 videotestsrc_convert_tmpline (p, i);
1526 paint_tmpline_ARGB (paintinfo * p, int x, int w)
1531 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1532 value = (p->color->A << 0) | (p->color->R << 8) |
1533 (p->color->G << 16) | (p->color->B << 24);
1535 value = (p->color->A << 24) | (p->color->R << 16) |
1536 (p->color->G << 8) | (p->color->B << 0);
1540 gst_orc_splat_u32 (p->tmpline + offset, value, w);
1544 paint_tmpline_AYUV (paintinfo * p, int x, int w)
1549 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1550 value = (p->color->A << 0) | (p->color->Y << 8) |
1551 (p->color->U << 16) | (p->color->V << 24);
1553 value = (p->color->A << 24) | (p->color->Y << 16) |
1554 (p->color->U << 8) | (p->color->V << 0);
1558 gst_orc_splat_u32 (p->tmpline + offset, value, w);
1563 paint_setup_I420 (paintinfo * p, GstVideoFrame * frame)
1565 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1566 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1567 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
1568 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
1569 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
1570 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
1571 p->size = frame->info.size;
1575 paint_setup_NV12 (paintinfo * p, GstVideoFrame * frame)
1577 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1578 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1579 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
1580 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
1582 p->vstride = p->ustride;
1583 p->size = frame->info.size;
1587 paint_setup_NV21 (paintinfo * p, GstVideoFrame * frame)
1589 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1590 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1591 p->vp = GST_VIDEO_FRAME_DATA (frame, 1);
1592 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 1);
1594 p->ustride = p->vstride;
1595 p->size = frame->info.size;
1599 convert_hline_I420 (paintinfo * p, int y)
1602 guint8 *Y = p->yp + y * p->ystride;
1603 guint8 *U = p->up + (y / 2) * p->ustride;
1604 guint8 *V = p->vp + (y / 2) * p->vstride;
1605 guint8 *ayuv = p->tmpline;
1607 for (i = 0; i < p->width; i++) {
1608 Y[i] = ayuv[4 * i + 1];
1610 for (i = 0; i < (p->width + 1) / 2; i++) {
1611 U[i] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1612 V[i] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1617 convert_hline_NV12 (paintinfo * p, int y)
1620 guint8 *Y = p->yp + y * p->ystride;
1621 guint8 *U = p->up + (y / 2) * p->ustride;
1622 guint8 *V = p->vp + (y / 2) * p->vstride;
1623 guint8 *ayuv = p->tmpline;
1625 for (i = 0; i < p->width; i++) {
1626 Y[i] = ayuv[4 * i + 1];
1628 for (i = 0; i < (p->width + 1) / 2; i++) {
1629 U[i * 2] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1630 V[i * 2] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1635 convert_hline_NV21 (paintinfo * p, int y)
1638 guint8 *Y = p->yp + y * p->ystride;
1639 guint8 *U = p->up + (y / 2) * p->ustride;
1640 guint8 *V = p->vp + (y / 2) * p->vstride;
1641 guint8 *ayuv = p->tmpline;
1643 for (i = 0; i < p->width; i++) {
1644 Y[i] = ayuv[4 * i + 1];
1646 for (i = 0; i < (p->width + 1) / 2; i++) {
1647 U[i * 2] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1648 V[i * 2] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1654 paint_setup_YV12 (paintinfo * p, GstVideoFrame * frame)
1656 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1657 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1658 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
1659 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
1660 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
1661 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
1662 p->size = frame->info.size;
1666 paint_setup_v308 (paintinfo * p, GstVideoFrame * frame)
1668 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1671 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1672 p->ustride = p->ystride;
1673 p->vstride = p->ystride;
1674 p->size = frame->info.size;
1678 paint_setup_AYUV (paintinfo * p, GstVideoFrame * frame)
1680 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
1684 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1685 p->ystride = p->astride;;
1686 p->ustride = p->astride;
1687 p->vstride = p->astride;
1688 p->size = frame->info.size;
1693 paint_setup_v410 (paintinfo * p, GstVideoFrame * frame)
1698 p->ystride = p->width * 4;
1699 p->endptr = dest + p->ystride * p->height;
1700 p->size = frame->info.size;
1705 paint_setup_v216 (paintinfo * p, GstVideoFrame * frame)
1707 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
1711 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1712 p->ystride = p->astride;;
1713 p->ustride = p->astride;
1714 p->vstride = p->astride;
1715 p->size = frame->info.size;
1719 paint_setup_v210 (paintinfo * p, GstVideoFrame * frame)
1721 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
1725 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1726 p->ystride = p->astride;;
1727 p->ustride = p->astride;
1728 p->vstride = p->astride;
1729 p->size = frame->info.size;
1733 paint_setup_UYVP (paintinfo * p, GstVideoFrame * frame)
1735 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
1739 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1740 p->ystride = p->astride;;
1741 p->ustride = p->astride;
1742 p->vstride = p->astride;
1743 p->size = frame->info.size;
1747 paint_setup_YUY2 (paintinfo * p, GstVideoFrame * frame)
1749 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1752 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1753 p->ustride = p->ystride;
1754 p->vstride = p->ystride;
1755 p->size = frame->info.size;
1759 paint_setup_UYVY (paintinfo * p, GstVideoFrame * frame)
1761 p->up = GST_VIDEO_FRAME_DATA (frame, 0);
1764 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1765 p->ustride = p->ystride;
1766 p->vstride = p->ystride;
1767 p->size = frame->info.size;
1771 paint_setup_YVYU (paintinfo * p, GstVideoFrame * frame)
1773 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
1776 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1777 p->ustride = p->ystride;
1778 p->vstride = p->ystride;
1779 p->size = frame->info.size;
1783 paint_setup_AY64 (paintinfo * p, GstVideoFrame * frame)
1785 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
1789 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1790 p->ystride = p->astride;
1791 p->ustride = p->astride;
1792 p->vstride = p->astride;
1793 p->size = frame->info.size;
1797 convert_hline_v308 (paintinfo * p, int y)
1800 guint8 *Y = p->yp + y * p->ystride;
1801 guint8 *U = p->up + y * p->ustride;
1802 guint8 *V = p->vp + y * p->vstride;
1803 guint8 *ayuv = p->tmpline;
1805 for (i = 0; i < p->width; i++) {
1806 Y[i * 3] = ayuv[4 * i + 1];
1807 U[i * 3] = ayuv[4 * i + 2];
1808 V[i * 3] = ayuv[4 * i + 3];
1813 convert_hline_AYUV (paintinfo * p, int y)
1816 guint8 *Y = p->yp + y * p->ystride;
1817 guint8 *U = p->up + y * p->ustride;
1818 guint8 *V = p->vp + y * p->vstride;
1819 guint8 *A = p->ap + y * p->ystride;
1820 guint8 *ayuv = p->tmpline;
1822 for (i = 0; i < p->width; i++) {
1823 A[i * 4] = ayuv[4 * i + 0];
1824 Y[i * 4] = ayuv[4 * i + 1];
1825 U[i * 4] = ayuv[4 * i + 2];
1826 V[i * 4] = ayuv[4 * i + 3];
1831 convert_hline_v216 (paintinfo * p, int y)
1834 guint8 *Y = p->yp + y * p->ystride;
1835 guint8 *U = p->up + y * p->ustride;
1836 guint8 *V = p->vp + y * p->vstride;
1837 guint8 *ayuv = p->tmpline;
1839 for (i = 0; i < p->width; i++) {
1840 GST_WRITE_UINT16_LE (Y + i * 4, TO_16 (ayuv[4 * i + 1]));
1842 for (i = 0; i < (p->width + 1) / 2; i++) {
1843 GST_WRITE_UINT16_LE (U + i * 8, TO_16 (ayuv[4 * (i * 2) + 2]));
1844 GST_WRITE_UINT16_LE (V + i * 8, TO_16 (ayuv[4 * (i * 2) + 3]));
1850 convert_hline_v410 (paintinfo * p, int y)
1853 guint8 *Y = p->yp + y * p->ystride;
1854 guint8 *ayuv = p->tmpline;
1856 for (i = 0; i < p->width; i++) {
1859 a = (TO_10 (ayuv[4 * i + 2]) << 22) |
1860 (TO_10 (ayuv[4 * i + 1]) << 12) | (TO_10 (ayuv[4 * i + 3]) << 2);
1861 GST_WRITE_UINT32_LE (Y + i * 4, a);
1867 convert_hline_v210 (paintinfo * p, int y)
1870 guint8 *Y = p->yp + y * p->ystride;
1871 guint8 *ayuv = p->tmpline;
1873 for (i = 0; i < p->width + 5; i += 6) {
1874 guint32 a0, a1, a2, a3;
1875 guint16 y0, y1, y2, y3, y4, y5;
1879 y0 = ayuv[4 * (i + 0) + 1];
1880 y1 = ayuv[4 * (i + 1) + 1];
1881 y2 = ayuv[4 * (i + 2) + 1];
1882 y3 = ayuv[4 * (i + 3) + 1];
1883 y4 = ayuv[4 * (i + 4) + 1];
1884 y5 = ayuv[4 * (i + 5) + 1];
1886 u0 = (ayuv[4 * (i + 0) + 2] + ayuv[4 * (i + 1) + 2] + 1) >> 1;
1887 u1 = (ayuv[4 * (i + 2) + 2] + ayuv[4 * (i + 3) + 2] + 1) >> 1;
1888 u2 = (ayuv[4 * (i + 4) + 2] + ayuv[4 * (i + 5) + 2] + 1) >> 1;
1890 v0 = (ayuv[4 * (i + 0) + 3] + ayuv[4 * (i + 1) + 3] + 1) >> 1;
1891 v1 = (ayuv[4 * (i + 2) + 3] + ayuv[4 * (i + 3) + 3] + 1) >> 1;
1892 v2 = (ayuv[4 * (i + 4) + 3] + ayuv[4 * (i + 5) + 3] + 1) >> 1;
1895 a0 = TO_10 (ayuv[4 * (i + 0) + 2]) | (TO_10 (ayuv[4 * (i + 0) + 1]) << 10)
1896 | (TO_10 (ayuv[4 * (i + 0) + 3]) << 20);
1897 a1 = TO_10 (ayuv[4 * (i + 1) + 1]) | (TO_10 (ayuv[4 * (i + 2) + 2]) << 10)
1898 | (TO_10 (ayuv[4 * (i + 2) + 1]) << 20);
1899 a2 = TO_10 (ayuv[4 * (i + 2) + 3]) | (TO_10 (ayuv[4 * (i + 3) + 1]) << 10)
1900 | (TO_10 (ayuv[4 * (i + 4) + 2]) << 20);
1901 a3 = TO_10 (ayuv[4 * (i + 4) + 1]) | (TO_10 (ayuv[4 * (i + 4) + 3]) << 10)
1902 | (TO_10 (ayuv[4 * (i + 5) + 1]) << 20);
1905 a0 = TO_10 (u0) | (TO_10 (y0) << 10) | (TO_10 (v0) << 20);
1906 a1 = TO_10 (y1) | (TO_10 (u1) << 10) | (TO_10 (y2) << 20);
1907 a2 = TO_10 (v1) | (TO_10 (y3) << 10) | (TO_10 (u2) << 20);
1908 a3 = TO_10 (y4) | (TO_10 (v2) << 10) | (TO_10 (y5) << 20);
1910 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 0, a0);
1911 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 4, a1);
1912 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 8, a2);
1913 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 12, a3);
1918 convert_hline_UYVP (paintinfo * p, int y)
1921 guint8 *Y = p->yp + y * p->ystride;
1922 guint8 *ayuv = p->tmpline;
1924 for (i = 0; i < p->width; i += 2) {
1929 y0 = ayuv[4 * (i + 0) + 1];
1930 y1 = ayuv[4 * (i + 1) + 1];
1931 u0 = (ayuv[4 * (i + 0) + 2] + ayuv[4 * (i + 1) + 2] + 1) >> 1;
1932 v0 = (ayuv[4 * (i + 0) + 3] + ayuv[4 * (i + 1) + 3] + 1) >> 1;
1934 Y[(i / 2) * 5 + 0] = u0;
1935 Y[(i / 2) * 5 + 1] = y0 >> 2;
1936 Y[(i / 2) * 5 + 2] = (y0 << 6) | (v0 >> 4);
1937 Y[(i / 2) * 5 + 3] = (v0 << 4) | (y1 >> 2);
1938 Y[(i / 2) * 5 + 4] = (y1 << 2);
1943 convert_hline_YUY2 (paintinfo * p, int y)
1946 guint8 *Y = p->yp + y * p->ystride;
1947 guint8 *U = p->up + y * p->ustride;
1948 guint8 *V = p->vp + y * p->vstride;
1949 guint8 *ayuv = p->tmpline;
1951 for (i = 0; i < p->width; i++) {
1952 Y[i * 2] = ayuv[4 * i + 1];
1954 for (i = 0; i < (p->width + 1) / 2; i++) {
1955 U[4 * i] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1956 V[4 * i] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1961 convert_hline_AY64 (paintinfo * p, int y)
1964 guint16 *ayuv16 = (guint16 *) (p->ap + y * p->ystride);
1965 guint8 *ayuv = p->tmpline;
1967 for (i = 0; i < p->width; i++) {
1968 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 0, TO_16 (ayuv[4 * i + 0]));
1969 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 1, TO_16 (ayuv[4 * i + 1]));
1970 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 2, TO_16 (ayuv[4 * i + 2]));
1971 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 3, TO_16 (ayuv[4 * i + 3]));
1977 paint_setup_IYU2 (paintinfo * p, GstVideoFrame * frame)
1980 p->up = GST_VIDEO_FRAME_DATA (frame, 0);
1983 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
1984 p->ustride = p->ystride;
1985 p->vstride = p->ystride;
1986 p->size = frame->info.size;
1990 convert_hline_IYU2 (paintinfo * p, int y)
1993 guint8 *Y = p->yp + y * p->ystride;
1994 guint8 *U = p->up + y * p->ustride;
1995 guint8 *V = p->vp + y * p->vstride;
1996 guint8 *ayuv = p->tmpline;
1998 for (i = 0; i < p->width; i++) {
1999 Y[i * 3] = ayuv[4 * i + 1];
2000 U[i * 3] = ayuv[4 * i + 2];
2001 V[i * 3] = ayuv[4 * i + 3];
2007 paint_setup_Y41B (paintinfo * p, GstVideoFrame * frame)
2009 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2010 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
2011 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
2012 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2013 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
2014 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
2015 p->size = frame->info.size;
2019 convert_hline_Y41B (paintinfo * p, int y)
2022 guint8 *Y = p->yp + y * p->ystride;
2023 guint8 *U = p->up + y * p->ustride;
2024 guint8 *V = p->vp + y * p->vstride;
2025 guint8 *ayuv = p->tmpline;
2027 for (i = 0; i < p->width; i++) {
2028 Y[i] = ayuv[4 * i + 1];
2030 for (i = 0; i < (p->width + 3) / 4; i++) {
2031 U[i] = (ayuv[4 * (i * 4) + 2] + ayuv[4 * (i * 4 + 1) + 2] +
2032 ayuv[4 * (i * 4 + 2) + 2] + ayuv[4 * (i * 4 + 3) + 2] + 2) >> 2;
2033 V[i] = (ayuv[4 * (i * 4) + 3] + ayuv[4 * (i * 4 + 1) + 3] +
2034 ayuv[4 * (i * 4 + 2) + 3] + ayuv[4 * (i * 4 + 3) + 3] + 2) >> 2;
2039 paint_setup_Y42B (paintinfo * p, GstVideoFrame * frame)
2041 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2042 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
2043 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
2044 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2045 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
2046 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
2047 p->size = frame->info.size;
2051 convert_hline_Y42B (paintinfo * p, int y)
2054 guint8 *Y = p->yp + y * p->ystride;
2055 guint8 *U = p->up + y * p->ustride;
2056 guint8 *V = p->vp + y * p->vstride;
2057 guint8 *ayuv = p->tmpline;
2059 for (i = 0; i < p->width; i++) {
2060 Y[i] = ayuv[4 * i + 1];
2062 for (i = 0; i < (p->width + 1) / 2; i++) {
2063 U[i] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
2064 V[i] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
2069 paint_setup_Y444 (paintinfo * p, GstVideoFrame * frame)
2071 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2072 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
2073 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
2074 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2075 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
2076 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
2077 p->size = frame->info.size;
2081 convert_hline_Y444 (paintinfo * p, int y)
2084 guint8 *Y = p->yp + y * p->ystride;
2085 guint8 *U = p->up + y * p->ustride;
2086 guint8 *V = p->vp + y * p->vstride;
2087 guint8 *ayuv = p->tmpline;
2089 for (i = 0; i < p->width; i++) {
2090 Y[i] = ayuv[4 * i + 1];
2091 U[i] = ayuv[4 * i + 2];
2092 V[i] = ayuv[4 * i + 3];
2097 paint_setup_Y800 (paintinfo * p, GstVideoFrame * frame)
2100 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2101 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2102 p->size = frame->info.size;
2106 convert_hline_Y800 (paintinfo * p, int y)
2109 guint8 *Y = p->yp + y * p->ystride;
2110 guint8 *ayuv = p->tmpline;
2112 for (i = 0; i < p->width; i++) {
2113 Y[i] = ayuv[4 * i + 1];
2118 paint_setup_YVU9 (paintinfo * p, GstVideoFrame * frame)
2120 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2121 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
2122 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
2123 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2124 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
2125 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
2126 p->size = frame->info.size;
2130 paint_setup_YUV9 (paintinfo * p, GstVideoFrame * frame)
2132 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2133 p->up = GST_VIDEO_FRAME_DATA (frame, 1);
2134 p->vp = GST_VIDEO_FRAME_DATA (frame, 2);
2135 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2136 p->ustride = GST_VIDEO_FRAME_STRIDE (frame, 1);
2137 p->vstride = GST_VIDEO_FRAME_STRIDE (frame, 2);
2138 p->size = frame->info.size;
2142 convert_hline_YUV9 (paintinfo * p, int y)
2145 guint8 *Y = p->yp + y * p->ystride;
2146 guint8 *U = p->up + (y / 4) * p->ustride;
2147 guint8 *V = p->vp + (y / 4) * p->vstride;
2148 guint8 *ayuv = p->tmpline;
2150 for (i = 0; i < p->width; i++) {
2151 Y[i] = ayuv[4 * i + 1];
2153 for (i = 0; i < (p->width + 3) / 4; i++) {
2154 U[i] = (ayuv[4 * (i * 4) + 2] + ayuv[4 * (i * 4 + 1) + 2] +
2155 ayuv[4 * (i * 4 + 2) + 2] + ayuv[4 * (i * 4 + 3) + 2] + 2) >> 2;
2156 V[i] = (ayuv[4 * (i * 4) + 3] + ayuv[4 * (i * 4 + 1) + 3] +
2157 ayuv[4 * (i * 4 + 2) + 3] + ayuv[4 * (i * 4 + 3) + 3] + 2) >> 2;
2162 paint_setup_ARGB8888 (paintinfo * p, GstVideoFrame * frame)
2164 paint_setup_xRGB8888 (p, frame);
2168 paint_setup_ABGR8888 (paintinfo * p, GstVideoFrame * frame)
2170 paint_setup_xBGR8888 (p, frame);
2174 paint_setup_RGBA8888 (paintinfo * p, GstVideoFrame * frame)
2176 paint_setup_RGBx8888 (p, frame);
2180 paint_setup_BGRA8888 (paintinfo * p, GstVideoFrame * frame)
2182 paint_setup_BGRx8888 (p, frame);
2186 paint_setup_xRGB8888 (paintinfo * p, GstVideoFrame * frame)
2188 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
2192 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2193 p->ystride = p->astride;
2194 p->ustride = p->astride;
2195 p->vstride = p->astride;
2196 p->size = frame->info.size;
2200 paint_setup_xBGR8888 (paintinfo * p, GstVideoFrame * frame)
2202 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
2206 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2207 p->ystride = p->astride;
2208 p->ustride = p->astride;
2209 p->vstride = p->astride;
2210 p->size = frame->info.size;
2214 paint_setup_RGBx8888 (paintinfo * p, GstVideoFrame * frame)
2216 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2220 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2221 p->ystride = p->astride;
2222 p->ustride = p->astride;
2223 p->vstride = p->astride;
2224 p->size = frame->info.size;
2228 paint_setup_BGRx8888 (paintinfo * p, GstVideoFrame * frame)
2230 p->vp = GST_VIDEO_FRAME_DATA (frame, 0);
2234 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2235 p->ystride = p->astride;
2236 p->ustride = p->astride;
2237 p->vstride = p->astride;
2238 p->size = frame->info.size;
2242 paint_setup_RGB888 (paintinfo * p, GstVideoFrame * frame)
2244 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2247 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2248 p->ustride = p->ystride;
2249 p->vstride = p->ystride;
2250 p->size = frame->info.size;
2254 paint_setup_BGR888 (paintinfo * p, GstVideoFrame * frame)
2256 p->vp = GST_VIDEO_FRAME_DATA (frame, 0);
2259 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2260 p->ustride = p->ystride;
2261 p->vstride = p->ystride;
2262 p->size = frame->info.size;
2266 paint_setup_ARGB64 (paintinfo * p, GstVideoFrame * frame)
2268 p->ap = GST_VIDEO_FRAME_DATA (frame, 0);
2272 p->astride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2273 p->ystride = p->astride;
2274 p->ustride = p->astride;
2275 p->vstride = p->astride;
2276 p->size = frame->info.size;
2280 convert_hline_str4 (paintinfo * p, int y)
2283 guint8 *A = p->ap + y * p->ystride;
2284 guint8 *R = p->yp + y * p->ystride;
2285 guint8 *G = p->up + y * p->ustride;
2286 guint8 *B = p->vp + y * p->vstride;
2287 guint8 *argb = p->tmpline;
2289 for (i = 0; i < p->width; i++) {
2291 R[4 * i] = argb[4 * i + 1];
2292 G[4 * i] = argb[4 * i + 2];
2293 B[4 * i] = argb[4 * i + 3];
2298 convert_hline_astr4 (paintinfo * p, int y)
2301 guint8 *A = p->ap + y * p->ystride;
2302 guint8 *R = p->yp + y * p->ystride;
2303 guint8 *G = p->up + y * p->ustride;
2304 guint8 *B = p->vp + y * p->vstride;
2305 guint8 *argb = p->tmpline;
2307 for (i = 0; i < p->width; i++) {
2308 A[4 * i] = argb[4 * i + 0];
2309 R[4 * i] = argb[4 * i + 1];
2310 G[4 * i] = argb[4 * i + 2];
2311 B[4 * i] = argb[4 * i + 3];
2316 convert_hline_astr8 (paintinfo * p, int y)
2319 guint16 *A = (guint16 *) (p->ap + y * p->ystride);
2320 guint16 *R = (guint16 *) (p->yp + y * p->ystride);
2321 guint16 *G = (guint16 *) (p->up + y * p->ustride);
2322 guint16 *B = (guint16 *) (p->vp + y * p->vstride);
2323 guint8 *argb = p->tmpline;
2325 for (i = 0; i < p->width; i++) {
2326 A[4 * i] = TO_16 (argb[4 * i + 0]);
2327 R[4 * i] = TO_16 (argb[4 * i + 1]);
2328 G[4 * i] = TO_16 (argb[4 * i + 2]);
2329 B[4 * i] = TO_16 (argb[4 * i + 3]);
2334 convert_hline_str3 (paintinfo * p, int y)
2337 guint8 *R = p->yp + y * p->ystride;
2338 guint8 *G = p->up + y * p->ustride;
2339 guint8 *B = p->vp + y * p->vstride;
2340 guint8 *argb = p->tmpline;
2342 for (i = 0; i < p->width; i++) {
2343 R[3 * i] = argb[4 * i + 1];
2344 G[3 * i] = argb[4 * i + 2];
2345 B[3 * i] = argb[4 * i + 3];
2350 paint_setup_RGB565 (paintinfo * p, GstVideoFrame * frame)
2352 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2353 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2354 p->ustride = p->ystride;
2355 p->vstride = p->ystride;
2356 p->size = frame->info.size;
2360 convert_hline_RGB565 (paintinfo * p, int y)
2363 guint8 *R = p->yp + y * p->ystride;
2364 guint8 *argb = p->tmpline;
2366 for (i = 0; i < p->width; i++) {
2367 guint16 value = ((argb[4 * i + 1] & 0xf8) << 8) |
2368 ((argb[4 * i + 2] & 0xfc) << 3) | ((argb[4 * i + 3] & 0xf8) >> 3);
2369 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2370 GST_WRITE_UINT16_LE (R + 2 * i, value);
2372 GST_WRITE_UINT16_BE (R + 2 * i, value);
2378 convert_hline_xRGB1555 (paintinfo * p, int y)
2381 guint8 *R = p->yp + y * p->ystride;
2382 guint8 *argb = p->tmpline;
2384 for (i = 0; i < p->width; i++) {
2385 guint16 value = ((argb[4 * i + 1] & 0xf8) << 7) |
2386 ((argb[4 * i + 2] & 0xf8) << 2) | ((argb[4 * i + 3] & 0xf8) >> 3);
2387 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2388 GST_WRITE_UINT16_LE (R + 2 * i, value);
2390 GST_WRITE_UINT16_BE (R + 2 * i, value);
2396 paint_setup_xRGB1555 (paintinfo * p, GstVideoFrame * frame)
2398 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2399 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2400 p->ustride = p->ystride;
2401 p->vstride = p->ystride;
2402 p->size = frame->info.size;
2407 paint_setup_bayer_bggr (paintinfo * p, GstVideoFrame * frame)
2409 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2410 p->ystride = GST_ROUND_UP_4 (p->width);
2411 p->ustride = GST_ROUND_UP_4 (p->width);
2412 p->vstride = GST_ROUND_UP_4 (p->width);
2413 p->size = p->ystride * p->height;
2414 p->bayer_x_invert = 0;
2415 p->bayer_y_invert = 0;
2419 paint_setup_bayer_rggb (paintinfo * p, GstVideoFrame * frame)
2421 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2422 p->ystride = GST_ROUND_UP_4 (p->width);
2423 p->ustride = GST_ROUND_UP_4 (p->width);
2424 p->vstride = GST_ROUND_UP_4 (p->width);
2425 p->size = p->ystride * p->height;
2426 p->bayer_x_invert = 1;
2427 p->bayer_y_invert = 1;
2431 paint_setup_bayer_grbg (paintinfo * p, GstVideoFrame * frame)
2433 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2434 p->ystride = GST_ROUND_UP_4 (p->width);
2435 p->ustride = GST_ROUND_UP_4 (p->width);
2436 p->vstride = GST_ROUND_UP_4 (p->width);
2437 p->size = p->ystride * p->height;
2438 p->bayer_x_invert = 0;
2439 p->bayer_y_invert = 1;
2443 paint_setup_bayer_gbrg (paintinfo * p, GstVideoFrame * frame)
2445 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2446 p->ystride = GST_ROUND_UP_4 (p->width);
2447 p->ustride = GST_ROUND_UP_4 (p->width);
2448 p->vstride = GST_ROUND_UP_4 (p->width);
2449 p->size = p->ystride * p->height;
2450 p->bayer_x_invert = 1;
2451 p->bayer_y_invert = 0;
2455 convert_hline_bayer (paintinfo * p, int y)
2458 guint8 *R = p->yp + y * p->ystride;
2459 guint8 *argb = p->tmpline;
2460 int x_inv = p->bayer_x_invert;
2461 int y_inv = p->bayer_y_invert;
2463 if ((y ^ y_inv) & 1) {
2464 for (i = 0; i < p->width; i++) {
2465 if ((i ^ x_inv) & 1) {
2466 R[i] = argb[4 * i + 1];
2468 R[i] = argb[4 * i + 2];
2472 for (i = 0; i < p->width; i++) {
2473 if ((i ^ x_inv) & 1) {
2474 R[i] = argb[4 * i + 2];
2476 R[i] = argb[4 * i + 3];
2483 paint_setup_GRAY8 (paintinfo * p, GstVideoFrame * frame)
2485 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2486 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2487 p->size = frame->info.size;
2491 convert_hline_GRAY8 (paintinfo * p, int y)
2494 guint8 *Y = p->yp + y * p->ystride;
2495 guint8 *ayuv = p->tmpline;
2497 /* FIXME this should use gray, not YUV */
2498 for (i = 0; i < p->width; i++) {
2499 Y[i] = ayuv[4 * i + 1];
2504 paint_setup_GRAY16 (paintinfo * p, GstVideoFrame * frame)
2506 p->yp = GST_VIDEO_FRAME_DATA (frame, 0);
2507 p->ystride = GST_VIDEO_FRAME_STRIDE (frame, 0);
2508 p->size = frame->info.size;
2512 convert_hline_GRAY16 (paintinfo * p, int y)
2515 guint8 *Y = p->yp + y * p->ystride;
2516 guint8 *ayuv = p->tmpline;
2518 /* FIXME this should use gray, not YUV */
2519 for (i = 0; i < p->width; i++) {
2520 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2521 GST_WRITE_UINT16_LE (Y + i * 2, ayuv[4 * i + 1] << 8);
2523 GST_WRITE_UINT16_BE (Y + i * 2, ayuv[4 * i + 1] << 8);