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, unsigned char *dest);
129 static void paint_setup_YV12 (paintinfo * p, unsigned char *dest);
130 static void paint_setup_YUY2 (paintinfo * p, unsigned char *dest);
131 static void paint_setup_UYVY (paintinfo * p, unsigned char *dest);
132 static void paint_setup_YVYU (paintinfo * p, unsigned char *dest);
134 static void paint_setup_IYU2 (paintinfo * p, unsigned char *dest);
136 static void paint_setup_Y41B (paintinfo * p, unsigned char *dest);
137 static void paint_setup_Y42B (paintinfo * p, unsigned char *dest);
138 static void paint_setup_Y444 (paintinfo * p, unsigned char *dest);
139 static void paint_setup_Y800 (paintinfo * p, unsigned char *dest);
140 static void paint_setup_AYUV (paintinfo * p, unsigned char *dest);
141 static void paint_setup_v308 (paintinfo * p, unsigned char *dest);
142 static void paint_setup_NV12 (paintinfo * p, unsigned char *dest);
143 static void paint_setup_NV21 (paintinfo * p, unsigned char *dest);
145 static void paint_setup_v410 (paintinfo * p, unsigned char *dest);
147 static void paint_setup_v216 (paintinfo * p, unsigned char *dest);
148 static void paint_setup_v210 (paintinfo * p, unsigned char *dest);
149 static void paint_setup_UYVP (paintinfo * p, unsigned char *dest);
150 static void paint_setup_AY64 (paintinfo * p, unsigned char *dest);
152 static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest);
153 static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest);
154 static void paint_setup_ARGB8888 (paintinfo * p, unsigned char *dest);
155 static void paint_setup_ABGR8888 (paintinfo * p, unsigned char *dest);
156 static void paint_setup_RGBA8888 (paintinfo * p, unsigned char *dest);
157 static void paint_setup_BGRA8888 (paintinfo * p, unsigned char *dest);
158 static void paint_setup_xRGB8888 (paintinfo * p, unsigned char *dest);
159 static void paint_setup_xBGR8888 (paintinfo * p, unsigned char *dest);
160 static void paint_setup_RGBx8888 (paintinfo * p, unsigned char *dest);
161 static void paint_setup_BGRx8888 (paintinfo * p, unsigned char *dest);
162 static void paint_setup_RGB888 (paintinfo * p, unsigned char *dest);
163 static void paint_setup_BGR888 (paintinfo * p, unsigned char *dest);
164 static void paint_setup_RGB565 (paintinfo * p, unsigned char *dest);
165 static void paint_setup_xRGB1555 (paintinfo * p, unsigned char *dest);
166 static void paint_setup_ARGB64 (paintinfo * p, unsigned char *dest);
168 static void paint_setup_bayer_bggr (paintinfo * p, unsigned char *dest);
169 static void paint_setup_bayer_rggb (paintinfo * p, unsigned char *dest);
170 static void paint_setup_bayer_gbrg (paintinfo * p, unsigned char *dest);
171 static void paint_setup_bayer_grbg (paintinfo * p, unsigned char *dest);
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, unsigned char *dest);
205 static void paint_setup_GRAY16 (paintinfo * p, unsigned char *dest);
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 (strcmp (find_format, format_list[i].format) == 0) {
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 (strcmp (name, format_list[i].name) == 0) {
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);
463 return (unsigned long) p->endptr;
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, unsigned char *dest, int w,
644 paintinfo pi = { NULL, };
646 struct format_list_struct *format;
648 videotestsrc_setup_paintinfo (v, p, w, h);
653 format->paint_setup (p, dest);
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, unsigned char *dest, int w,
749 paintinfo pi = { NULL, };
751 struct format_list_struct *format;
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, dest);
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, unsigned char *dest, int w,
784 paintinfo pi = { NULL, };
786 struct format_list_struct *format;
788 videotestsrc_setup_paintinfo (v, p, w, h);
793 format->paint_setup (p, dest);
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, unsigned char *dest, int w, int h)
812 paintinfo pi = { NULL, };
814 struct format_list_struct *format;
816 videotestsrc_setup_paintinfo (v, p, w, h);
821 format->paint_setup (p, dest);
823 for (j = 0; j < h; j++) {
824 /* use fixed size for now */
827 p->color = &p->foreground_color;
828 p->paint_tmpline (p, 0, x2);
829 p->color = &p->background_color;
830 p->paint_tmpline (p, x2, (w - x2));
831 videotestsrc_convert_tmpline (p, j);
836 gst_video_test_src_snow (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
840 paintinfo pi = { NULL, };
842 struct format_list_struct *format;
843 struct vts_color_struct color;
845 videotestsrc_setup_paintinfo (v, p, w, h);
850 format->paint_setup (p, dest);
852 color = p->colors[COLOR_BLACK];
855 for (j = 0; j < h; j++) {
856 for (i = 0; i < w; i++) {
857 int y = random_char ();
858 p->tmpline_u8[i] = y;
860 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
861 &p->foreground_color, &p->background_color, p->width);
862 videotestsrc_convert_tmpline (p, j);
867 gst_video_test_src_unicolor (GstVideoTestSrc * v, unsigned char *dest, int w,
868 int h, int color_index)
871 paintinfo pi = { NULL, };
873 struct format_list_struct *format;
875 videotestsrc_setup_paintinfo (v, p, w, h);
880 format->paint_setup (p, dest);
882 p->color = p->colors + color_index;
883 if (color_index == COLOR_BLACK) {
884 p->color = &p->background_color;
886 if (color_index == COLOR_WHITE) {
887 p->color = &p->foreground_color;
890 for (i = 0; i < h; i++) {
891 p->paint_tmpline (p, 0, w);
892 videotestsrc_convert_tmpline (p, i);
897 gst_video_test_src_black (GstVideoTestSrc * v, guchar * dest, int w, int h)
899 gst_video_test_src_unicolor (v, dest, w, h, COLOR_BLACK);
903 gst_video_test_src_white (GstVideoTestSrc * v, guchar * dest, int w, int h)
905 gst_video_test_src_unicolor (v, dest, w, h, COLOR_WHITE);
909 gst_video_test_src_red (GstVideoTestSrc * v, guchar * dest, int w, int h)
911 gst_video_test_src_unicolor (v, dest, w, h, COLOR_RED);
915 gst_video_test_src_green (GstVideoTestSrc * v, guchar * dest, int w, int h)
917 gst_video_test_src_unicolor (v, dest, w, h, COLOR_GREEN);
921 gst_video_test_src_blue (GstVideoTestSrc * v, guchar * dest, int w, int h)
923 gst_video_test_src_unicolor (v, dest, w, h, COLOR_BLUE);
927 gst_video_test_src_blink (GstVideoTestSrc * v, unsigned char *dest, int w,
931 paintinfo pi = { NULL, };
933 struct format_list_struct *format;
935 videotestsrc_setup_paintinfo (v, p, w, h);
941 format->paint_setup (p, dest);
943 if (v->n_frames & 1) {
944 p->color = &p->foreground_color;
946 p->color = &p->background_color;
949 for (i = 0; i < h; i++) {
950 p->paint_tmpline (p, 0, w);
951 videotestsrc_convert_tmpline (p, i);
956 gst_video_test_src_solid (GstVideoTestSrc * v, unsigned char *dest, int w,
960 paintinfo pi = { NULL, };
962 struct format_list_struct *format;
964 videotestsrc_setup_paintinfo (v, p, w, h);
970 format->paint_setup (p, dest);
972 p->color = &p->foreground_color;
974 for (i = 0; i < h; i++) {
975 p->paint_tmpline (p, 0, w);
976 videotestsrc_convert_tmpline (p, i);
981 gst_video_test_src_checkers1 (GstVideoTestSrc * v, guchar * dest, int w, int h)
984 paintinfo pi = { NULL, };
986 struct format_list_struct *format;
988 videotestsrc_setup_paintinfo (v, p, w, h);
994 format->paint_setup (p, dest);
996 for (y = 0; y < h; y++) {
997 for (x = 0; x < w; x++) {
999 p->color = p->colors + COLOR_GREEN;
1001 p->color = p->colors + COLOR_RED;
1003 p->paint_tmpline (p, x, 1);
1005 videotestsrc_convert_tmpline (p, y);
1010 gst_video_test_src_checkers2 (GstVideoTestSrc * v, guchar * dest, int w, int h)
1013 paintinfo pi = { NULL, };
1015 struct format_list_struct *format;
1017 videotestsrc_setup_paintinfo (v, p, w, h);
1022 format->paint_setup (p, dest);
1024 for (y = 0; y < h; y++) {
1025 for (x = 0; x < w; x += 2) {
1026 guint len = MIN (2, w - x);
1029 p->color = p->colors + COLOR_GREEN;
1031 p->color = p->colors + COLOR_RED;
1033 p->paint_tmpline (p, x, len);
1035 videotestsrc_convert_tmpline (p, y);
1040 gst_video_test_src_checkers4 (GstVideoTestSrc * v, guchar * dest, int w, int h)
1043 paintinfo pi = { NULL, };
1045 struct format_list_struct *format;
1047 videotestsrc_setup_paintinfo (v, p, w, h);
1052 format->paint_setup (p, dest);
1054 for (y = 0; y < h; y++) {
1055 for (x = 0; x < w; x += 4) {
1056 guint len = MIN (4, w - x);
1059 p->color = p->colors + COLOR_GREEN;
1061 p->color = p->colors + COLOR_RED;
1063 p->paint_tmpline (p, x, len);
1065 videotestsrc_convert_tmpline (p, y);
1070 gst_video_test_src_checkers8 (GstVideoTestSrc * v, guchar * dest, int w, int h)
1073 paintinfo pi = { NULL, };
1075 struct format_list_struct *format;
1077 videotestsrc_setup_paintinfo (v, p, w, h);
1082 format->paint_setup (p, dest);
1084 for (y = 0; y < h; y++) {
1085 for (x = 0; x < w; x += 8) {
1086 guint len = MIN (8, w - x);
1089 p->color = p->colors + COLOR_GREEN;
1091 p->color = p->colors + COLOR_RED;
1093 p->paint_tmpline (p, x, len);
1095 videotestsrc_convert_tmpline (p, y);
1099 static const guint8 sine_table[256] = {
1100 128, 131, 134, 137, 140, 143, 146, 149,
1101 152, 156, 159, 162, 165, 168, 171, 174,
1102 176, 179, 182, 185, 188, 191, 193, 196,
1103 199, 201, 204, 206, 209, 211, 213, 216,
1104 218, 220, 222, 224, 226, 228, 230, 232,
1105 234, 236, 237, 239, 240, 242, 243, 245,
1106 246, 247, 248, 249, 250, 251, 252, 252,
1107 253, 254, 254, 255, 255, 255, 255, 255,
1108 255, 255, 255, 255, 255, 255, 254, 254,
1109 253, 252, 252, 251, 250, 249, 248, 247,
1110 246, 245, 243, 242, 240, 239, 237, 236,
1111 234, 232, 230, 228, 226, 224, 222, 220,
1112 218, 216, 213, 211, 209, 206, 204, 201,
1113 199, 196, 193, 191, 188, 185, 182, 179,
1114 176, 174, 171, 168, 165, 162, 159, 156,
1115 152, 149, 146, 143, 140, 137, 134, 131,
1116 128, 124, 121, 118, 115, 112, 109, 106,
1117 103, 99, 96, 93, 90, 87, 84, 81,
1118 79, 76, 73, 70, 67, 64, 62, 59,
1119 56, 54, 51, 49, 46, 44, 42, 39,
1120 37, 35, 33, 31, 29, 27, 25, 23,
1121 21, 19, 18, 16, 15, 13, 12, 10,
1122 9, 8, 7, 6, 5, 4, 3, 3,
1123 2, 1, 1, 0, 0, 0, 0, 0,
1124 0, 0, 0, 0, 0, 0, 1, 1,
1125 2, 3, 3, 4, 5, 6, 7, 8,
1126 9, 10, 12, 13, 15, 16, 18, 19,
1127 21, 23, 25, 27, 29, 31, 33, 35,
1128 37, 39, 42, 44, 46, 49, 51, 54,
1129 56, 59, 62, 64, 67, 70, 73, 76,
1130 79, 81, 84, 87, 90, 93, 96, 99,
1131 103, 106, 109, 112, 115, 118, 121, 124
1136 gst_video_test_src_zoneplate (GstVideoTestSrc * v, unsigned char *dest,
1141 paintinfo pi = { NULL, };
1143 struct format_list_struct *format;
1144 struct vts_color_struct color;
1145 int t = v->n_frames;
1146 int xreset = -(w / 2) - v->xoffset; /* starting values for x^2 and y^2, centering the ellipse */
1147 int yreset = -(h / 2) - v->yoffset;
1158 int delta_kxt = v->kxt * t;
1160 int scale_kxy = 0xffff / (w / 2);
1161 int scale_kx2 = 0xffff / w;
1163 videotestsrc_setup_paintinfo (v, p, w, h);
1168 format->paint_setup (p, dest);
1170 color = p->colors[COLOR_BLACK];
1173 /* Zoneplate equation:
1175 * phase = k0 + kx*x + ky*y + kt*t
1176 * + kxt*x*t + kyt*y*t + kxy*x*y
1177 * + kx2*x*x + ky2*y*y + Kt2*t*t
1181 for (j = 0, y = yreset; j < h; j++, y++) {
1182 for (i = 0, x = xreset; i < w; i++, x++) {
1188 phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t);
1191 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
1192 /* phase = phase + (v->kxy * x * y) / (w/2); */
1195 /*normalise x/y terms to rate of change of phase at the picture edge */
1197 phase + ((v->kx2 * x * x) / w) + ((v->ky2 * y * y) / h) +
1198 ((v->kt2 * t * t) >> 1);
1200 color.Y = sine_table[phase & 0xff];
1205 p->paint_tmpline (p, i, 1);
1210 /* optimised version, with original code shown in comments */
1214 kt2 = v->kt2 * t * t;
1215 for (j = 0, y = yreset; j < h; j++, y++) {
1219 accum_kyt += v->kyt * t;
1220 delta_kxy = v->kxy * y * scale_kxy;
1221 accum_kxy = delta_kxy * xreset;
1222 ky2 = (v->ky2 * y * y) / h;
1223 for (i = 0, x = xreset; i < w; i++, x++) {
1230 /* phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t); */
1231 phase = phase + accum_kx + accum_ky + kt;
1234 accum_kxt += delta_kxt;
1235 accum_kxy += delta_kxy;
1236 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
1237 phase = phase + accum_kxt + accum_kyt;
1239 /* phase = phase + (v->kxy * x * y) / (w/2); */
1240 /* phase = phase + accum_kxy / (w/2); */
1241 phase = phase + (accum_kxy >> 16);
1244 /*normalise x/y terms to rate of change of phase at the picture edge */
1245 /*phase = phase + ((v->kx2 * x * x)/w) + ((v->ky2 * y * y)/h) + ((v->kt2 * t * t)>>1); */
1246 phase = phase + ((v->kx2 * x * x * scale_kx2) >> 16) + ky2 + (kt2 >> 1);
1248 p->tmpline_u8[i] = sine_table[phase & 0xff];
1250 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1251 &p->foreground_color, &p->background_color, p->width);
1252 videotestsrc_convert_tmpline (p, j);
1257 gst_video_test_src_chromazoneplate (GstVideoTestSrc * v, unsigned char *dest,
1262 paintinfo pi = { NULL, };
1264 struct format_list_struct *format;
1265 struct vts_color_struct color;
1266 int t = v->n_frames;
1268 int xreset = -(w / 2) - v->xoffset; /* starting values for x^2 and y^2, centering the ellipse */
1269 int yreset = -(h / 2) - v->yoffset;
1280 int delta_kxt = v->kxt * t;
1282 int scale_kxy = 0xffff / (w / 2);
1283 int scale_kx2 = 0xffff / w;
1285 videotestsrc_setup_paintinfo (v, p, w, h);
1290 format->paint_setup (p, dest);
1292 color = p->colors[COLOR_BLACK];
1295 /* Zoneplate equation:
1297 * phase = k0 + kx*x + ky*y + kt*t
1298 * + kxt*x*t + kyt*y*t + kxy*x*y
1299 * + kx2*x*x + ky2*y*y + Kt2*t*t
1302 /* optimised version, with original code shown in comments */
1306 kt2 = v->kt2 * t * t;
1307 for (j = 0, y = yreset; j < h; j++, y++) {
1311 accum_kyt += v->kyt * t;
1312 delta_kxy = v->kxy * y * scale_kxy;
1313 accum_kxy = delta_kxy * xreset;
1314 ky2 = (v->ky2 * y * y) / h;
1315 for (i = 0, x = xreset; i < w; i++, x++) {
1322 /* phase = phase + (v->kx * i) + (v->ky * j) + (v->kt * t); */
1323 phase = phase + accum_kx + accum_ky + kt;
1326 accum_kxt += delta_kxt;
1327 accum_kxy += delta_kxy;
1328 /* phase = phase + (v->kxt * i * t) + (v->kyt * j * t); */
1329 phase = phase + accum_kxt + accum_kyt;
1331 /* phase = phase + (v->kxy * x * y) / (w/2); */
1332 /* phase = phase + accum_kxy / (w/2); */
1333 phase = phase + (accum_kxy >> 16);
1336 /*normalise x/y terms to rate of change of phase at the picture edge */
1337 /*phase = phase + ((v->kx2 * x * x)/w) + ((v->ky2 * y * y)/h) + ((v->kt2 * t * t)>>1); */
1338 phase = phase + ((v->kx2 * x * x * scale_kx2) >> 16) + ky2 + (kt2 >> 1);
1341 color.U = sine_table[phase & 0xff];
1342 color.V = sine_table[phase & 0xff];
1348 color.gray = color.Y << 8;
1349 p->paint_tmpline (p, i, 1);
1351 videotestsrc_convert_tmpline (p, j);
1355 #undef SCALE_AMPLITUDE
1357 gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
1362 paintinfo pi = { NULL, };
1364 struct format_list_struct *format;
1369 videotestsrc_setup_paintinfo (v, p, w, h);
1374 format->paint_setup (p, dest);
1376 for (i = 1; i < 8; i++) {
1377 freq[i] = 200 * pow (2.0, -(i - 1) / 4.0);
1380 for (j = 0; j < h; j++) {
1381 for (i = 0; i < w; i++) {
1386 sqrt ((2 * i - w) * (2 * i - w) + (2 * j - h) * (2 * j -
1388 seg = floor (dist * 16);
1389 if (seg == 0 || seg >= 8) {
1390 p->tmpline_u8[i] = 0;
1392 d = floor (256 * dist * freq[seg] + 0.5);
1393 p->tmpline_u8[i] = sine_table[d & 0xff];
1396 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1397 &p->foreground_color, &p->background_color, p->width);
1398 videotestsrc_convert_tmpline (p, j);
1403 gst_video_test_src_gamut (GstVideoTestSrc * v, guchar * dest, int w, int h)
1406 paintinfo pi = { NULL, };
1408 struct format_list_struct *format;
1409 struct vts_color_struct yuv_primary;
1410 struct vts_color_struct yuv_secondary;
1412 videotestsrc_setup_paintinfo (v, p, w, h);
1417 format->paint_setup (p, dest);
1419 for (y = 0; y < h; y++) {
1420 int region = (y * 4) / h;
1424 yuv_primary = p->colors[COLOR_BLACK];
1425 yuv_secondary = p->colors[COLOR_BLACK];
1426 yuv_secondary.Y = 0;
1429 yuv_primary = p->colors[COLOR_WHITE];
1430 yuv_secondary = p->colors[COLOR_WHITE];
1431 yuv_secondary.Y = 255;
1434 yuv_primary = p->colors[COLOR_RED];
1435 yuv_secondary = p->colors[COLOR_RED];
1436 yuv_secondary.V = 255;
1439 yuv_primary = p->colors[COLOR_BLUE];
1440 yuv_secondary = p->colors[COLOR_BLUE];
1441 yuv_secondary.U = 255;
1445 for (x = 0; x < w; x += 8) {
1446 int len = MIN (8, w - x);
1448 if ((x ^ y) & (1 << 4)) {
1449 p->color = &yuv_primary;
1451 p->color = &yuv_secondary;
1453 p->paint_tmpline (p, x, len);
1455 videotestsrc_convert_tmpline (p, y);
1460 gst_video_test_src_ball (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
1463 paintinfo pi = { NULL, };
1465 struct format_list_struct *format;
1466 int t = v->n_frames;
1470 videotestsrc_setup_paintinfo (v, p, w, h);
1475 format->paint_setup (p, dest);
1477 x = radius + (0.5 + 0.5 * sin (2 * G_PI * t / 200)) * (w - 2 * radius);
1478 y = radius + (0.5 + 0.5 * sin (2 * G_PI * sqrt (2) * t / 200)) * (h -
1481 for (i = 0; i < h; i++) {
1482 if (i < y - radius || i > y + radius) {
1483 memset (p->tmpline_u8, 0, w);
1485 int r = rint (sqrt (radius * radius - (i - y) * (i - y)));
1490 x2 = MAX (0, x - r);
1491 for (j = x1; j < x2; j++) {
1492 p->tmpline_u8[j] = 0;
1495 x1 = MAX (0, x - r);
1496 x2 = MIN (w, x + r + 1);
1497 for (j = x1; j < x2; j++) {
1498 double rr = radius - sqrt ((j - x) * (j - x) + (i - y) * (i - y));
1501 p->tmpline_u8[j] = CLAMP ((int) floor (256 * rr), 0, 255);
1504 x1 = MIN (w, x + r + 1);
1506 for (j = x1; j < x2; j++) {
1507 p->tmpline_u8[j] = 0;
1510 videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
1511 &p->foreground_color, &p->background_color, p->width);
1512 videotestsrc_convert_tmpline (p, i);
1517 paint_tmpline_ARGB (paintinfo * p, int x, int w)
1522 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1523 value = (p->color->A << 0) | (p->color->R << 8) |
1524 (p->color->G << 16) | (p->color->B << 24);
1526 value = (p->color->A << 24) | (p->color->R << 16) |
1527 (p->color->G << 8) | (p->color->B << 0);
1531 gst_orc_splat_u32 (p->tmpline + offset, value, w);
1535 paint_tmpline_AYUV (paintinfo * p, int x, int w)
1540 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1541 value = (p->color->A << 0) | (p->color->Y << 8) |
1542 (p->color->U << 16) | (p->color->V << 24);
1544 value = (p->color->A << 24) | (p->color->Y << 16) |
1545 (p->color->U << 8) | (p->color->V << 0);
1549 gst_orc_splat_u32 (p->tmpline + offset, value, w);
1554 paint_setup_I420 (paintinfo * p, unsigned char *dest)
1557 p->ystride = GST_ROUND_UP_4 (p->width);
1558 p->up = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
1559 p->ustride = GST_ROUND_UP_8 (p->width) / 2;
1560 p->vp = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
1561 p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
1562 p->endptr = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
1566 paint_setup_NV12 (paintinfo * p, unsigned char *dest)
1569 p->ystride = GST_ROUND_UP_4 (p->width);
1570 p->up = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
1572 p->ustride = p->ystride;
1573 p->vstride = p->ystride;
1574 p->endptr = p->up + (p->ystride * GST_ROUND_UP_2 (p->height)) / 2;
1578 paint_setup_NV21 (paintinfo * p, unsigned char *dest)
1581 p->ystride = GST_ROUND_UP_4 (p->width);
1582 p->vp = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
1584 p->ustride = p->ystride;
1585 p->vstride = p->ystride;
1586 p->endptr = p->vp + (p->ystride * GST_ROUND_UP_2 (p->height)) / 2;
1590 convert_hline_I420 (paintinfo * p, int y)
1593 guint8 *Y = p->yp + y * p->ystride;
1594 guint8 *U = p->up + (y / 2) * p->ustride;
1595 guint8 *V = p->vp + (y / 2) * p->vstride;
1596 guint8 *ayuv = p->tmpline;
1598 for (i = 0; i < p->width; i++) {
1599 Y[i] = ayuv[4 * i + 1];
1601 for (i = 0; i < (p->width + 1) / 2; i++) {
1602 U[i] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1603 V[i] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1608 convert_hline_NV12 (paintinfo * p, int y)
1611 guint8 *Y = p->yp + y * p->ystride;
1612 guint8 *U = p->up + (y / 2) * p->ustride;
1613 guint8 *V = p->vp + (y / 2) * p->vstride;
1614 guint8 *ayuv = p->tmpline;
1616 for (i = 0; i < p->width; i++) {
1617 Y[i] = ayuv[4 * i + 1];
1619 for (i = 0; i < (p->width + 1) / 2; i++) {
1620 U[i * 2] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1621 V[i * 2] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1626 convert_hline_NV21 (paintinfo * p, int y)
1629 guint8 *Y = p->yp + y * p->ystride;
1630 guint8 *U = p->up + (y / 2) * p->ustride;
1631 guint8 *V = p->vp + (y / 2) * p->vstride;
1632 guint8 *ayuv = p->tmpline;
1634 for (i = 0; i < p->width; i++) {
1635 Y[i] = ayuv[4 * i + 1];
1637 for (i = 0; i < (p->width + 1) / 2; i++) {
1638 U[i * 2] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1639 V[i * 2] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1645 paint_setup_YV12 (paintinfo * p, unsigned char *dest)
1648 p->ystride = GST_ROUND_UP_4 (p->width);
1649 p->vp = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
1650 p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
1651 p->up = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
1652 p->ustride = GST_ROUND_UP_8 (p->ystride) / 2;
1653 p->endptr = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
1657 paint_setup_v308 (paintinfo * p, unsigned char *dest)
1662 p->ystride = GST_ROUND_UP_4 (p->width * 3);
1663 p->ustride = GST_ROUND_UP_4 (p->width * 3);
1664 p->vstride = GST_ROUND_UP_4 (p->width * 3);
1665 p->endptr = dest + p->ystride * p->height;
1669 paint_setup_AYUV (paintinfo * p, unsigned char *dest)
1675 p->ystride = p->width * 4;
1676 p->ustride = p->width * 4;
1677 p->vstride = p->width * 4;
1678 p->endptr = dest + p->ystride * p->height;
1683 paint_setup_v410 (paintinfo * p, unsigned char *dest)
1688 p->ystride = p->width * 4;
1689 p->endptr = dest + p->ystride * p->height;
1694 paint_setup_v216 (paintinfo * p, unsigned char *dest)
1700 p->ystride = p->width * 4;
1701 p->ustride = p->width * 4;
1702 p->vstride = p->width * 4;
1703 p->endptr = dest + p->ystride * p->height;
1707 paint_setup_v210 (paintinfo * p, unsigned char *dest)
1713 p->ystride = ((p->width + 47) / 48) * 128; /* no, really. */
1714 p->endptr = dest + p->ystride * p->height;
1718 paint_setup_UYVP (paintinfo * p, unsigned char *dest)
1724 p->ystride = GST_ROUND_UP_4 ((p->width * 2 * 5 + 3) / 4);
1725 GST_ERROR ("stride %d", p->ystride);
1726 p->endptr = dest + p->ystride * p->height;
1730 paint_setup_YUY2 (paintinfo * p, unsigned char *dest)
1735 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
1736 p->ustride = GST_ROUND_UP_2 (p->width) * 2;
1737 p->vstride = GST_ROUND_UP_2 (p->width) * 2;
1738 p->endptr = dest + p->ystride * p->height;
1742 paint_setup_UYVY (paintinfo * p, unsigned char *dest)
1747 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
1748 p->ustride = GST_ROUND_UP_2 (p->width) * 2;
1749 p->vstride = GST_ROUND_UP_2 (p->width) * 2;
1750 p->endptr = dest + p->ystride * p->height;
1754 paint_setup_YVYU (paintinfo * p, unsigned char *dest)
1759 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
1760 p->ustride = GST_ROUND_UP_2 (p->width) * 2;
1761 p->vstride = GST_ROUND_UP_2 (p->width) * 2;
1762 p->endptr = dest + p->ystride * p->height;
1766 paint_setup_AY64 (paintinfo * p, unsigned char *dest)
1772 p->ystride = p->width * 8;
1773 p->ustride = p->width * 8;
1774 p->vstride = p->width * 8;
1775 p->endptr = dest + p->ystride * p->height;
1779 convert_hline_v308 (paintinfo * p, int y)
1782 guint8 *Y = p->yp + y * p->ystride;
1783 guint8 *U = p->up + y * p->ustride;
1784 guint8 *V = p->vp + y * p->vstride;
1785 guint8 *ayuv = p->tmpline;
1787 for (i = 0; i < p->width; i++) {
1788 Y[i * 3] = ayuv[4 * i + 1];
1789 U[i * 3] = ayuv[4 * i + 2];
1790 V[i * 3] = ayuv[4 * i + 3];
1795 convert_hline_AYUV (paintinfo * p, int y)
1798 guint8 *Y = p->yp + y * p->ystride;
1799 guint8 *U = p->up + y * p->ustride;
1800 guint8 *V = p->vp + y * p->vstride;
1801 guint8 *A = p->ap + y * p->ystride;
1802 guint8 *ayuv = p->tmpline;
1804 for (i = 0; i < p->width; i++) {
1805 A[i * 4] = ayuv[4 * i + 0];
1806 Y[i * 4] = ayuv[4 * i + 1];
1807 U[i * 4] = ayuv[4 * i + 2];
1808 V[i * 4] = ayuv[4 * i + 3];
1813 convert_hline_v216 (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 *ayuv = p->tmpline;
1821 for (i = 0; i < p->width; i++) {
1822 GST_WRITE_UINT16_LE (Y + i * 4, TO_16 (ayuv[4 * i + 1]));
1824 for (i = 0; i < (p->width + 1) / 2; i++) {
1825 GST_WRITE_UINT16_LE (U + i * 8, TO_16 (ayuv[4 * (i * 2) + 2]));
1826 GST_WRITE_UINT16_LE (V + i * 8, TO_16 (ayuv[4 * (i * 2) + 3]));
1832 convert_hline_v410 (paintinfo * p, int y)
1835 guint8 *Y = p->yp + y * p->ystride;
1836 guint8 *ayuv = p->tmpline;
1838 for (i = 0; i < p->width; i++) {
1841 a = (TO_10 (ayuv[4 * i + 2]) << 22) |
1842 (TO_10 (ayuv[4 * i + 1]) << 12) | (TO_10 (ayuv[4 * i + 3]) << 2);
1843 GST_WRITE_UINT32_LE (Y + i * 4, a);
1849 convert_hline_v210 (paintinfo * p, int y)
1852 guint8 *Y = p->yp + y * p->ystride;
1853 guint8 *ayuv = p->tmpline;
1855 for (i = 0; i < p->width + 5; i += 6) {
1856 guint32 a0, a1, a2, a3;
1857 guint16 y0, y1, y2, y3, y4, y5;
1861 y0 = ayuv[4 * (i + 0) + 1];
1862 y1 = ayuv[4 * (i + 1) + 1];
1863 y2 = ayuv[4 * (i + 2) + 1];
1864 y3 = ayuv[4 * (i + 3) + 1];
1865 y4 = ayuv[4 * (i + 4) + 1];
1866 y5 = ayuv[4 * (i + 5) + 1];
1868 u0 = (ayuv[4 * (i + 0) + 2] + ayuv[4 * (i + 1) + 2] + 1) >> 1;
1869 u1 = (ayuv[4 * (i + 2) + 2] + ayuv[4 * (i + 3) + 2] + 1) >> 1;
1870 u2 = (ayuv[4 * (i + 4) + 2] + ayuv[4 * (i + 5) + 2] + 1) >> 1;
1872 v0 = (ayuv[4 * (i + 0) + 3] + ayuv[4 * (i + 1) + 3] + 1) >> 1;
1873 v1 = (ayuv[4 * (i + 2) + 3] + ayuv[4 * (i + 3) + 3] + 1) >> 1;
1874 v2 = (ayuv[4 * (i + 4) + 3] + ayuv[4 * (i + 5) + 3] + 1) >> 1;
1877 a0 = TO_10 (ayuv[4 * (i + 0) + 2]) | (TO_10 (ayuv[4 * (i + 0) + 1]) << 10)
1878 | (TO_10 (ayuv[4 * (i + 0) + 3]) << 20);
1879 a1 = TO_10 (ayuv[4 * (i + 1) + 1]) | (TO_10 (ayuv[4 * (i + 2) + 2]) << 10)
1880 | (TO_10 (ayuv[4 * (i + 2) + 1]) << 20);
1881 a2 = TO_10 (ayuv[4 * (i + 2) + 3]) | (TO_10 (ayuv[4 * (i + 3) + 1]) << 10)
1882 | (TO_10 (ayuv[4 * (i + 4) + 2]) << 20);
1883 a3 = TO_10 (ayuv[4 * (i + 4) + 1]) | (TO_10 (ayuv[4 * (i + 4) + 3]) << 10)
1884 | (TO_10 (ayuv[4 * (i + 5) + 1]) << 20);
1887 a0 = TO_10 (u0) | (TO_10 (y0) << 10) | (TO_10 (v0) << 20);
1888 a1 = TO_10 (y1) | (TO_10 (u1) << 10) | (TO_10 (y2) << 20);
1889 a2 = TO_10 (v1) | (TO_10 (y3) << 10) | (TO_10 (u2) << 20);
1890 a3 = TO_10 (y4) | (TO_10 (v2) << 10) | (TO_10 (y5) << 20);
1892 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 0, a0);
1893 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 4, a1);
1894 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 8, a2);
1895 GST_WRITE_UINT32_LE (Y + (i / 6) * 16 + 12, a3);
1900 convert_hline_UYVP (paintinfo * p, int y)
1903 guint8 *Y = p->yp + y * p->ystride;
1904 guint8 *ayuv = p->tmpline;
1906 for (i = 0; i < p->width; i += 2) {
1911 y0 = ayuv[4 * (i + 0) + 1];
1912 y1 = ayuv[4 * (i + 1) + 1];
1913 u0 = (ayuv[4 * (i + 0) + 2] + ayuv[4 * (i + 1) + 2] + 1) >> 1;
1914 v0 = (ayuv[4 * (i + 0) + 3] + ayuv[4 * (i + 1) + 3] + 1) >> 1;
1916 Y[(i / 2) * 5 + 0] = u0;
1917 Y[(i / 2) * 5 + 1] = y0 >> 2;
1918 Y[(i / 2) * 5 + 2] = (y0 << 6) | (v0 >> 4);
1919 Y[(i / 2) * 5 + 3] = (v0 << 4) | (y1 >> 2);
1920 Y[(i / 2) * 5 + 4] = (y1 << 2);
1925 convert_hline_YUY2 (paintinfo * p, int y)
1928 guint8 *Y = p->yp + y * p->ystride;
1929 guint8 *U = p->up + y * p->ustride;
1930 guint8 *V = p->vp + y * p->vstride;
1931 guint8 *ayuv = p->tmpline;
1933 for (i = 0; i < p->width; i++) {
1934 Y[i * 2] = ayuv[4 * i + 1];
1936 for (i = 0; i < (p->width + 1) / 2; i++) {
1937 U[4 * i] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
1938 V[4 * i] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
1943 convert_hline_AY64 (paintinfo * p, int y)
1946 guint16 *ayuv16 = (guint16 *) (p->ap + y * p->ystride);
1947 guint8 *ayuv = p->tmpline;
1949 for (i = 0; i < p->width; i++) {
1950 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 0, TO_16 (ayuv[4 * i + 0]));
1951 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 1, TO_16 (ayuv[4 * i + 1]));
1952 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 2, TO_16 (ayuv[4 * i + 2]));
1953 GST_WRITE_UINT16_LE (ayuv16 + i * 4 + 3, TO_16 (ayuv[4 * i + 3]));
1959 paint_setup_IYU2 (paintinfo * p, unsigned char *dest)
1965 p->ystride = GST_ROUND_UP_4 (p->width * 3);
1966 p->endptr = dest + p->ystride * p->height;
1970 convert_hline_IYU2 (paintinfo * p, int y)
1973 guint8 *Y = p->yp + y * p->ystride;
1974 guint8 *U = p->up + y * p->ustride;
1975 guint8 *V = p->vp + y * p->vstride;
1976 guint8 *ayuv = p->tmpline;
1978 for (i = 0; i < p->width; i++) {
1979 Y[i * 3] = ayuv[4 * i + 1];
1980 U[i * 3] = ayuv[4 * i + 2];
1981 V[i * 3] = ayuv[4 * i + 3];
1987 paint_setup_Y41B (paintinfo * p, unsigned char *dest)
1990 p->ystride = GST_ROUND_UP_4 (p->width);
1991 p->up = p->yp + p->ystride * p->height;
1992 p->ustride = GST_ROUND_UP_16 (p->width) / 4;
1993 p->vp = p->up + p->ustride * p->height;
1994 p->vstride = GST_ROUND_UP_16 (p->width) / 4;
1995 p->endptr = p->vp + p->vstride * p->height;
1999 convert_hline_Y41B (paintinfo * p, int y)
2002 guint8 *Y = p->yp + y * p->ystride;
2003 guint8 *U = p->up + y * p->ustride;
2004 guint8 *V = p->vp + y * p->vstride;
2005 guint8 *ayuv = p->tmpline;
2007 for (i = 0; i < p->width; i++) {
2008 Y[i] = ayuv[4 * i + 1];
2010 for (i = 0; i < (p->width + 3) / 4; i++) {
2011 U[i] = (ayuv[4 * (i * 4) + 2] + ayuv[4 * (i * 4 + 1) + 2] +
2012 ayuv[4 * (i * 4 + 2) + 2] + ayuv[4 * (i * 4 + 3) + 2] + 2) >> 2;
2013 V[i] = (ayuv[4 * (i * 4) + 3] + ayuv[4 * (i * 4 + 1) + 3] +
2014 ayuv[4 * (i * 4 + 2) + 3] + ayuv[4 * (i * 4 + 3) + 3] + 2) >> 2;
2019 paint_setup_Y42B (paintinfo * p, unsigned char *dest)
2022 p->ystride = GST_ROUND_UP_4 (p->width);
2023 p->up = p->yp + p->ystride * p->height;
2024 p->ustride = GST_ROUND_UP_8 (p->width) / 2;
2025 p->vp = p->up + p->ustride * p->height;
2026 p->vstride = GST_ROUND_UP_8 (p->width) / 2;
2027 p->endptr = p->vp + p->vstride * p->height;
2031 convert_hline_Y42B (paintinfo * p, int y)
2034 guint8 *Y = p->yp + y * p->ystride;
2035 guint8 *U = p->up + y * p->ustride;
2036 guint8 *V = p->vp + y * p->vstride;
2037 guint8 *ayuv = p->tmpline;
2039 for (i = 0; i < p->width; i++) {
2040 Y[i] = ayuv[4 * i + 1];
2042 for (i = 0; i < (p->width + 1) / 2; i++) {
2043 U[i] = (ayuv[4 * (i * 2) + 2] + ayuv[4 * (i * 2 + 1) + 2] + 1) >> 1;
2044 V[i] = (ayuv[4 * (i * 2) + 3] + ayuv[4 * (i * 2 + 1) + 3] + 1) >> 1;
2049 paint_setup_Y444 (paintinfo * p, unsigned char *dest)
2052 p->ystride = GST_ROUND_UP_4 (p->width);
2053 p->ustride = GST_ROUND_UP_4 (p->width);
2054 p->vstride = GST_ROUND_UP_4 (p->width);
2055 p->up = p->yp + p->ystride * p->height;
2056 p->vp = p->up + p->ystride * p->height;
2057 p->endptr = p->vp + p->ystride * p->height;
2061 convert_hline_Y444 (paintinfo * p, int y)
2064 guint8 *Y = p->yp + y * p->ystride;
2065 guint8 *U = p->up + y * p->ustride;
2066 guint8 *V = p->vp + y * p->vstride;
2067 guint8 *ayuv = p->tmpline;
2069 for (i = 0; i < p->width; i++) {
2070 Y[i] = ayuv[4 * i + 1];
2071 U[i] = ayuv[4 * i + 2];
2072 V[i] = ayuv[4 * i + 3];
2077 paint_setup_Y800 (paintinfo * p, unsigned char *dest)
2081 p->ystride = GST_ROUND_UP_4 (p->width);
2082 p->endptr = dest + p->ystride * p->height;
2086 convert_hline_Y800 (paintinfo * p, int y)
2089 guint8 *Y = p->yp + y * p->ystride;
2090 guint8 *ayuv = p->tmpline;
2092 for (i = 0; i < p->width; i++) {
2093 Y[i] = ayuv[4 * i + 1];
2098 paint_setup_YVU9 (paintinfo * p, unsigned char *dest)
2100 int h = GST_ROUND_UP_4 (p->height);
2103 p->ystride = GST_ROUND_UP_4 (p->width);
2104 p->vp = p->yp + p->ystride * h;
2105 p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
2106 p->up = p->vp + p->vstride * h / 4;
2107 p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
2108 p->endptr = p->up + p->ustride * h / 4;
2112 paint_setup_YUV9 (paintinfo * p, unsigned char *dest)
2115 int h = GST_ROUND_UP_4 (p->height);
2118 p->ystride = GST_ROUND_UP_4 (p->width);
2119 p->up = p->yp + p->ystride * h;
2120 p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
2121 p->vp = p->up + p->ustride * h / 4;
2122 p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
2123 p->endptr = p->vp + p->vstride * h / 4;
2127 convert_hline_YUV9 (paintinfo * p, int y)
2130 guint8 *Y = p->yp + y * p->ystride;
2131 guint8 *U = p->up + (y / 4) * p->ustride;
2132 guint8 *V = p->vp + (y / 4) * p->vstride;
2133 guint8 *ayuv = p->tmpline;
2135 for (i = 0; i < p->width; i++) {
2136 Y[i] = ayuv[4 * i + 1];
2138 for (i = 0; i < (p->width + 3) / 4; i++) {
2139 U[i] = (ayuv[4 * (i * 4) + 2] + ayuv[4 * (i * 4 + 1) + 2] +
2140 ayuv[4 * (i * 4 + 2) + 2] + ayuv[4 * (i * 4 + 3) + 2] + 2) >> 2;
2141 V[i] = (ayuv[4 * (i * 4) + 3] + ayuv[4 * (i * 4 + 1) + 3] +
2142 ayuv[4 * (i * 4 + 2) + 3] + ayuv[4 * (i * 4 + 3) + 3] + 2) >> 2;
2147 paint_setup_ARGB8888 (paintinfo * p, unsigned char *dest)
2149 paint_setup_xRGB8888 (p, dest);
2153 paint_setup_ABGR8888 (paintinfo * p, unsigned char *dest)
2155 paint_setup_xBGR8888 (p, dest);
2159 paint_setup_RGBA8888 (paintinfo * p, unsigned char *dest)
2161 paint_setup_RGBx8888 (p, dest);
2165 paint_setup_BGRA8888 (paintinfo * p, unsigned char *dest)
2167 paint_setup_BGRx8888 (p, dest);
2171 paint_setup_xRGB8888 (paintinfo * p, unsigned char *dest)
2177 p->ystride = p->width * 4;
2178 p->ustride = p->width * 4;
2179 p->vstride = p->width * 4;
2180 p->endptr = p->dest + p->ystride * p->height;
2184 paint_setup_xBGR8888 (paintinfo * p, unsigned char *dest)
2190 p->ystride = p->width * 4;
2191 p->ustride = p->width * 4;
2192 p->vstride = p->width * 4;
2193 p->endptr = p->dest + p->ystride * p->height;
2197 paint_setup_RGBx8888 (paintinfo * p, unsigned char *dest)
2203 p->ystride = p->width * 4;
2204 p->ustride = p->width * 4;
2205 p->vstride = p->width * 4;
2206 p->endptr = p->dest + p->ystride * p->height;
2210 paint_setup_BGRx8888 (paintinfo * p, unsigned char *dest)
2216 p->ystride = p->width * 4;
2217 p->ustride = p->width * 4;
2218 p->vstride = p->width * 4;
2219 p->endptr = p->dest + p->ystride * p->height;
2223 paint_setup_RGB888 (paintinfo * p, unsigned char *dest)
2228 p->ystride = GST_ROUND_UP_4 (p->width * 3);
2229 p->ustride = GST_ROUND_UP_4 (p->width * 3);
2230 p->vstride = GST_ROUND_UP_4 (p->width * 3);
2231 p->endptr = p->dest + p->ystride * p->height;
2235 paint_setup_BGR888 (paintinfo * p, unsigned char *dest)
2240 p->ystride = GST_ROUND_UP_4 (p->width * 3);
2241 p->ustride = GST_ROUND_UP_4 (p->width * 3);
2242 p->vstride = GST_ROUND_UP_4 (p->width * 3);
2243 p->endptr = p->dest + p->ystride * p->height;
2247 paint_setup_ARGB64 (paintinfo * p, unsigned char *dest)
2253 p->ystride = p->width * 8;
2254 p->ustride = p->width * 8;
2255 p->vstride = p->width * 8;
2256 p->endptr = p->dest + p->ystride * p->height;
2260 convert_hline_str4 (paintinfo * p, int y)
2263 guint8 *A = p->ap + y * p->ystride;
2264 guint8 *R = p->yp + y * p->ystride;
2265 guint8 *G = p->up + y * p->ustride;
2266 guint8 *B = p->vp + y * p->vstride;
2267 guint8 *argb = p->tmpline;
2269 for (i = 0; i < p->width; i++) {
2271 R[4 * i] = argb[4 * i + 1];
2272 G[4 * i] = argb[4 * i + 2];
2273 B[4 * i] = argb[4 * i + 3];
2278 convert_hline_astr4 (paintinfo * p, int y)
2281 guint8 *A = p->ap + y * p->ystride;
2282 guint8 *R = p->yp + y * p->ystride;
2283 guint8 *G = p->up + y * p->ustride;
2284 guint8 *B = p->vp + y * p->vstride;
2285 guint8 *argb = p->tmpline;
2287 for (i = 0; i < p->width; i++) {
2288 A[4 * i] = argb[4 * i + 0];
2289 R[4 * i] = argb[4 * i + 1];
2290 G[4 * i] = argb[4 * i + 2];
2291 B[4 * i] = argb[4 * i + 3];
2296 convert_hline_astr8 (paintinfo * p, int y)
2299 guint16 *A = (guint16 *) (p->ap + y * p->ystride);
2300 guint16 *R = (guint16 *) (p->yp + y * p->ystride);
2301 guint16 *G = (guint16 *) (p->up + y * p->ustride);
2302 guint16 *B = (guint16 *) (p->vp + y * p->vstride);
2303 guint8 *argb = p->tmpline;
2305 for (i = 0; i < p->width; i++) {
2306 A[4 * i] = TO_16 (argb[4 * i + 0]);
2307 R[4 * i] = TO_16 (argb[4 * i + 1]);
2308 G[4 * i] = TO_16 (argb[4 * i + 2]);
2309 B[4 * i] = TO_16 (argb[4 * i + 3]);
2314 convert_hline_str3 (paintinfo * p, int y)
2317 guint8 *R = p->yp + y * p->ystride;
2318 guint8 *G = p->up + y * p->ustride;
2319 guint8 *B = p->vp + y * p->vstride;
2320 guint8 *argb = p->tmpline;
2322 for (i = 0; i < p->width; i++) {
2323 R[3 * i] = argb[4 * i + 1];
2324 G[3 * i] = argb[4 * i + 2];
2325 B[3 * i] = argb[4 * i + 3];
2330 paint_setup_RGB565 (paintinfo * p, unsigned char *dest)
2333 p->ystride = GST_ROUND_UP_4 (p->width * 2);
2334 p->ustride = GST_ROUND_UP_4 (p->width * 2);
2335 p->vstride = GST_ROUND_UP_4 (p->width * 2);
2336 p->endptr = p->dest + p->ystride * p->height;
2340 convert_hline_RGB565 (paintinfo * p, int y)
2343 guint8 *R = p->yp + y * p->ystride;
2344 guint8 *argb = p->tmpline;
2346 for (i = 0; i < p->width; i++) {
2347 guint16 value = ((argb[4 * i + 1] & 0xf8) << 8) |
2348 ((argb[4 * i + 2] & 0xfc) << 3) | ((argb[4 * i + 3] & 0xf8) >> 3);
2349 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2350 GST_WRITE_UINT16_LE (R + 2 * i, value);
2352 GST_WRITE_UINT16_BE (R + 2 * i, value);
2358 convert_hline_xRGB1555 (paintinfo * p, int y)
2361 guint8 *R = p->yp + y * p->ystride;
2362 guint8 *argb = p->tmpline;
2364 for (i = 0; i < p->width; i++) {
2365 guint16 value = ((argb[4 * i + 1] & 0xf8) << 7) |
2366 ((argb[4 * i + 2] & 0xf8) << 2) | ((argb[4 * i + 3] & 0xf8) >> 3);
2367 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2368 GST_WRITE_UINT16_LE (R + 2 * i, value);
2370 GST_WRITE_UINT16_BE (R + 2 * i, value);
2376 paint_setup_xRGB1555 (paintinfo * p, unsigned char *dest)
2379 p->ystride = GST_ROUND_UP_4 (p->width * 2);
2380 p->ustride = GST_ROUND_UP_4 (p->width * 2);
2381 p->vstride = GST_ROUND_UP_4 (p->width * 2);
2382 p->endptr = p->dest + p->ystride * p->height;
2387 paint_setup_bayer_bggr (paintinfo * p, unsigned char *dest)
2390 p->ystride = GST_ROUND_UP_4 (p->width);
2391 p->ustride = GST_ROUND_UP_4 (p->width);
2392 p->vstride = GST_ROUND_UP_4 (p->width);
2393 p->endptr = p->dest + p->ystride * p->height;
2394 p->bayer_x_invert = 0;
2395 p->bayer_y_invert = 0;
2399 paint_setup_bayer_rggb (paintinfo * p, unsigned char *dest)
2402 p->ystride = GST_ROUND_UP_4 (p->width);
2403 p->ustride = GST_ROUND_UP_4 (p->width);
2404 p->vstride = GST_ROUND_UP_4 (p->width);
2405 p->endptr = p->dest + p->ystride * p->height;
2406 p->bayer_x_invert = 1;
2407 p->bayer_y_invert = 1;
2411 paint_setup_bayer_grbg (paintinfo * p, unsigned char *dest)
2414 p->ystride = GST_ROUND_UP_4 (p->width);
2415 p->ustride = GST_ROUND_UP_4 (p->width);
2416 p->vstride = GST_ROUND_UP_4 (p->width);
2417 p->endptr = p->dest + p->ystride * p->height;
2418 p->bayer_x_invert = 0;
2419 p->bayer_y_invert = 1;
2423 paint_setup_bayer_gbrg (paintinfo * p, unsigned char *dest)
2426 p->ystride = GST_ROUND_UP_4 (p->width);
2427 p->ustride = GST_ROUND_UP_4 (p->width);
2428 p->vstride = GST_ROUND_UP_4 (p->width);
2429 p->endptr = p->dest + p->ystride * p->height;
2430 p->bayer_x_invert = 1;
2431 p->bayer_y_invert = 0;
2435 convert_hline_bayer (paintinfo * p, int y)
2438 guint8 *R = p->yp + y * p->ystride;
2439 guint8 *argb = p->tmpline;
2440 int x_inv = p->bayer_x_invert;
2441 int y_inv = p->bayer_y_invert;
2443 if ((y ^ y_inv) & 1) {
2444 for (i = 0; i < p->width; i++) {
2445 if ((i ^ x_inv) & 1) {
2446 R[i] = argb[4 * i + 1];
2448 R[i] = argb[4 * i + 2];
2452 for (i = 0; i < p->width; i++) {
2453 if ((i ^ x_inv) & 1) {
2454 R[i] = argb[4 * i + 2];
2456 R[i] = argb[4 * i + 3];
2463 paint_setup_GRAY8 (paintinfo * p, unsigned char *dest)
2466 p->ystride = GST_ROUND_UP_4 (p->width);
2467 p->endptr = dest + p->ystride * p->height;
2471 convert_hline_GRAY8 (paintinfo * p, int y)
2474 guint8 *Y = p->yp + y * p->ystride;
2475 guint8 *ayuv = p->tmpline;
2477 /* FIXME this should use gray, not YUV */
2478 for (i = 0; i < p->width; i++) {
2479 Y[i] = ayuv[4 * i + 1];
2484 paint_setup_GRAY16 (paintinfo * p, unsigned char *dest)
2487 p->ystride = GST_ROUND_UP_4 (p->width * 2);
2488 p->endptr = dest + p->ystride * p->height;
2492 convert_hline_GRAY16 (paintinfo * p, int y)
2495 guint8 *Y = p->yp + y * p->ystride;
2496 guint8 *ayuv = p->tmpline;
2498 /* FIXME this should use gray, not YUV */
2499 for (i = 0; i < p->width; i++) {
2500 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2501 GST_WRITE_UINT16_LE (Y + i * 2, ayuv[4 * i + 1] << 8);
2503 GST_WRITE_UINT16_BE (Y + i * 2, ayuv[4 * i + 1] << 8);