Index: avcodec.h
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/gst/ffmpegcolorspace/avcodec.h,v
retrieving revision 1.1.1.3
diff -u -1 -0 -r1.1.1.3 avcodec.h
--- avcodec.h	5 Sep 2007 15:15:34 -0000	1.1.1.3
+++ avcodec.h	8 May 2008 12:26:33 -0000
@@ -46,30 +46,31 @@
  * image data is stored in AVFrame.data[0]. The palette is transported in
  * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
  * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
  * also endian-specific). Note also that the individual RGB palette
  * components stored in AVFrame.data[1] should be in the range 0..255.
  * This is important as many custom PAL8 video codecs that were designed
  * to run on the IBM VGA graphics adapter use 6-bit palette components.
  */
 enum PixelFormat {
     PIX_FMT_YUV420P,   ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples) (I420)
+    PIX_FMT_NV12,      ///< Packed YUV 4:2:0 (separate Y plane, interleaved Cb & Cr planes)
     PIX_FMT_YVU420P,   ///< Planar YUV 4:2:0 (1 Cb & Cr sample per 2x2 Y samples) (YV12)
     PIX_FMT_YUV422,    ///< Packed pixel, Y0 Cb Y1 Cr 
     PIX_FMT_RGB24,     ///< Packed pixel, 3 bytes per pixel, RGBRGB...
     PIX_FMT_BGR24,     ///< Packed pixel, 3 bytes per pixel, BGRBGR...
     PIX_FMT_YUV422P,   ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
     PIX_FMT_YUV444P,   ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
     PIX_FMT_RGBA32,    ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
-    PIX_FMT_BGRA32,     ///< Packed pixel, 4 bytes per pixel, ARGBARGB...
+    PIX_FMT_BGRA32,    ///< Packed pixel, 4 bytes per pixel, ARGBARGB...
     PIX_FMT_ARGB32,    ///< Packed pixel, 4 bytes per pixel, ABGRABGR..., stored in cpu endianness
-    PIX_FMT_ABGR32,     ///< Packed pixel, 4 bytes per pixel, RGBARGBA...
+    PIX_FMT_ABGR32,    ///< Packed pixel, 4 bytes per pixel, RGBARGBA...
     PIX_FMT_RGB32,     ///< Packed pixel, 4 bytes per pixel, BGRxBGRx..., stored in cpu endianness
     PIX_FMT_xRGB32,    ///< Packed pixel, 4 bytes per pixel, xBGRxBGR..., stored in cpu endianness
     PIX_FMT_BGR32,     ///< Packed pixel, 4 bytes per pixel, xRGBxRGB...
     PIX_FMT_BGRx32,    ///< Packed pixel, 4 bytes per pixel, RGBxRGBx...
     PIX_FMT_YUV410P,   ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
     PIX_FMT_YVU410P,   ///< Planar YVU 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
     PIX_FMT_YUV411P,   ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
     PIX_FMT_RGB565,    ///< always stored in cpu endianness 
     PIX_FMT_RGB555,    ///< always stored in cpu endianness, most significant bit to 1 
     PIX_FMT_GRAY8,
Index: gstffmpegcodecmap.c
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/gst/ffmpegcolorspace/gstffmpegcodecmap.c,v
retrieving revision 1.1.1.5
diff -u -1 -0 -r1.1.1.5 gstffmpegcodecmap.c
--- gstffmpegcodecmap.c	5 Sep 2007 15:15:34 -0000	1.1.1.5
+++ gstffmpegcodecmap.c	8 May 2008 12:26:33 -0000
@@ -160,20 +160,23 @@
   GstCaps *caps = NULL;
 
   int bpp = 0, depth = 0, endianness = 0;
   gulong g_mask = 0, r_mask = 0, b_mask = 0, a_mask = 0;
   guint32 fmt = 0;
 
   switch (pix_fmt) {
     case PIX_FMT_YUV420P:
       fmt = GST_MAKE_FOURCC ('I', '4', '2', '0');
       break;
+    case PIX_FMT_NV12:
+      fmt = GST_MAKE_FOURCC ('N', 'V', '1', '2');
+      break;
     case PIX_FMT_YVU420P:
       fmt = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
       break;
     case PIX_FMT_YUV422:
       fmt = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
       break;
     case PIX_FMT_UYVY422:
       fmt = GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
       break;
     case PIX_FMT_UYVY411:
@@ -586,20 +589,23 @@
           break;
         case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
           context->pix_fmt = PIX_FMT_UYVY422;
           break;
         case GST_MAKE_FOURCC ('I', 'Y', 'U', '1'):
           context->pix_fmt = PIX_FMT_UYVY411;
           break;
         case GST_MAKE_FOURCC ('I', '4', '2', '0'):
           context->pix_fmt = PIX_FMT_YUV420P;
           break;
+        case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
+          context->pix_fmt = PIX_FMT_NV12;
+          break;
         case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
           context->pix_fmt = PIX_FMT_YVU420P;
           break;
         case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
           context->pix_fmt = PIX_FMT_YUV411P;
           break;
         case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
           context->pix_fmt = PIX_FMT_YUV422P;
           break;
         case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
@@ -792,20 +798,35 @@
       stride2 = GST_ROUND_UP_4 (w2);
       h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
       size2 = stride2 * h2;
       picture->data[0] = ptr;
       picture->data[2] = picture->data[0] + size;
       picture->data[1] = picture->data[2] + size2;
       picture->linesize[0] = stride;
       picture->linesize[1] = stride2;
       picture->linesize[2] = stride2;
       return size + 2 * size2;
+    case PIX_FMT_NV12:
+      stride = GST_ROUND_UP_4 (width);
+      h2 = ROUND_UP_X (height, pinfo->y_chroma_shift);
+      size = stride * h2;
+      w2 = 2 * DIV_ROUND_UP_X (width, pinfo->x_chroma_shift);
+      stride2 = GST_ROUND_UP_4 (w2);
+      h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
+      size2 = stride2 * h2;
+      picture->data[0] = ptr;
+      picture->data[1] = picture->data[0] + size;
+      picture->data[2] = NULL;
+      picture->linesize[0] = stride;
+      picture->linesize[1] = stride2;
+      picture->linesize[2] = NULL;
+      return size + size2;
     case PIX_FMT_RGB24:
     case PIX_FMT_BGR24:
       stride = GST_ROUND_UP_4 (width * 3);
       size = stride * height;
       picture->data[0] = ptr;
       picture->data[1] = NULL;
       picture->data[2] = NULL;
       picture->linesize[0] = stride;
       return size;
     case PIX_FMT_AYUV4444:
Index: imgconvert.c
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/gst/ffmpegcolorspace/imgconvert.c,v
retrieving revision 1.1.1.5
diff -u -1 -0 -r1.1.1.5 imgconvert.c
--- imgconvert.c	30 Mar 2008 12:32:47 -0000	1.1.1.5
+++ imgconvert.c	8 May 2008 12:26:33 -0000
@@ -57,20 +57,31 @@
         /* .format         = */ PIX_FMT_YVU420P,
         /* .name           = */ "yvu420p",
         /* .nb_channels    = */ 3,
         /* .color_type     = */ FF_COLOR_YUV,
         /* .pixel_type     = */ FF_PIXEL_PLANAR,
         /* .is_alpha       = */ 0,
         /* .x_chroma_shift = */ 1,
         /* .y_chroma_shift = */ 1,
         /* .depth          = */ 8,
       },
+  /* [PIX_FMT_NV12] = */ {
+        /* .format         = */ PIX_FMT_NV12,
+        /* .name           = */ "nv12",
+        /* .nb_channels    = */ 2,
+        /* .color_type     = */ FF_COLOR_YUV,
+        /* .pixel_type     = */ FF_PIXEL_PACKED,
+        /* .is_alpha       = */ 0,
+        /* .x_chroma_shift = */ 1,
+        /* .y_chroma_shift = */ 1,
+        /* .depth          = */ 8,
+      },
   /* [PIX_FMT_YUV422P] = */ {
         /* .format         = */ PIX_FMT_YUV422P,
         /* .name           = */ "yuv422p",
         /* .nb_channels    = */ 3,
         /* .color_type     = */ FF_COLOR_YUV,
         /* .pixel_type     = */ FF_PIXEL_PLANAR,
         /* .is_alpha       = */ 0,
         /* .x_chroma_shift = */ 1,
         /* .y_chroma_shift = */ 0,
         /* .depth          = */ 8,
@@ -2030,20 +2041,33 @@
   {PIX_FMT_YUV420P, PIX_FMT_RGB24, yuv420p_to_rgb24},
   {PIX_FMT_YUV420P, PIX_FMT_RGB32, yuv420p_to_rgb32},
   {PIX_FMT_YUV420P, PIX_FMT_BGR32, yuv420p_to_bgr32},
   {PIX_FMT_YUV420P, PIX_FMT_xRGB32, yuv420p_to_xrgb32},
   {PIX_FMT_YUV420P, PIX_FMT_BGRx32, yuv420p_to_bgrx32},
   {PIX_FMT_YUV420P, PIX_FMT_RGBA32, yuv420p_to_rgba32},
   {PIX_FMT_YUV420P, PIX_FMT_BGRA32, yuv420p_to_bgra32},
   {PIX_FMT_YUV420P, PIX_FMT_ARGB32, yuv420p_to_argb32},
   {PIX_FMT_YUV420P, PIX_FMT_ABGR32, yuv420p_to_abgr32},
 
+  {PIX_FMT_NV12, PIX_FMT_RGB555, nv12_to_rgb555},
+  {PIX_FMT_NV12, PIX_FMT_RGB565, nv12_to_rgb565},
+  {PIX_FMT_NV12, PIX_FMT_BGR24, nv12_to_bgr24},
+  {PIX_FMT_NV12, PIX_FMT_RGB24, nv12_to_rgb24},
+  {PIX_FMT_NV12, PIX_FMT_RGB32, nv12_to_rgb32},
+  {PIX_FMT_NV12, PIX_FMT_BGR32, nv12_to_bgr32},
+  {PIX_FMT_NV12, PIX_FMT_xRGB32, nv12_to_xrgb32},
+  {PIX_FMT_NV12, PIX_FMT_BGRx32, nv12_to_bgrx32},
+  {PIX_FMT_NV12, PIX_FMT_RGBA32, nv12_to_rgba32},
+  {PIX_FMT_NV12, PIX_FMT_BGRA32, nv12_to_bgra32},
+  {PIX_FMT_NV12, PIX_FMT_ARGB32, nv12_to_argb32},
+  {PIX_FMT_NV12, PIX_FMT_ABGR32, nv12_to_abgr32},
+
   {PIX_FMT_YUV422P, PIX_FMT_YUV422, yuv422p_to_yuv422},
   {PIX_FMT_YUV422P, PIX_FMT_UYVY422, yuv422p_to_uyvy422},
 
   {PIX_FMT_YUV444P, PIX_FMT_RGB24, yuv444p_to_rgb24},
 
   {PIX_FMT_YUVJ420P, PIX_FMT_RGB555, yuvj420p_to_rgb555},
   {PIX_FMT_YUVJ420P, PIX_FMT_RGB565, yuvj420p_to_rgb565},
   {PIX_FMT_YUVJ420P, PIX_FMT_BGR24, yuvj420p_to_bgr24},
   {PIX_FMT_YUVJ420P, PIX_FMT_RGB24, yuvj420p_to_rgb24},
   {PIX_FMT_YUVJ420P, PIX_FMT_RGB32, yuvj420p_to_rgb32},
@@ -2057,20 +2081,21 @@
 
   {PIX_FMT_YUVJ444P, PIX_FMT_RGB24, yuvj444p_to_rgb24},
 
   {PIX_FMT_YUV422, PIX_FMT_YUV420P, yuv422_to_yuv420p},
   {PIX_FMT_YUV422, PIX_FMT_YUV422P, yuv422_to_yuv422p},
 
   {PIX_FMT_UYVY422, PIX_FMT_YUV420P, uyvy422_to_yuv420p},
   {PIX_FMT_UYVY422, PIX_FMT_YUV422P, uyvy422_to_yuv422p},
 
   {PIX_FMT_RGB24, PIX_FMT_YUV420P, rgb24_to_yuv420p},
+  {PIX_FMT_RGB24, PIX_FMT_NV12, rgb24_to_nv12},
   {PIX_FMT_RGB24, PIX_FMT_RGB565, rgb24_to_rgb565},
   {PIX_FMT_RGB24, PIX_FMT_RGB555, rgb24_to_rgb555},
   {PIX_FMT_RGB24, PIX_FMT_RGB32, rgb24_to_rgb32},
   {PIX_FMT_RGB24, PIX_FMT_BGR32, rgb24_to_bgr32},
   {PIX_FMT_RGB24, PIX_FMT_xRGB32, rgb24_to_xrgb32},
   {PIX_FMT_RGB24, PIX_FMT_BGRx32, rgb24_to_bgrx32},
   {PIX_FMT_RGB24, PIX_FMT_RGBA32, rgb24_to_rgba32},
   {PIX_FMT_RGB24, PIX_FMT_BGR24, rgb24_to_bgr24},
   {PIX_FMT_RGB24, PIX_FMT_BGRA32, rgb24_to_bgra32},
   {PIX_FMT_RGB24, PIX_FMT_ARGB32, rgb24_to_argb32},
@@ -2079,78 +2104,90 @@
   {PIX_FMT_RGB24, PIX_FMT_PAL8, rgb24_to_pal8},
   {PIX_FMT_RGB24, PIX_FMT_YUV444P, rgb24_to_yuv444p},
   {PIX_FMT_RGB24, PIX_FMT_YUVJ420P, rgb24_to_yuvj420p},
   {PIX_FMT_RGB24, PIX_FMT_YUVJ444P, rgb24_to_yuvj444p},
   {PIX_FMT_RGB24, PIX_FMT_AYUV4444, rgb24_to_ayuv4444},
 
   {PIX_FMT_RGB32, PIX_FMT_RGB24, rgb32_to_rgb24},
   {PIX_FMT_RGB32, PIX_FMT_RGB555, rgba32_to_rgb555},
   {PIX_FMT_RGB32, PIX_FMT_PAL8, rgb32_to_pal8},
   {PIX_FMT_RGB32, PIX_FMT_YUV420P, rgb32_to_yuv420p},
+  {PIX_FMT_RGB32, PIX_FMT_NV12, rgb32_to_nv12},
   {PIX_FMT_RGB32, PIX_FMT_GRAY8, rgb32_to_gray},
 
   {PIX_FMT_xRGB32, PIX_FMT_RGB24, xrgb32_to_rgb24},
   {PIX_FMT_xRGB32, PIX_FMT_PAL8, xrgb32_to_pal8},
   {PIX_FMT_xRGB32, PIX_FMT_YUV420P, xrgb32_to_yuv420p},
+  {PIX_FMT_xRGB32, PIX_FMT_NV12, xrgb32_to_nv12},
   {PIX_FMT_xRGB32, PIX_FMT_GRAY8, xrgb32_to_gray},
 
   {PIX_FMT_RGBA32, PIX_FMT_BGRA32, rgba32_to_bgra32},
   {PIX_FMT_RGBA32, PIX_FMT_ABGR32, rgba32_to_abgr32},
   {PIX_FMT_RGBA32, PIX_FMT_ARGB32, rgba32_to_argb32},
   {PIX_FMT_RGBA32, PIX_FMT_BGR32, rgba32_to_bgr32},
   {PIX_FMT_RGBA32, PIX_FMT_BGRx32, rgba32_to_bgrx32},
   {PIX_FMT_RGBA32, PIX_FMT_ABGR32, rgba32_to_abgr32},
   {PIX_FMT_RGBA32, PIX_FMT_RGB24, rgba32_to_rgb24},
   {PIX_FMT_RGBA32, PIX_FMT_RGB555, rgba32_to_rgb555},
   {PIX_FMT_RGBA32, PIX_FMT_PAL8, rgba32_to_pal8},
   {PIX_FMT_RGBA32, PIX_FMT_YUV420P, rgba32_to_yuv420p},
+  {PIX_FMT_RGBA32, PIX_FMT_NV12, rgba32_to_nv12},
   {PIX_FMT_RGBA32, PIX_FMT_GRAY8, rgba32_to_gray},
   {PIX_FMT_RGBA32, PIX_FMT_AYUV4444, rgba32_to_ayuv4444},
 
   {PIX_FMT_BGR24, PIX_FMT_RGB24, bgr24_to_rgb24},
   {PIX_FMT_BGR24, PIX_FMT_YUV420P, bgr24_to_yuv420p},
+  {PIX_FMT_BGR24, PIX_FMT_NV12, bgr24_to_nv12},
+  {PIX_FMT_BGR24, PIX_FMT_NV12, bgr24_to_rgb24},
   {PIX_FMT_BGR24, PIX_FMT_GRAY8, bgr24_to_gray},
 
   {PIX_FMT_BGR32, PIX_FMT_RGB24, bgr32_to_rgb24},
   {PIX_FMT_BGR32, PIX_FMT_RGBA32, bgr32_to_rgba32},
   {PIX_FMT_BGR32, PIX_FMT_YUV420P, bgr32_to_yuv420p},
+  {PIX_FMT_BGR32, PIX_FMT_NV12, bgr32_to_nv12},
   {PIX_FMT_BGR32, PIX_FMT_GRAY8, bgr32_to_gray},
 
   {PIX_FMT_BGRx32, PIX_FMT_RGB24, bgrx32_to_rgb24},
   {PIX_FMT_BGRx32, PIX_FMT_RGBA32, bgrx32_to_rgba32},
   {PIX_FMT_BGRx32, PIX_FMT_YUV420P, bgrx32_to_yuv420p},
+  {PIX_FMT_BGRx32, PIX_FMT_NV12, bgrx32_to_nv12},
   {PIX_FMT_BGRx32, PIX_FMT_GRAY8, bgrx32_to_gray},
 
   {PIX_FMT_BGRA32, PIX_FMT_RGB24, bgra32_to_rgb24},
   {PIX_FMT_BGRA32, PIX_FMT_RGBA32, bgra32_to_rgba32},
   {PIX_FMT_BGRA32, PIX_FMT_YUV420P, bgra32_to_yuv420p},
+  {PIX_FMT_BGRA32, PIX_FMT_NV12, bgra32_to_nv12},
   {PIX_FMT_BGRA32, PIX_FMT_GRAY8, bgra32_to_gray},
   {PIX_FMT_BGRA32, PIX_FMT_AYUV4444, bgra32_to_ayuv4444},
 
   {PIX_FMT_ABGR32, PIX_FMT_RGB24, abgr32_to_rgb24},
   {PIX_FMT_ABGR32, PIX_FMT_RGBA32, abgr32_to_rgba32},
   {PIX_FMT_ABGR32, PIX_FMT_YUV420P, abgr32_to_yuv420p},
+  {PIX_FMT_ABGR32, PIX_FMT_NV12, abgr32_to_nv12},
   {PIX_FMT_ABGR32, PIX_FMT_GRAY8, abgr32_to_gray},
 
   {PIX_FMT_ARGB32, PIX_FMT_RGB24, argb32_to_rgb24},
   {PIX_FMT_ARGB32, PIX_FMT_RGBA32, argb32_to_rgba32},
   {PIX_FMT_ARGB32, PIX_FMT_YUV420P, argb32_to_yuv420p},
+  {PIX_FMT_ARGB32, PIX_FMT_NV12, argb32_to_nv12},
   {PIX_FMT_ARGB32, PIX_FMT_GRAY8, argb32_to_gray},
 
   {PIX_FMT_RGB555, PIX_FMT_RGB24, rgb555_to_rgb24},
   {PIX_FMT_RGB555, PIX_FMT_RGB32, rgb555_to_rgba32},
   {PIX_FMT_RGB555, PIX_FMT_RGBA32, rgb555_to_rgba32},
   {PIX_FMT_RGB555, PIX_FMT_YUV420P, rgb555_to_yuv420p},
+  {PIX_FMT_RGB555, PIX_FMT_NV12, rgb555_to_nv12},
   {PIX_FMT_RGB555, PIX_FMT_GRAY8, rgb555_to_gray},
 
   {PIX_FMT_RGB565, PIX_FMT_RGB24, rgb565_to_rgb24},
   {PIX_FMT_RGB565, PIX_FMT_YUV420P, rgb565_to_yuv420p},
+  {PIX_FMT_RGB565, PIX_FMT_NV12, rgb565_to_nv12},
   {PIX_FMT_RGB565, PIX_FMT_GRAY8, rgb565_to_gray},
 
   {PIX_FMT_GRAY8, PIX_FMT_RGB555, gray_to_rgb555},
   {PIX_FMT_GRAY8, PIX_FMT_RGB565, gray_to_rgb565},
   {PIX_FMT_GRAY8, PIX_FMT_RGB24, gray_to_rgb24},
   {PIX_FMT_GRAY8, PIX_FMT_BGR24, gray_to_bgr24},
   {PIX_FMT_GRAY8, PIX_FMT_RGB32, gray_to_rgb32},
   {PIX_FMT_GRAY8, PIX_FMT_BGR32, gray_to_bgr32},
   {PIX_FMT_GRAY8, PIX_FMT_xRGB32, gray_to_xrgb32},
   {PIX_FMT_GRAY8, PIX_FMT_BGRx32, gray_to_bgrx32},
Index: imgconvert_template.h
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/gst/ffmpegcolorspace/imgconvert_template.h,v
retrieving revision 1.1.1.2
diff -u -1 -0 -r1.1.1.2 imgconvert_template.h
--- imgconvert_template.h	7 Dec 2006 11:06:15 -0000	1.1.1.2
+++ imgconvert_template.h	8 May 2008 12:26:33 -0000
@@ -93,35 +93,122 @@
 
             YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
             RGB_OUT(d1 + BPP, r, g, b);
 
             d1 += 2 * BPP;
 
             y1_ptr += 2;
             cb_ptr++;
             cr_ptr++;
         }
-        /* handle width */
+        /* handle odd width */
         if (w) {
             YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
-            /* output 2 pixels */
+            /* output 1 pixel */
             YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
             RGB_OUT(d1, r, g, b);
             d1 += BPP;
 
             y1_ptr++;
             cb_ptr++;
             cr_ptr++;
         }
     }
 }
 
+static void glue(nv12_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+                                        int width, int height)
+{
+    const uint8_t *y1_ptr, *y2_ptr, *c_ptr;
+    uint8_t *d, *d1, *d2;
+    int w, y, cb, cr, r_add, g_add, b_add;
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    unsigned int r, g, b;
+
+    d = dst->data[0];
+    y1_ptr = src->data[0];
+    c_ptr = src->data[1];
+    for(;height >= 2; height -= 2) {
+        d1 = d;
+        d2 = d + dst->linesize[0];
+        y2_ptr = y1_ptr + src->linesize[0];
+        for(w = width; w >= 2; w -= 2) {
+            YUV_TO_RGB1_CCIR(c_ptr[0], c_ptr[1]);
+            /* output 4 pixels */
+            YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+            RGB_OUT(d1, r, g, b);
+
+            YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
+            RGB_OUT(d1 + BPP, r, g, b);
+
+            YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
+            RGB_OUT(d2, r, g, b);
+
+            YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
+            RGB_OUT(d2 + BPP, r, g, b);
+
+            d1 += 2 * BPP;
+            d2 += 2 * BPP;
+
+            y1_ptr += 2;
+            y2_ptr += 2;
+            c_ptr += 2;
+        }
+        /* handle odd width */
+        if (w) {
+            YUV_TO_RGB1_CCIR(c_ptr[0], c_ptr[1]);
+            YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+            RGB_OUT(d1, r, g, b);
+
+            YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
+            RGB_OUT(d2, r, g, b);
+            d1 += BPP;
+            d2 += BPP;
+            y1_ptr++;
+            y2_ptr++;
+            c_ptr += 2;
+        }
+        d += 2 * dst->linesize[0];
+        y1_ptr += 2 * src->linesize[0] - width;
+        c_ptr += src->linesize[1] - width;
+    }
+    /* handle odd height */
+    if (height) {
+        d1 = d;
+        for(w = width; w >= 2; w -= 2) {
+            YUV_TO_RGB1_CCIR(c_ptr[0], c_ptr[1]);
+            /* output 2 pixels */
+            YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+            RGB_OUT(d1, r, g, b);
+
+            YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
+            RGB_OUT(d1 + BPP, r, g, b);
+
+            d1 += 2 * BPP;
+
+            y1_ptr += 2;
+            c_ptr += 2;
+        }
+        /* handle odd width */
+        if (w) {
+            YUV_TO_RGB1_CCIR(c_ptr[0], c_ptr[1]);
+            /* output 1 pixel */
+            YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+            RGB_OUT(d1, r, g, b);
+            d1 += BPP;
+
+            y1_ptr++;
+            c_ptr += 2;
+        }
+    }
+}
+
 static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                          int width, int height)
 {
     const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
     uint8_t *d, *d1, *d2;
     int w, y, cb, cr, r_add, g_add, b_add, width2;
     uint8_t *cm = cropTbl + MAX_NEG_CROP;
     unsigned int r, g, b;
 
     d = dst->data[0];
@@ -310,20 +397,124 @@
         }
         if (w) {
             RGB_IN(r, g, b, p);
             lum[0] = RGB_TO_Y_CCIR(r, g, b);
             cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
             cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
         }
     }
 }
 
+static void glue(RGB_NAME, _to_nv12)(AVPicture *dst, const AVPicture *src,
+                                        int width, int height)
+{
+    int wrap, wrap3;
+    int r, g, b, r1, g1, b1, w;
+    uint8_t *lum, *c;
+    const uint8_t *p;
+
+    lum = dst->data[0];
+    c = dst->data[1];
+
+    wrap = dst->linesize[0];
+    wrap3 = src->linesize[0];
+    p = src->data[0];
+    for(;height>=2;height -= 2) {
+        for(w = width; w >= 2; w -= 2) {
+            RGB_IN(r, g, b, p);
+            r1 = r;
+            g1 = g;
+            b1 = b;
+            lum[0] = RGB_TO_Y_CCIR(r, g, b);
+
+            RGB_IN(r, g, b, p + BPP);
+            r1 += r;
+            g1 += g;
+            b1 += b;
+            lum[1] = RGB_TO_Y_CCIR(r, g, b);
+            p += wrap3;
+            lum += wrap;
+
+            RGB_IN(r, g, b, p);
+            r1 += r;
+            g1 += g;
+            b1 += b;
+            lum[0] = RGB_TO_Y_CCIR(r, g, b);
+
+            RGB_IN(r, g, b, p + BPP);
+            r1 += r;
+            g1 += g;
+            b1 += b;
+            lum[1] = RGB_TO_Y_CCIR(r, g, b);
+
+            c[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
+            c[1] = RGB_TO_V_CCIR(r1, g1, b1, 2);
+
+
+            c += 2;
+            p += -wrap3 + 2 * BPP;
+            lum += -wrap + 2;
+        }
+	/* handle odd width */
+        if (w) {
+            RGB_IN(r, g, b, p);
+            r1 = r;
+            g1 = g;
+            b1 = b;
+            lum[0] = RGB_TO_Y_CCIR(r, g, b);
+            p += wrap3;
+            lum += wrap;
+            RGB_IN(r, g, b, p);
+            r1 += r;
+            g1 += g;
+            b1 += b;
+            lum[0] = RGB_TO_Y_CCIR(r, g, b);
+            c[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
+            c[1] = RGB_TO_V_CCIR(r1, g1, b1, 1);
+            c += 2;
+            p += -wrap3 + BPP;
+            lum += -wrap + 1;
+        }
+        p += wrap3 + (wrap3 - width * BPP);
+        lum += wrap + (wrap - width);
+        c += dst->linesize[1] - width;
+    }
+    /* handle odd height */
+    if (height) {
+        for(w = width; w >= 2; w -= 2) {
+            RGB_IN(r, g, b, p);
+            r1 = r;
+            g1 = g;
+            b1 = b;
+            lum[0] = RGB_TO_Y_CCIR(r, g, b);
+
+            RGB_IN(r, g, b, p + BPP);
+            r1 += r;
+            g1 += g;
+            b1 += b;
+            lum[1] = RGB_TO_Y_CCIR(r, g, b);
+            c[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
+            c[1] = RGB_TO_V_CCIR(r1, g1, b1, 1);
+            c += 2;
+            p += 2 * BPP;
+            lum += 2;
+        }
+	/* handle odd width */
+        if (w) {
+            RGB_IN(r, g, b, p);
+            lum[0] = RGB_TO_Y_CCIR(r, g, b);
+            c[0] = RGB_TO_U_CCIR(r, g, b, 0);
+            c[1] = RGB_TO_V_CCIR(r, g, b, 0);
+        }
+    }
+}
+
 static void glue(RGB_NAME, _to_gray)(AVPicture *dst, const AVPicture *src,
                                      int width, int height)
 {
     const unsigned char *p;
     unsigned char *q;
     int r, g, b, dst_wrap, src_wrap;
     int x, y;
 
     p = src->data[0];
     src_wrap = src->linesize[0] - BPP * width;
