All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Francois Moine <moinejf@free.fr>
To: Hans de Goede <j.w.r.degoede@hhs.nl>
Cc: Video 4 Linux <video4linux-list@redhat.com>
Subject: [PATCH] v4l library YVYU decoding
Date: Mon, 01 Sep 2008 10:04:28 +0200	[thread overview]
Message-ID: <1220256268.1753.17.camel@localhost> (raw)

[-- Attachment #1: Type: text/plain, Size: 276 bytes --]

Hi Hans,

Here is a new YVYU decoding patch which replaces the previous one.

Sorry for it is not tested: the webcam 046d:0896 does not work well.

Cheers.

-- 
Ken ar c'hentañ |             ** Breizh ha Linux atav! **
Jef             |               http://moinejf.free.fr/


[-- Attachment #2: yvyu.pat --]
[-- Type: text/plain, Size: 4713 bytes --]


This patch adds the decoding of YVYU images generated by vc0321.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>

--- v4l-dvb-423381bc0d61/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h.orig	2008-08-29 14:00:57.000000000 +0200
+++ v4l-dvb-423381bc0d61/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h	2008-08-31 16:31:40.000000000 +0200
@@ -59,6 +59,10 @@
 #define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R','G','G','B')
 #endif
 
+#ifndef V4L2_PIX_FMT_YVYU
+#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U')
+#endif
+
 #define V4LCONVERT_ERROR_MSG_SIZE 256
 
 #define V4LCONVERT_ERR(...) \
@@ -87,6 +91,15 @@
 void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dst,
   int width, int height);
 
+void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
+  int width, int height);
+
+void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dst,
+  int width, int height);
+
+void v4lconvert_yvyu_to_yuv420(const unsigned char *src, unsigned char *dst,
+  int width, int height);
+
 void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst,
   int width, int height);
 
--- v4l-dvb-423381bc0d61/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c.orig	2008-08-29 14:00:57.000000000 +0200
+++ v4l-dvb-423381bc0d61/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c	2008-08-31 15:47:58.000000000 +0200
@@ -49,6 +49,7 @@
   V4L2_PIX_FMT_SN9C10X,
   V4L2_PIX_FMT_PAC207,
   V4L2_PIX_FMT_PJPG,
+  V4L2_PIX_FMT_YVYU,
 };
 
 static const unsigned int supported_dst_pixfmts[] = {
@@ -518,6 +519,23 @@
       }
       break;
 
+    case V4L2_PIX_FMT_YVYU:
+      switch (dest_fmt->fmt.pix.pixelformat) {
+      case V4L2_PIX_FMT_RGB24:
+	v4lconvert_yvyu_to_rgb24(src, dest, dest_fmt->fmt.pix.width,
+				   dest_fmt->fmt.pix.height);
+	break;
+      case V4L2_PIX_FMT_BGR24:
+	v4lconvert_yvyu_to_bgr24(src, dest, dest_fmt->fmt.pix.width,
+				   dest_fmt->fmt.pix.height);
+	break;
+      default:
+	v4lconvert_yvyu_to_yuv420(src, dest, dest_fmt->fmt.pix.width,
+		    dest_fmt->fmt.pix.height);
+	break;
+      }
+      break;
+
     default:
       V4LCONVERT_ERR("Unknown src format in conversion\n");
       errno = EINVAL;
--- v4l-dvb-423381bc0d61/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c.orig	2008-08-29 14:00:57.000000000 +0200
+++ v4l-dvb-423381bc0d61/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c	2008-08-31 16:44:29.000000000 +0200
@@ -130,6 +130,91 @@
   }
 }
 
+void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dest,
+  int width, int height)
+{
+  int j;
+
+  while (--height >= 0) {
+    for (j = 0; j < width; j += 2) {
+      int u = src[3];
+      int v = src[1];
+      int u1 = (((u - 128) << 7) +  (u - 128)) >> 6;
+      int rg = (((u - 128) << 1) +  (u - 128) +
+		((v - 128) << 2) + ((v - 128) << 1)) >> 3;
+      int v1 = (((v - 128) << 1) +  (v - 128)) >> 1;
+
+      *dest++ = CLIP(*src + u1);
+      *dest++ = CLIP(*src - rg);
+      *dest++ = CLIP(*src + v1);
+
+      *dest++ = CLIP(src[2] + u1);
+      *dest++ = CLIP(src[2] - rg);
+      *dest++ = CLIP(src[2] + v1);
+      src += 4;
+    }
+  }
+}
+
+void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dest,
+  int width, int height)
+{
+  int j;
+
+  while (--height >= 0) {
+    for (j = 0; j < width; j += 2) {
+      int u = src[3];
+      int v = src[1];
+      int u1 = (((u - 128) << 7) +  (u - 128)) >> 6;
+      int rg = (((u - 128) << 1) +  (u - 128) +
+		((v - 128) << 2) + ((v - 128) << 1)) >> 3;
+      int v1 = (((v - 128) << 1) +  (v - 128)) >> 1;
+
+      *dest++ = CLIP(*src + v1);
+      *dest++ = CLIP(*src - rg);
+      *dest++ = CLIP(*src + u1);
+
+      *dest++ = CLIP(src[2] + v1);
+      *dest++ = CLIP(src[2] - rg);
+      *dest++ = CLIP(src[2] + u1);
+      src += 4;
+    }
+  }
+}
+
+void v4lconvert_yvyu_to_yuv420(const unsigned char *src, unsigned char *dest,
+  int width, int height)
+{
+  int i, j;
+  const unsigned char *src1;
+  unsigned char *vdest;
+
+  /* copy the Y values */
+  src1 = src;
+  for (i = 0; i < height; i++) {
+    for (j = 0; j < width; j += 2) {
+      *dest++ = *src1;
+      *dest++ = src1[2];
+      src1 += 4;
+    }
+  }
+
+  /* copy the U and V values */
+  src++;				/* point to V */
+  src1 = src + width * 2;		/* next line */
+  vdest = dest + width * height / 4;
+  for (i = 0; i < height; i += 2) {
+    for (j = 0; j < width; j += 2) {
+      *dest++ = ((int) src[2] + src1[2]) / 2;	/* U */
+      *vdest++ = ((int) *src + *src1) / 2;	/* V */
+      src += 4;
+      src1 += 4;
+    }
+    src = src1;
+    src1 += width * 2;
+  }
+}
+
 void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst,
   int width, int height)
 {

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

             reply	other threads:[~2008-09-01  8:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-01  8:04 Jean-Francois Moine [this message]
2008-09-03 12:46 ` [PATCH] v4l library YVYU decoding Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1220256268.1753.17.camel@localhost \
    --to=moinejf@free.fr \
    --cc=j.w.r.degoede@hhs.nl \
    --cc=video4linux-list@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.