videotestsrc: Add support for 16 bit grayscale in native endianness
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Tue, 26 May 2009 12:38:43 +0000 (14:38 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Tue, 26 May 2009 13:26:29 +0000 (15:26 +0200)
gst/videotestsrc/videotestsrc.c
gst/videotestsrc/videotestsrc.h

index 13de130..3c5f1d5 100644 (file)
@@ -299,6 +299,35 @@ static const struct vts_color_struct_yuv vts_colors_bt601_ycbcr_75[] = {
   {32, 128, 128},
 };
 
+static const struct vts_color_struct_gray vts_colors_gray_100[] = {
+  {235 << 8},
+  {210 << 8},
+  {170 << 8},
+  {145 << 8},
+  {106 << 8},
+  {81 << 8},
+  {41 << 8},
+  {16 << 8},
+  {16 << 8},
+  {16 << 8},
+  {-0 << 8},
+  {32 << 8},
+};
+
+static const struct vts_color_struct_gray vts_colors_gray_75[] = {
+  {180 << 8},
+  {162 << 8},
+  {131 << 8},
+  {112 << 8},
+  {84 << 8},
+  {65 << 8},
+  {35 << 8},
+  {16 << 8},
+  {16 << 8},
+  {16 << 8},
+  {-0 << 8},
+  {32 << 8},
+};
 
 static void paint_setup_I420 (paintinfo * p, unsigned char *dest);
 static void paint_setup_YV12 (paintinfo * p, unsigned char *dest);
@@ -366,6 +395,11 @@ static void paint_hline_xRGB1555 (paintinfo * p, int x, int y, int w);
 
 static void paint_hline_bayer (paintinfo * p, int x, int y, int w);
 
+static void paint_setup_GRAY8 (paintinfo * p, unsigned char *dest);
+static void paint_setup_GRAY16 (paintinfo * p, unsigned char *dest);
+static void paint_hline_GRAY8 (paintinfo * p, int x, int y, int w);
+static void paint_hline_GRAY16 (paintinfo * p, int x, int y, int w);
+
 struct fourcc_list_struct fourcc_list[] = {
 /* packed */
   {VTS_YUV, "YUY2", "YUY2", 16, paint_setup_YUY2, paint_hline_YUY2},
@@ -433,7 +467,8 @@ struct fourcc_list_struct fourcc_list[] = {
   {VTS_YUV, "Y800", "Y800", 8, paint_setup_Y800, paint_hline_Y800},
 
   /* Not exactly YUV but it's the same as above */
-  {VTS_YUV, "GRAY8", "GRAY8", 8, paint_setup_Y800, paint_hline_Y800},
+  {VTS_GRAY, "GRAY8", "GRAY8", 8, paint_setup_GRAY8, paint_hline_GRAY8},
+  {VTS_GRAY, "GRAY16", "GRAY16", 16, paint_setup_GRAY16, paint_hline_GRAY16},
 
   {VTS_RGB, "RGB ", "xRGB8888", 32, paint_setup_xRGB8888, paint_hline_str4, 24,
       0x00ff0000, 0x0000ff00, 0x000000ff},
@@ -476,16 +511,19 @@ paintinfo_find_by_structure (const GstStructure * structure)
   g_return_val_if_fail (structure, NULL);
 
   if (strcmp (media_type, "video/x-raw-gray") == 0) {
-    gint bpp, depth;
+    gint bpp, depth, endianness = 0;
 
     ret = gst_structure_get_int (structure, "bpp", &bpp) &&
         gst_structure_get_int (structure, "depth", &depth);
-    if (!ret || bpp != 8 || depth != 8)
+    if (!ret || bpp != depth || (depth != 8 && depth != 16))
+      return NULL;
+
+    ret = gst_structure_get_int (structure, "endianness", &endianness);
+    if ((!ret || endianness != G_BYTE_ORDER) && bpp == 16)
       return NULL;
 
     for (i = 0; i < n_fourccs; i++) {
-      if (fourcc_list[i].type == VTS_YUV
-          && strcmp (fourcc_list[i].fourcc, "GRAY8") == 0) {
+      if (fourcc_list[i].type == VTS_GRAY && fourcc_list[i].bitspp == bpp) {
         return fourcc_list + i;
       }
     }
@@ -625,14 +663,17 @@ paint_get_structure (struct fourcc_list_struct * format)
             format->alpha_mask, NULL);
       }
       break;
+    case VTS_GRAY:
+      structure = gst_structure_new ("video/x-raw-gray",
+          "bpp", G_TYPE_INT, format->bitspp, "depth", G_TYPE_INT,
+          format->bitspp, NULL);
+      if (format->bitspp == 16)
+        gst_structure_set (structure, "endianness", G_TYPE_INT, G_BYTE_ORDER,
+            NULL);
+      break;
     case VTS_YUV:
-      if (strcmp (format->fourcc, "GRAY8") == 0) {
-        structure = gst_structure_new ("video/x-raw-gray",
-            "bpp", G_TYPE_INT, 8, "depth", G_TYPE_INT, 8, NULL);
-      } else {
-        structure = gst_structure_new ("video/x-raw-yuv",
-            "format", GST_TYPE_FOURCC, fourcc, NULL);
-      }
+      structure = gst_structure_new ("video/x-raw-yuv",
+          "format", GST_TYPE_FOURCC, fourcc, NULL);
       break;
     case VTS_BAYER:
       structure = gst_structure_new ("video/x-raw-bayer", NULL);
@@ -681,6 +722,7 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -700,6 +742,7 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
 
     p->yuv_color = p->yuv_colors + i;
     p->rgb_color = p->rgb_colors + i;
+    p->gray_color = p->gray_colors + i;
     for (j = 0; j < y1; j++) {
       p->paint_hline (p, x1, j, (x2 - x1));
     }
@@ -718,6 +761,7 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
     }
     p->yuv_color = p->yuv_colors + k;
     p->rgb_color = p->rgb_colors + k;
+    p->gray_color = p->gray_colors + k;
     for (j = y1; j < y2; j++) {
       p->paint_hline (p, x1, j, (x2 - x1));
     }
@@ -738,6 +782,7 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
 
     p->yuv_color = p->yuv_colors + k;
     p->rgb_color = p->rgb_colors + k;
+    p->gray_color = p->gray_colors + k;
     for (j = y2; j < h; j++) {
       p->paint_hline (p, x1, j, (x2 - x1));
     }
@@ -758,6 +803,7 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
 
     p->yuv_color = p->yuv_colors + k;
     p->rgb_color = p->rgb_colors + k;
+    p->gray_color = p->gray_colors + k;
     for (j = y2; j < h; j++) {
       p->paint_hline (p, x1, j, (x2 - x1));
     }
@@ -767,11 +813,14 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
     int x1 = w * 3 / 4;
     struct vts_color_struct_rgb rgb_color;
     struct vts_color_struct_yuv yuv_color;
+    struct vts_color_struct_gray gray_color;
 
     rgb_color = p->rgb_colors[COLOR_BLACK];
     yuv_color = p->yuv_colors[COLOR_BLACK];
+    gray_color = p->gray_colors[COLOR_BLACK];
     p->rgb_color = &rgb_color;
     p->yuv_color = &yuv_color;
+    p->gray_color = &gray_color;
 
     for (i = x1; i < w; i++) {
       for (j = y2; j < h; j++) {
@@ -781,6 +830,7 @@ gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
         rgb_color.R = y;
         rgb_color.G = y;
         rgb_color.B = y;
+        gray_color.G = (y << 8) | random_char ();
         p->paint_hline (p, i, j, 1);
       }
     }
@@ -804,6 +854,7 @@ gst_video_test_src_smpte75 (GstVideoTestSrc * v, unsigned char *dest, int w,
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_75;
   }
+  p->gray_colors = vts_colors_gray_75;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -820,6 +871,7 @@ gst_video_test_src_smpte75 (GstVideoTestSrc * v, unsigned char *dest, int w,
 
     p->yuv_color = p->yuv_colors + i;
     p->rgb_color = p->rgb_colors + i;
+    p->gray_color = p->gray_colors + i;
     for (j = 0; j < h; j++) {
       p->paint_hline (p, x1, j, (x2 - x1));
     }
@@ -836,6 +888,7 @@ gst_video_test_src_snow (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
   struct fourcc_list_struct *fourcc;
   struct vts_color_struct_rgb rgb_color;
   struct vts_color_struct_yuv yuv_color;
+  struct vts_color_struct_gray gray_color;
 
   p->rgb_colors = vts_colors_rgb;
   if (v->color_spec == GST_VIDEO_TEST_SRC_BT601) {
@@ -843,6 +896,7 @@ gst_video_test_src_snow (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -854,8 +908,10 @@ gst_video_test_src_snow (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
 
   rgb_color = p->rgb_colors[COLOR_BLACK];
   yuv_color = p->yuv_colors[COLOR_BLACK];
+  gray_color = p->gray_colors[COLOR_BLACK];
   p->rgb_color = &rgb_color;
   p->yuv_color = &yuv_color;
+  p->gray_color = &gray_color;
 
   for (i = 0; i < w; i++) {
     for (j = 0; j < h; j++) {
@@ -865,6 +921,7 @@ gst_video_test_src_snow (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
       rgb_color.R = y;
       rgb_color.G = y;
       rgb_color.B = y;
+      gray_color.G = (y << 8) | random_char ();
       p->paint_hline (p, i, j, 1);
     }
   }
@@ -885,6 +942,7 @@ gst_video_test_src_unicolor (GstVideoTestSrc * v, unsigned char *dest, int w,
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -896,6 +954,7 @@ gst_video_test_src_unicolor (GstVideoTestSrc * v, unsigned char *dest, int w,
 
   p->rgb_color = p->rgb_colors + color_index;
   p->yuv_color = p->yuv_colors + color_index;
+  p->gray_color = p->gray_colors + color_index;
 
   for (i = 0; i < h; i++) {
     p->paint_hline (p, 0, i, w);
@@ -946,6 +1005,7 @@ gst_video_test_src_checkers1 (GstVideoTestSrc * v, guchar * dest, int w, int h)
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -958,10 +1018,12 @@ gst_video_test_src_checkers1 (GstVideoTestSrc * v, guchar * dest, int w, int h)
   for (y = 0; y < h; y++) {
     p->rgb_color = p->rgb_colors + COLOR_GREEN;
     p->yuv_color = p->yuv_colors + COLOR_GREEN;
+    p->gray_color = p->gray_colors + COLOR_GREEN;
     p->paint_hline (p, 0, y, w);
     for (x = (y % 2); x < w; x += 2) {
       p->rgb_color = p->rgb_colors + COLOR_RED;
       p->yuv_color = p->yuv_colors + COLOR_RED;
+      p->gray_color = p->gray_colors + COLOR_RED;
       p->paint_hline (p, x, y, 1);
     }
   }
@@ -981,6 +1043,7 @@ gst_video_test_src_checkers2 (GstVideoTestSrc * v, guchar * dest, int w, int h)
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -992,6 +1055,7 @@ gst_video_test_src_checkers2 (GstVideoTestSrc * v, guchar * dest, int w, int h)
 
   p->rgb_color = p->rgb_colors + COLOR_GREEN;
   p->yuv_color = p->yuv_colors + COLOR_GREEN;
+  p->gray_color = p->gray_colors + COLOR_GREEN;
   for (y = 0; y < h; y++) {
     p->paint_hline (p, 0, y, w);
   }
@@ -1002,6 +1066,7 @@ gst_video_test_src_checkers2 (GstVideoTestSrc * v, guchar * dest, int w, int h)
 
       p->rgb_color = p->rgb_colors + COLOR_RED;
       p->yuv_color = p->yuv_colors + COLOR_RED;
+      p->gray_color = p->gray_colors + COLOR_RED;
       p->paint_hline (p, x, y + 0, len);
       if (G_LIKELY ((y + 1) < h)) {
         p->paint_hline (p, x, y + 1, len);
@@ -1024,6 +1089,7 @@ gst_video_test_src_checkers4 (GstVideoTestSrc * v, guchar * dest, int w, int h)
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -1035,6 +1101,7 @@ gst_video_test_src_checkers4 (GstVideoTestSrc * v, guchar * dest, int w, int h)
 
   p->rgb_color = p->rgb_colors + COLOR_GREEN;
   p->yuv_color = p->yuv_colors + COLOR_GREEN;
+  p->gray_color = p->gray_colors + COLOR_GREEN;
   for (y = 0; y < h; y++) {
     p->paint_hline (p, 0, y, w);
   }
@@ -1045,6 +1112,7 @@ gst_video_test_src_checkers4 (GstVideoTestSrc * v, guchar * dest, int w, int h)
 
       p->rgb_color = p->rgb_colors + COLOR_RED;
       p->yuv_color = p->yuv_colors + COLOR_RED;
+      p->gray_color = p->gray_colors + COLOR_RED;
       p->paint_hline (p, x, y + 0, len);
       if (G_LIKELY ((y + 1) < h)) {
         p->paint_hline (p, x, y + 1, len);
@@ -1073,6 +1141,7 @@ gst_video_test_src_checkers8 (GstVideoTestSrc * v, guchar * dest, int w, int h)
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -1084,6 +1153,7 @@ gst_video_test_src_checkers8 (GstVideoTestSrc * v, guchar * dest, int w, int h)
 
   p->rgb_color = p->rgb_colors + COLOR_GREEN;
   p->yuv_color = p->yuv_colors + COLOR_GREEN;
+  p->gray_color = p->gray_colors + COLOR_GREEN;
   for (y = 0; y < h; y++) {
     for (x = 0; x < w; x += 8) {
       int len = MIN (8, w - x);
@@ -1091,9 +1161,11 @@ gst_video_test_src_checkers8 (GstVideoTestSrc * v, guchar * dest, int w, int h)
       if ((x ^ y) & (1 << 4)) {
         p->rgb_color = p->rgb_colors + COLOR_GREEN;
         p->yuv_color = p->yuv_colors + COLOR_GREEN;
+        p->gray_color = p->gray_colors + COLOR_GREEN;
       } else {
         p->rgb_color = p->rgb_colors + COLOR_RED;
         p->yuv_color = p->yuv_colors + COLOR_RED;
+        p->gray_color = p->gray_colors + COLOR_RED;
       }
       p->paint_hline (p, x, y, len);
     }
@@ -1111,6 +1183,7 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, unsigned char *dest,
   struct fourcc_list_struct *fourcc;
   struct vts_color_struct_rgb rgb_color;
   struct vts_color_struct_yuv yuv_color;
+  struct vts_color_struct_gray gray_color;
   static uint8_t sine_array[256];
   static int sine_array_inited = FALSE;
 
@@ -1151,6 +1224,7 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, unsigned char *dest,
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -1162,8 +1236,10 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, unsigned char *dest,
 
   rgb_color = p->rgb_colors[COLOR_BLACK];
   yuv_color = p->yuv_colors[COLOR_BLACK];
+  gray_color = p->gray_colors[COLOR_BLACK];
   p->rgb_color = &rgb_color;
   p->yuv_color = &yuv_color;
+  p->gray_color = &gray_color;
 
   /* Zoneplate equation:
    *
@@ -1245,6 +1321,8 @@ gst_video_test_src_zoneplate (GstVideoTestSrc * v, unsigned char *dest,
       rgb_color.R = yuv_color.Y;
       rgb_color.G = yuv_color.Y;
       rgb_color.B = yuv_color.Y;
+
+      gray_color.G = yuv_color.Y << 8;
       p->paint_hline (p, i, j, 1);
     }
   }
@@ -1264,6 +1342,7 @@ gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
   struct fourcc_list_struct *fourcc;
   struct vts_color_struct_rgb rgb_color;
   struct vts_color_struct_yuv yuv_color;
+  struct vts_color_struct_gray gray_color;
   static uint8_t sine_array[256];
   static int sine_array_inited = FALSE;
   double freq[8];
@@ -1287,6 +1366,7 @@ gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
   } else {
     p->yuv_colors = vts_colors_bt709_ycbcr_100;
   }
+  p->gray_colors = vts_colors_gray_100;
   p->width = w;
   p->height = h;
   fourcc = v->fourcc;
@@ -1298,8 +1378,10 @@ gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
 
   rgb_color = p->rgb_colors[COLOR_BLACK];
   yuv_color = p->yuv_colors[COLOR_BLACK];
+  gray_color = p->gray_colors[COLOR_BLACK];
   p->rgb_color = &rgb_color;
   p->yuv_color = &yuv_color;
+  p->gray_color = &gray_color;
 
   for (i = 1; i < 8; i++) {
     freq[i] = 200 * pow (2.0, -(i - 1) / 4.0);
@@ -1324,6 +1406,7 @@ gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
       seg = floor (dist * 16);
       if (seg == 0 || seg >= 8) {
         yuv_color.Y = 255;
+        gray_color.G = 65535;
       } else {
 #ifdef SCALE_AMPLITUDE
         double a;
@@ -1334,8 +1417,10 @@ gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
         if (a < 0)
           a = 0;
         yuv_color.Y = 128 + a * (sine_array[d & 0xff] - 128);
+        gray_color.G = 128 + a * (sine_array[d & 0xff] - 128);
 #else
         yuv_color.Y = sine_array[d & 0xff];
+        gray_color.G = sine_array[d & 0xff];
 #endif
       }
       rgb_color.R = yuv_color.Y;
@@ -1346,7 +1431,6 @@ gst_video_test_src_circular (GstVideoTestSrc * v, unsigned char *dest,
   }
 }
 
-
 static void
 paint_setup_I420 (paintinfo * p, unsigned char *dest)
 {
@@ -2010,3 +2094,36 @@ paint_hline_bayer (paintinfo * p, int x, int y, int w)
     }
   }
 }
+
+static void
+paint_setup_GRAY8 (paintinfo * p, unsigned char *dest)
+{
+  p->yp = dest;
+  p->ystride = GST_ROUND_UP_4 (p->width);
+  p->endptr = dest + p->ystride * p->height;
+}
+
+static void
+paint_hline_GRAY8 (paintinfo * p, int x, int y, int w)
+{
+  int offset = y * p->ystride;
+  guint8 color = p->gray_color->G >> 8;
+
+  oil_splat_u8_ns (p->yp + offset + x, &color, w);
+}
+
+static void
+paint_setup_GRAY16 (paintinfo * p, unsigned char *dest)
+{
+  p->yp = dest;
+  p->ystride = GST_ROUND_UP_4 (p->width * 2);
+  p->endptr = dest + p->ystride * p->height;
+}
+
+static void
+paint_hline_GRAY16 (paintinfo * p, int x, int y, int w)
+{
+  int offset = y * p->ystride;
+
+  oil_splat_u16_ns ((guint16 *) (p->yp + offset + 2 * x), &p->gray_color->G, w);
+}
index e23c39e..5880833 100644 (file)
@@ -25,6 +25,7 @@
 enum {
   VTS_YUV,
   VTS_RGB,
+  VTS_GRAY,
   VTS_BAYER
 };
 
@@ -34,6 +35,9 @@ struct vts_color_struct_yuv {
 struct vts_color_struct_rgb {
   guint8 R, G, B;
 };
+struct vts_color_struct_gray {
+  guint16 G;
+};
 
 typedef struct paintinfo_struct paintinfo;
 struct paintinfo_struct
@@ -50,8 +54,10 @@ struct paintinfo_struct
   int height;
   const struct vts_color_struct_rgb *rgb_colors;
   const struct vts_color_struct_yuv *yuv_colors;
+  const struct vts_color_struct_gray *gray_colors;
   const struct vts_color_struct_rgb *rgb_color;
   const struct vts_color_struct_yuv *yuv_color;
+  const struct vts_color_struct_gray *gray_color;
   //const struct vts_color_struct *color;
   void (*paint_hline) (paintinfo * p, int x, int y, int w);
 };