diff mbox

[4/4] gspca_pac7302: add support for green balance adjustment

Message ID 1347811240-4000-4-git-send-email-fschaefer.oss@googlemail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Frank Schäfer Sept. 16, 2012, 4 p.m. UTC
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
 drivers/media/usb/gspca/pac7302.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

Comments

Frank Schäfer Sept. 19, 2012, 5:25 p.m. UTC | #1
Am 16.09.2012 18:00, schrieb Frank Schäfer:
> Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
> ---
>  drivers/media/usb/gspca/pac7302.c |   23 ++++++++++++++++++++++-
>  1 files changed, 22 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
> index 8a0f4d6..9b62b74 100644
> --- a/drivers/media/usb/gspca/pac7302.c
> +++ b/drivers/media/usb/gspca/pac7302.c
> @@ -78,6 +78,7 @@
>   * Page | Register   | Function
>   * -----+------------+---------------------------------------------------
>   *  0   | 0x01       | setredbalance()
> + *  0   | 0x02       | setgreenbalance()
>   *  0   | 0x03       | setbluebalance()
>   *  0   | 0x0f..0x20 | setcolors()
>   *  0   | 0xa2..0xab | setbrightcont()
> @@ -121,6 +122,7 @@ struct sd {
>  	struct v4l2_ctrl *saturation;
>  	struct v4l2_ctrl *white_balance;
>  	struct v4l2_ctrl *red_balance;
> +	struct v4l2_ctrl *green_balance;
>  	struct v4l2_ctrl *blue_balance;
>  	struct { /* flip cluster */
>  		struct v4l2_ctrl *hflip;
> @@ -470,6 +472,17 @@ static void setredbalance(struct gspca_dev *gspca_dev)
>  	reg_w(gspca_dev, 0xdc, 0x01);
>  }
>  
> +static void setgreenbalance(struct gspca_dev *gspca_dev)
> +{
> +	struct sd *sd = (struct sd *) gspca_dev;
> +
> +	reg_w(gspca_dev, 0xff, 0x00);			/* page 0 */
> +	reg_w(gspca_dev, 0x02,
> +	      rgbbalance_ctrl_to_reg_value(sd->green_balance->val));
> +
> +	reg_w(gspca_dev, 0xdc, 0x01);
> +}
> +
>  static void setbluebalance(struct gspca_dev *gspca_dev)
>  {
>  	struct sd *sd = (struct sd *) gspca_dev;
> @@ -620,6 +633,9 @@ static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
>  	case V4L2_CID_RED_BALANCE:
>  		setredbalance(gspca_dev);
>  		break;
> +	case V4L2_CID_GREEN_BALANCE:
> +		setgreenbalance(gspca_dev);
> +		break;
>  	case V4L2_CID_BLUE_BALANCE:
>  		setbluebalance(gspca_dev);
>  		break;
> @@ -652,7 +668,7 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
>  	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
>  
>  	gspca_dev->vdev.ctrl_handler = hdl;
> -	v4l2_ctrl_handler_init(hdl, 12);
> +	v4l2_ctrl_handler_init(hdl, 13);
>  
>  	sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>  					V4L2_CID_BRIGHTNESS, 0, 32, 1, 16);
> @@ -669,6 +685,11 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
>  					PAC7302_RGB_BALANCE_MIN,
>  					PAC7302_RGB_BALANCE_MAX,
>  					1, PAC7302_RGB_BALANCE_DEFAULT);
> +	sd->green_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
> +					V4L2_CID_GREEN_BALANCE,
> +					PAC7302_RGB_BALANCE_MIN,
> +					PAC7302_RGB_BALANCE_MAX,
> +					1, PAC7302_RGB_BALANCE_DEFAULT);
>  	sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>  					V4L2_CID_BLUE_BALANCE,
>  					PAC7302_RGB_BALANCE_MIN,

Hans, it seems like you didn't pick up these patches up yet...
Is there anything wrong with them ?

Regards,
Frank



--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hans de Goede Sept. 19, 2012, 8:34 p.m. UTC | #2
Hi,

On 09/19/2012 07:25 PM, Frank Schäfer wrote:
> Am 16.09.2012 18:00, schrieb Frank Schäfer:
>> Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
>> ---
>>   drivers/media/usb/gspca/pac7302.c |   23 ++++++++++++++++++++++-
>>   1 files changed, 22 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
>> index 8a0f4d6..9b62b74 100644
>> --- a/drivers/media/usb/gspca/pac7302.c
>> +++ b/drivers/media/usb/gspca/pac7302.c
>> @@ -78,6 +78,7 @@
>>    * Page | Register   | Function
>>    * -----+------------+---------------------------------------------------
>>    *  0   | 0x01       | setredbalance()
>> + *  0   | 0x02       | setgreenbalance()
>>    *  0   | 0x03       | setbluebalance()
>>    *  0   | 0x0f..0x20 | setcolors()
>>    *  0   | 0xa2..0xab | setbrightcont()
>> @@ -121,6 +122,7 @@ struct sd {
>>   	struct v4l2_ctrl *saturation;
>>   	struct v4l2_ctrl *white_balance;
>>   	struct v4l2_ctrl *red_balance;
>> +	struct v4l2_ctrl *green_balance;
>>   	struct v4l2_ctrl *blue_balance;
>>   	struct { /* flip cluster */
>>   		struct v4l2_ctrl *hflip;
>> @@ -470,6 +472,17 @@ static void setredbalance(struct gspca_dev *gspca_dev)
>>   	reg_w(gspca_dev, 0xdc, 0x01);
>>   }
>>
>> +static void setgreenbalance(struct gspca_dev *gspca_dev)
>> +{
>> +	struct sd *sd = (struct sd *) gspca_dev;
>> +
>> +	reg_w(gspca_dev, 0xff, 0x00);			/* page 0 */
>> +	reg_w(gspca_dev, 0x02,
>> +	      rgbbalance_ctrl_to_reg_value(sd->green_balance->val));
>> +
>> +	reg_w(gspca_dev, 0xdc, 0x01);
>> +}
>> +
>>   static void setbluebalance(struct gspca_dev *gspca_dev)
>>   {
>>   	struct sd *sd = (struct sd *) gspca_dev;
>> @@ -620,6 +633,9 @@ static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
>>   	case V4L2_CID_RED_BALANCE:
>>   		setredbalance(gspca_dev);
>>   		break;
>> +	case V4L2_CID_GREEN_BALANCE:
>> +		setgreenbalance(gspca_dev);
>> +		break;
>>   	case V4L2_CID_BLUE_BALANCE:
>>   		setbluebalance(gspca_dev);
>>   		break;
>> @@ -652,7 +668,7 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
>>   	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
>>
>>   	gspca_dev->vdev.ctrl_handler = hdl;
>> -	v4l2_ctrl_handler_init(hdl, 12);
>> +	v4l2_ctrl_handler_init(hdl, 13);
>>
>>   	sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>>   					V4L2_CID_BRIGHTNESS, 0, 32, 1, 16);
>> @@ -669,6 +685,11 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
>>   					PAC7302_RGB_BALANCE_MIN,
>>   					PAC7302_RGB_BALANCE_MAX,
>>   					1, PAC7302_RGB_BALANCE_DEFAULT);
>> +	sd->green_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>> +					V4L2_CID_GREEN_BALANCE,
>> +					PAC7302_RGB_BALANCE_MIN,
>> +					PAC7302_RGB_BALANCE_MAX,
>> +					1, PAC7302_RGB_BALANCE_DEFAULT);
>>   	sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>>   					V4L2_CID_BLUE_BALANCE,
>>   					PAC7302_RGB_BALANCE_MIN,
>
> Hans, it seems like you didn't pick up these patches up yet...
> Is there anything wrong with them ?

I've somehow completely missed them. Can you resend the entire set please?

Thanks,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Frank Schäfer Sept. 19, 2012, 8:54 p.m. UTC | #3
Am 19.09.2012 22:34, schrieb Hans de Goede:
> Hi,
>
> On 09/19/2012 07:25 PM, Frank Schäfer wrote:
>> Am 16.09.2012 18:00, schrieb Frank Schäfer:
>>> Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
>>> ---
>>>   drivers/media/usb/gspca/pac7302.c |   23 ++++++++++++++++++++++-
>>>   1 files changed, 22 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/drivers/media/usb/gspca/pac7302.c
>>> b/drivers/media/usb/gspca/pac7302.c
>>> index 8a0f4d6..9b62b74 100644
>>> --- a/drivers/media/usb/gspca/pac7302.c
>>> +++ b/drivers/media/usb/gspca/pac7302.c
>>> @@ -78,6 +78,7 @@
>>>    * Page | Register   | Function
>>>    *
>>> -----+------------+---------------------------------------------------
>>>    *  0   | 0x01       | setredbalance()
>>> + *  0   | 0x02       | setgreenbalance()
>>>    *  0   | 0x03       | setbluebalance()
>>>    *  0   | 0x0f..0x20 | setcolors()
>>>    *  0   | 0xa2..0xab | setbrightcont()
>>> @@ -121,6 +122,7 @@ struct sd {
>>>       struct v4l2_ctrl *saturation;
>>>       struct v4l2_ctrl *white_balance;
>>>       struct v4l2_ctrl *red_balance;
>>> +    struct v4l2_ctrl *green_balance;
>>>       struct v4l2_ctrl *blue_balance;
>>>       struct { /* flip cluster */
>>>           struct v4l2_ctrl *hflip;
>>> @@ -470,6 +472,17 @@ static void setredbalance(struct gspca_dev
>>> *gspca_dev)
>>>       reg_w(gspca_dev, 0xdc, 0x01);
>>>   }
>>>
>>> +static void setgreenbalance(struct gspca_dev *gspca_dev)
>>> +{
>>> +    struct sd *sd = (struct sd *) gspca_dev;
>>> +
>>> +    reg_w(gspca_dev, 0xff, 0x00);            /* page 0 */
>>> +    reg_w(gspca_dev, 0x02,
>>> +          rgbbalance_ctrl_to_reg_value(sd->green_balance->val));
>>> +
>>> +    reg_w(gspca_dev, 0xdc, 0x01);
>>> +}
>>> +
>>>   static void setbluebalance(struct gspca_dev *gspca_dev)
>>>   {
>>>       struct sd *sd = (struct sd *) gspca_dev;
>>> @@ -620,6 +633,9 @@ static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
>>>       case V4L2_CID_RED_BALANCE:
>>>           setredbalance(gspca_dev);
>>>           break;
>>> +    case V4L2_CID_GREEN_BALANCE:
>>> +        setgreenbalance(gspca_dev);
>>> +        break;
>>>       case V4L2_CID_BLUE_BALANCE:
>>>           setbluebalance(gspca_dev);
>>>           break;
>>> @@ -652,7 +668,7 @@ static int sd_init_controls(struct gspca_dev
>>> *gspca_dev)
>>>       struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
>>>
>>>       gspca_dev->vdev.ctrl_handler = hdl;
>>> -    v4l2_ctrl_handler_init(hdl, 12);
>>> +    v4l2_ctrl_handler_init(hdl, 13);
>>>
>>>       sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>>>                       V4L2_CID_BRIGHTNESS, 0, 32, 1, 16);
>>> @@ -669,6 +685,11 @@ static int sd_init_controls(struct gspca_dev
>>> *gspca_dev)
>>>                       PAC7302_RGB_BALANCE_MIN,
>>>                       PAC7302_RGB_BALANCE_MAX,
>>>                       1, PAC7302_RGB_BALANCE_DEFAULT);
>>> +    sd->green_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>>> +                    V4L2_CID_GREEN_BALANCE,
>>> +                    PAC7302_RGB_BALANCE_MIN,
>>> +                    PAC7302_RGB_BALANCE_MAX,
>>> +                    1, PAC7302_RGB_BALANCE_DEFAULT);
>>>       sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
>>>                       V4L2_CID_BLUE_BALANCE,
>>>                       PAC7302_RGB_BALANCE_MIN,
>>
>> Hans, it seems like you didn't pick up these patches up yet...
>> Is there anything wrong with them ?
>
> I've somehow completely missed them. Can you resend the entire set
> please?

No problem, but I can't do that before weekend (I'm currently not at home).
I've sent these 4 patches on last Sunday (16. Sept) evening.
Maybe you can pick them up from patchwork ?
http://patchwork.linuxtv.org/patch/14433/

Regards,
Frank

>
> Thanks,
>
> Hans

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hans de Goede Sept. 20, 2012, 9:08 a.m. UTC | #4
Hi,

On 09/19/2012 10:54 PM, Frank Schäfer wrote:
> Am 19.09.2012 22:34, schrieb Hans de Goede:

<snip>

>>> Hans, it seems like you didn't pick up these patches up yet...
>>> Is there anything wrong with them ?
>>
>> I've somehow completely missed them. Can you resend the entire set
>> please?
>
> No problem, but I can't do that before weekend (I'm currently not at home).
> I've sent these 4 patches on last Sunday (16. Sept) evening.
> Maybe you can pick them up from patchwork ?
> http://patchwork.linuxtv.org/patch/14433/

Ah yes, patchwork, that will work. Unfortunately that only solves the
me having missed the patches problem.

First of all thanks for working on this! I'm afraid you've managed to find
one of the weak spots in the v4l2 API, namely how we deal with RGB gains.

Many webcams have RGB gains, but we don't have standard CID-s for these,
instead we've Blue and Red Balance. This has grown historically because of
the bttv cards which actually have Blue and Red balance controls in hardware,
rather then the usual RGB gain triplet. Various gspca drivers cope with this
in different ways.

If you look at the pac7302 driver before your latest 4 patches it has
a Red and Blue balance control controlling the Red and Blue gain, and a
Whitebalance control, which is not White balance at all, but simply
controls the green gain...

And as said other drivers have similar (albeit usually different) hacks.

At a minimum I would like you to rework your patches to:
1) Not add the new Green balance, and instead modify the existing whitebalance
to control the new green gain you've found. Keeping things as broken as
they are, but not worse; and
2) Try to use both the page 0 reg 0x01 - 0x03 and page 0 reg 0xc5 - 0xc7
at the same time to get a wider ranged control. Maybe 0xc5 - 0xc7 are
simply the most significant bits of a wider ranged gain ?
Note that if you cannot control them both from a single control in such
a way that you get a smooth control range, then lets just fix
0xc5 - 0xc7 at a value of 2 for all 3 and be done with it, but at least
we should try :)

As said the above is the minimum, what I would really like is a discussion
on linux-media about adding proper RGB gain controls for all the cameras
which have these.

Note this brings with itself the question should we export such lowlevel
controls at all ? In some drivers the per color gains are simply all
kept at the same level and controlled as part of the master gain control,
giving it a wider and/or more fine grained range, leading to better autogain
behavior. Given how our sw autowhitebalance works (and that that works
reasonable well), their is not much added value in exporting them separately,
while they do tend to improve the standard gain control when used as part
of it ...

So what we really need is a plan how to deal with these controls, and then
send an RFC for this to the list.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Frank Schäfer Sept. 20, 2012, 11:54 a.m. UTC | #5
Hi,

Am 20.09.2012 11:08, schrieb Hans de Goede:
> Hi,
>
>>>> Hans, it seems like you didn't pick up these patches up yet...
>>>> Is there anything wrong with them ?
>>>
>>> I've somehow completely missed them. Can you resend the entire set
>>> please?
>>
>> No problem, but I can't do that before weekend (I'm currently not at
>> home).
>> I've sent these 4 patches on last Sunday (16. Sept) evening.
>> Maybe you can pick them up from patchwork ?
>> http://patchwork.linuxtv.org/patch/14433/
>
> Ah yes, patchwork, that will work. Unfortunately that only solves the
> me having missed the patches problem.
>
> First of all thanks for working on this! I'm afraid you've managed to
> find
> one of the weak spots in the v4l2 API, namely how we deal with RGB gains.

It seems like this is one of my talents... :(

>
> Many webcams have RGB gains, but we don't have standard CID-s for these,
> instead we've Blue and Red Balance. This has grown historically
> because of
> the bttv cards which actually have Blue and Red balance controls in
> hardware,
> rather then the usual RGB gain triplet. Various gspca drivers cope
> with this
> in different ways.
>
> If you look at the pac7302 driver before your latest 4 patches it has
> a Red and Blue balance control controlling the Red and Blue gain, and a
> Whitebalance control, which is not White balance at all, but simply
> controls the green gain...

Ok, so if I understand you right, red+green+blue balance = white balance.
And because we already have defined red, blue and whitebalance controls
for historical reasons, we don't need green balance ?
Maybe that matches physics, but I don't think it's a sane approach for a
user interface...


>
> And as said other drivers have similar (albeit usually different) hacks.
>
> At a minimum I would like you to rework your patches to:
> 1) Not add the new Green balance, and instead modify the existing
> whitebalance
> to control the new green gain you've found. Keeping things as broken as
> they are, but not worse; and

I prefer waiting for the results of the discussion you are proposing
further down.

> 2) Try to use both the page 0 reg 0x01 - 0x03 and page 0 reg 0xc5 - 0xc7
> at the same time to get a wider ranged control. Maybe 0xc5 - 0xc7 are
> simply the most significant bits of a wider ranged gain ?

I don't think so. The windows driver does not use them.
It even doesn't use the full range of registers 0x01-0x03.
Of course, I have expermiented with the full range and it works, but it
doesn't make much sense to use it.

Experimenting with the device to determine the meaing of unknown
registerts, you will notice, that there are several registert which
affect RGB.
But that doesn't mean that they are suitable for a user control...

> Note that if you cannot control them both from a single control in such
> a way that you get a smooth control range, then lets just fix
> 0xc5 - 0xc7 at a value of 2 for all 3 and be done with it, but at least
> we should try :)

There is no need to fix registers 0xc5 and 0xc7.
The Windows driver sets them to 1, which is exactly the value we are
currently using as default value with the blue and red value controls.

>
> As said the above is the minimum, what I would really like is a
> discussion
> on linux-media about adding proper RGB gain controls for all the cameras
> which have these.
>
> Note this brings with itself the question should we export such lowlevel
> controls at all ? In some drivers the per color gains are simply all
> kept at the same level and controlled as part of the master gain control,
> giving it a wider and/or more fine grained range, leading to better
> autogain
> behavior. Given how our sw autowhitebalance works (and that that works
> reasonable well), their is not much added value in exporting them
> separately,
> while they do tend to improve the standard gain control when used as part
> of it ...

I would say, let the drivers decide how to do things. It also depends on
the hardware design.

Regards,
Frank

>
> So what we really need is a plan how to deal with these controls, and
> then
> send an RFC for this to the list.
>
> Regards,
>
> Hans

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Frank Schäfer Sept. 23, 2012, 1:27 p.m. UTC | #6
Hi,

Am 20.09.2012 13:54, schrieb Frank Schäfer:
> Hi,
>
> Am 20.09.2012 11:08, schrieb Hans de Goede:
>> Hi,
>>
>>>>> Hans, it seems like you didn't pick up these patches up yet...
>>>>> Is there anything wrong with them ?
>>>> I've somehow completely missed them. Can you resend the entire set
>>>> please?
>>> No problem, but I can't do that before weekend (I'm currently not at
>>> home).
>>> I've sent these 4 patches on last Sunday (16. Sept) evening.
>>> Maybe you can pick them up from patchwork ?
>>> http://patchwork.linuxtv.org/patch/14433/
>> Ah yes, patchwork, that will work. Unfortunately that only solves the
>> me having missed the patches problem.
>>
>> First of all thanks for working on this! I'm afraid you've managed to
>> find
>> one of the weak spots in the v4l2 API, namely how we deal with RGB gains.
> It seems like this is one of my talents... :(
>
>> Many webcams have RGB gains, but we don't have standard CID-s for these,
>> instead we've Blue and Red Balance. This has grown historically
>> because of
>> the bttv cards which actually have Blue and Red balance controls in
>> hardware,
>> rather then the usual RGB gain triplet. Various gspca drivers cope
>> with this
>> in different ways.
>>
>> If you look at the pac7302 driver before your latest 4 patches it has
>> a Red and Blue balance control controlling the Red and Blue gain, and a
>> Whitebalance control, which is not White balance at all, but simply
>> controls the green gain...
> Ok, so if I understand you right, red+green+blue balance = white balance.
> And because we already have defined red, blue and whitebalance controls
> for historical reasons, we don't need green balance ?
> Maybe that matches physics, but I don't think it's a sane approach for a
> user interface...
>
>
>> And as said other drivers have similar (albeit usually different) hacks.
>>
>> At a minimum I would like you to rework your patches to:
>> 1) Not add the new Green balance, and instead modify the existing
>> whitebalance
>> to control the new green gain you've found. Keeping things as broken as
>> they are, but not worse; and
> I prefer waiting for the results of the discussion you are proposing
> further down.
>
>> 2) Try to use both the page 0 reg 0x01 - 0x03 and page 0 reg 0xc5 - 0xc7
>> at the same time to get a wider ranged control. Maybe 0xc5 - 0xc7 are
>> simply the most significant bits of a wider ranged gain ?
> I don't think so. The windows driver does not use them.
> It even doesn't use the full range of registers 0x01-0x03.
> Of course, I have expermiented with the full range and it works, but it
> doesn't make much sense to use it.
>
> Experimenting with the device to determine the meaing of unknown
> registerts, you will notice, that there are several registert which
> affect RGB.
> But that doesn't mean that they are suitable for a user control...
>
>> Note that if you cannot control them both from a single control in such
>> a way that you get a smooth control range, then lets just fix
>> 0xc5 - 0xc7 at a value of 2 for all 3 and be done with it, but at least
>> we should try :)
> There is no need to fix registers 0xc5 and 0xc7.
> The Windows driver sets them to 1, which is exactly the value we are
> currently using as default value with the blue and red value controls.
>
>> As said the above is the minimum, what I would really like is a
>> discussion
>> on linux-media about adding proper RGB gain controls for all the cameras
>> which have these.
>>
>> Note this brings with itself the question should we export such lowlevel
>> controls at all ? In some drivers the per color gains are simply all
>> kept at the same level and controlled as part of the master gain control,
>> giving it a wider and/or more fine grained range, leading to better
>> autogain
>> behavior. Given how our sw autowhitebalance works (and that that works
>> reasonable well), their is not much added value in exporting them
>> separately,
>> while they do tend to improve the standard gain control when used as part
>> of it ...
> I would say, let the drivers decide how to do things. It also depends on
> the hardware design.
>
> Regards,
> Frank
>
>> So what we really need is a plan how to deal with these controls, and
>> then
>> send an RFC for this to the list.
>>
>> Regards,
>>
>> Hans
>>

Hans, I don't have the bandwidth to go through a long discussion in
which probably nobody is really interested.
So please just drop the last two patches which are related to the
V4L2_CID_GREEN_BALANCE issue.
I documented the registers and behavior of the Windows driver, so if you
one day come to the conclusion that such a control would be usefull, it
can be added easily at any time later.

But I would really like to see the first two patches getting applied for
3.7.
The first one is a documentation fix, the second one clearly improves
the behavior of the red and blue balance control (as explained above).
I will resend both patches.


Regards,
Frank
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hans de Goede Sept. 24, 2012, 10:47 a.m. UTC | #7
Hi,

Sorry for the slow response ...

On 09/20/2012 01:54 PM, Frank Schäfer wrote:
> Hi,
>
> Am 20.09.2012 11:08, schrieb Hans de Goede:

<snip>

>> Many webcams have RGB gains, but we don't have standard CID-s for these,
>> instead we've Blue and Red Balance. This has grown historically
>> because of
>> the bttv cards which actually have Blue and Red balance controls in
>> hardware,
>> rather then the usual RGB gain triplet. Various gspca drivers cope
>> with this
>> in different ways.
>>
>> If you look at the pac7302 driver before your latest 4 patches it has
>> a Red and Blue balance control controlling the Red and Blue gain, and a
>> Whitebalance control, which is not White balance at all, but simply
>> controls the green gain...
>
> Ok, so if I understand you right, red+green+blue balance = white balance.
> And because we already have defined red, blue and whitebalance controls
> for historical reasons, we don't need green balance ?
> Maybe that matches physics, but I don't think it's a sane approach for a
> user interface...

No what I was trying to say is that the balance controls are for hardware
which actually has balance controls and not per color gains (such as the
bt87x chips), but they are being abused by many drivers to add support for
per color gains. And then you miss one control. And in the case of the pac7302
driver the "original" route was taken of using whitebalance to control
the green gain. Which is wrong IMHO, but it is what the driver does know.

A proper fix would be to introduce new controls for all 3 gains, and use
those instead of using the balance controls + adding a 3th balance control
being discussed in the thread titled:
"Gain controls in v4l2-ctrl framework".

>> And as said other drivers have similar (albeit usually different) hacks.
>>
>> At a minimum I would like you to rework your patches to:
>> 1) Not add the new Green balance, and instead modify the existing
>> whitebalance
>> to control the new green gain you've found. Keeping things as broken as
>> they are, but not worse; and
>
> I prefer waiting for the results of the discussion you are proposing
> further down.
>

I see in your next mail that you've changed your mind. So I would like to
move forward with this by adding your 2 patches + 1 more patch to also
make the whitebalance control (which really is the green gain control)
use 0x02 rather then 0xc6. To do this we must make sure that 0xc6 has
a proper fixed / default setting. So what does the windows driver use
for this? 1 like with 0xc5 and 0xc7 ?

And can you do a 3th patch to make the whitebalance control control
0x02 rather then 0xc6 like you did for red and blue balance?

Then later on when the "Gain controls in v4l2-ctrl framework" discussion
is done we can change these controls to the new controls.

>> 2) Try to use both the page 0 reg 0x01 - 0x03 and page 0 reg 0xc5 - 0xc7
>> at the same time to get a wider ranged control. Maybe 0xc5 - 0xc7 are
>> simply the most significant bits of a wider ranged gain ?
>
> I don't think so. The windows driver does not use them.
> It even doesn't use the full range of registers 0x01-0x03.
> Of course, I have expermiented with the full range and it works, but it
> doesn't make much sense to use it.
>

Ok.


Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Frank Schäfer Sept. 24, 2012, 1:36 p.m. UTC | #8
Hi Hans,

Am 24.09.2012 12:47, schrieb Hans de Goede:
> Hi,
>
> Sorry for the slow response ...
>
> On 09/20/2012 01:54 PM, Frank Schäfer wrote:
>> Hi,
>>
>> Am 20.09.2012 11:08, schrieb Hans de Goede:
>
> <snip>
>
>>> Many webcams have RGB gains, but we don't have standard CID-s for
>>> these,
>>> instead we've Blue and Red Balance. This has grown historically
>>> because of
>>> the bttv cards which actually have Blue and Red balance controls in
>>> hardware,
>>> rather then the usual RGB gain triplet. Various gspca drivers cope
>>> with this
>>> in different ways.
>>>
>>> If you look at the pac7302 driver before your latest 4 patches it has
>>> a Red and Blue balance control controlling the Red and Blue gain, and a
>>> Whitebalance control, which is not White balance at all, but simply
>>> controls the green gain...
>>
>> Ok, so if I understand you right, red+green+blue balance = white
>> balance.
>> And because we already have defined red, blue and whitebalance controls
>> for historical reasons, we don't need green balance ?
>> Maybe that matches physics, but I don't think it's a sane approach for a
>> user interface...
>
> No what I was trying to say is that the balance controls are for hardware
> which actually has balance controls and not per color gains (such as the
> bt87x chips), but they are being abused by many drivers to add support
> for
> per color gains. And then you miss one control. And in the case of the
> pac7302
> driver the "original" route was taken of using whitebalance to control
> the green gain. Which is wrong IMHO, but it is what the driver does know.
>
> A proper fix would be to introduce new controls for all 3 gains, and use
> those instead of using the balance controls + adding a 3th balance
> control
> being discussed in the thread titled:
> "Gain controls in v4l2-ctrl framework".

Ok, it seems I'm misunderstanding the meaning of color "gain" and
"balance"...

Anyway, I would say that it makes sense to have per color AND global
controls, so a V4L2_CID_GREEN_BALANCE would be missing.
Weather it makes sense to use them at the same time is a different question.

And why do you think the controls in question are gain controls instead
of balance controls ?
The Windows driver calls them balance controls, too (which could of
course also be a Windows driver or API issue...).


>
>>> And as said other drivers have similar (albeit usually different)
>>> hacks.
>>>
>>> At a minimum I would like you to rework your patches to:
>>> 1) Not add the new Green balance, and instead modify the existing
>>> whitebalance
>>> to control the new green gain you've found. Keeping things as broken as
>>> they are, but not worse; and
>>
>> I prefer waiting for the results of the discussion you are proposing
>> further down.
>>
>
> I see in your next mail that you've changed your mind. So I would like to
> move forward with this by adding your 2 patches + 1 more patch to also
> make the whitebalance control (which really is the green gain control)
> use 0x02 rather then 0xc6. To do this we must make sure that 0xc6 has
> a proper fixed / default setting. So what does the windows driver use
> for this? 1 like with 0xc5 and 0xc7 ?
>
> And can you do a 3th patch to make the whitebalance control control
> 0x02 rather then 0xc6 like you did for red and blue balance?

No, we shouldn't do that.
Reg 0xc6 (currently called "white balance temperature") definitely works
different compared to register 0x02.
Whatever it does exactly, it's not green gain or balance adjustment.
Will try to figure out next time.
The Windows driver doesn't use this register for an (user settable)
image control. It just sets its value to 55, which I fixed with one of
the patches from my previous patch series, so we have the correct
default value now.
0xc6 is also different from regs 0xc5 and 0xc7: settable values are
0-255 compared to 0-3.

So let's not touch 0xc6 / "white balance" until we know its real meaning
and just apply the first 2 patches.

Regards,
Frank


>
> Then later on when the "Gain controls in v4l2-ctrl framework" discussion
> is done we can change these controls to the new controls.
>
>>> 2) Try to use both the page 0 reg 0x01 - 0x03 and page 0 reg 0xc5 -
>>> 0xc7
>>> at the same time to get a wider ranged control. Maybe 0xc5 - 0xc7 are
>>> simply the most significant bits of a wider ranged gain ?
>>
>> I don't think so. The windows driver does not use them.
>> It even doesn't use the full range of registers 0x01-0x03.
>> Of course, I have expermiented with the full range and it works, but it
>> doesn't make much sense to use it.
>>
>
> Ok.
>
>
> Regards,
>
> Hans

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hans de Goede Sept. 24, 2012, 2:07 p.m. UTC | #9
Hi,

On 09/24/2012 03:36 PM, Frank Schäfer wrote:
> Hi Hans,
>
> Am 24.09.2012 12:47, schrieb Hans de Goede:
>> Hi,
>>
>> Sorry for the slow response ...
>>
>> On 09/20/2012 01:54 PM, Frank Schäfer wrote:
>>> Hi,
>>>
>>> Am 20.09.2012 11:08, schrieb Hans de Goede:
>>
>> <snip>
>>
>>>> Many webcams have RGB gains, but we don't have standard CID-s for
>>>> these,
>>>> instead we've Blue and Red Balance. This has grown historically
>>>> because of
>>>> the bttv cards which actually have Blue and Red balance controls in
>>>> hardware,
>>>> rather then the usual RGB gain triplet. Various gspca drivers cope
>>>> with this
>>>> in different ways.
>>>>
>>>> If you look at the pac7302 driver before your latest 4 patches it has
>>>> a Red and Blue balance control controlling the Red and Blue gain, and a
>>>> Whitebalance control, which is not White balance at all, but simply
>>>> controls the green gain...
>>>
>>> Ok, so if I understand you right, red+green+blue balance = white
>>> balance.
>>> And because we already have defined red, blue and whitebalance controls
>>> for historical reasons, we don't need green balance ?
>>> Maybe that matches physics, but I don't think it's a sane approach for a
>>> user interface...
>>
>> No what I was trying to say is that the balance controls are for hardware
>> which actually has balance controls and not per color gains (such as the
>> bt87x chips), but they are being abused by many drivers to add support
>> for
>> per color gains. And then you miss one control. And in the case of the
>> pac7302
>> driver the "original" route was taken of using whitebalance to control
>> the green gain. Which is wrong IMHO, but it is what the driver does know.
>>
>> A proper fix would be to introduce new controls for all 3 gains, and use
>> those instead of using the balance controls + adding a 3th balance
>> control
>> being discussed in the thread titled:
>> "Gain controls in v4l2-ctrl framework".
>
> Ok, it seems I'm misunderstanding the meaning of color "gain" and
> "balance"...
>
> Anyway, I would say that it makes sense to have per color AND global
> controls, so a V4L2_CID_GREEN_BALANCE would be missing.
> Weather it makes sense to use them at the same time is a different question.
>
> And why do you think the controls in question are gain controls instead
> of balance controls ?

"Balance" suggest balancing it against some fixed value, where as once
there are 3 for all of r, g and b, there is no fixed value, then the registers
are just controlling an amplification factor (which could be less then 1.0)
and that is normally called a gain.

If you look in most sensor datasheets they talk about color gains not
balance controls ...

Anyways this is mostly just semantics. We are working on defining standard
controls for per color gains, and once we have those we can map them to
reg 0x01 - 0x03.

> The Windows driver calls them balance controls, too (which could of
> course also be a Windows driver or API issue...).
>
>
>>
>>>> And as said other drivers have similar (albeit usually different)
>>>> hacks.
>>>>
>>>> At a minimum I would like you to rework your patches to:
>>>> 1) Not add the new Green balance, and instead modify the existing
>>>> whitebalance
>>>> to control the new green gain you've found. Keeping things as broken as
>>>> they are, but not worse; and
>>>
>>> I prefer waiting for the results of the discussion you are proposing
>>> further down.
>>>
>>
>> I see in your next mail that you've changed your mind. So I would like to
>> move forward with this by adding your 2 patches + 1 more patch to also
>> make the whitebalance control (which really is the green gain control)
>> use 0x02 rather then 0xc6. To do this we must make sure that 0xc6 has
>> a proper fixed / default setting. So what does the windows driver use
>> for this? 1 like with 0xc5 and 0xc7 ?
>>
>> And can you do a 3th patch to make the whitebalance control control
>> 0x02 rather then 0xc6 like you did for red and blue balance?
>
> No, we shouldn't do that.
> Reg 0xc6 (currently called "white balance temperature") definitely works
> different compared to register 0x02.
> Whatever it does exactly, it's not green gain or balance adjustment.
> Will try to figure out next time.
> The Windows driver doesn't use this register for an (user settable)
> image control. It just sets its value to 55, which I fixed with one of
> the patches from my previous patch series, so we have the correct
> default value now.

Ah, interesting!

> 0xc6 is also different from regs 0xc5 and 0xc7: settable values are
> 0-255 compared to 0-3.

True, I should have noticed that.

> So let's not touch 0xc6 / "white balance" until we know its real meaning
> and just apply the first 2 patches.

OK, will do.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index 8a0f4d6..9b62b74 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -78,6 +78,7 @@ 
  * Page | Register   | Function
  * -----+------------+---------------------------------------------------
  *  0   | 0x01       | setredbalance()
+ *  0   | 0x02       | setgreenbalance()
  *  0   | 0x03       | setbluebalance()
  *  0   | 0x0f..0x20 | setcolors()
  *  0   | 0xa2..0xab | setbrightcont()
@@ -121,6 +122,7 @@  struct sd {
 	struct v4l2_ctrl *saturation;
 	struct v4l2_ctrl *white_balance;
 	struct v4l2_ctrl *red_balance;
+	struct v4l2_ctrl *green_balance;
 	struct v4l2_ctrl *blue_balance;
 	struct { /* flip cluster */
 		struct v4l2_ctrl *hflip;
@@ -470,6 +472,17 @@  static void setredbalance(struct gspca_dev *gspca_dev)
 	reg_w(gspca_dev, 0xdc, 0x01);
 }
 
+static void setgreenbalance(struct gspca_dev *gspca_dev)
+{
+	struct sd *sd = (struct sd *) gspca_dev;
+
+	reg_w(gspca_dev, 0xff, 0x00);			/* page 0 */
+	reg_w(gspca_dev, 0x02,
+	      rgbbalance_ctrl_to_reg_value(sd->green_balance->val));
+
+	reg_w(gspca_dev, 0xdc, 0x01);
+}
+
 static void setbluebalance(struct gspca_dev *gspca_dev)
 {
 	struct sd *sd = (struct sd *) gspca_dev;
@@ -620,6 +633,9 @@  static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
 	case V4L2_CID_RED_BALANCE:
 		setredbalance(gspca_dev);
 		break;
+	case V4L2_CID_GREEN_BALANCE:
+		setgreenbalance(gspca_dev);
+		break;
 	case V4L2_CID_BLUE_BALANCE:
 		setbluebalance(gspca_dev);
 		break;
@@ -652,7 +668,7 @@  static int sd_init_controls(struct gspca_dev *gspca_dev)
 	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
 
 	gspca_dev->vdev.ctrl_handler = hdl;
-	v4l2_ctrl_handler_init(hdl, 12);
+	v4l2_ctrl_handler_init(hdl, 13);
 
 	sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 					V4L2_CID_BRIGHTNESS, 0, 32, 1, 16);
@@ -669,6 +685,11 @@  static int sd_init_controls(struct gspca_dev *gspca_dev)
 					PAC7302_RGB_BALANCE_MIN,
 					PAC7302_RGB_BALANCE_MAX,
 					1, PAC7302_RGB_BALANCE_DEFAULT);
+	sd->green_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
+					V4L2_CID_GREEN_BALANCE,
+					PAC7302_RGB_BALANCE_MIN,
+					PAC7302_RGB_BALANCE_MAX,
+					1, PAC7302_RGB_BALANCE_DEFAULT);
 	sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 					V4L2_CID_BLUE_BALANCE,
 					PAC7302_RGB_BALANCE_MIN,