This source file includes following definitions.
- gspca_expo_autogain
- gspca_coarse_grained_expo_autogain
1
2
3
4
5
6
7 #include "gspca.h"
8
9
10
11
12
13
14 int gspca_expo_autogain(
15 struct gspca_dev *gspca_dev,
16 int avg_lum,
17 int desired_avg_lum,
18 int deadzone,
19 int gain_knee,
20 int exposure_knee)
21 {
22 s32 gain, orig_gain, exposure, orig_exposure;
23 int i, steps, retval = 0;
24
25 if (v4l2_ctrl_g_ctrl(gspca_dev->autogain) == 0)
26 return 0;
27
28 orig_gain = gain = v4l2_ctrl_g_ctrl(gspca_dev->gain);
29 orig_exposure = exposure = v4l2_ctrl_g_ctrl(gspca_dev->exposure);
30
31
32
33 steps = abs(desired_avg_lum - avg_lum) / deadzone;
34
35 gspca_dbg(gspca_dev, D_FRAM, "autogain: lum: %d, desired: %d, steps: %d\n",
36 avg_lum, desired_avg_lum, steps);
37
38 for (i = 0; i < steps; i++) {
39 if (avg_lum > desired_avg_lum) {
40 if (gain > gain_knee)
41 gain--;
42 else if (exposure > exposure_knee)
43 exposure--;
44 else if (gain > gspca_dev->gain->default_value)
45 gain--;
46 else if (exposure > gspca_dev->exposure->minimum)
47 exposure--;
48 else if (gain > gspca_dev->gain->minimum)
49 gain--;
50 else
51 break;
52 } else {
53 if (gain < gspca_dev->gain->default_value)
54 gain++;
55 else if (exposure < exposure_knee)
56 exposure++;
57 else if (gain < gain_knee)
58 gain++;
59 else if (exposure < gspca_dev->exposure->maximum)
60 exposure++;
61 else if (gain < gspca_dev->gain->maximum)
62 gain++;
63 else
64 break;
65 }
66 }
67
68 if (gain != orig_gain) {
69 v4l2_ctrl_s_ctrl(gspca_dev->gain, gain);
70 retval = 1;
71 }
72 if (exposure != orig_exposure) {
73 v4l2_ctrl_s_ctrl(gspca_dev->exposure, exposure);
74 retval = 1;
75 }
76
77 if (retval)
78 gspca_dbg(gspca_dev, D_FRAM, "autogain: changed gain: %d, expo: %d\n",
79 gain, exposure);
80 return retval;
81 }
82 EXPORT_SYMBOL(gspca_expo_autogain);
83
84
85
86
87
88
89
90
91
92
93
94
95
96 int gspca_coarse_grained_expo_autogain(
97 struct gspca_dev *gspca_dev,
98 int avg_lum,
99 int desired_avg_lum,
100 int deadzone)
101 {
102 s32 gain_low, gain_high, gain, orig_gain, exposure, orig_exposure;
103 int steps, retval = 0;
104
105 if (v4l2_ctrl_g_ctrl(gspca_dev->autogain) == 0)
106 return 0;
107
108 orig_gain = gain = v4l2_ctrl_g_ctrl(gspca_dev->gain);
109 orig_exposure = exposure = v4l2_ctrl_g_ctrl(gspca_dev->exposure);
110
111 gain_low = (s32)(gspca_dev->gain->maximum - gspca_dev->gain->minimum) /
112 5 * 2 + gspca_dev->gain->minimum;
113 gain_high = (s32)(gspca_dev->gain->maximum - gspca_dev->gain->minimum) /
114 5 * 4 + gspca_dev->gain->minimum;
115
116
117
118 steps = (desired_avg_lum - avg_lum) / deadzone;
119
120 gspca_dbg(gspca_dev, D_FRAM, "autogain: lum: %d, desired: %d, steps: %d\n",
121 avg_lum, desired_avg_lum, steps);
122
123 if ((gain + steps) > gain_high &&
124 exposure < gspca_dev->exposure->maximum) {
125 gain = gain_high;
126 gspca_dev->exp_too_low_cnt++;
127 gspca_dev->exp_too_high_cnt = 0;
128 } else if ((gain + steps) < gain_low &&
129 exposure > gspca_dev->exposure->minimum) {
130 gain = gain_low;
131 gspca_dev->exp_too_high_cnt++;
132 gspca_dev->exp_too_low_cnt = 0;
133 } else {
134 gain += steps;
135 if (gain > gspca_dev->gain->maximum)
136 gain = gspca_dev->gain->maximum;
137 else if (gain < gspca_dev->gain->minimum)
138 gain = gspca_dev->gain->minimum;
139 gspca_dev->exp_too_high_cnt = 0;
140 gspca_dev->exp_too_low_cnt = 0;
141 }
142
143 if (gspca_dev->exp_too_high_cnt > 3) {
144 exposure--;
145 gspca_dev->exp_too_high_cnt = 0;
146 } else if (gspca_dev->exp_too_low_cnt > 3) {
147 exposure++;
148 gspca_dev->exp_too_low_cnt = 0;
149 }
150
151 if (gain != orig_gain) {
152 v4l2_ctrl_s_ctrl(gspca_dev->gain, gain);
153 retval = 1;
154 }
155 if (exposure != orig_exposure) {
156 v4l2_ctrl_s_ctrl(gspca_dev->exposure, exposure);
157 retval = 1;
158 }
159
160 if (retval)
161 gspca_dbg(gspca_dev, D_FRAM, "autogain: changed gain: %d, expo: %d\n",
162 gain, exposure);
163 return retval;
164 }
165 EXPORT_SYMBOL(gspca_coarse_grained_expo_autogain);