Web lists-archives.com

[Spca50x-devs] PATCH: Various bugfixes for gspcav2-2.0.3




Hi,

The attached patch fixes the following:

spca501:

1) The spca501 driver currently converts the interlaced yuv delivered by the
   spca501 to YUYV, but this doubles the U and V resolution, YUV420 is a much
   better mach as that maches the U and V resoltion from the cam. And YUV420 is
   much better supported by applications. As an additional advantage YUV420
   also is smaller.

2) The spca501 driver did not check for buffer overflows when adding data to
   its temp buffer. In order for things to still work at 640x480 resolution I
   had to make the temp buffer larger, I guess there is some trailing garbage
   and/or a footer behind the frame data.

3) The intel spca501 I'm using for testing maxes out its contrast until
   one of contrast / brightness or color has been set, so set those on stream
   start.


spca561:

1) The spca561 does not produce BGGR bayer, it produces GBRG bayer.
2) The value and address were swapped in one writereg call.

Regards,

Hans
--- gspcav2-2.0.3/gspca.c	2008-06-21 11:43:06.000000000 +0200
+++ gspcav2-2.0.3.bugfixes/gspca.c	2008-06-26 20:14:25.000000000 +0200
@@ -712,6 +712,9 @@
 	case V4L2_PIX_FMT_MJPEG:
 	case V4L2_PIX_FMT_JPEG:
 	case V4L2_PIX_FMT_SBGGR8:	/* 'BA81' Bayer */
+	case V4L2_PIX_FMT_SGBRG8:
+	case V4L2_PIX_FMT_SGRBG8:
+	case V4L2_PIX_FMT_SRGGB8:
 		return 8;
 	}
 	PDEBUG(D_ERR|D_CONF, "Unknown pixel format %c%c%c%c",
--- gspcav2-2.0.3/gspca.h	2008-06-19 08:54:16.000000000 +0200
+++ gspcav2-2.0.3.bugfixes/gspca.h	2008-06-26 19:59:20.000000000 +0200
@@ -12,6 +12,18 @@
 /* debug option */
 /* #define GSPCA_DEBUG 1 */
 
+#ifndef V4L2_PIX_FMT_SGBRG8
+#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G','B','R','G')
+#endif
+
+#ifndef V4L2_PIX_FMT_SGRBG8
+#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G','R','B','G')
+#endif
+
+#ifndef V4L2_PIX_FMT_SRGGB8
+#define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R','G','G','B')
+#endif
+
 #ifdef GSPCA_DEBUG
 /* GSPCA our debug messages */
 extern int gspca_debug;
--- gspcav2-2.0.3/spca501.c	2008-05-17 09:02:50.000000000 +0200
+++ gspcav2-2.0.3.bugfixes/spca501.c	2008-06-26 22:51:20.000000000 +0200
@@ -35,8 +35,8 @@
 	struct gspca_dev gspca_dev;		/* !! must be the first item */
 
 	int buflen;
-	unsigned char tmpbuf[640 * 480 * 3 / 2]; /* YYUV per line */
-	unsigned char tmpbuf2[640 * 480 * 2];	/* YUYV */
+	unsigned char tmpbuf[640 * 480 *  2]; /* YYUV per line */
+	unsigned char tmpbuf2[640 * 480 * 3 / 2];/* YUV420 */
 
 	unsigned short contrast;
 	unsigned char brightness;
@@ -52,6 +52,11 @@
 #define ViewQuestM318B 6
 };
 
+static void setbrightness(struct gspca_dev *gspca_dev);
+static void setcontrast(struct gspca_dev *gspca_dev);
+static void setcolors(struct gspca_dev *gspca_dev);
+
+
 /* V4L2 controls supported by the driver */
 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
@@ -106,9 +111,9 @@
 };
 
 static struct cam_mode vga_mode[] = {
-	{V4L2_PIX_FMT_YUYV, 160, 120, 2},
-	{V4L2_PIX_FMT_YUYV, 320, 240, 1},
-	{V4L2_PIX_FMT_YUYV, 640, 480, 0},
+	{V4L2_PIX_FMT_YUV420, 160, 120, 2},
+	{V4L2_PIX_FMT_YUV420, 320, 240, 1},
+	{V4L2_PIX_FMT_YUV420, 640, 480, 0},
 };
 
 #define SPCA50X_REG_USB 0x2	/* spca505 501 */
@@ -2014,6 +2019,13 @@
 	}
 	err_code = reg_write(dev, SPCA501_REG_CTLRL,
 					 (__u16) 0x1, (__u16) 0x2);
+	/* HDG atleast the Intel CreateAndShare needs to have one of its
+	   brightness / contrast / color set otherwise it assumes wath seems
+	   max contrast. Note that strange enough setting any of these is
+	   enough to fix the max contrast problem, to be sure we set all 3 */
+	setbrightness(gspca_dev);
+	setcontrast(gspca_dev);
+	setcolors(gspca_dev);
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -2040,28 +2052,29 @@
 			int height)
 {
 	unsigned char *Ui, *Vi, *yi, *yi1;
-	unsigned char *out1;
+	unsigned char *Yout, *Yout1, *Uout, *Vout;
 	int i, j;
 
 	yi = in;
-	for (i = height / 2; --i >= 0; ) {
-		out1 = out + width * 2;		/* next line */
+	for (i = 0; i < height; i += 2) {
+		Yout = out + i * width;
+		Yout1 = out + (i + 1) * width;
+		Uout = out + width * height + i * width / 4;
+		Vout = out + width * height + width * height / 4
+			+ i * width / 4;
+
 		Ui = yi + width;
 		yi1 = Ui + width / 2;
 		Vi = yi1 + width;
 		for (j = width / 2; --j >= 0; ) {
-			*out++ = 128 + *yi++;
-			*out++ = 128 + *Ui;
-			*out++ = 128 + *yi++;
-			*out++ = 128 + *Vi;
-
-			*out1++ = 128 + *yi1++;
-			*out1++ = 128 + *Ui++;
-			*out1++ = 128 + *yi1++;
-			*out1++ = 128 + *Vi++;
+			*Yout++ = 128 + *yi++;
+			*Yout++ = 128 + *yi++;
+			*Yout1++ = 128 + *yi1++;
+			*Yout1++ = 128 + *yi1++;
+			*Uout++ = 128 + *Ui++;
+			*Vout++ = 128 + *Vi++;
 		}
 		yi += width * 2;
-		out = out1;
 	}
 }
 
@@ -2082,9 +2095,9 @@
 						LAST_PACKET,
 						frame,
 						sd->tmpbuf2,
-						gspca_dev->width
+						(gspca_dev->width
 							* gspca_dev->height
-							* 2);
+							* 3) / 2);
 		}
 		gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
 				data, 0);
@@ -2101,6 +2114,10 @@
 	}
 	data += 1;
 	len -= 1;
+	if ((sd->buflen + len) > (640 * 480 * 2)) {
+		gspca_dev->last_packet_type = DISCARD_PACKET;
+		return;
+	}
 	memcpy(&sd->tmpbuf[sd->buflen], data, len);
 	sd->buflen += len;
 }
--- gspcav2-2.0.3/spca561.c	2008-06-16 09:42:16.000000000 +0200
+++ gspcav2-2.0.3.bugfixes/spca561.c	2008-06-26 20:28:53.000000000 +0200
@@ -102,10 +102,10 @@
 };
 
 static struct cam_mode sif_mode[] = {
-	{V4L2_PIX_FMT_SBGGR8, 160, 120, 3},
-	{V4L2_PIX_FMT_SBGGR8, 176, 144, 2},
-	{V4L2_PIX_FMT_SBGGR8, 320, 240, 1},
-	{V4L2_PIX_FMT_SBGGR8, 352, 288, 0},
+	{V4L2_PIX_FMT_SGBRG8, 160, 120, 3},
+	{V4L2_PIX_FMT_SGBRG8, 176, 144, 2},
+	{V4L2_PIX_FMT_SGBRG8, 320, 240, 1},
+	{V4L2_PIX_FMT_SGBRG8, 352, 288, 0},
 };
 
 /*
@@ -722,7 +722,7 @@
 /* this function is called at close time */
 static void sd_close(struct gspca_dev *gspca_dev)
 {
-	reg_w_val(gspca_dev->dev, 0, 0x8114);
+	reg_w_val(gspca_dev->dev, 0x8114, 0);
 }
 
 /*
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Spca50x-devs mailing list
Spca50x-devs@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/spca50x-devs