Commit fd18046f authored by Jean-Francois Moine's avatar Jean-Francois Moine Committed by Mauro Carvalho Chehab

V4L/DVB (13895): gspca - zc3xx: Fix the contrast control.

The previous calculation gave bad gamma tables.
Signed-off-by: default avatarJean-Francois Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 878b35ae
...@@ -115,7 +115,7 @@ static struct ctrl sd_ctrls[] = { ...@@ -115,7 +115,7 @@ static struct ctrl sd_ctrls[] = {
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
.name = "Contrast", .name = "Contrast",
.minimum = 0, .minimum = 0,
.maximum = 256, .maximum = 255,
.step = 1, .step = 1,
.default_value = 128, .default_value = 128,
}, },
...@@ -6053,105 +6053,55 @@ static void setcontrast(struct gspca_dev *gspca_dev) ...@@ -6053,105 +6053,55 @@ static void setcontrast(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
const __u8 *Tgamma, *Tgradient; const __u8 *Tgamma;
int g, i, k; int g, i, k, adj, gp;
static const __u8 kgamma_tb[16] = /* delta for contrast */ u8 gr[16];
static const u8 delta_tb[16] = /* delta for contrast */
{0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08, {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}; 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08};
static const __u8 kgrad_tb[16] = static const u8 gamma_tb[6][16] = {
{0x1b, 0x06, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x04};
static const __u8 Tgamma_1[16] =
{0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f, {0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f,
0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff}; 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] =
{0x01, 0x0c, 0x1f, 0x3a, 0x53, 0x6d, 0x85, 0x9c, {0x01, 0x0c, 0x1f, 0x3a, 0x53, 0x6d, 0x85, 0x9c,
0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff}; 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] =
{0x04, 0x16, 0x30, 0x4e, 0x68, 0x81, 0x98, 0xac, {0x04, 0x16, 0x30, 0x4e, 0x68, 0x81, 0x98, 0xac,
0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff}; 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] =
{0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, {0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff}; 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] =
{0x20, 0x4b, 0x6e, 0x8d, 0xa3, 0xb5, 0xc5, 0xd2, {0x20, 0x4b, 0x6e, 0x8d, 0xa3, 0xb5, 0xc5, 0xd2,
0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff}; 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 */
{0x24, 0x44, 0x64, 0x84, 0x9d, 0xb2, 0xc4, 0xd3, {0x24, 0x44, 0x64, 0x84, 0x9d, 0xb2, 0xc4, 0xd3,
0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}; 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
}; };
#ifdef GSPCA_DEBUG
__u8 v[16];
#endif
Tgamma = gamma_tb[sd->gamma]; Tgamma = gamma_tb[sd->gamma - 1];
Tgradient = gradient_tb[sd->gamma];
k = (sd->contrast - 128) /* -128 / 128 */ k = ((int) sd->contrast - 128); /* -128 / 128 */
* Tgamma[0]; adj = 0;
PDEBUG(D_CONF, "gamma:%d contrast:%d gamma coeff: %d/128", gp = 0;
sd->gamma, sd->contrast, k);
for (i = 0; i < 16; i++) { 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) if (g > 0xff)
g = 0xff; g = 0xff;
else if (g <= 0) else if (g <= 0)
g = 1; g = 1;
reg_w(dev, g, 0x0120 + i); /* gamma */ reg_w(dev, g, 0x0120 + i); /* gamma */
#ifdef GSPCA_DEBUG if (k > 0)
if (gspca_debug & D_CONF) adj--;
v[i] = g; else
#endif adj++;
}
PDEBUG(D_CONF, "tb: %02x %02x %02x %02x %02x %02x %02x %02x", if (i != 0) {
v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); if (gp == 0)
PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", gr[i - 1] = 0;
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;
else else
g = 1; gr[i - 1] = g - gp;
} }
reg_w(dev, g, 0x0130 + i); /* gradient */ gp = g;
#ifdef GSPCA_DEBUG
if (gspca_debug & D_CONF)
v[i] = g;
#endif
} }
PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", gr[15] = gr[14] / 2;
v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); for (i = 0; i < 16; i++)
PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", reg_w(dev, gr[i], 0x0130 + i); /* gradient */
v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]);
} }
static void setquality(struct gspca_dev *gspca_dev) static void setquality(struct gspca_dev *gspca_dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment