546516aeb6ced5ca3a961c13f09b876c5fad1486
[platform/upstream/gstreamer.git] / tests / check / libs / video.c
1 /* GStreamer unit test for video
2  *
3  * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4  * Copyright (C) <2006> Jan Schmidt <thaytan@mad.scientist.com>
5  * Copyright (C) <2008,2011> Tim-Philipp Müller <tim centricular net>
6  * Copyright (C) <2012> Collabora Ltd. <tim.muller@collabora.co.uk>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #ifdef HAVE_VALGRIND
29 # include <valgrind/valgrind.h>
30 #endif
31
32 #include <unistd.h>
33
34 #include <gst/check/gstcheck.h>
35
36 #include <gst/video/video.h>
37 #if 0
38 #include <gst/video/video-overlay-composition.h>
39 #endif
40 #include <string.h>
41
42 /* These are from the current/old videotestsrc; we check our new public API
43  * in libgstvideo against the old one to make sure the sizes and offsets
44  * end up the same */
45
46 typedef struct paintinfo_struct paintinfo;
47 struct paintinfo_struct
48 {
49   unsigned char *dest;          /* pointer to first byte of video data */
50   unsigned char *yp, *up, *vp;  /* pointers to first byte of each component
51                                  * for both packed/planar YUV and RGB */
52   unsigned char *ap;            /* pointer to first byte of alpha component */
53   unsigned char *endptr;        /* pointer to byte beyond last video data */
54   int ystride;
55   int ustride;
56   int vstride;
57   int width;
58   int height;
59 };
60
61 struct fourcc_list_struct
62 {
63   const char *fourcc;
64   const char *name;
65   int bitspp;
66   void (*paint_setup) (paintinfo * p, unsigned char *dest);
67 };
68
69 static void paint_setup_I420 (paintinfo * p, unsigned char *dest);
70 static void paint_setup_YV12 (paintinfo * p, unsigned char *dest);
71 static void paint_setup_YUY2 (paintinfo * p, unsigned char *dest);
72 static void paint_setup_UYVY (paintinfo * p, unsigned char *dest);
73 static void paint_setup_YVYU (paintinfo * p, unsigned char *dest);
74 static void paint_setup_IYU2 (paintinfo * p, unsigned char *dest);
75 static void paint_setup_Y41B (paintinfo * p, unsigned char *dest);
76 static void paint_setup_Y42B (paintinfo * p, unsigned char *dest);
77 static void paint_setup_GRAY8 (paintinfo * p, unsigned char *dest);
78 static void paint_setup_AYUV (paintinfo * p, unsigned char *dest);
79
80 #if 0
81 static void paint_setup_IMC1 (paintinfo * p, unsigned char *dest);
82 static void paint_setup_IMC2 (paintinfo * p, unsigned char *dest);
83 static void paint_setup_IMC3 (paintinfo * p, unsigned char *dest);
84 static void paint_setup_IMC4 (paintinfo * p, unsigned char *dest);
85 #endif
86 static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest);
87 static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest);
88
89 int fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h);
90
91 struct fourcc_list_struct fourcc_list[] = {
92 /* packed */
93   {"YUY2", "YUY2", 16, paint_setup_YUY2},
94   {"UYVY", "UYVY", 16, paint_setup_UYVY},
95   {"Y422", "Y422", 16, paint_setup_UYVY},
96   {"UYNV", "UYNV", 16, paint_setup_UYVY},       /* FIXME: UYNV? */
97   {"YVYU", "YVYU", 16, paint_setup_YVYU},
98   {"AYUV", "AYUV", 32, paint_setup_AYUV},
99
100   /* interlaced */
101   /*{   "IUYV", "IUY2", 16, paint_setup_YVYU }, */
102
103   /* inverted */
104   /*{   "cyuv", "cyuv", 16, paint_setup_YVYU }, */
105
106   /*{   "Y41P", "Y41P", 12, paint_setup_YVYU }, */
107
108   /* interlaced */
109   /*{   "IY41", "IY41", 12, paint_setup_YVYU }, */
110
111   /*{   "Y211", "Y211", 8, paint_setup_YVYU }, */
112
113   /*{   "Y41T", "Y41T", 12, paint_setup_YVYU }, */
114   /*{   "Y42P", "Y42P", 16, paint_setup_YVYU }, */
115   /*{   "CLJR", "CLJR", 8, paint_setup_YVYU }, */
116   /*{   "IYU1", "IYU1", 12, paint_setup_YVYU }, */
117   {"IYU2", "IYU2", 24, paint_setup_IYU2},
118
119 /* planar */
120   /* YVU9 */
121   {"YVU9", "YVU9", 9, paint_setup_YVU9},
122   /* YUV9 */
123   {"YUV9", "YUV9", 9, paint_setup_YUV9},
124   /* IF09 */
125   /* YV12 */
126   {"YV12", "YV12", 12, paint_setup_YV12},
127   /* I420 */
128   {"I420", "I420", 12, paint_setup_I420},
129   /* NV12 */
130   /* NV21 */
131 #if 0
132   /* IMC1 */
133   {"IMC1", "IMC1", 16, paint_setup_IMC1},
134   /* IMC2 */
135   {"IMC2", "IMC2", 12, paint_setup_IMC2},
136   /* IMC3 */
137   {"IMC3", "IMC3", 16, paint_setup_IMC3},
138   /* IMC4 */
139   {"IMC4", "IMC4", 12, paint_setup_IMC4},
140 #endif
141   /* CLPL */
142   /* Y41B */
143   {"Y41B", "Y41B", 12, paint_setup_Y41B},
144   /* Y42B */
145   {"Y42B", "Y42B", 16, paint_setup_Y42B},
146   /* GRAY8 grayscale */
147   {"GRAY8", "GRAY8", 8, paint_setup_GRAY8}
148 };
149
150 /* returns the size in bytes for one video frame of the given dimensions
151  * given the fourcc */
152 int
153 fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h)
154 {
155   paintinfo pi = { NULL, };
156   paintinfo *p = &pi;
157
158   p->width = w;
159   p->height = h;
160
161   fourcc->paint_setup (p, NULL);
162
163   return (unsigned long) p->endptr;
164 }
165
166 static void
167 paint_setup_I420 (paintinfo * p, unsigned char *dest)
168 {
169   p->yp = dest;
170   p->ystride = GST_ROUND_UP_4 (p->width);
171   p->up = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
172   p->ustride = GST_ROUND_UP_8 (p->width) / 2;
173   p->vp = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
174   p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
175   p->endptr = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
176 }
177
178 static void
179 paint_setup_YV12 (paintinfo * p, unsigned char *dest)
180 {
181   p->yp = dest;
182   p->ystride = GST_ROUND_UP_4 (p->width);
183   p->vp = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
184   p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
185   p->up = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
186   p->ustride = GST_ROUND_UP_8 (p->ystride) / 2;
187   p->endptr = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
188 }
189
190 static void
191 paint_setup_AYUV (paintinfo * p, unsigned char *dest)
192 {
193   p->ap = dest;
194   p->yp = dest + 1;
195   p->up = dest + 2;
196   p->vp = dest + 3;
197   p->ystride = p->width * 4;
198   p->endptr = dest + p->ystride * p->height;
199 }
200
201 static void
202 paint_setup_YUY2 (paintinfo * p, unsigned char *dest)
203 {
204   p->yp = dest;
205   p->up = dest + 1;
206   p->vp = dest + 3;
207   p->ystride = GST_ROUND_UP_2 (p->width) * 2;
208   p->endptr = dest + p->ystride * p->height;
209 }
210
211 static void
212 paint_setup_UYVY (paintinfo * p, unsigned char *dest)
213 {
214   p->yp = dest + 1;
215   p->up = dest;
216   p->vp = dest + 2;
217   p->ystride = GST_ROUND_UP_2 (p->width) * 2;
218   p->endptr = dest + p->ystride * p->height;
219 }
220
221 static void
222 paint_setup_YVYU (paintinfo * p, unsigned char *dest)
223 {
224   p->yp = dest;
225   p->up = dest + 3;
226   p->vp = dest + 1;
227   p->ystride = GST_ROUND_UP_2 (p->width) * 2;
228   p->endptr = dest + p->ystride * p->height;
229 }
230
231 static void
232 paint_setup_IYU2 (paintinfo * p, unsigned char *dest)
233 {
234   /* untested */
235   p->yp = dest + 1;
236   p->up = dest + 0;
237   p->vp = dest + 2;
238   p->ystride = GST_ROUND_UP_4 (p->width * 3);
239   p->endptr = dest + p->ystride * p->height;
240 }
241
242 static void
243 paint_setup_Y41B (paintinfo * p, unsigned char *dest)
244 {
245   p->yp = dest;
246   p->ystride = GST_ROUND_UP_4 (p->width);
247   p->up = p->yp + p->ystride * p->height;
248   p->ustride = GST_ROUND_UP_16 (p->width) / 4;
249   p->vp = p->up + p->ustride * p->height;
250   p->vstride = GST_ROUND_UP_16 (p->width) / 4;
251   p->endptr = p->vp + p->vstride * p->height;
252 }
253
254 static void
255 paint_setup_Y42B (paintinfo * p, unsigned char *dest)
256 {
257   p->yp = dest;
258   p->ystride = GST_ROUND_UP_4 (p->width);
259   p->up = p->yp + p->ystride * p->height;
260   p->ustride = GST_ROUND_UP_8 (p->width) / 2;
261   p->vp = p->up + p->ustride * p->height;
262   p->vstride = GST_ROUND_UP_8 (p->width) / 2;
263   p->endptr = p->vp + p->vstride * p->height;
264 }
265
266 static void
267 paint_setup_GRAY8 (paintinfo * p, unsigned char *dest)
268 {
269   /* untested */
270   p->yp = dest;
271   p->ystride = GST_ROUND_UP_4 (p->width);
272   p->endptr = dest + p->ystride * p->height;
273 }
274
275 #if 0
276 static void
277 paint_setup_IMC1 (paintinfo * p, unsigned char *dest)
278 {
279   p->yp = dest;
280   p->up = dest + p->width * p->height;
281   p->vp = dest + p->width * p->height + p->width * p->height / 2;
282 }
283
284 static void
285 paint_setup_IMC2 (paintinfo * p, unsigned char *dest)
286 {
287   p->yp = dest;
288   p->vp = dest + p->width * p->height;
289   p->up = dest + p->width * p->height + p->width / 2;
290 }
291
292 static void
293 paint_setup_IMC3 (paintinfo * p, unsigned char *dest)
294 {
295   p->yp = dest;
296   p->up = dest + p->width * p->height + p->width * p->height / 2;
297   p->vp = dest + p->width * p->height;
298 }
299
300 static void
301 paint_setup_IMC4 (paintinfo * p, unsigned char *dest)
302 {
303   p->yp = dest;
304   p->vp = dest + p->width * p->height + p->width / 2;
305   p->up = dest + p->width * p->height;
306 }
307 #endif
308
309 static void
310 paint_setup_YVU9 (paintinfo * p, unsigned char *dest)
311 {
312   p->yp = dest;
313   p->ystride = GST_ROUND_UP_4 (p->width);
314   p->vp = p->yp + p->ystride * p->height;
315   p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
316   p->up = p->vp + p->vstride * (GST_ROUND_UP_4 (p->height) / 4);
317   p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
318   p->endptr = p->up + p->ustride * (GST_ROUND_UP_4 (p->height) / 4);
319 }
320
321 static void
322 paint_setup_YUV9 (paintinfo * p, unsigned char *dest)
323 {
324   p->yp = dest;
325   p->ystride = GST_ROUND_UP_4 (p->width);
326   p->up = p->yp + p->ystride * p->height;
327   p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
328   p->vp = p->up + p->ustride * (GST_ROUND_UP_4 (p->height) / 4);
329   p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
330   p->endptr = p->vp + p->vstride * (GST_ROUND_UP_4 (p->height) / 4);
331 }
332
333 #define gst_video_format_is_packed video_format_is_packed
334 static gboolean
335 video_format_is_packed (GstVideoFormat fmt)
336 {
337   switch (fmt) {
338     case GST_VIDEO_FORMAT_I420:
339     case GST_VIDEO_FORMAT_YV12:
340     case GST_VIDEO_FORMAT_Y41B:
341     case GST_VIDEO_FORMAT_Y42B:
342     case GST_VIDEO_FORMAT_GRAY8:
343     case GST_VIDEO_FORMAT_YUV9:
344     case GST_VIDEO_FORMAT_YVU9:
345       return FALSE;
346     case GST_VIDEO_FORMAT_IYU1:
347     case GST_VIDEO_FORMAT_YUY2:
348     case GST_VIDEO_FORMAT_YVYU:
349     case GST_VIDEO_FORMAT_UYVY:
350     case GST_VIDEO_FORMAT_AYUV:
351     case GST_VIDEO_FORMAT_RGBx:
352     case GST_VIDEO_FORMAT_BGRx:
353     case GST_VIDEO_FORMAT_xRGB:
354     case GST_VIDEO_FORMAT_xBGR:
355     case GST_VIDEO_FORMAT_RGBA:
356     case GST_VIDEO_FORMAT_BGRA:
357     case GST_VIDEO_FORMAT_ARGB:
358     case GST_VIDEO_FORMAT_ABGR:
359     case GST_VIDEO_FORMAT_RGB:
360     case GST_VIDEO_FORMAT_BGR:
361     case GST_VIDEO_FORMAT_RGB8_PALETTED:
362       return TRUE;
363     default:
364       g_return_val_if_reached (FALSE);
365   }
366   return FALSE;
367 }
368
369 GST_START_TEST (test_video_formats_all)
370 {
371   GstStructure *s;
372   const GValue *val, *list_val;
373   GstCaps *caps;
374   guint num, n, num_formats;
375
376   num_formats = 100;
377   fail_unless (gst_video_format_to_string (num_formats) == NULL);
378   while (gst_video_format_to_string (num_formats) == NULL)
379     --num_formats;
380   GST_INFO ("number of known video formats: %d", num_formats);
381
382   caps = gst_caps_from_string ("video/x-raw, format=" GST_VIDEO_FORMATS_ALL);
383   s = gst_caps_get_structure (caps, 0);
384   val = gst_structure_get_value (s, "format");
385   fail_unless (val != NULL);
386   fail_unless (GST_VALUE_HOLDS_LIST (val));
387   num = gst_value_list_get_size (val);
388   fail_unless (num > 0);
389   for (n = 0; n < num; ++n) {
390     const gchar *fmt_str;
391
392     list_val = gst_value_list_get_value (val, n);
393     fail_unless (G_VALUE_HOLDS_STRING (list_val));
394     fmt_str = g_value_get_string (list_val);
395     GST_INFO ("format: %s", fmt_str);
396     fail_if (gst_video_format_from_string (fmt_str) ==
397         GST_VIDEO_FORMAT_UNKNOWN);
398   }
399   fail_unless_equals_int (num, num_formats);
400
401   gst_caps_unref (caps);
402 }
403
404 GST_END_TEST;
405
406 GST_START_TEST (test_video_formats)
407 {
408   guint i;
409
410   for (i = 0; i < G_N_ELEMENTS (fourcc_list); ++i) {
411     const GstVideoFormatInfo *vf_info;
412     GstVideoFormat fmt;
413     const gchar *s;
414     guint32 fourcc;
415     guint w, h;
416
417     s = fourcc_list[i].fourcc;
418     fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
419     fmt = gst_video_format_from_fourcc (fourcc);
420
421     if (fmt == GST_VIDEO_FORMAT_UNKNOWN) {
422       GST_DEBUG ("Unknown format %s, skipping tests", fourcc_list[i].fourcc);
423       continue;
424     }
425
426     vf_info = gst_video_format_get_info (fmt);
427     fail_unless (vf_info != NULL);
428
429     fail_unless_equals_int (GST_VIDEO_FORMAT_INFO_FORMAT (vf_info), fmt);
430
431     GST_INFO ("Fourcc %s, packed=%d", fourcc_list[i].fourcc,
432         gst_video_format_is_packed (fmt));
433
434     fail_unless (GST_VIDEO_FORMAT_INFO_IS_YUV (vf_info));
435
436     /* use any non-NULL pointer so we can compare against NULL */
437     {
438       paintinfo paintinfo = { 0, };
439       fourcc_list[i].paint_setup (&paintinfo, (unsigned char *) s);
440       if (paintinfo.ap != NULL) {
441         fail_unless (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vf_info));
442       } else {
443         fail_if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vf_info));
444       }
445     }
446
447     for (w = 1; w <= 65; ++w) {
448       for (h = 1; h <= 65; ++h) {
449         GstVideoInfo vinfo;
450         paintinfo paintinfo = { 0, };
451         guint off0, off1, off2, off3;
452         guint cs0, cs1, cs2, cs3;
453         guint size;
454
455         GST_LOG ("%s, %dx%d", fourcc_list[i].fourcc, w, h);
456
457         gst_video_info_init (&vinfo);
458         gst_video_info_set_format (&vinfo, fmt, w, h);
459
460         paintinfo.width = w;
461         paintinfo.height = h;
462         fourcc_list[i].paint_setup (&paintinfo, NULL);
463         fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0),
464             paintinfo.ystride);
465         if (!gst_video_format_is_packed (fmt)
466             && !GST_VIDEO_INFO_N_PLANES (&vinfo) > 2) {
467           /* planar */
468           fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 1),
469               paintinfo.ustride);
470           fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 2),
471               paintinfo.vstride);
472           /* check component_width * height against offsets/size somehow? */
473         }
474
475         size = GST_VIDEO_INFO_SIZE (&vinfo);
476         off0 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 0);
477         off1 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 1);
478         off2 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 2);
479
480         GST_INFO ("size %d <> %d", size, paintinfo.endptr);
481         GST_INFO ("off0 %d <> %d", off0, paintinfo.yp);
482         GST_INFO ("off1 %d <> %d", off1, paintinfo.up);
483         GST_INFO ("off2 %d <> %d", off2, paintinfo.vp);
484
485         fail_unless_equals_int (size, (unsigned long) paintinfo.endptr);
486         fail_unless_equals_int (off0, (unsigned long) paintinfo.yp);
487         fail_unless_equals_int (off1, (unsigned long) paintinfo.up);
488         fail_unless_equals_int (off2, (unsigned long) paintinfo.vp);
489
490         /* should be 0 if there's no alpha component */
491         off3 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 3);
492         fail_unless_equals_int (off3, (unsigned long) paintinfo.ap);
493
494         cs0 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 0) *
495             GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 0);
496         cs1 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 1) *
497             GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 1);
498         cs2 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 2) *
499             GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 2);
500
501         /* GST_LOG ("cs0=%d,cs1=%d,cs2=%d,off0=%d,off1=%d,off2=%d,size=%d",
502            cs0, cs1, cs2, off0, off1, off2, size); */
503
504         if (!gst_video_format_is_packed (fmt))
505           fail_unless (cs0 <= off1);
506
507         if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vinfo.finfo)) {
508           cs3 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 3) *
509               GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 2);
510           fail_unless (cs3 < size);
511           /* U/V/alpha shouldn't take up more space than the Y component */
512           fail_if (cs1 > cs0, "cs1 (%d) should be <= cs0 (%d)", cs1, cs0);
513           fail_if (cs2 > cs0, "cs2 (%d) should be <= cs0 (%d)", cs2, cs0);
514           fail_if (cs3 > cs0, "cs3 (%d) should be <= cs0 (%d)", cs3, cs0);
515
516           /* all components together shouldn't take up more space than size */
517           fail_unless (cs0 + cs1 + cs2 + cs3 <= size);
518         } else {
519           /* U/V shouldn't take up more space than the Y component */
520           fail_if (cs1 > cs0, "cs1 (%d) should be <= cs0 (%d)", cs1, cs0);
521           fail_if (cs2 > cs0, "cs2 (%d) should be <= cs0 (%d)", cs2, cs0);
522
523           /* all components together shouldn't take up more space than size */
524           fail_unless (cs0 + cs1 + cs2 <= size,
525               "cs0 (%d) + cs1 (%d) + cs2 (%d) should be <= size (%d)",
526               cs0, cs1, cs2, size);
527         }
528       }
529     }
530   }
531 }
532
533 GST_END_TEST;
534
535 GST_START_TEST (test_video_formats_rgb)
536 {
537   GstVideoInfo vinfo;
538   gint width, height, framerate_n, framerate_d, par_n, par_d;
539   GstCaps *caps;
540   GstStructure *structure;
541
542   gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGB, 800, 600);
543   vinfo.par_n = 1;
544   vinfo.par_d = 1;
545   vinfo.fps_n = 0;
546   vinfo.fps_d = 1;
547   caps = gst_video_info_to_caps (&vinfo);
548   structure = gst_caps_get_structure (caps, 0);
549
550   fail_unless (gst_structure_get_int (structure, "width", &width));
551   fail_unless (gst_structure_get_int (structure, "height", &height));
552   fail_unless (gst_structure_get_fraction (structure, "framerate", &framerate_n,
553           &framerate_d));
554   fail_unless (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
555           &par_n, &par_d));
556
557   fail_unless (width == 800);
558   fail_unless (height == 600);
559   fail_unless (framerate_n == 0);
560   fail_unless (framerate_d == 1);
561   fail_unless (par_n == 1);
562   fail_unless (par_d == 1);
563
564   gst_caps_unref (caps);
565 }
566
567 GST_END_TEST;
568
569 GST_START_TEST (test_dar_calc)
570 {
571   guint display_ratio_n, display_ratio_d;
572
573   /* Ensure that various Display Ratio calculations are correctly done */
574   /* video 768x576, par 16/15, display par 16/15 = 4/3 */
575   fail_unless (gst_video_calculate_display_ratio (&display_ratio_n,
576           &display_ratio_d, 768, 576, 16, 15, 16, 15));
577   fail_unless (display_ratio_n == 4 && display_ratio_d == 3);
578
579   /* video 720x480, par 32/27, display par 1/1 = 16/9 */
580   fail_unless (gst_video_calculate_display_ratio (&display_ratio_n,
581           &display_ratio_d, 720, 480, 32, 27, 1, 1));
582   fail_unless (display_ratio_n == 16 && display_ratio_d == 9);
583
584   /* video 360x288, par 533333/500000, display par 16/15 = 
585    * dar 1599999/1600000 */
586   fail_unless (gst_video_calculate_display_ratio (&display_ratio_n,
587           &display_ratio_d, 360, 288, 533333, 500000, 16, 15));
588   fail_unless (display_ratio_n == 1599999 && display_ratio_d == 1280000);
589 }
590
591 GST_END_TEST;
592
593 GST_START_TEST (test_parse_caps_rgb)
594 {
595   struct
596   {
597     const gchar *tmpl_caps_string;
598     GstVideoFormat fmt;
599   } formats[] = {
600     /* 24 bit */
601     {
602     GST_VIDEO_CAPS_MAKE ("RGB"), GST_VIDEO_FORMAT_RGB}, {
603     GST_VIDEO_CAPS_MAKE ("BGR"), GST_VIDEO_FORMAT_BGR},
604         /* 32 bit (no alpha) */
605     {
606     GST_VIDEO_CAPS_MAKE ("RGBx"), GST_VIDEO_FORMAT_RGBx}, {
607     GST_VIDEO_CAPS_MAKE ("xRGB"), GST_VIDEO_FORMAT_xRGB}, {
608     GST_VIDEO_CAPS_MAKE ("BGRx"), GST_VIDEO_FORMAT_BGRx}, {
609     GST_VIDEO_CAPS_MAKE ("xBGR"), GST_VIDEO_FORMAT_xBGR},
610         /* 32 bit (with alpha) */
611     {
612     GST_VIDEO_CAPS_MAKE ("RGBA"), GST_VIDEO_FORMAT_RGBA}, {
613     GST_VIDEO_CAPS_MAKE ("ARGB"), GST_VIDEO_FORMAT_ARGB}, {
614     GST_VIDEO_CAPS_MAKE ("BGRA"), GST_VIDEO_FORMAT_BGRA}, {
615     GST_VIDEO_CAPS_MAKE ("ABGR"), GST_VIDEO_FORMAT_ABGR},
616         /* 16 bit */
617     {
618     GST_VIDEO_CAPS_MAKE ("RGB16"), GST_VIDEO_FORMAT_RGB16}, {
619     GST_VIDEO_CAPS_MAKE ("BGR16"), GST_VIDEO_FORMAT_BGR16}, {
620     GST_VIDEO_CAPS_MAKE ("RGB15"), GST_VIDEO_FORMAT_RGB15}, {
621     GST_VIDEO_CAPS_MAKE ("BGR15"), GST_VIDEO_FORMAT_BGR15}
622   };
623   gint i;
624
625   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
626     GstVideoInfo vinfo;
627     GstCaps *caps, *caps2;
628
629     caps = gst_caps_from_string (formats[i].tmpl_caps_string);
630     gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * (i + 1), "height",
631         G_TYPE_INT, i + 1, "framerate", GST_TYPE_FRACTION, 15, 1,
632         "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
633         "interlace-mode", G_TYPE_STRING, "progressive", NULL);
634     g_assert (gst_caps_is_fixed (caps));
635
636     GST_DEBUG ("testing caps: %" GST_PTR_FORMAT, caps);
637
638     gst_video_info_init (&vinfo);
639     fail_unless (gst_video_info_from_caps (&vinfo, caps));
640     fail_unless_equals_int (GST_VIDEO_INFO_FORMAT (&vinfo), formats[i].fmt);
641     fail_unless_equals_int (GST_VIDEO_INFO_WIDTH (&vinfo), 2 * (i + 1));
642     fail_unless_equals_int (GST_VIDEO_INFO_HEIGHT (&vinfo), i + 1);
643
644     /* make sure they're serialised back correctly */
645     caps2 = gst_video_info_to_caps (&vinfo);
646     fail_unless (caps != NULL);
647     fail_unless (gst_caps_is_equal (caps, caps2),
648         "caps [%" GST_PTR_FORMAT "] not equal to caps2 [%" GST_PTR_FORMAT "]",
649         caps, caps2);
650
651     gst_caps_unref (caps);
652     gst_caps_unref (caps2);
653   }
654 }
655
656 GST_END_TEST;
657
658 GST_START_TEST (test_events)
659 {
660   GstEvent *e;
661   gboolean in_still;
662
663   e = gst_video_event_new_still_frame (TRUE);
664   fail_if (e == NULL, "Failed to create still frame event");
665   fail_unless (gst_video_event_parse_still_frame (e, &in_still),
666       "Failed to parse still frame event");
667   fail_unless (gst_video_event_parse_still_frame (e, NULL),
668       "Failed to parse still frame event w/ in_still == NULL");
669   fail_unless (in_still == TRUE);
670   gst_event_unref (e);
671
672   e = gst_video_event_new_still_frame (FALSE);
673   fail_if (e == NULL, "Failed to create still frame event");
674   fail_unless (gst_video_event_parse_still_frame (e, &in_still),
675       "Failed to parse still frame event");
676   fail_unless (gst_video_event_parse_still_frame (e, NULL),
677       "Failed to parse still frame event w/ in_still == NULL");
678   fail_unless (in_still == FALSE);
679   gst_event_unref (e);
680 }
681
682 GST_END_TEST;
683
684 GST_START_TEST (test_convert_frame)
685 {
686   GstVideoInfo vinfo;
687   GstCaps *from_caps, *to_caps;
688   GstBuffer *from_buffer;
689   GstSample *from_sample, *to_sample;
690   GError *error = NULL;
691   gint i;
692   GstMapInfo map;
693
694   gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
695
696   from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
697
698   gst_buffer_map (from_buffer, &map, GST_MAP_WRITE);
699   for (i = 0; i < 640 * 480; i++) {
700     map.data[4 * i + 0] = 0;    /* x */
701     map.data[4 * i + 1] = 255;  /* R */
702     map.data[4 * i + 2] = 0;    /* G */
703     map.data[4 * i + 3] = 0;    /* B */
704   }
705   gst_buffer_unmap (from_buffer, &map);
706
707   gst_video_info_init (&vinfo);
708   gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640, 480);
709   vinfo.fps_n = 25;
710   vinfo.fps_d = 1;
711   vinfo.par_n = 1;
712   vinfo.par_d = 1;
713   from_caps = gst_video_info_to_caps (&vinfo);
714
715   from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
716
717   to_caps =
718       gst_caps_from_string
719       ("something/that, does=(string)not, exist=(boolean)FALSE");
720
721   to_sample =
722       gst_video_convert_sample (from_sample, to_caps,
723       GST_CLOCK_TIME_NONE, &error);
724   fail_if (to_sample != NULL);
725   fail_unless (error != NULL);
726   g_error_free (error);
727   error = NULL;
728
729   gst_caps_unref (to_caps);
730   gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420, 240, 320);
731   vinfo.fps_n = 25;
732   vinfo.fps_d = 1;
733   vinfo.par_n = 1;
734   vinfo.par_d = 2;
735   to_caps = gst_video_info_to_caps (&vinfo);
736
737   to_sample =
738       gst_video_convert_sample (from_sample, to_caps,
739       GST_CLOCK_TIME_NONE, &error);
740   fail_unless (to_sample != NULL);
741   fail_unless (error == NULL);
742
743   gst_buffer_unref (from_buffer);
744   gst_caps_unref (from_caps);
745   gst_sample_unref (from_sample);
746   gst_sample_unref (to_sample);
747   gst_caps_unref (to_caps);
748 }
749
750 GST_END_TEST;
751
752 typedef struct
753 {
754   GMainLoop *loop;
755   GstSample *sample;
756   GError *error;
757 } ConvertFrameContext;
758
759 static void
760 convert_sample_async_callback (GstSample * sample, GError * err,
761     ConvertFrameContext * cf_data)
762 {
763   cf_data->sample = sample;
764   cf_data->error = err;
765
766   g_main_loop_quit (cf_data->loop);
767 }
768
769 GST_START_TEST (test_convert_frame_async)
770 {
771   GstVideoInfo vinfo;
772   GstCaps *from_caps, *to_caps;
773   GstBuffer *from_buffer;
774   GstSample *from_sample;
775   gint i;
776   GstMapInfo map;
777   GMainLoop *loop;
778   ConvertFrameContext cf_data = { NULL, NULL, NULL };
779
780   gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
781
782   from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
783
784   gst_buffer_map (from_buffer, &map, GST_MAP_WRITE);
785   for (i = 0; i < 640 * 480; i++) {
786     map.data[4 * i + 0] = 0;    /* x */
787     map.data[4 * i + 1] = 255;  /* R */
788     map.data[4 * i + 2] = 0;    /* G */
789     map.data[4 * i + 3] = 0;    /* B */
790   }
791   gst_buffer_unmap (from_buffer, &map);
792
793   gst_video_info_init (&vinfo);
794   gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640, 470);
795   vinfo.par_n = 1;
796   vinfo.par_d = 1;
797   vinfo.fps_n = 25;
798   vinfo.fps_d = 1;
799   from_caps = gst_video_info_to_caps (&vinfo);
800
801   to_caps =
802       gst_caps_from_string
803       ("something/that, does=(string)not, exist=(boolean)FALSE");
804
805   loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
806
807   from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
808   gst_buffer_unref (from_buffer);
809   gst_caps_unref (from_caps);
810
811   gst_video_convert_sample_async (from_sample, to_caps,
812       GST_CLOCK_TIME_NONE,
813       (GstVideoConvertSampleCallback) convert_sample_async_callback, &cf_data,
814       NULL);
815
816   g_main_loop_run (loop);
817
818   fail_if (cf_data.sample != NULL);
819   fail_unless (cf_data.error != NULL);
820   g_error_free (cf_data.error);
821   cf_data.error = NULL;
822
823   gst_caps_unref (to_caps);
824   gst_video_info_init (&vinfo);
825   gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420, 240, 320);
826   vinfo.par_n = 1;
827   vinfo.par_d = 2;
828   vinfo.fps_n = 25;
829   vinfo.fps_d = 1;
830   to_caps = gst_video_info_to_caps (&vinfo);
831   gst_video_convert_sample_async (from_sample, to_caps,
832       GST_CLOCK_TIME_NONE,
833       (GstVideoConvertSampleCallback) convert_sample_async_callback, &cf_data,
834       NULL);
835   g_main_loop_run (loop);
836   fail_unless (cf_data.sample != NULL);
837   fail_unless (cf_data.error == NULL);
838
839   gst_sample_unref (cf_data.sample);
840   gst_caps_unref (to_caps);
841
842   g_main_loop_unref (loop);
843 }
844
845 GST_END_TEST;
846
847 GST_START_TEST (test_video_size_from_caps)
848 {
849   GstVideoInfo vinfo;
850   GstCaps *caps;
851
852   caps = gst_caps_new_simple ("video/x-raw",
853       "format", G_TYPE_STRING, "YV12",
854       "width", G_TYPE_INT, 640,
855       "height", G_TYPE_INT, 480, "framerate", GST_TYPE_FRACTION, 25, 1, NULL);
856
857   gst_video_info_init (&vinfo);
858   fail_unless (gst_video_info_from_caps (&vinfo, caps));
859   fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == (640 * 480 * 12 / 8));
860
861   gst_caps_unref (caps);
862 }
863
864 GST_END_TEST;
865
866 #if 0
867 /* FIXME 0.11: port overlay composition to buffer meta */
868 GST_START_TEST (test_overlay_composition)
869 {
870   GstVideoOverlayComposition *comp1, *comp2;
871   GstVideoOverlayRectangle *rect1, *rect2;
872   GstBuffer *pix1, *pix2, *buf;
873   guint seq1, seq2;
874   guint w, h, stride;
875   gint x, y;
876
877   pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
878   memset (GST_BUFFER_DATA (pix1), 0, GST_BUFFER_SIZE (pix1));
879
880   rect1 = gst_video_overlay_rectangle_new_argb (pix1, 200, 50, 200 * 4,
881       600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
882
883   gst_buffer_unref (pix1);
884   pix1 = NULL;
885
886   comp1 = gst_video_overlay_composition_new (rect1);
887   fail_unless (gst_video_overlay_composition_n_rectangles (comp1) == 1);
888   fail_unless (gst_video_overlay_composition_get_rectangle (comp1, 0) == rect1);
889   fail_unless (gst_video_overlay_composition_get_rectangle (comp1, 1) == NULL);
890
891   /* rectangle was created first, sequence number should be smaller */
892   seq1 = gst_video_overlay_rectangle_get_seqnum (rect1);
893   seq2 = gst_video_overlay_composition_get_seqnum (comp1);
894   fail_unless (seq1 < seq2);
895
896   /* composition took own ref, so refcount is 2 now, so this should fail */
897   ASSERT_CRITICAL (gst_video_overlay_rectangle_set_render_rectangle (rect1, 50,
898           600, 300, 50));
899
900   /* drop our ref, so refcount is 1 (we know it will continue to be valid) */
901   gst_video_overlay_rectangle_unref (rect1);
902   gst_video_overlay_rectangle_set_render_rectangle (rect1, 50, 600, 300, 50);
903
904   comp2 = gst_video_overlay_composition_new (rect1);
905   fail_unless (gst_video_overlay_composition_n_rectangles (comp2) == 1);
906   fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 0) == rect1);
907   fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 1) == NULL);
908
909   fail_unless (seq1 < gst_video_overlay_composition_get_seqnum (comp2));
910   fail_unless (seq2 < gst_video_overlay_composition_get_seqnum (comp2));
911
912   /* now refcount is 2 again because comp2 has also taken a ref, so must fail */
913   ASSERT_CRITICAL (gst_video_overlay_rectangle_set_render_rectangle (rect1, 0,
914           0, 1, 1));
915
916   /* this should make a copy of the rectangles so drop the original
917    * second ref on rect1 */
918   comp2 = gst_video_overlay_composition_make_writable (comp2);
919   gst_video_overlay_rectangle_set_render_rectangle (rect1, 51, 601, 301, 51);
920
921   rect2 = gst_video_overlay_composition_get_rectangle (comp2, 0);
922   fail_unless (gst_video_overlay_composition_n_rectangles (comp2) == 1);
923   fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 0) == rect2);
924   fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 1) == NULL);
925   fail_unless (rect1 != rect2);
926
927   gst_video_overlay_composition_add_rectangle (comp1, rect2);
928   gst_video_overlay_composition_ref (comp1);
929   ASSERT_CRITICAL (gst_video_overlay_composition_add_rectangle (comp1, rect2));
930   gst_video_overlay_composition_unref (comp1);
931
932   /* make sure the copy really worked */
933   gst_video_overlay_rectangle_get_render_rectangle (rect1, &x, &y, &w, &h);
934   fail_unless_equals_int (x, 51);
935   fail_unless_equals_int (y, 601);
936   fail_unless_equals_int (w, 301);
937   fail_unless_equals_int (h, 51);
938
939   /* get scaled pixbuf and touch last byte */
940   pix1 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
941       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
942   fail_unless (GST_BUFFER_SIZE (pix1) > ((h - 1) * stride + (w * 4) - 1),
943       "size %u vs. last pixel offset %u", GST_BUFFER_SIZE (pix1),
944       ((h - 1) * stride + (w * 4) - 1));
945   fail_unless_equals_int (*(GST_BUFFER_DATA (pix1) + ((h - 1) * stride +
946               (w * 4) - 1)), 0);
947
948   gst_video_overlay_rectangle_get_render_rectangle (rect2, &x, &y, &w, &h);
949   fail_unless_equals_int (x, 50);
950   fail_unless_equals_int (y, 600);
951   fail_unless_equals_int (w, 300);
952   fail_unless_equals_int (h, 50);
953
954   /* get scaled pixbuf and touch last byte */
955   pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect2, &stride,
956       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
957   fail_unless (GST_BUFFER_SIZE (pix2) > ((h - 1) * stride + (w * 4) - 1),
958       "size %u vs. last pixel offset %u", GST_BUFFER_SIZE (pix1),
959       ((h - 1) * stride + (w * 4) - 1));
960   fail_unless_equals_int (*(GST_BUFFER_DATA (pix2) + ((h - 1) * stride +
961               (w * 4) - 1)), 0);
962
963   /* get scaled pixbuf again, should be the same buffer as before (caching) */
964   pix1 = gst_video_overlay_rectangle_get_pixels_argb (rect2, &stride,
965       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
966   fail_unless (pix1 == pix2);
967
968   /* now compare the original unscaled ones */
969   pix1 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
970       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
971   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect2, &w, &h,
972       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
973
974   /* the original pixel buffers should be identical */
975   fail_unless (pix1 == pix2);
976   fail_unless_equals_int (w, 200);
977   fail_unless_equals_int (h, 50);
978
979   /* touch last byte */
980   fail_unless (GST_BUFFER_SIZE (pix1) > ((h - 1) * stride + (w * 4) - 1),
981       "size %u vs. last pixel offset %u", GST_BUFFER_SIZE (pix1),
982       ((h - 1) * stride + (w * 4) - 1));
983   fail_unless_equals_int (*(GST_BUFFER_DATA (pix1) + ((h - 1) * stride +
984               (w * 4) - 1)), 0);
985
986   /* test attaching and retrieving of compositions to/from buffers */
987   buf = gst_buffer_new ();
988   fail_unless (gst_video_buffer_get_overlay_composition (buf) == NULL);
989
990   gst_buffer_ref (buf);
991   /* buffer now has refcount of 2, so its metadata is not writable.
992    * only check this if we are not running in valgrind, as it leaks */
993 #ifdef HAVE_VALGRIND
994   if (!RUNNING_ON_VALGRIND) {
995     ASSERT_CRITICAL (gst_video_buffer_set_overlay_composition (buf, comp1));
996   }
997 #endif
998   gst_buffer_unref (buf);
999   gst_video_buffer_set_overlay_composition (buf, comp1);
1000   fail_unless (gst_video_buffer_get_overlay_composition (buf) == comp1);
1001   gst_video_buffer_set_overlay_composition (buf, comp2);
1002   fail_unless (gst_video_buffer_get_overlay_composition (buf) == comp2);
1003   gst_video_buffer_set_overlay_composition (buf, NULL);
1004   fail_unless (gst_video_buffer_get_overlay_composition (buf) == NULL);
1005
1006   /* make sure the buffer cleans up its composition ref when unreffed */
1007   gst_video_buffer_set_overlay_composition (buf, comp2);
1008   gst_buffer_unref (buf);
1009
1010   gst_video_overlay_composition_unref (comp2);
1011   gst_video_overlay_composition_unref (comp1);
1012 }
1013
1014 GST_END_TEST;
1015
1016 GST_START_TEST (test_overlay_composition_premultiplied_alpha)
1017 {
1018   GstVideoOverlayRectangle *rect1;
1019   GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5;
1020   GstBuffer *pix6, *pix7, *pix8, *pix9, *pix10;
1021   guint8 *data5, *data7;
1022   guint w, h, stride, w2, h2, stride2;
1023
1024   pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1025   memset (GST_BUFFER_DATA (pix1), 0x80, GST_BUFFER_SIZE (pix1));
1026
1027   rect1 = gst_video_overlay_rectangle_new_argb (pix1, 200, 50, 200 * 4,
1028       600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1029   gst_buffer_unref (pix1);
1030
1031   /* same flags, unscaled, should be the same buffer */
1032   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1033       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1034   fail_unless (pix1 == pix2);
1035
1036   /* same flags, but scaled */
1037   pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1038       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1039   fail_if (pix3 == pix1 || pix3 == pix2);
1040
1041   /* same again, should hopefully get the same (cached) buffer as before */
1042   pix4 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1043       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1044   fail_unless (pix4 == pix3);
1045
1046   /* just to update the vars */
1047   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1048       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1049
1050   /* now, let's try to get premultiplied alpha from the unpremultiplied input */
1051   pix5 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w2, &h2,
1052       &stride2, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1053   fail_if (pix5 == pix1 || pix5 == pix2 || pix5 == pix3);
1054   fail_unless_equals_int (stride, stride2);
1055   fail_unless_equals_int (w, w2);
1056   fail_unless_equals_int (h, h2);
1057   fail_unless_equals_int (GST_BUFFER_SIZE (pix2), GST_BUFFER_SIZE (pix5));
1058   data5 = GST_BUFFER_DATA (pix5);
1059   fail_if (memcmp (data5, GST_BUFFER_DATA (pix2), GST_BUFFER_SIZE (pix5)) == 0);
1060
1061   /* make sure it actually did what we expected it to do (input=0x80808080) */
1062 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1063   /* B - G - R - A */
1064   fail_unless_equals_int (data5[0], 0x40);
1065   fail_unless_equals_int (data5[1], 0x40);
1066   fail_unless_equals_int (data5[2], 0x40);
1067   fail_unless_equals_int (data5[3], 0x80);
1068 #else
1069   /* A - R - G - B */
1070   fail_unless_equals_int (data5[0], 0x40);
1071   fail_unless_equals_int (data5[1], 0x40);
1072   fail_unless_equals_int (data5[2], 0x40);
1073   fail_unless_equals_int (data5[3], 0x80);
1074 #endif
1075
1076   /* same again, now we should be getting back the same buffer as before,
1077    * as it should have been cached */
1078   pix6 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w2, &h2,
1079       &stride2, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1080   fail_unless (pix6 == pix5);
1081
1082   /* just to update the stride var */
1083   pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1084       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1085   fail_unless (pix3 == pix4);
1086
1087   /* now try to get scaled premultiplied alpha from unpremultiplied input */
1088   pix7 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride2,
1089       GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1090   fail_if (pix7 == pix1 || pix7 == pix2 || pix7 == pix3 || pix7 == pix5);
1091   fail_unless_equals_int (stride, stride2);
1092
1093   data7 = GST_BUFFER_DATA (pix7);
1094   /* make sure it actually did what we expected it to do (input=0x80808080)
1095    * hoping that the scaling didn't mess up our values */
1096 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1097   /* B - G - R - A */
1098   fail_unless_equals_int (data7[0], 0x40);
1099   fail_unless_equals_int (data7[1], 0x40);
1100   fail_unless_equals_int (data7[2], 0x40);
1101   fail_unless_equals_int (data7[3], 0x80);
1102 #else
1103   /* A - R - G - B */
1104   fail_unless_equals_int (data7[0], 0x40);
1105   fail_unless_equals_int (data7[1], 0x40);
1106   fail_unless_equals_int (data7[2], 0x40);
1107   fail_unless_equals_int (data7[3], 0x80);
1108 #endif
1109
1110   /* and the same again, it should be cached now */
1111   pix8 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride2,
1112       GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1113   fail_unless (pix8 == pix7);
1114
1115   /* make sure other cached stuff is still there */
1116   pix9 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1117       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1118   fail_unless (pix9 == pix3);
1119   pix10 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w2, &h2,
1120       &stride2, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1121   fail_unless (pix10 == pix5);
1122
1123   gst_video_overlay_rectangle_unref (rect1);
1124 }
1125
1126 GST_END_TEST;
1127 #endif
1128
1129
1130 GST_START_TEST (test_overlay_composition_global_alpha)
1131 {
1132   GstVideoOverlayRectangle *rect1;
1133   GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5;
1134   guint8 *data2, *data4, *data5;
1135   guint w, h, stride, stride3, w4, h4, stride4, stride5;
1136   guint seq1, seq2;
1137   gfloat ga1, ga2;
1138   GstVideoOverlayFormatFlags flags1;
1139
1140   pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1141   memset (GST_BUFFER_DATA (pix1), 0x80, GST_BUFFER_SIZE (pix1));
1142
1143   rect1 = gst_video_overlay_rectangle_new_argb (pix1, 200, 50, 200 * 4,
1144       600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1145   gst_buffer_unref (pix1);
1146
1147   /* same flags, unscaled, should be the same buffer */
1148   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1149       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1150   fail_unless (pix1 == pix2);
1151
1152   /* same flags, but scaled */
1153   pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride3,
1154       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1155   fail_if (pix3 == pix1 || pix3 == pix2);
1156
1157   /* get unscaled premultiplied data, new cached rectangle should be created */
1158   pix4 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w4, &h4,
1159       &stride4, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1160   fail_if (pix4 == pix2 || pix4 == pix3);
1161   fail_unless_equals_int (stride, stride4);
1162   fail_unless_equals_int (w, w4);
1163   fail_unless_equals_int (h, h4);
1164   fail_unless_equals_int (GST_BUFFER_SIZE (pix2), GST_BUFFER_SIZE (pix4));
1165   data4 = GST_BUFFER_DATA (pix4);
1166   fail_if (memcmp (data4, GST_BUFFER_DATA (pix1), GST_BUFFER_SIZE (pix1)) == 0);
1167   /* make sure it actually did what we expected it to do (input=0x80808080) */
1168 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1169   /* B - G - R - A */
1170   fail_unless_equals_int (data4[0], 0x40);
1171   fail_unless_equals_int (data4[1], 0x40);
1172   fail_unless_equals_int (data4[2], 0x40);
1173   fail_unless_equals_int (data4[3], 0x80);
1174 #else
1175   /* A - R - G - B */
1176   fail_unless_equals_int (data4[0], 0x80);
1177   fail_unless_equals_int (data4[1], 0x40);
1178   fail_unless_equals_int (data4[2], 0x40);
1179   fail_unless_equals_int (data4[3], 0x40);
1180 #endif
1181
1182   /* now premultiplied and scaled, again a new cached rectangle should be cached */
1183   pix5 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride5,
1184       GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1185   fail_if (pix5 == pix2 || pix5 == pix3 || pix5 == pix4);
1186   /* stride and size should be equal to the first scaled rect */
1187   fail_unless_equals_int (stride5, stride3);
1188   fail_unless_equals_int (GST_BUFFER_SIZE (pix3), GST_BUFFER_SIZE (pix3));
1189   data5 = GST_BUFFER_DATA (pix5);
1190   /* data should be different (premutliplied) though */
1191   fail_if (memcmp (data5, GST_BUFFER_DATA (pix3), GST_BUFFER_SIZE (pix3)) == 0);
1192   /* make sure it actually did what we expected it to do (input=0x80808080) */
1193 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1194   /* B - G - R - A */
1195   fail_unless_equals_int (data5[0], 0x40);
1196   fail_unless_equals_int (data5[1], 0x40);
1197   fail_unless_equals_int (data5[2], 0x40);
1198   fail_unless_equals_int (data5[3], 0x80);
1199 #else
1200   /* A - R - G - B */
1201   fail_unless_equals_int (data5[0], 0x80);
1202   fail_unless_equals_int (data5[1], 0x40);
1203   fail_unless_equals_int (data5[2], 0x40);
1204   fail_unless_equals_int (data5[3], 0x40);
1205 #endif
1206
1207   /* global_alpha should initially be 1.0 */
1208   ga1 = gst_video_overlay_rectangle_get_global_alpha (rect1);
1209   fail_unless_equals_float (ga1, 1.0);
1210
1211   /* now set global_alpha */
1212   seq1 = gst_video_overlay_rectangle_get_seqnum (rect1);
1213   gst_video_overlay_rectangle_set_global_alpha (rect1, 0.5);
1214   ga2 = gst_video_overlay_rectangle_get_global_alpha (rect1);
1215   fail_unless_equals_float (ga2, 0.5);
1216
1217   /* seqnum should have changed */
1218   seq2 = gst_video_overlay_rectangle_get_seqnum (rect1);
1219   fail_unless (seq1 < seq2);
1220
1221   /* internal flags should have been set */
1222   flags1 = gst_video_overlay_rectangle_get_flags (rect1);
1223   fail_unless_equals_int (flags1, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1224
1225   /* request unscaled pixel-data, global-alpha not applied */
1226   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1227       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1228   /* this should just return the same buffer */
1229   fail_unless (pix2 == pix1);
1230   data2 = GST_BUFFER_DATA (pix2);
1231   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix1),
1232           GST_BUFFER_SIZE (pix1)) == 0);
1233   /* make sure we got the initial data (input=0x80808080) */
1234 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1235   /* B - G - R - A */
1236   fail_unless_equals_int (data2[0], 0x80);
1237   fail_unless_equals_int (data2[1], 0x80);
1238   fail_unless_equals_int (data2[2], 0x80);
1239   fail_unless_equals_int (data2[3], 0x80);
1240 #else
1241   /* A - R - G - B */
1242   fail_unless_equals_int (data2[0], 0x80);
1243   fail_unless_equals_int (data2[1], 0x80);
1244   fail_unless_equals_int (data2[2], 0x80);
1245   fail_unless_equals_int (data2[3], 0x80);
1246 #endif
1247
1248   /* unscaled pixel-data, global-alpha applied */
1249   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1250       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1251   /* this should be the same buffer with on-the-fly modified alpha-channel */
1252   fail_unless (pix2 == pix1);
1253   data2 = GST_BUFFER_DATA (pix2);
1254   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix1),
1255           GST_BUFFER_SIZE (pix1)) == 0);
1256   /* make sure we got the initial data with adjusted alpha-channel */
1257 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1258   /* B - G - R - A */
1259   fail_unless_equals_int (data2[0], 0x80);
1260   fail_unless_equals_int (data2[1], 0x80);
1261   fail_unless_equals_int (data2[2], 0x80);
1262   fail_unless_equals_int (data2[3], 0x40);
1263 #else
1264   /* A - R - G - B */
1265   fail_unless_equals_int (data2[0], 0x40);
1266   fail_unless_equals_int (data2[1], 0x80);
1267   fail_unless_equals_int (data2[2], 0x80);
1268   fail_unless_equals_int (data2[3], 0x80);
1269 #endif
1270
1271   /* adjust global_alpha once more */
1272   gst_video_overlay_rectangle_set_global_alpha (rect1, 0.25);
1273   ga2 = gst_video_overlay_rectangle_get_global_alpha (rect1);
1274   fail_unless_equals_float (ga2, 0.25);
1275   /* and again request unscaled pixel-data, global-alpha applied */
1276   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1277       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1278   fail_unless (pix2 == pix1);
1279   data2 = GST_BUFFER_DATA (pix2);
1280   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix1),
1281           GST_BUFFER_SIZE (pix1)) == 0);
1282   /* make sure we got the initial data with adjusted alpha-channel */
1283 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1284   /* B - G - R - A */
1285   fail_unless_equals_int (data2[0], 0x80);
1286   fail_unless_equals_int (data2[1], 0x80);
1287   fail_unless_equals_int (data2[2], 0x80);
1288   fail_unless_equals_int (data2[3], 0x20);
1289 #else
1290   /* A - R - G - B */
1291   fail_unless_equals_int (data2[0], 0x20);
1292   fail_unless_equals_int (data2[1], 0x80);
1293   fail_unless_equals_int (data2[2], 0x80);
1294   fail_unless_equals_int (data2[3], 0x80);
1295 #endif
1296
1297   /* again: unscaled pixel-data, global-alpha not applied,
1298    * this should revert alpha-channel to initial values */
1299   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1300       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1301   fail_unless (pix2 == pix1);
1302   data2 = GST_BUFFER_DATA (pix2);
1303   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix1),
1304           GST_BUFFER_SIZE (pix1)) == 0);
1305   /* make sure we got the initial data (input=0x80808080) */
1306 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1307   /* B - G - R - A */
1308   fail_unless_equals_int (data2[0], 0x80);
1309   fail_unless_equals_int (data2[1], 0x80);
1310   fail_unless_equals_int (data2[2], 0x80);
1311   fail_unless_equals_int (data2[3], 0x80);
1312 #else
1313   /* A - R - G - B */
1314   fail_unless_equals_int (data2[0], 0x80);
1315   fail_unless_equals_int (data2[1], 0x80);
1316   fail_unless_equals_int (data2[2], 0x80);
1317   fail_unless_equals_int (data2[3], 0x80);
1318 #endif
1319
1320   /* now scaled, global-alpha not applied */
1321   pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1322       GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1323   /* this should just return the rect/buffer, that was cached for these
1324    * scaling dimensions */
1325   fail_unless (pix2 == pix3);
1326   data2 = GST_BUFFER_DATA (pix2);
1327   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix3),
1328           GST_BUFFER_SIZE (pix3)) == 0);
1329   /* make sure we got the initial data (input=0x80808080) */
1330 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1331   /* B - G - R - A */
1332   fail_unless_equals_int (data2[0], 0x80);
1333   fail_unless_equals_int (data2[1], 0x80);
1334   fail_unless_equals_int (data2[2], 0x80);
1335   fail_unless_equals_int (data2[3], 0x80);
1336 #else
1337   /* A - R - G - B */
1338   fail_unless_equals_int (data2[0], 0x80);
1339   fail_unless_equals_int (data2[1], 0x80);
1340   fail_unless_equals_int (data2[2], 0x80);
1341   fail_unless_equals_int (data2[3], 0x80);
1342 #endif
1343
1344   /* scaled, global-alpha (0.25) applied */
1345   pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1346       GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1347   /* this should just return the rect/buffer, that was cached for these
1348    * scaling dimensions with modified alpha channel */
1349   fail_unless (pix2 == pix3);
1350   data2 = GST_BUFFER_DATA (pix2);
1351   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix3),
1352           GST_BUFFER_SIZE (pix3)) == 0);
1353   /* make sure we got the data we expect for global-alpha=0.25 */
1354 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1355   /* B - G - R - A */
1356   fail_unless_equals_int (data2[0], 0x80);
1357   fail_unless_equals_int (data2[1], 0x80);
1358   fail_unless_equals_int (data2[2], 0x80);
1359   fail_unless_equals_int (data2[3], 0x20);
1360 #else
1361   /* A - R - G - B */
1362   fail_unless_equals_int (data2[0], 0x20);
1363   fail_unless_equals_int (data2[1], 0x80);
1364   fail_unless_equals_int (data2[2], 0x80);
1365   fail_unless_equals_int (data2[3], 0x80);
1366 #endif
1367
1368   /* now unscaled premultiplied data, global-alpha not applied,
1369    * is this really a valid use case?*/
1370   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1371       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA |
1372       GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1373   /* this should just return the rect/buffer, that was cached for the
1374    * premultiplied data */
1375   fail_unless (pix2 == pix4);
1376   data2 = GST_BUFFER_DATA (pix2);
1377   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix4),
1378           GST_BUFFER_SIZE (pix4)) == 0);
1379   /* make sure we got what we expected */
1380 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1381   /* B - G - R - A */
1382   fail_unless_equals_int (data2[0], 0x40);
1383   fail_unless_equals_int (data2[1], 0x40);
1384   fail_unless_equals_int (data2[2], 0x40);
1385   fail_unless_equals_int (data2[3], 0x80);
1386 #else
1387   /* A - R - G - B */
1388   fail_unless_equals_int (data2[0], 0x80);
1389   fail_unless_equals_int (data2[1], 0x40);
1390   fail_unless_equals_int (data2[2], 0x40);
1391   fail_unless_equals_int (data2[3], 0x40);
1392 #endif
1393
1394   /* unscaled premultiplied data, global-alpha (0.25) applied */
1395   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1396       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1397   /* this should just return the rect/buffer, that was cached for the
1398    * premultiplied data */
1399   fail_unless (pix2 == pix4);
1400   data2 = GST_BUFFER_DATA (pix2);
1401   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix4),
1402           GST_BUFFER_SIZE (pix4)) == 0);
1403   /* make sure we got what we expected:
1404    * (0x40 / (0x80/0xFF) * (0x20/0xFF) = 0x10
1405    * NOTE: unless we are using round() for the premultiplied case
1406    * in gst_video_overlay_rectangle_apply_global_alpha() we get rounding
1407    * error, i.e. 0x0F here */
1408 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1409   /* B - G - R - A */
1410   fail_unless_equals_int (data2[0], 0x0F);
1411   fail_unless_equals_int (data2[1], 0x0F);
1412   fail_unless_equals_int (data2[2], 0x0F);
1413   fail_unless_equals_int (data2[3], 0x20);
1414 #else
1415   /* A - R - G - B */
1416   fail_unless_equals_int (data2[0], 0x20);
1417   fail_unless_equals_int (data2[1], 0x0F);
1418   fail_unless_equals_int (data2[2], 0x0F);
1419   fail_unless_equals_int (data2[3], 0x0F);
1420 #endif
1421
1422   /* set global_alpha once more */
1423   gst_video_overlay_rectangle_set_global_alpha (rect1, 0.75);
1424   /* and verify that also premultiplied data is adjusted
1425    * correspondingly (though with increasing rounding errors) */
1426   pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h,
1427       &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1428   /* this should just return the rect/buffer, that was cached for the
1429    * premultiplied data */
1430   fail_unless (pix2 == pix4);
1431   data2 = GST_BUFFER_DATA (pix2);
1432   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix4),
1433           GST_BUFFER_SIZE (pix4)) == 0);
1434   /* make sure we got what we expected:
1435    * (0x0F / (0x20/0xFF) * (0x60/0xFF) = 0x2D
1436    * NOTE: using floats everywhere we would get 0x30
1437    * here we will actually end up with 0x2C */
1438 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1439   /* B - G - R - A */
1440   fail_unless_equals_int (data2[0], 0x2C);
1441   fail_unless_equals_int (data2[1], 0x2C);
1442   fail_unless_equals_int (data2[2], 0x2C);
1443   fail_unless_equals_int (data2[3], 0x60);
1444 #else
1445   /* A - R - G - B */
1446   fail_unless_equals_int (data2[0], 0x60);
1447   fail_unless_equals_int (data2[1], 0x2C);
1448   fail_unless_equals_int (data2[2], 0x2C);
1449   fail_unless_equals_int (data2[3], 0x2C);
1450 #endif
1451
1452   /* now scaled and premultiplied data, global-alpha not applied,
1453    * is this really a valid use case?*/
1454   pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1455       GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA |
1456       GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1457   /* this should just return the rect/buffer, that was cached for the
1458    * first premultiplied+scaled rect*/
1459   fail_unless (pix2 == pix5);
1460   fail_unless (stride == stride5);
1461   data2 = GST_BUFFER_DATA (pix2);
1462   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix5),
1463           GST_BUFFER_SIZE (pix5)) == 0);
1464   /* make sure we got what we expected */
1465 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1466   /* B - G - R - A */
1467   fail_unless_equals_int (data2[0], 0x40);
1468   fail_unless_equals_int (data2[1], 0x40);
1469   fail_unless_equals_int (data2[2], 0x40);
1470   fail_unless_equals_int (data2[3], 0x80);
1471 #else
1472   /* A - R - G - B */
1473   fail_unless_equals_int (data2[0], 0x80);
1474   fail_unless_equals_int (data2[1], 0x40);
1475   fail_unless_equals_int (data2[2], 0x40);
1476   fail_unless_equals_int (data2[3], 0x40);
1477 #endif
1478
1479   /* scaled and premultiplied data, global-alpha applied */
1480   pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride,
1481       GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1482   /* this should just return the rect/buffer, that was cached for the
1483    * first premultiplied+scaled rect*/
1484   fail_unless (pix2 == pix5);
1485   fail_unless (stride == stride5);
1486   data2 = GST_BUFFER_DATA (pix2);
1487   fail_unless (memcmp (data2, GST_BUFFER_DATA (pix5),
1488           GST_BUFFER_SIZE (pix5)) == 0);
1489   /* make sure we got what we expected; see above note about rounding errors! */
1490 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1491   /* B - G - R - A */
1492   fail_unless_equals_int (data2[0], 0x2F);
1493   fail_unless_equals_int (data2[1], 0x2F);
1494   fail_unless_equals_int (data2[2], 0x2F);
1495   fail_unless_equals_int (data2[3], 0x60);
1496 #else
1497   /* A - R - G - B */
1498   fail_unless_equals_int (data2[0], 0x60);
1499   fail_unless_equals_int (data2[1], 0x2F);
1500   fail_unless_equals_int (data2[2], 0x2F);
1501   fail_unless_equals_int (data2[3], 0x2F);
1502 #endif
1503
1504   gst_video_overlay_rectangle_unref (rect1);
1505 }
1506
1507 GST_END_TEST;
1508
1509 static Suite *
1510 video_suite (void)
1511 {
1512   Suite *s = suite_create ("video support library");
1513   TCase *tc_chain = tcase_create ("general");
1514
1515   suite_add_tcase (s, tc_chain);
1516   tcase_add_test (tc_chain, test_video_formats);
1517   tcase_add_test (tc_chain, test_video_formats_rgb);
1518   tcase_add_test (tc_chain, test_video_formats_all);
1519   tcase_add_test (tc_chain, test_dar_calc);
1520   tcase_add_test (tc_chain, test_parse_caps_rgb);
1521   tcase_add_test (tc_chain, test_events);
1522   tcase_add_test (tc_chain, test_convert_frame);
1523   tcase_add_test (tc_chain, test_convert_frame_async);
1524   tcase_add_test (tc_chain, test_video_size_from_caps);
1525 #if 0
1526   /* FIXME 0.11: port overlay compositions */
1527   tcase_add_test (tc_chain, test_overlay_composition);
1528   tcase_add_test (tc_chain, test_overlay_composition_premultiplied_alpha);
1529   tcase_add_test (tc_chain, test_overlay_composition_global_alpha);
1530 #endif
1531
1532   return s;
1533 }
1534
1535 GST_CHECK_MAIN (video);