ffmpegcolorspace: Fix IYU1 support
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 3 Nov 2010 09:35:35 +0000 (10:35 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 3 Nov 2010 09:49:35 +0000 (10:49 +0100)
Fix conversions to IYU1, they allocated infinite amounts of memory before
because no conversion to IYU1 was actually implemented and it was running
into an infinite loop trying to find suitable intermediate formats.

Also fix the stride and sizes used for IYU1.

gst/ffmpegcolorspace/gstffmpegcodecmap.c
gst/ffmpegcolorspace/imgconvert.c

index bc885b1..318a90e 100644 (file)
@@ -958,14 +958,14 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
       picture->linesize[0] = stride;
       return size;
     case PIX_FMT_UYVY411:
-      /* FIXME, probably not the right stride */
-      stride = GST_ROUND_UP_4 (width);
+      stride =
+          GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) + GST_ROUND_UP_4 (width) / 2);
       size = stride * height;
       picture->data[0] = ptr;
       picture->data[1] = NULL;
       picture->data[2] = NULL;
-      picture->linesize[0] = width + width / 2;
-      return size + size / 2;
+      picture->linesize[0] = stride;
+      return size;
     case PIX_FMT_Y800:
     case PIX_FMT_GRAY8:
       stride = GST_ROUND_UP_4 (width);
index 64ac475..cb145bb 100644 (file)
@@ -1325,6 +1325,42 @@ uyvy411_to_yuv411p (AVPicture * dst, const AVPicture * src,
 }
 
 static void
+yuv411p_to_uyvy411 (AVPicture * dst, const AVPicture * src,
+    int width, int height)
+{
+  uint8_t *p, *p1;
+  const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+  int w;
+
+  p1 = dst->data[0];
+  lum1 = src->data[0];
+  cb1 = src->data[1];
+  cr1 = src->data[2];
+  for (; height > 0; height--) {
+    p = p1;
+    lum = lum1;
+    cb = cb1;
+    cr = cr1;
+    for (w = width; w >= 4; w -= 4) {
+      p[0] = cb[0];
+      p[1] = lum[0];
+      p[2] = lum[1];
+      p[3] = cr[0];
+      p[4] = lum[2];
+      p[5] = lum[3];
+      p += 6;
+      lum += 4;
+      cb++;
+      cr++;
+    }
+    p1 += dst->linesize[0];
+    lum1 += src->linesize[0];
+    cb1 += src->linesize[1];
+    cr1 += src->linesize[2];
+  }
+}
+
+static void
 yuv420p_to_yuv422 (AVPicture * dst, const AVPicture * src,
     int width, int height)
 {
@@ -3437,6 +3473,7 @@ static ConvertEntry convert_table[] = {
   {PIX_FMT_PAL8, PIX_FMT_ABGR32, pal8_to_abgr32},
 
   {PIX_FMT_UYVY411, PIX_FMT_YUV411P, uyvy411_to_yuv411p},
+  {PIX_FMT_YUV411P, PIX_FMT_UYVY411, yuv411p_to_uyvy411},
 
   {PIX_FMT_V308, PIX_FMT_RGB24, v308_to_rgb24},