From fd18046fffc24b06c9820d9b540c518fc0e1b627 Mon Sep 17 00:00:00 2001 From: Jean-Francois Moine Date: Mon, 4 Jan 2010 15:54:59 -0300 Subject: [PATCH] V4L/DVB (13895): gspca - zc3xx: Fix the contrast control. The previous calculation gave bad gamma tables. Signed-off-by: Jean-Francois Moine Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/zc3xx.c | 110 ++++++++---------------------- 1 file changed, 30 insertions(+), 80 deletions(-) diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c index e0dd0ea0588e..d217c042dee9 100644 --- a/drivers/media/video/gspca/zc3xx.c +++ b/drivers/media/video/gspca/zc3xx.c @@ -115,7 +115,7 @@ static struct ctrl sd_ctrls[] = { .type = V4L2_CTRL_TYPE_INTEGER, .name = "Contrast", .minimum = 0, - .maximum = 256, + .maximum = 255, .step = 1, .default_value = 128, }, @@ -6053,105 +6053,55 @@ static void setcontrast(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; struct usb_device *dev = gspca_dev->dev; - const __u8 *Tgamma, *Tgradient; - int g, i, k; - static const __u8 kgamma_tb[16] = /* delta for contrast */ + const __u8 *Tgamma; + int g, i, k, adj, gp; + u8 gr[16]; + static const u8 delta_tb[16] = /* delta for contrast */ {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}; - static const __u8 kgrad_tb[16] = - {0x1b, 0x06, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x04}; - static const __u8 Tgamma_1[16] = + static const u8 gamma_tb[6][16] = { {0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f, - 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff}; - static const __u8 Tgradient_1[16] = - {0x00, 0x01, 0x05, 0x0b, 0x10, 0x15, 0x18, 0x1a, - 0x1a, 0x18, 0x16, 0x14, 0x12, 0x0f, 0x0d, 0x06}; - static const __u8 Tgamma_2[16] = + 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff}, {0x01, 0x0c, 0x1f, 0x3a, 0x53, 0x6d, 0x85, 0x9c, - 0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff}; - static const __u8 Tgradient_2[16] = - {0x05, 0x0f, 0x16, 0x1a, 0x19, 0x19, 0x17, 0x15, - 0x12, 0x10, 0x0e, 0x0b, 0x09, 0x08, 0x06, 0x03}; - static const __u8 Tgamma_3[16] = + 0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff}, {0x04, 0x16, 0x30, 0x4e, 0x68, 0x81, 0x98, 0xac, - 0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff}; - static const __u8 Tgradient_3[16] = - {0x0c, 0x16, 0x1b, 0x1c, 0x19, 0x18, 0x15, 0x12, - 0x10, 0x0d, 0x0b, 0x09, 0x08, 0x06, 0x05, 0x03}; - static const __u8 Tgamma_4[16] = + 0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff}, {0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, - 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff}; - static const __u8 Tgradient_4[16] = - {0x26, 0x22, 0x20, 0x1c, 0x16, 0x13, 0x10, 0x0d, - 0x0b, 0x09, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02}; - static const __u8 Tgamma_5[16] = + 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff}, {0x20, 0x4b, 0x6e, 0x8d, 0xa3, 0xb5, 0xc5, 0xd2, - 0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff}; - static const __u8 Tgradient_5[16] = - {0x37, 0x26, 0x20, 0x1a, 0x14, 0x10, 0x0e, 0x0b, - 0x09, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x02}; - static const __u8 Tgamma_6[16] = /* ?? was gamma 5 */ + 0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff}, {0x24, 0x44, 0x64, 0x84, 0x9d, 0xb2, 0xc4, 0xd3, - 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}; - static const __u8 Tgradient_6[16] = - {0x18, 0x20, 0x20, 0x1c, 0x16, 0x13, 0x10, 0x0e, - 0x0b, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01}; - static const __u8 *gamma_tb[] = { - NULL, Tgamma_1, Tgamma_2, - Tgamma_3, Tgamma_4, Tgamma_5, Tgamma_6 - }; - static const __u8 *gradient_tb[] = { - NULL, Tgradient_1, Tgradient_2, - Tgradient_3, Tgradient_4, Tgradient_5, Tgradient_6 + 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}, }; -#ifdef GSPCA_DEBUG - __u8 v[16]; -#endif - Tgamma = gamma_tb[sd->gamma]; - Tgradient = gradient_tb[sd->gamma]; + Tgamma = gamma_tb[sd->gamma - 1]; - k = (sd->contrast - 128) /* -128 / 128 */ - * Tgamma[0]; - PDEBUG(D_CONF, "gamma:%d contrast:%d gamma coeff: %d/128", - sd->gamma, sd->contrast, k); + k = ((int) sd->contrast - 128); /* -128 / 128 */ + adj = 0; + gp = 0; for (i = 0; i < 16; i++) { - g = Tgamma[i] + kgamma_tb[i] * k / 128; + g = Tgamma[i] - delta_tb[i] * k / 128 - adj / 2; if (g > 0xff) g = 0xff; else if (g <= 0) g = 1; reg_w(dev, g, 0x0120 + i); /* gamma */ -#ifdef GSPCA_DEBUG - if (gspca_debug & D_CONF) - v[i] = g; -#endif - } - PDEBUG(D_CONF, "tb: %02x %02x %02x %02x %02x %02x %02x %02x", - v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); - PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", - v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); - for (i = 0; i < 16; i++) { - g = Tgradient[i] - kgrad_tb[i] * k / 128; - if (g > 0xff) - g = 0xff; - else if (g <= 0) { - if (i != 15) - g = 0; + if (k > 0) + adj--; + else + adj++; + + if (i != 0) { + if (gp == 0) + gr[i - 1] = 0; else - g = 1; + gr[i - 1] = g - gp; } - reg_w(dev, g, 0x0130 + i); /* gradient */ -#ifdef GSPCA_DEBUG - if (gspca_debug & D_CONF) - v[i] = g; -#endif + gp = g; } - PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", - v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); - PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", - v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); + gr[15] = gr[14] / 2; + for (i = 0; i < 16; i++) + reg_w(dev, gr[i], 0x0130 + i); /* gradient */ } static void setquality(struct gspca_dev *gspca_dev) -- 2.30.2