videotestsrc: Remove more redundant code
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 6 Jun 2012 09:15:50 +0000 (11:15 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Wed, 6 Jun 2012 09:18:56 +0000 (11:18 +0200)
Use the video library to do the setup instead of keeping a separate incomplete
list.

gst/videotestsrc/gstvideotestsrc.c
gst/videotestsrc/gstvideotestsrc.h
gst/videotestsrc/videotestsrc.c
gst/videotestsrc/videotestsrc.h

index 1b46203..97579bc 100644 (file)
@@ -550,12 +550,12 @@ gst_video_test_src_get_property (GObject * object, guint prop_id,
 static gboolean
 gst_video_test_src_parse_caps (const GstCaps * caps,
     gint * width, gint * height, gint * fps_n, gint * fps_d,
-    GstVideoColorimetry * colorimetry)
+    GstVideoColorimetry * colorimetry, gint * x_inv, gint * y_inv)
 {
   const GstStructure *structure;
   GstPadLinkReturn ret;
   const GValue *framerate;
-  const gchar *csp;
+  const gchar *str;
 
   GST_DEBUG ("parsing caps");
 
@@ -571,9 +571,23 @@ gst_video_test_src_parse_caps (const GstCaps * caps,
   } else
     goto no_framerate;
 
-  if ((csp = gst_structure_get_string (structure, "colorimetry")))
-    gst_video_colorimetry_from_string (colorimetry, csp);
-
+  if ((str = gst_structure_get_string (structure, "colorimetry")))
+    gst_video_colorimetry_from_string (colorimetry, str);
+
+  if ((str = gst_structure_get_string (structure, "format"))) {
+    if (g_str_equal (str, "bggr")) {
+      *x_inv = *y_inv = 0;
+    } else if (g_str_equal (str, "rggb")) {
+      *x_inv = *y_inv = 1;
+    } else if (g_str_equal (str, "grbg")) {
+      *x_inv = 0;
+      *y_inv = 1;
+    } else if (g_str_equal (str, "grbg")) {
+      *x_inv = 1;
+      *y_inv = 0;
+    } else
+      goto invalid_format;
+  }
   return ret;
 
   /* ERRORS */
@@ -582,6 +596,11 @@ no_framerate:
     GST_DEBUG ("videotestsrc no framerate given");
     return FALSE;
   }
+invalid_format:
+  {
+    GST_DEBUG ("videotestsrc invalid bayer format given");
+    return FALSE;
+  }
 }
 
 static gboolean
@@ -610,7 +629,10 @@ gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
 
   /* no downstream pool, make our own */
   if (pool == NULL) {
-    pool = gst_video_buffer_pool_new ();
+    if (videotestsrc->bayer)
+      pool = gst_buffer_pool_new ();
+    else
+      pool = gst_video_buffer_pool_new ();
   }
 
   config = gst_buffer_pool_get_config (pool);
@@ -634,7 +656,6 @@ gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
 static gboolean
 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
 {
-  struct format_list_struct *format;
   const GstStructure *structure;
   GstVideoTestSrc *videotestsrc;
   GstVideoInfo info;
@@ -649,19 +670,25 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
       goto parse_failed;
 
   } else if (gst_structure_has_name (structure, "video/x-bayer")) {
+    gint x_inv = 0, y_inv = 0;
+
+    gst_video_info_init (&info);
+
+    info.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
+
     if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
-            &info.fps_n, &info.fps_d, &info.colorimetry))
+            &info.fps_n, &info.fps_d, &info.colorimetry, &x_inv, &y_inv))
       goto parse_failed;
 
-    info.size =
-        gst_video_test_src_get_size (videotestsrc, info.width, info.height);
-  }
+    info.size = GST_ROUND_UP_4 (info.width) * info.height;
+    info.stride[0] = GST_ROUND_UP_4 (info.width);
 
-  if (!(format = paintinfo_find_by_structure (structure)))
-    goto unknown_format;
+    videotestsrc->bayer = TRUE;
+    videotestsrc->x_invert = x_inv;
+    videotestsrc->y_invert = y_inv;
+  }
 
   /* looks ok here */
-  videotestsrc->format = format;
   videotestsrc->info = info;
 
   GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
@@ -684,11 +711,6 @@ parse_failed:
     GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
     return FALSE;
   }
-unknown_format:
-  {
-    GST_DEBUG ("videotestsrc format not found");
-    return FALSE;
-  }
 }
 
 static gboolean
@@ -789,7 +811,8 @@ gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
 
   src = GST_VIDEO_TEST_SRC (psrc);
 
-  if (G_UNLIKELY (src->format == NULL))
+  if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&src->info) ==
+          GST_VIDEO_FORMAT_UNKNOWN))
     goto not_negotiated;
 
   /* 0 framerate and we are at the second frame, eos */
index e079594..f64837e 100644 (file)
@@ -124,9 +124,9 @@ struct _GstVideoTestSrc {
 
   /* video state */
   GstVideoInfo info;
-
-  char *format_name;
-  struct format_list_struct *format;
+  gboolean bayer;
+  gint x_invert;
+  gint y_invert;
 
   /* private */
   gint64 timestamp_offset;              /* base offset */
index 635ed57..d0a39bc 100644 (file)
@@ -34,9 +34,6 @@
 
 #define TO_16(x) (((x)<<8) | (x))
 
-static void paint_tmpline_ARGB (paintinfo * p, int x, int w);
-static void paint_tmpline_AYUV (paintinfo * p, int x, int w);
-
 static unsigned char
 random_char (void)
 {
@@ -124,285 +121,12 @@ static const struct vts_color_struct vts_colors_bt601_ycbcr_75[] = {
 };
 
 
-static void paint_setup_generic (paintinfo * p, GstVideoFrame * frame);
-
-static void paint_setup_bayer_bggr (paintinfo * p, GstVideoFrame * frame);
-static void paint_setup_bayer_rggb (paintinfo * p, GstVideoFrame * frame);
-static void paint_setup_bayer_gbrg (paintinfo * p, GstVideoFrame * frame);
-static void paint_setup_bayer_grbg (paintinfo * p, GstVideoFrame * frame);
+static void paint_tmpline_ARGB (paintinfo * p, int x, int w);
+static void paint_tmpline_AYUV (paintinfo * p, int x, int w);
 
 static void convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y);
-#if 0
-static void convert_hline_I420 (paintinfo * p, int y);
-static void convert_hline_NV12 (paintinfo * p, int y);
-static void convert_hline_NV21 (paintinfo * p, int y);
-static void convert_hline_YUY2 (paintinfo * p, int y);
-#ifdef disabled
-static void convert_hline_IYU2 (paintinfo * p, int y);
-#endif
-static void convert_hline_Y41B (paintinfo * p, int y);
-static void convert_hline_Y42B (paintinfo * p, int y);
-static void convert_hline_Y444 (paintinfo * p, int y);
-static void convert_hline_Y800 (paintinfo * p, int y);
-static void convert_hline_v308 (paintinfo * p, int y);
-static void convert_hline_AYUV (paintinfo * p, int y);
-#ifdef disabled
-static void convert_hline_v410 (paintinfo * p, int y);
-#endif
-static void convert_hline_v216 (paintinfo * p, int y);
-static void convert_hline_v210 (paintinfo * p, int y);
-static void convert_hline_UYVP (paintinfo * p, int y);
-static void convert_hline_AY64 (paintinfo * p, int y);
-
-static void convert_hline_YUV9 (paintinfo * p, int y);
-static void convert_hline_astr4 (paintinfo * p, int y);
-static void convert_hline_astr8 (paintinfo * p, int y);
-static void convert_hline_str4 (paintinfo * p, int y);
-static void convert_hline_str3 (paintinfo * p, int y);
-static void convert_hline_RGB565 (paintinfo * p, int y);
-static void convert_hline_xRGB1555 (paintinfo * p, int y);
-
-static void convert_hline_GRAY8 (paintinfo * p, int y);
-static void convert_hline_GRAY16 (paintinfo * p, int y);
-static void convert_hline_I420_10LE (paintinfo * p, int y);
-static void convert_hline_I420_10BE (paintinfo * p, int y);
-#endif
-
 static void convert_hline_bayer (paintinfo * p, GstVideoFrame * frame, int y);
 
-struct format_list_struct format_list[] = {
-/* packed */
-  {VTS_YUV, "YUY2", "YUY2", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "UYVY", "UYVY", paint_setup_generic, convert_hline_generic},
-#ifdef disabled
-  {VTS_YUV, "Y422", "Y422", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "UYNV", "UYNV", paint_setup_generic, convert_hline_generic},        /* FIXME: UYNV? */
-#endif
-  {VTS_YUV, "YVYU", "YVYU", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "v308", "v308", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "AYUV", "AYUV", paint_setup_generic, convert_hline_generic},
-#ifdef disabled
-  {VTS_YUV, "v410", "v410", paint_setup_generic, convert_hline_generic},
-#endif
-  {VTS_YUV, "v210", "v210", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "v216", "v216", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "UYVP", "UYVP", paint_setup_generic, convert_hline_generic},
-  {VTS_YUV, "AYUV64", "AY64", paint_setup_generic, convert_hline_generic},
-
-#ifdef disabled
-  {VTS_YUV, "IYU2", "IYU2", paint_setup_generic, convert_hline_generic},
-#endif
-
-/* planar */
-  /* YVU9 */
-  {VTS_YUV, "YVU9", "YVU9", paint_setup_generic, convert_hline_generic},
-  /* YUV9 */
-  {VTS_YUV, "YUV9", "YUV9", paint_setup_generic, convert_hline_generic},
-  /* IF09 */
-  /* YV12 */
-  {VTS_YUV, "YV12", "YV12", paint_setup_generic, convert_hline_generic},
-  /* I420 */
-  {VTS_YUV, "I420", "I420", paint_setup_generic, convert_hline_generic},
-  /* NV12 */
-  {VTS_YUV, "NV12", "NV12", paint_setup_generic, convert_hline_generic},
-  /* NV21 */
-  {VTS_YUV, "NV21", "NV21", paint_setup_generic, convert_hline_generic},
-  /* CLPL */
-  /* Y41B */
-  {VTS_YUV, "Y41B", "Y41B", paint_setup_generic, convert_hline_generic},
-  /* Y42B */
-  {VTS_YUV, "Y42B", "Y42B", paint_setup_generic, convert_hline_generic},
-  /* Y444 */
-  {VTS_YUV, "Y444", "Y444", paint_setup_generic, convert_hline_generic},
-
-  {VTS_YUV, "I420_10LE", "I420-10LE", paint_setup_generic,
-      convert_hline_generic},
-  {VTS_YUV, "I420_10BE", "I420-10BE", paint_setup_generic,
-      convert_hline_generic},
-
-  /* Not exactly YUV but it's the same as above */
-  {VTS_GRAY, "GRAY8", "GRAY8", paint_setup_generic, convert_hline_generic},
-  {VTS_GRAY, "GRAY16_LE", "GRAY16", paint_setup_generic,
-      convert_hline_generic},
-  {VTS_GRAY, "GRAY16_BE", "GRAY16", paint_setup_generic,
-      convert_hline_generic},
-
-  {VTS_RGB, "xRGB", "xRGB8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "xBGR", "xBGR8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "RGBx", "RGBx8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "BGRx", "BGRx8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "ARGB", "ARGB8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "ABGR", "ABGR8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "RGBA", "RGBA8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "BGRA", "BGRA8888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "RGB", "RGB888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "BGR", "BGR888", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "RGB16", "RGB565", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "RGB15", "xRGB1555", paint_setup_generic, convert_hline_generic},
-  {VTS_RGB, "ARGB64", "ARGB8888", paint_setup_generic, convert_hline_generic},
-
-  {VTS_BAYER, "bggr", "Bayer", paint_setup_bayer_bggr, convert_hline_bayer},
-  {VTS_BAYER, "rggb", "Bayer", paint_setup_bayer_rggb, convert_hline_bayer},
-  {VTS_BAYER, "grbg", "Bayer", paint_setup_bayer_grbg, convert_hline_bayer},
-  {VTS_BAYER, "gbrg", "Bayer", paint_setup_bayer_gbrg, convert_hline_bayer}
-};
-
-int n_formats = G_N_ELEMENTS (format_list);
-
-struct format_list_struct *
-paintinfo_find_by_structure (const GstStructure * structure)
-{
-  int i;
-  const char *media_type = gst_structure_get_name (structure);
-
-  g_return_val_if_fail (structure, NULL);
-
-  if (strcmp (media_type, "video/x-raw") == 0) {
-    const gchar *format;
-
-    format = gst_structure_get_string (structure, "format");
-    if (!format) {
-      GST_WARNING ("incomplete caps structure: %" GST_PTR_FORMAT, structure);
-      return NULL;
-    }
-
-    for (i = 0; i < n_formats; i++) {
-      if (g_str_equal (format, format_list[i].format)) {
-        return format_list + i;
-      }
-    }
-    return NULL;
-  } else if (strcmp (media_type, "video/x-bayer") == 0) {
-    const gchar *format;
-
-    format = gst_structure_get_string (structure, "format");
-    if (!format) {
-      GST_WARNING ("incomplete caps structure: %" GST_PTR_FORMAT, structure);
-      return NULL;
-    }
-
-    for (i = 0; i < n_formats; i++) {
-      if (format_list[i].type == VTS_BAYER &&
-          g_str_equal (format, format_list[i].format)) {
-        return format_list + i;
-      }
-    }
-    return NULL;
-  }
-
-  g_critical ("format not found for media type %s", media_type);
-
-  return NULL;
-}
-
-struct format_list_struct *
-paintrect_find_format (const gchar * find_format)
-{
-  int i;
-
-  for (i = 0; i < n_formats; i++) {
-    if (g_str_equal (find_format, format_list[i].format)) {
-      return format_list + i;
-    }
-  }
-  return NULL;
-}
-
-struct format_list_struct *
-paintrect_find_name (const char *name)
-{
-  int i;
-
-  for (i = 0; i < n_formats; i++) {
-    if (g_str_equal (name, format_list[i].name)) {
-      return format_list + i;
-    }
-  }
-  return NULL;
-}
-
-
-GstStructure *
-paint_get_structure (struct format_list_struct * format)
-{
-  GstStructure *structure = NULL;
-
-  g_return_val_if_fail (format, NULL);
-
-  switch (format->type) {
-    case VTS_RGB:
-    case VTS_GRAY:
-      structure = gst_structure_new ("video/x-raw",
-          "format", G_TYPE_STRING, format->format, NULL);
-      break;
-    case VTS_YUV:
-    {
-      GValue value_list = { 0 };
-      GValue value = { 0 };
-
-      structure = gst_structure_new ("video/x-raw",
-          "format", G_TYPE_STRING, format->format, NULL);
-
-      if (strcmp (format->format, "Y800") != 0) {
-        g_value_init (&value_list, GST_TYPE_LIST);
-
-        g_value_init (&value, G_TYPE_STRING);
-        g_value_set_static_string (&value, "bt601");
-        gst_value_list_append_value (&value_list, &value);
-
-        g_value_set_static_string (&value, "bt709");
-        gst_value_list_append_value (&value_list, &value);
-
-        gst_structure_set_value (structure, "colorimetry", &value_list);
-        g_value_reset (&value_list);
-
-        if (strcmp (format->format, "AYUV") &&
-            strcmp (format->format, "v308") &&
-            strcmp (format->format, "v410") &&
-            strcmp (format->format, "Y444")) {
-          g_value_set_static_string (&value, "mpeg2");
-          gst_value_list_append_value (&value_list, &value);
-
-          g_value_set_static_string (&value, "jpeg");
-          gst_value_list_append_value (&value_list, &value);
-
-          gst_structure_set_value (structure, "chroma-site", &value_list);
-        }
-        g_value_unset (&value_list);
-      }
-      break;
-    }
-    case VTS_BAYER:
-      structure = gst_structure_new ("video/x-bayer",
-          "format", G_TYPE_STRING, format->format, NULL);
-      break;
-    default:
-      g_assert_not_reached ();
-      break;
-  }
-  return structure;
-}
-
-/* returns the size in bytes for one video frame of the given dimensions
- * given the format in GstVideoTestSrc */
-int
-gst_video_test_src_get_size (GstVideoTestSrc * v, int w, int h)
-{
-  paintinfo pi = PAINT_INFO_INIT;
-  paintinfo *p = &pi;
-  struct format_list_struct *format;
-
-  p->width = w;
-  p->height = h;
-  format = v->format;
-  if (format == NULL)
-    return 0;
-
-  format->paint_setup (p, NULL);
-
-  return p->size;
-}
-
 #define SCALEBITS 10
 #define ONE_HALF  (1 << (SCALEBITS - 1))
 #define FIX(x)    ((int) ((x) * (1<<SCALEBITS) + 0.5))
@@ -446,29 +170,38 @@ gst_video_test_src_get_size (GstVideoTestSrc * v, int w, int h)
 static void
 videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h)
 {
-  int a, r, g, b;
+  gint a, r, g, b;
+  gint width;
+  GstVideoInfo *info = &v->info;
 
-  if (v->info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
+  width = GST_VIDEO_INFO_WIDTH (info);
+
+  if (info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
     p->colors = vts_colors_bt601_ycbcr_100;
   } else {
     p->colors = vts_colors_bt709_ycbcr_100;
   }
-  p->width = w;
-  p->height = h;
 
-  p->convert_tmpline = v->format->convert_hline;
-  if (v->format->type == VTS_RGB || v->format->type == VTS_BAYER) {
+  if (v->bayer) {
     p->paint_tmpline = paint_tmpline_ARGB;
+    p->convert_tmpline = convert_hline_bayer;
   } else {
-    p->paint_tmpline = paint_tmpline_AYUV;
+    p->convert_tmpline = convert_hline_generic;
+    if (GST_VIDEO_INFO_IS_RGB (info)) {
+      p->paint_tmpline = paint_tmpline_ARGB;
+    } else {
+      p->paint_tmpline = paint_tmpline_AYUV;
+    }
   }
   p->tmpline = v->tmpline;
   p->tmpline2 = v->tmpline2;
   p->tmpline_u8 = v->tmpline_u8;
   p->tmpline_u16 = v->tmpline_u16;
-  p->x_offset = (v->horizontal_speed * v->n_frames) % p->width;
+  p->x_offset = (v->horizontal_speed * v->n_frames) % width;
   if (p->x_offset < 0)
-    p->x_offset += p->width;
+    p->x_offset += width;
+  p->x_invert = v->x_invert;
+  p->y_invert = v->y_invert;
 
   a = (v->foreground_color >> 24) & 0xff;
   r = (v->foreground_color >> 16) & 0xff;
@@ -478,7 +211,8 @@ videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h)
   p->foreground_color.R = r;
   p->foreground_color.G = g;
   p->foreground_color.B = b;
-  if (v->info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
+
+  if (info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
     p->foreground_color.Y = RGB_TO_Y_CCIR (r, g, b);
     p->foreground_color.U = RGB_TO_U_CCIR (r, g, b, 0);
     p->foreground_color.V = RGB_TO_V_CCIR (r, g, b, 0);
@@ -497,7 +231,8 @@ videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h)
   p->background_color.R = r;
   p->background_color.G = g;
   p->background_color.B = b;
-  if (v->info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
+
+  if (info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
     p->background_color.Y = RGB_TO_Y_CCIR (r, g, b);
     p->background_color.U = RGB_TO_U_CCIR (r, g, b, 0);
     p->background_color.V = RGB_TO_V_CCIR (r, g, b, 0);
@@ -515,18 +250,19 @@ videotestsrc_convert_tmpline (paintinfo * p, GstVideoFrame * frame, int j)
 {
   int x = p->x_offset;
   int i;
+  int width = frame->info.width;
 
   if (x != 0) {
-    memcpy (p->tmpline2, p->tmpline, p->width * 4);
-    memcpy (p->tmpline, p->tmpline2 + x * 4, (p->width - x) * 4);
-    memcpy (p->tmpline + (p->width - x) * 4, p->tmpline2, x * 4);
+    memcpy (p->tmpline2, p->tmpline, width * 4);
+    memcpy (p->tmpline, p->tmpline2 + x * 4, (width - x) * 4);
+    memcpy (p->tmpline + (width - x) * 4, p->tmpline2, x * 4);
   }
 
-  for (i = p->width; i < p->width + 5; i++) {
-    p->tmpline[4 * i + 0] = p->tmpline[4 * (p->width - 1) + 0];
-    p->tmpline[4 * i + 1] = p->tmpline[4 * (p->width - 1) + 1];
-    p->tmpline[4 * i + 2] = p->tmpline[4 * (p->width - 1) + 2];
-    p->tmpline[4 * i + 3] = p->tmpline[4 * (p->width - 1) + 3];
+  for (i = width; i < width + 5; i++) {
+    p->tmpline[4 * i + 0] = p->tmpline[4 * (width - 1) + 0];
+    p->tmpline[4 * i + 1] = p->tmpline[4 * (width - 1) + 1];
+    p->tmpline[4 * i + 2] = p->tmpline[4 * (width - 1) + 2];
+    p->tmpline[4 * i + 3] = p->tmpline[4 * (width - 1) + 3];
   }
 
   p->convert_tmpline (p, frame, j);
@@ -557,7 +293,7 @@ videotestsrc_blend_line (GstVideoTestSrc * v, guint8 * dest, guint8 * src,
     struct vts_color_struct *a, struct vts_color_struct *b, int n)
 {
   int i;
-  if (v->format->type == VTS_RGB || v->format->type == VTS_BAYER) {
+  if (v->bayer || GST_VIDEO_INFO_IS_RGB (&v->info)) {
     for (i = 0; i < n; i++) {
       dest[i * 4 + 0] = BLEND (a->A, b->A, src[i]);
       dest[i * 4 + 1] = BLEND (a->R, b->R, src[i]);
@@ -583,15 +319,9 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
-  videotestsrc_setup_paintinfo (v, p, frame->info.width, frame->info.height);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
+  videotestsrc_setup_paintinfo (v, p, w, h);
 
   y1 = 2 * h / 3;
   y2 = 3 * h / 4;
@@ -688,7 +418,6 @@ gst_video_test_src_smpte75 (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
@@ -697,11 +426,6 @@ gst_video_test_src_smpte75 (GstVideoTestSrc * v, GstVideoFrame * frame)
   } else {
     p->colors = vts_colors_bt709_ycbcr_75;
   }
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   /* color bars */
   for (j = 0; j < h; j++) {
@@ -723,15 +447,9 @@ gst_video_test_src_smpte100 (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   /* color bars */
   for (j = 0; j < h; j++) {
@@ -752,15 +470,9 @@ gst_video_test_src_bar (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   for (j = 0; j < h; j++) {
     /* use fixed size for now */
@@ -781,16 +493,10 @@ gst_video_test_src_snow (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   struct vts_color_struct color;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   color = p->colors[COLOR_BLACK];
   p->color = &color;
@@ -801,7 +507,7 @@ gst_video_test_src_snow (GstVideoTestSrc * v, GstVideoFrame * frame)
       p->tmpline_u8[i] = y;
     }
     videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
-        &p->foreground_color, &p->background_color, p->width);
+        &p->foreground_color, &p->background_color, w);
     videotestsrc_convert_tmpline (p, frame, j);
   }
 }
@@ -813,15 +519,9 @@ gst_video_test_src_unicolor (GstVideoTestSrc * v, GstVideoFrame * frame,
   int i;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   p->color = p->colors + color_index;
   if (color_index == COLOR_BLACK) {
@@ -873,17 +573,10 @@ gst_video_test_src_blink (GstVideoTestSrc * v, GstVideoFrame * frame)
   int i;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
 
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
-
   if (v->n_frames & 1) {
     p->color = &p->foreground_color;
   } else {
@@ -902,17 +595,10 @@ gst_video_test_src_solid (GstVideoTestSrc * v, GstVideoFrame * frame)
   int i;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
 
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
-
   p->color = &p->foreground_color;
 
   for (i = 0; i < h; i++) {
@@ -927,17 +613,10 @@ gst_video_test_src_checkers1 (GstVideoTestSrc * v, GstVideoFrame * frame)
   int x, y;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
 
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
-
   for (y = 0; y < h; y++) {
     for (x = 0; x < w; x++) {
       if ((x ^ y) & 1) {
@@ -957,15 +636,9 @@ gst_video_test_src_checkers2 (GstVideoTestSrc * v, GstVideoFrame * frame)
   int x, y;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   for (y = 0; y < h; y++) {
     for (x = 0; x < w; x += 2) {
@@ -988,15 +661,9 @@ gst_video_test_src_checkers4 (GstVideoTestSrc * v, GstVideoFrame * frame)
   int x, y;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   for (y = 0; y < h; y++) {
     for (x = 0; x < w; x += 4) {
@@ -1019,15 +686,9 @@ gst_video_test_src_checkers8 (GstVideoTestSrc * v, GstVideoFrame * frame)
   int x, y;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   for (y = 0; y < h; y++) {
     for (x = 0; x < w; x += 8) {
@@ -1087,7 +748,6 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   struct vts_color_struct color;
   int t = v->n_frames;
   int w = frame->info.width, h = frame->info.height;
@@ -1109,11 +769,6 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
   int scale_kx2 = 0xffff / w;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   color = p->colors[COLOR_BLACK];
   p->color = &color;
@@ -1196,7 +851,7 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
       p->tmpline_u8[i] = sine_table[phase & 0xff];
     }
     videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
-        &p->foreground_color, &p->background_color, p->width);
+        &p->foreground_color, &p->background_color, w);
     videotestsrc_convert_tmpline (p, frame, j);
   }
 }
@@ -1208,7 +863,6 @@ gst_video_test_src_chromazoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   struct vts_color_struct color;
   int t = v->n_frames;
   int w = frame->info.width, h = frame->info.height;
@@ -1231,11 +885,6 @@ gst_video_test_src_chromazoneplate (GstVideoTestSrc * v, GstVideoFrame * frame)
   int scale_kx2 = 0xffff / w;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   color = p->colors[COLOR_BLACK];
   p->color = &color;
@@ -1308,18 +957,12 @@ gst_video_test_src_circular (GstVideoTestSrc * v, GstVideoFrame * frame)
   int j;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   double freq[8];
   int w = frame->info.width, h = frame->info.height;
 
   int d;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   for (i = 1; i < 8; i++) {
     freq[i] = 200 * pow (2.0, -(i - 1) / 4.0);
@@ -1342,7 +985,7 @@ gst_video_test_src_circular (GstVideoTestSrc * v, GstVideoFrame * frame)
       }
     }
     videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
-        &p->foreground_color, &p->background_color, p->width);
+        &p->foreground_color, &p->background_color, w);
     videotestsrc_convert_tmpline (p, frame, j);
   }
 }
@@ -1353,17 +996,11 @@ gst_video_test_src_gamut (GstVideoTestSrc * v, GstVideoFrame * frame)
   int x, y;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   struct vts_color_struct yuv_primary;
   struct vts_color_struct yuv_secondary;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   for (y = 0; y < h; y++) {
     int region = (y * 4) / h;
@@ -1411,18 +1048,12 @@ gst_video_test_src_ball (GstVideoTestSrc * v, GstVideoFrame * frame)
   int i;
   paintinfo pi = PAINT_INFO_INIT;
   paintinfo *p = &pi;
-  struct format_list_struct *format;
   int t = v->n_frames;
   double x, y;
   int radius = 20;
   int w = frame->info.width, h = frame->info.height;
 
   videotestsrc_setup_paintinfo (v, p, w, h);
-  format = v->format;
-  if (format == NULL)
-    return;
-
-  format->paint_setup (p, frame);
 
   x = radius + (0.5 + 0.5 * sin (2 * G_PI * t / 200)) * (w - 2 * radius);
   y = radius + (0.5 + 0.5 * sin (2 * G_PI * sqrt (2) * t / 200)) * (h -
@@ -1458,7 +1089,7 @@ gst_video_test_src_ball (GstVideoTestSrc * v, GstVideoFrame * frame)
       }
     }
     videotestsrc_blend_line (v, p->tmpline, p->tmpline_u8,
-        &p->foreground_color, &p->background_color, p->width);
+        &p->foreground_color, &p->background_color, w);
     videotestsrc_convert_tmpline (p, frame, i);
   }
 }
@@ -1500,20 +1131,13 @@ paint_tmpline_AYUV (paintinfo * p, int x, int w)
 }
 
 static void
-paint_setup_generic (paintinfo * p, GstVideoFrame * frame)
-{
-  p->size = frame->info.size;
-}
-
-static void
 convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y)
 {
   const GstVideoFormatInfo *finfo = frame->info.finfo;
-  gint i, width = p->width;
+  gint i, width = GST_VIDEO_FRAME_WIDTH (frame);
   gpointer src;
 
-  if (finfo->unpack_format == GST_VIDEO_FORMAT_AYUV64 ||
-      finfo->unpack_format == GST_VIDEO_FORMAT_ARGB64) {
+  if (GST_VIDEO_FORMAT_INFO_DEPTH (finfo, 0) == 16) {
     /* 16 bits */
     for (i = 0; i < width; i++) {
       p->tmpline_u16[i * 4 + 0] = TO_16 (p->tmpline[i * 4 + 0]);
@@ -1531,49 +1155,18 @@ convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y)
 }
 
 static void
-paint_setup_bayer_bggr (paintinfo * p, GstVideoFrame * frame)
-{
-  p->size = GST_ROUND_UP_4 (p->width) * p->height;
-  p->bayer_x_invert = 0;
-  p->bayer_y_invert = 0;
-}
-
-static void
-paint_setup_bayer_rggb (paintinfo * p, GstVideoFrame * frame)
-{
-  p->size = GST_ROUND_UP_4 (p->width) * p->height;
-  p->bayer_x_invert = 1;
-  p->bayer_y_invert = 1;
-}
-
-static void
-paint_setup_bayer_grbg (paintinfo * p, GstVideoFrame * frame)
-{
-  p->size = GST_ROUND_UP_4 (p->width) * p->height;
-  p->bayer_x_invert = 0;
-  p->bayer_y_invert = 1;
-}
-
-static void
-paint_setup_bayer_gbrg (paintinfo * p, GstVideoFrame * frame)
-{
-  p->size = GST_ROUND_UP_4 (p->width) * p->height;
-  p->bayer_x_invert = 1;
-  p->bayer_y_invert = 0;
-}
-
-static void
 convert_hline_bayer (paintinfo * p, GstVideoFrame * frame, int y)
 {
   int i;
   guint8 *data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
-  guint8 *R = data + y * GST_ROUND_UP_4 (p->width);
+  guint8 *R = data + y * GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
   guint8 *argb = p->tmpline;
-  int x_inv = p->bayer_x_invert;
-  int y_inv = p->bayer_y_invert;
+  gint width = GST_VIDEO_FRAME_WIDTH (frame);
+  int x_inv = p->x_invert;
+  int y_inv = p->y_invert;
 
   if ((y ^ y_inv) & 1) {
-    for (i = 0; i < p->width; i++) {
+    for (i = 0; i < width; i++) {
       if ((i ^ x_inv) & 1) {
         R[i] = argb[4 * i + 1];
       } else {
@@ -1581,7 +1174,7 @@ convert_hline_bayer (paintinfo * p, GstVideoFrame * frame, int y)
       }
     }
   } else {
-    for (i = 0; i < p->width; i++) {
+    for (i = 0; i < width; i++) {
       if ((i ^ x_inv) & 1) {
         R[i] = argb[4 * i + 2];
       } else {
index ee1f7fb..3b0657a 100644 (file)
 
 #include <glib.h>
 
-enum {
-  VTS_YUV,
-  VTS_RGB,
-  VTS_GRAY,
-  VTS_BAYER
-};
-
-enum {
-  VTS_BAYER_BGGR,
-  VTS_BAYER_RGGB,
-  VTS_BAYER_GRBG,
-  VTS_BAYER_GBRG
-};
-
 struct vts_color_struct {
   guint8 Y, U, V, A;
   guint8 R, G, B;
@@ -44,21 +30,19 @@ struct vts_color_struct {
 
 
 typedef struct paintinfo_struct paintinfo;
+
 struct paintinfo_struct
 {
-  int size;                     /* size of a frame */
-  int width;
-  int height;
   const struct vts_color_struct *colors;
   const struct vts_color_struct *color;
-  /*  const struct vts_color_struct *color; */
-  void (*paint_hline) (paintinfo * p, int x, int y, int w);
+
   void (*paint_tmpline) (paintinfo * p, int x, int w);
   void (*convert_tmpline) (paintinfo * p, GstVideoFrame *frame, int y);
+  void (*convert_hline) (paintinfo * p, GstVideoFrame *frame, int y);
   int x_offset;
 
-  int bayer_x_invert;
-  int bayer_y_invert;
+  int x_invert;
+  int y_invert;
 
   guint8 *tmpline;
   guint8 *tmpline2;
@@ -70,25 +54,6 @@ struct paintinfo_struct
 };
 #define PAINT_INFO_INIT {0, }
 
-struct format_list_struct
-{
-  int type;
-  const char *format;
-  const char *name;
-  void (*paint_setup) (paintinfo * p, GstVideoFrame *frame);
-  void (*convert_hline) (paintinfo * p, GstVideoFrame *frame, int y);
-};
-
-struct format_list_struct *
-        paintrect_find_format           (const gchar *find_format);
-struct format_list_struct *
-        paintrect_find_name             (const char *name);
-struct format_list_struct *
-        paintinfo_find_by_structure     (const GstStructure *structure);
-GstStructure *
-        paint_get_structure             (struct format_list_struct *format);
-
-int     gst_video_test_src_get_size     (GstVideoTestSrc * v, int w, int h);
 void    gst_video_test_src_smpte        (GstVideoTestSrc * v, GstVideoFrame *frame);
 void    gst_video_test_src_smpte75      (GstVideoTestSrc * v, GstVideoFrame *frame);
 void    gst_video_test_src_snow         (GstVideoTestSrc * v, GstVideoFrame *frame);
@@ -111,7 +76,4 @@ void    gst_video_test_src_ball         (GstVideoTestSrc * v, GstVideoFrame *fra
 void    gst_video_test_src_smpte100     (GstVideoTestSrc * v, GstVideoFrame *frame);
 void    gst_video_test_src_bar          (GstVideoTestSrc * v, GstVideoFrame *frame);
 
-extern struct format_list_struct format_list[];
-extern int n_formats;
-
 #endif