This source file includes following definitions.
- live_histogram_read_y
- live_histogram_get_range
- shooting_calc_autoiso_coef
- shooting_recalc_conf_autoiso_values
- shooting_set_autoiso
1 #include "camera_info.h"
2 #include "math.h"
3 #include "conf.h"
4 #include "viewport.h"
5 #include "shooting.h"
6 #include "modes.h"
7 #include "lens.h"
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #ifdef THUMB_FW
25
26 #define HISTO_STEP_SIZE 48
27 #else
28
29 #define HISTO_STEP_SIZE 36
30 #endif
31
32
33
34
35
36 int live_histogram_read_y(unsigned short *h)
37 {
38 #ifdef THUMB_FW
39 int vp_width = vid_get_viewport_width_proper() * 2;
40 #else
41 int vp_width = vid_get_viewport_width_proper() * 6 / 4;
42 #endif
43
44 int yscale = vid_get_viewport_yscale();
45 int vp_height_full = vid_get_viewport_height_proper();
46
47 if(vp_height_full > 480) {
48
49 yscale = vp_height_full/240;
50 }
51
52 int vp_height = vp_height_full / yscale;
53
54
55 int total = ((vp_width + HISTO_STEP_SIZE/2)/HISTO_STEP_SIZE) * vp_height;
56
57 memset(h, 0, sizeof(unsigned short)*256);
58
59 unsigned char *img = vid_get_viewport_active_buffer();
60 if (img)
61 {
62 int vp_offset = vid_get_viewport_byte_width() * yscale;
63 img += vid_get_viewport_image_offset() + 1;
64
65 int x, y;
66 for (y=0; y<vp_height; y+=1, img+=vp_offset)
67 {
68 for (x=HISTO_STEP_SIZE/2; x<vp_width; x+=HISTO_STEP_SIZE)
69 {
70 h[img[x]] += 1;
71
72 }
73 }
74 } else {
75
76
77 h[0] = total;
78 }
79
80 return total;
81 }
82
83 static int live_histogram_get_range(unsigned short *histo, int total,int from, int to)
84 {
85 if (from < 0) from = 0;
86 if (to > 255) to = 255;
87
88 int rv = 0;
89 for(; from<=to; from++)
90 rv += histo[from];
91
92 return (rv * 100) / total;
93 }
94
95
96
97 static const int shutter1_values[] = { 0, 2, 4, 6, 8, 15, 30, 60, 125, 250, 500, 1000, 2000 };
98 static const int shutter2_values[] = { 0, 1, 2, 4, 6, 8, 12, 15, 20, 25, 30, 40, 50, 60, 80, 100, 125, 160, 200, 250, 500, 1000, 2000 };
99
100 static void shooting_calc_autoiso_coef( int min_shutter )
101 {
102 if (shutter2_values[conf.autoiso2_shutter_enum] >= min_shutter)
103 {
104 conf.autoiso2_coef = 0.0;
105 }
106 else
107 {
108 conf.autoiso2_coef = (float)(conf.autoiso2_max_iso_auto_real - conf.autoiso_max_iso_auto_real) /
109 (float)( shutter2_values[conf.autoiso2_shutter_enum] - min_shutter);
110 }
111 }
112
113 static void shooting_recalc_conf_autoiso_values()
114 {
115
116 conf.autoiso_max_iso_hi_real = shooting_iso_market_to_real(conf.autoiso_max_iso_hi) ;
117 conf.autoiso_max_iso_auto_real = shooting_iso_market_to_real(conf.autoiso_max_iso_auto) ;
118 conf.autoiso_min_iso_real = shooting_iso_market_to_real(conf.autoiso_min_iso) ;
119 conf.autoiso2_max_iso_auto_real = shooting_iso_market_to_real(conf.autoiso2_max_iso_auto) ;
120
121
122
123
124 if ( !shutter2_values[conf.autoiso2_shutter_enum] )
125 conf.autoiso2_max_iso_auto_real = conf.autoiso_max_iso_auto_real;
126
127
128 shooting_calc_autoiso_coef( shutter1_values[conf.autoiso_shutter_enum] );
129 }
130
131 void shooting_set_autoiso(int iso_mode)
132 {
133 short max_iso;
134
135 if (iso_mode<=0)
136 shooting_recalc_conf_autoiso_values();
137
138 switch (iso_mode)
139 {
140 case -1:
141
142 max_iso = conf.autoiso_max_iso_hi_real;
143 break;
144 case 0:
145
146 max_iso = conf.autoiso_max_iso_auto_real;
147 break;
148 default:
149 return;
150 }
151
152
153 if (camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_TV || camera_info.state.mode_shooting==MODE_STITCH)
154 return;
155
156 int ev_overexp = 0;
157 if (conf.overexp_ev_enum)
158 {
159 unsigned short *histo = malloc(256*sizeof(unsigned short));
160 if(histo) {
161
162 int total = live_histogram_read_y(histo);
163
164
165 if (live_histogram_get_range(histo,total,255-conf.autoiso2_over,255) >= conf.overexp_threshold)
166 ev_overexp = conf.overexp_ev_enum << 5;
167 free(histo);
168 }
169 }
170
171 float current_shutter = shooting_get_shutter_speed_from_tv96(shooting_get_tv96());
172
173 short current_iso = shooting_get_iso_real();
174
175 short min_shutter = shutter1_values[conf.autoiso_shutter_enum];
176 if (min_shutter == 0)
177 {
178 short IS_factor = (shooting_get_is_mode()<=1)?conf.autoiso_is_factor:1;
179 min_shutter = get_focal_length(lens_get_zoom_point())*conf.autoiso_user_factor / (IS_factor*1000);
180
181 if (shutter2_values[conf.autoiso2_shutter_enum])
182 shooting_calc_autoiso_coef( min_shutter );
183 }
184
185 short target_iso = current_iso * min_shutter * current_shutter;
186 short min_iso = conf.autoiso_min_iso_real;
187
188 if (target_iso > max_iso)
189 {
190 ev_overexp=0;
191
192
193
194
195
196 if ( !iso_mode && conf.autoiso2_coef < 0.0 )
197 {
198 target_iso = (max_iso - min_shutter*conf.autoiso2_coef) / ( 1.0 - conf.autoiso2_coef / (current_shutter * current_iso) );
199 if ( target_iso > conf.autoiso2_max_iso_auto_real )
200 target_iso = conf.autoiso2_max_iso_auto_real;
201 }
202 else
203 {
204 target_iso = max_iso;
205 }
206 }
207 else if (target_iso < min_iso)
208 {
209 target_iso = min_iso;
210 }
211
212 float target_shutter = current_shutter * current_iso / target_iso;
213
214 if (target_shutter > 0)
215 shooting_set_tv96_direct(shooting_get_tv96_from_shutter_speed(target_shutter) + ev_overexp, SET_NOW);
216
217 shooting_set_iso_real(target_iso, SET_NOW);
218 }
219
220