aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/gspca/gspca.c89
-rw-r--r--drivers/media/video/gspca/gspca.h2
2 files changed, 0 insertions, 91 deletions
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index 38b124ec23a3..2b393b2cf62d 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -2435,95 +2435,6 @@ int gspca_resume(struct usb_interface *intf)
2435} 2435}
2436EXPORT_SYMBOL(gspca_resume); 2436EXPORT_SYMBOL(gspca_resume);
2437#endif 2437#endif
2438/* -- cam driver utility functions -- */
2439
2440/* auto gain and exposure algorithm based on the knee algorithm described here:
2441 http://ytse.tricolour.net/docs/LowLightOptimization.html
2442
2443 Returns 0 if no changes were made, 1 if the gain and or exposure settings
2444 where changed. */
2445int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
2446 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee)
2447{
2448 int i, steps, gain, orig_gain, exposure, orig_exposure, autogain;
2449 const struct ctrl *gain_ctrl = NULL;
2450 const struct ctrl *exposure_ctrl = NULL;
2451 const struct ctrl *autogain_ctrl = NULL;
2452 int retval = 0;
2453
2454 for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) {
2455 if (gspca_dev->ctrl_dis & (1 << i))
2456 continue;
2457 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN)
2458 gain_ctrl = &gspca_dev->sd_desc->ctrls[i];
2459 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE)
2460 exposure_ctrl = &gspca_dev->sd_desc->ctrls[i];
2461 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_AUTOGAIN)
2462 autogain_ctrl = &gspca_dev->sd_desc->ctrls[i];
2463 }
2464 if (!gain_ctrl || !exposure_ctrl || !autogain_ctrl) {
2465 PDEBUG(D_ERR, "Error: gspca_auto_gain_n_exposure called "
2466 "on cam without (auto)gain/exposure");
2467 return 0;
2468 }
2469
2470 if (gain_ctrl->get(gspca_dev, &gain) ||
2471 exposure_ctrl->get(gspca_dev, &exposure) ||
2472 autogain_ctrl->get(gspca_dev, &autogain) || !autogain)
2473 return 0;
2474
2475 orig_gain = gain;
2476 orig_exposure = exposure;
2477
2478 /* If we are of a multiple of deadzone, do multiple steps to reach the
2479 desired lumination fast (with the risc of a slight overshoot) */
2480 steps = abs(desired_avg_lum - avg_lum) / deadzone;
2481
2482 PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d",
2483 avg_lum, desired_avg_lum, steps);
2484
2485 for (i = 0; i < steps; i++) {
2486 if (avg_lum > desired_avg_lum) {
2487 if (gain > gain_knee)
2488 gain--;
2489 else if (exposure > exposure_knee)
2490 exposure--;
2491 else if (gain > gain_ctrl->qctrl.default_value)
2492 gain--;
2493 else if (exposure > exposure_ctrl->qctrl.minimum)
2494 exposure--;
2495 else if (gain > gain_ctrl->qctrl.minimum)
2496 gain--;
2497 else
2498 break;
2499 } else {
2500 if (gain < gain_ctrl->qctrl.default_value)
2501 gain++;
2502 else if (exposure < exposure_knee)
2503 exposure++;
2504 else if (gain < gain_knee)
2505 gain++;
2506 else if (exposure < exposure_ctrl->qctrl.maximum)
2507 exposure++;
2508 else if (gain < gain_ctrl->qctrl.maximum)
2509 gain++;
2510 else
2511 break;
2512 }
2513 }
2514
2515 if (gain != orig_gain) {
2516 gain_ctrl->set(gspca_dev, gain);
2517 retval = 1;
2518 }
2519 if (exposure != orig_exposure) {
2520 exposure_ctrl->set(gspca_dev, exposure);
2521 retval = 1;
2522 }
2523
2524 return retval;
2525}
2526EXPORT_SYMBOL(gspca_auto_gain_n_exposure);
2527 2438
2528/* -- module insert / remove -- */ 2439/* -- module insert / remove -- */
2529static int __init gspca_init(void) 2440static int __init gspca_init(void)
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index dd15e07d4666..dc688c7f5e48 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -251,8 +251,6 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
251int gspca_suspend(struct usb_interface *intf, pm_message_t message); 251int gspca_suspend(struct usb_interface *intf, pm_message_t message);
252int gspca_resume(struct usb_interface *intf); 252int gspca_resume(struct usb_interface *intf);
253#endif 253#endif
254int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
255 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
256int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum, 254int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
257 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee); 255 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
258int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev, 256int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,