It seems I have found the option just on time ;) Here is the patch, after creating it I downloaded again the source to see if it works, so I hope there will be no problems. The stile part was really the hardest ;) Thank you very much for the help, hope I was not a pain in the neck with all the questions
Best regards Stefan Krastanov 2009/3/8 GWater <[email protected]> > Am Sonntag 08 März 2009 17:19:00 schrieb Stefan Krastanov: > > OK, all done except the stile problem - I get this: > > > > Must be run from the top-level dir. of a kernel tree > > > > And the script is in here /usr/src/linux-headers-2.6.27-13/scripts/ - > > that's the kernel I am running at the moment (Ubuntu 8.10) > > > > I tried a few combinations of directories, but it's not working, what > > should I do. > > > > 2009/3/8 Brian Johnson <[email protected]> > > > > > Also works fine for me as well. Besides the style issues Vasily > > > mentioned I also pushed the small patch i posted yesterday as well so > > > you'll want to get the current HEAD and redo your patch agaaints that > > > so it applies cleanly > > > > > > On Sun, Mar 8, 2009 at 11:45 AM, Vasily Khoruzhick <[email protected] > > > > > > > > wrote: > > > > On Sunday 08 March 2009 17:22:25 Stefan Krastanov wrote: > > > >> It worked, sorry for the delay. > > > >> > > > >> stable_yavg interval is changed to smaller one. > > > >> the fix about how long should be the exposure field(the one you gave > > > >> me yesterday) is included > > > >> the function is commented - I hope it would be useful. > > > >> > > > >> Regards > > > >> Stefan Krastanov > > > > > > > > Works fine for me, but your patch has some style problems. Please > check > > > > > > it > > > > > > > with /usr/src/linux/scripts/checkpatch.pl patch_name, fix style > > > > problems > > > > > > and > > > > > > > resend it again. > > > > > > > > Thank you :) > > > > > > > > Regards > > > > Vasily > > > > > > SImple: > use the "--no-tree" option. > > GWater > --~--~---------~--~----~------------~-------~--~----~ Lets make microdia webcams plug'n play, (currently plug'n pray) To post to this group, send email to [email protected] Visit us online https://groups.google.com/group/microdia -~----------~----~----~----~------~----~------~--~---
From e4651219ed860f1d60176504fb9c7b71465db348 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov <[email protected]> Date: Sun, 8 Mar 2009 17:44:53 +0100 Subject: [PATCH] new software AE function to address problems with exposure oscillations on mt9v011 Signed-off-by: Stefan Krastanov <[email protected]> --- sn9c20x-dev.c | 107 ++++++++++++++++++++------------------------------------ sn9c20x.h | 3 +- 2 files changed, 40 insertions(+), 70 deletions(-) diff --git a/sn9c20x-dev.c b/sn9c20x-dev.c index e99b463..1b56033 100644 --- a/sn9c20x-dev.c +++ b/sn9c20x-dev.c @@ -112,11 +112,11 @@ int sn9c20x_initialize_sensor(struct usb_sn9c20x *dev) int ret = 0; int i; - dev->camera.min_yavg = 60; - dev->camera.max_yavg = 150; - dev->camera.min_stable_yavg = 70; - dev->camera.max_stable_yavg = 140; - dev->camera.old_yavg = -1; + dev->camera.min_yavg = 80; + dev->camera.max_yavg = 130; + dev->camera.old_step = 0; + dev->camera.older_step = 0; + dev->camera.exposure_step = 16; /* Probe sensor first if sensor set to probe*/ if (dev->camera.sensor == PROBE_SENSOR) { @@ -181,7 +181,6 @@ int sn9c20x_initialize_sensor(struct usb_sn9c20x *dev) dev->camera.set_hvflip = mt9v111_set_hvflip; dev->camera.set_exposure = mt9v111_set_exposure; dev->camera.set_auto_exposure = mt9v111_set_autoexposure; - dev->camera.set_auto_whitebalance = mt9v111_set_autowhitebalance; dev->camera.hstart = 2; dev->camera.vstart = 2; UDIA_INFO("Detected MT9V111 Sensor.\n"); @@ -293,14 +292,12 @@ int dev_sn9c20x_button_detection(struct usb_sn9c20x *dev) * * @returns 0 or negative error value * - * @author Vasily Khoruzhick + * @author Stefan Krastanov */ int dev_sn9c20x_perform_soft_ae(struct usb_sn9c20x *dev) { - int yavg; - int koef = 100, new_exp, i; + int yavg, new_exp; yavg = -1; - i = 10; if (!dev->camera.set_exposure) return -1; @@ -312,79 +309,51 @@ int dev_sn9c20x_perform_soft_ae(struct usb_sn9c20x *dev) return -1; } - /* Image is too dark */ + /* image too dark */ if (yavg < dev->camera.min_yavg) { - /* yavg can't be 0 - in that way new_exp == infinity */ - if (yavg == 0) - yavg = 1; - if (dev->camera.old_yavg != -1) { - /* Previous correction was made to make image darker, - * but we made it too dark. Calculating our error - * and taking it into account. - * Usually error is 0.7 - 2, so we multiply it by 100 - */ - if (dev->camera.old_yavg > dev->camera.max_yavg) - koef = 100 * dev->camera. - min_stable_yavg / yavg; - else - koef = 100; - } - - /* Calculating new exposure value. We assuming that - * exposure linearly depends on YAVG, but we taking - * our calculated error into account */ - new_exp = (dev->camera.min_stable_yavg - * dev->vsettings.exposure * 100) / (yavg * koef); - - /* Exposure can't be more than 0xff or less than 0x1 */ + /*change exposure just a bit*/ + new_exp = dev->vsettings.exposure+dev->camera.exposure_step; if (new_exp > 0xff) new_exp = 0xff; if (new_exp < 0x1) new_exp = 1; - - dev->camera.old_yavg = yavg; - - /* Applying new exposure */ + /*set it*/ dev->vsettings.exposure = new_exp; dev->camera.set_exposure(dev); - } - - /* Image is too bright */ - else if (yavg > dev->camera.max_yavg) { - /* yavg can't be 0 - in that way new_exp == infinity */ - if (yavg == 0) - yavg = 1; - if (dev->camera.old_yavg != -1) { + /*note the direction of the change*/ + dev->camera.older_step = dev->camera.old_step; + dev->camera.old_step = 1;/*it's going up*/ - /* Previous correction was made to make image brighter, - * but we made it too bright. Calculating our error - * and taking it into account. - * Usually error is 0.7 - 2, so we multiply it by 100 - */ - if (dev->camera.old_yavg < dev->camera.min_yavg) - koef = 100 * yavg / dev->camera. - max_stable_yavg; - else - koef = 100; - } - - /* Calculating new exposure value. We assuming that - * exposure linearly depends on YAVG, but we taking - * our calculated error into account */ - new_exp = (koef * dev->camera.max_stable_yavg - * dev->vsettings.exposure) / (yavg * 100); - - /* Exposure can't be more than 0xff or less than 0x1 */ + /*check if it's oscillating and take smaller step if it is*/ + if (dev->camera.old_step ^ dev->camera.older_step) + dev->camera.exposure_step /= 2; + /* oscilating - divide the step by 2 */ + else + dev->camera.exposure_step += 2; + /* same direction - step must be bigger */ + } + /*image too light*/ + if (yavg > dev->camera.max_yavg) { + /*change exposure just a bit*/ + new_exp = dev->vsettings.exposure-dev->camera.exposure_step; if (new_exp > 0xff) new_exp = 0xff; if (new_exp < 0x1) new_exp = 1; - - dev->camera.old_yavg = yavg; - - /* Applying new exposure */ + /*set it*/ dev->vsettings.exposure = new_exp; dev->camera.set_exposure(dev); + /*note the direction of the change*/ + dev->camera.older_step = dev->camera.old_step; + dev->camera.old_step = 0;/*it's going down*/ + + /*check if it's oscillating and take smaller step if it is*/ + if (dev->camera.old_step ^ dev->camera.older_step) + dev->camera.exposure_step /= 2; + /* oscilating - divide the step by 2 */ + else + dev->camera.exposure_step += 2; + /* same direction - step must be bigger */ } return 0; diff --git a/sn9c20x.h b/sn9c20x.h index 27bab4a..630e507 100644 --- a/sn9c20x.h +++ b/sn9c20x.h @@ -306,7 +306,8 @@ struct sn9c20x_camera { __u8 i2c_flags; __u8 address; - int min_yavg, max_yavg, min_stable_yavg, max_stable_yavg, old_yavg; + int min_yavg, max_yavg, old_step, older_step; + unsigned int exposure_step; atomic_t yavg; -- 1.5.6.3
