From f02be79d61022f399bb08573fd42d068cdf75b7b Mon Sep 17 00:00:00 2001
From: Roman Shaposhnik <roman@shaposhnik.org>
Date: Fri, 22 Oct 2004 02:04:30 +0000
Subject:    * Introducing IIDC1394 grabbing interface.      Use it with -grab
 dc1394

   * Introducing yet another packed pix_fmt in order to support some of
     the IIDC1394 modes: uyvy411 (Cb Y0 Y1 Cr Y2 Y3).

Originally committed as revision 3621 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavcodec/avcodec.h    |  1 +
 libavcodec/imgconvert.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/utils.c      |  1 +
 3 files changed, 68 insertions(+)

(limited to 'libavcodec')

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4919e977ab..88f83b9b27 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -203,6 +203,7 @@ enum PixelFormat {
     PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
     PIX_FMT_XVMC_MPEG2_IDCT,
     PIX_FMT_UYVY422,   ///< Packed pixel, Cb Y0 Cr Y1 
+    PIX_FMT_UYVY411,   ///< Packed pixel, Cb Y0 Y1 Cr Y2 Y3
     PIX_FMT_NB,
 };
 
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 7bcb8ee23d..040b2c7939 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -227,6 +227,14 @@ static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
     [PIX_FMT_XVMC_MPEG2_IDCT] = {
         .name = "xvmcidct",
     },
+    [PIX_FMT_UYVY411] = {
+        .name = "uyvy411",
+        .nb_channels = 1,
+        .color_type = FF_COLOR_YUV,
+        .pixel_type = FF_PIXEL_PACKED,
+        .depth = 8,
+        .x_chroma_shift = 2, .y_chroma_shift = 0,
+    },
 };
 
 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift)
@@ -308,6 +316,12 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[2] = NULL;
         picture->linesize[0] = width * 2;
         return size * 2;
+    case PIX_FMT_UYVY411:
+        picture->data[0] = ptr;
+        picture->data[1] = NULL;
+        picture->data[2] = NULL;
+        picture->linesize[0] = width + width/2;
+        return size + size/2;
     case PIX_FMT_GRAY8:
         picture->data[0] = ptr;
         picture->data[1] = NULL;
@@ -355,6 +369,8 @@ int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
             pix_fmt == PIX_FMT_RGB565 ||
             pix_fmt == PIX_FMT_RGB555)
             w = width * 2;
+	else if (pix_fmt == PIX_FMT_UYVY411)
+	  w = width + width/2;
 	else if (pix_fmt == PIX_FMT_PAL8)
 	  w = width;
 	else
@@ -466,6 +482,9 @@ static int avg_bits_per_pixel(int pix_fmt)
         case PIX_FMT_RGB555:
             bits = 16;
             break;
+	case PIX_FMT_UYVY411:
+	    bits = 12;
+	    break;
         default:
             bits = pf->depth * pf->nb_channels;
             break;
@@ -579,6 +598,9 @@ void img_copy(AVPicture *dst, const AVPicture *src,
         case PIX_FMT_RGB555:
             bits = 16;
             break;
+	case PIX_FMT_UYVY411:
+	    bits = 12;
+	    break;
         default:
             bits = pf->depth * pf->nb_channels;
             break;
@@ -864,6 +886,40 @@ static void yuv422p_to_uyvy422(AVPicture *dst, const AVPicture *src,
     }
 }
 
+static void uyvy411_to_yuv411p(AVPicture *dst, const AVPicture *src,
+                              int width, int height)
+{
+    const uint8_t *p, *p1;
+    uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+    int w;
+
+    p1 = src->data[0];
+    lum1 = dst->data[0];
+    cb1 = dst->data[1];
+    cr1 = dst->data[2];
+    for(;height > 0; height--) {
+        p = p1;
+        lum = lum1;
+        cb = cb1;
+        cr = cr1;
+        for(w = width; w >= 4; w -= 4) {
+            cb[0] = p[0];
+	    lum[0] = p[1];
+            lum[1] = p[2];
+            cr[0] = p[3];
+	    lum[2] = p[4];
+	    lum[3] = p[5];
+            p += 6;
+            lum += 4;
+            cb++;
+            cr++;
+        }
+        p1 += src->linesize[0];
+        lum1 += dst->linesize[0];
+        cb1 += dst->linesize[1];
+        cr1 += dst->linesize[2];
+    }
+}
 
 
 #define SCALEBITS 10
@@ -1777,6 +1833,12 @@ static ConvertEntry convert_table[PIX_FMT_NB][PIX_FMT_NB] = {
             .convert = pal8_to_rgba32
         },
     },
+    [PIX_FMT_UYVY411] = { 
+        [PIX_FMT_YUV411P] = { 
+            .convert = uyvy411_to_yuv411p,
+        },
+    },
+
 };
 
 int avpicture_alloc(AVPicture *picture,
@@ -2003,6 +2065,10 @@ int img_convert(AVPicture *dst, int dst_pix_fmt,
         dst_pix_fmt == PIX_FMT_UYVY422) {
         /* specific case: convert to YUV422P first */
         int_pix_fmt = PIX_FMT_YUV422P;
+    } else if (src_pix_fmt == PIX_FMT_UYVY411 ||
+        dst_pix_fmt == PIX_FMT_UYVY411) {
+        /* specific case: convert to YUV411P first */
+        int_pix_fmt = PIX_FMT_YUV411P;
     } else if ((src_pix->color_type == FF_COLOR_GRAY &&
                 src_pix_fmt != PIX_FMT_GRAY8) || 
                (dst_pix->color_type == FF_COLOR_GRAY &&
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2d2fc14c0e..05e63ae7f2 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -159,6 +159,7 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
         h_align= 16;
         break;
     case PIX_FMT_YUV411P:
+    case PIX_FMT_UYVY411:
         w_align=32;
         h_align=8;
         break;
-- 
cgit v1.2.3