Package: opencv
Severity: wishlist
Tags: patch

Hi,

The UYVY format is not supported in v4l of OpenCV.
Opencv cannot be used because it is not supported though
iSight of MacBook is this format.
I wrote the patch to support it and check working.
Please apply this patch.

Best regards,
 Nobuhiro

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.25-1-686-bigmem (SMP w/2 CPU cores)
Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash


-- 
Nobuhiro Iwamatsu
        [EMAIL PROTECTED]
        [EMAIL PROTECTED]

        GPG ID : 3170EBE9
--- opencv-1.0.0/otherlibs/highgui/cvcap_v4l.cpp	2006-09-27 10:40:03.000000000 +0900
+++ opencv-1.0.0/otherlibs/highgui/cvcap_v4l.cpp	2008-07-26 13:12:28.000000000 +0900
@@ -146,6 +146,9 @@
   some drivers working, but not fully with V4L2. (so, we do not know when we
   need to switch from V4L2 to V4L.
 
+Sat, 26 Jul 2008 12:59:04 +0900 Nobuhiro Iwamatsu <[EMAIL PROTECTED]>
+- Add support UYVY format.
+
 make & enjoy!
 
 */
@@ -254,6 +257,7 @@
      PALETTE_YVU420 = 0,
      PALETTE_YUV411P = 0,
      PALETTE_YUYV = 0,
+     PALETTE_UYVY = 0,
      PALETTE_SBGGR8 = 0,
      PALETTE_SN9C10X = 0,
      PALETTE_MJPEG = 0;
@@ -551,7 +555,6 @@
   else
 #endif
 #endif
-
   if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0)
   {
     PALETTE_YUYV = 1;
@@ -574,6 +577,10 @@
   if (try_palette_v4l2(capture, V4L2_PIX_FMT_SBGGR8) == 0)
   {
     PALETTE_SBGGR8 = 1;
+  } else 
+  if (try_palette_v4l2(capture, V4L2_PIX_FMT_UYVY) == 0)
+  {
+    PALETTE_UYVY = 1;
   }
   else
   {
@@ -1592,6 +1599,47 @@
    }
 }
 
+#define YUV2RGB(y, u, v, r, g, b) \
+	r = y + ((v*1436) >> 10); \
+	g = y - ((u*352 + v*731) >> 10); \
+	b = y + ((u*1814) >> 10); \
+	r = r < 0 ? 0 : r; \
+	g = g < 0 ? 0 : g; \
+	b = b < 0 ? 0 : b; \
+	r = r > 255 ? 255 : r; \
+	g = g > 255 ? 255 : g; \
+	b = b > 255 ? 255 : b
+
+static void 
+uyvy_to_rgb24 (int width, int height, unsigned char *src, unsigned char *dst)
+{
+	unsigned char *s;
+	unsigned char *d;
+	int l, c;
+	register int r, g, b, y0, y1, u, v;
+   
+	l = height;
+	s = src;
+	d = dst;
+	while (l--) {
+		c = width >> 1;
+		while (c--) {
+			u = *s++; u -= 128;
+			y0 = *s++;
+			v = *s++; v -= 128;
+			y1 = *s++;
+			YUV2RGB(y0, u, v, r, g, b);
+			*d++ = b;
+			*d++ = g;
+			*d++ = r;
+			YUV2RGB(y1, u, v, r, g, b);
+			*d++ = b;
+			*d++ = g;
+			*d++ = r;
+		}
+	}
+}
+
 #ifdef HAVE_JPEG
 #ifdef __USE_GNU
 /* support for MJPEG is only available with libjpeg and gcc,
@@ -2047,6 +2095,12 @@
 		      capture->form.fmt.pix.height,
 		      (unsigned char*)(capture->buffers[capture->bufferIndex].start),
 		      (unsigned char*)capture->frame.imageData);
+    
+    if (PALETTE_UYVY == 1)
+	uyvy_to_rgb24(capture->form.fmt.pix.width,
+		      capture->form.fmt.pix.height,
+		      (unsigned char*)(capture->buffers[capture->bufferIndex].start),
+		      (unsigned char*)capture->frame.imageData);
 
     if (PALETTE_SBGGR8 == 1)
     {

Reply via email to