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