This source file includes following definitions.
- shooting_update_state
- shooting_get_prop
- shooting_get_prop_int
- shooting_set_prop
- shooting_get_is_mode
- shooting_get_bv96
- shooting_get_canon_overexposure_value
- shooting_get_flash_mode
- shooting_get_focus_mode
- shooting_get_ev_correction1
- shooting_get_ev_correction2
- shooting_get_resolution
- shooting_get_display_mode
- shooting_get_exif_subject_dist
- shooting_is_flash
- shooting_in_progress
- shooting_get_canon_image_format
- shooting_set_canon_image_format
- shooting_get_imager_active
- shooting_get_analog_video_standard
- shooting_get_digital_zoom_mode
- shooting_get_digital_zoom_state
- shooting_get_real_focus_mode
- shooting_get_focus_state
- shooting_get_focus_ok
- shooting_get_drive_mode
- shooting_get_zoom
- shooting_get_canon_iso_mode
- shooting_get_sv96_market
- shooting_get_sv96_real
- shooting_get_sv96_delta
- shooting_get_sv96_from_iso
- shooting_get_iso_from_sv96
- shooting_iso_market_to_real
- shooting_iso_real_to_market
- shooting_sv96_market_to_real
- shooting_sv96_real_to_market
- shooting_get_iso_override_value
- shooting_get_iso_mode
- shooting_get_iso_real
- shooting_get_iso_market
- set_iso_mode
- shooting_set_iso_mode
- shooting_set_sv96
- shooting_set_iso_real
- iso_init
- shooting_get_tv96
- shooting_get_tv96_from_shutter_speed
- shooting_get_shutter_speed_from_tv96
- shooting_get_tv96_override_value
- find_nearest_shutter_speed_entry
- find_canon_shutter_speed
- shooting_set_tv96_direct
- shooting_set_tv96
- shooting_get_user_tv96
- shooting_get_user_tv_id
- shooting_set_user_tv_by_id
- shooting_set_user_tv_by_id_rel
- shooting_set_user_tv96
- shooting_get_tv_str
- shooting_get_av96
- shooting_get_aperture_sizes_table_size
- shooting_get_aperture_from_av96
- shooting_get_av96_from_aperture
- shooting_get_av96_override_value
- shooting_get_real_aperture
- shooting_get_min_real_aperture
- find_nearest_aperture_entry
- find_canon_aperture
- shooting_set_av96_direct
- shooting_set_av96
- shooting_get_user_av96
- shooting_get_user_av_id
- shooting_set_user_av_by_id
- shooting_set_user_av_by_id_rel
- shooting_set_user_av96
- shooting_get_av_str
- shooting_set_nd_filter_state
- shooting_get_min_av96
- shooting_get_max_av96
- shooting_init
- get_file_counter
- get_exposure_counter
- get_file_counter
- get_exposure_counter
- get_target_dir_name
- shooting_get_luminance
- shooting_get_subject_distance_override_value
- shooting_mode_canon2chdk
- shooting_mode_chdk2canon
- sd_over_modes
- shooting_get_lens_to_focal_plane_width
- shooting_get_hyperfocal_distance_1e3_f
- shooting_get_near_limit_f
- shooting_get_far_limit_f
- shooting_is_infinity_distance
- shooting_get_canon_subject_distance
- shooting_get_subject_distance_
- shooting_update_dof_values
- shooting_get_subject_distance
- shooting_get_hyperfocal_distance
- shooting_can_focus
- shooting_get_common_focus_mode
- shooting_is_flash_ready
- shooting_set_image_quality
- shooting_set_zoom
- shooting_set_zoom_rel
- shooting_set_zoom_speed
- shooting_set_zoom
- shooting_set_zoom_rel
- shooting_set_zoom_speed
- set_focus_bypass
- shooting_set_focus
- shooting_video_bitrate_change
- shooting_video_minbitrate_change
- shooting_get_video_recorded_size_kb
- shooting_set_flash_sync_curtain
- unlock_optical_zoom
- shooting_set_mode_canon
- shooting_set_mode_chdk
- shooting_tv_bracketing
- shooting_av_bracketing
- shooting_iso_bracketing
- shooting_subject_distance_bracketing
- bracketing_reset
- bracketing_step
- shooting_bracketing
- captseq_hack_override_active
- set_movie_status
- get_movie_status
- is_video_recording
- mode_is_video
- rec_mode_active
- mode_get
- get_ev_video_avail
- get_ev_video
- set_ev_video_avail
- set_ev_video
- shooting_set_flash_override
- shooting_expo_param_override_thumb
- shooting_expo_iso_override_thumb
- shooting_set_playrec_mode
1 #include "platform.h"
2 #include "keyboard.h"
3 #include "math.h"
4 #include "conf.h"
5 #include "histogram.h"
6 #include "usb_remote.h"
7 #include "autoiso.h"
8 #include "levent.h"
9 #include "script_api.h"
10
11
12
13
14
15
16
17
18
19
20 int rec_mode_active(void);
21
22
23
24 extern volatile long focus_busy;
25 extern long playrec_mode;
26
27
28 extern const ShutterSpeed shutter_speeds_table[];
29 extern const unsigned int SS_SIZE;
30 extern const ApertureSize aperture_sizes_table[];
31 extern const unsigned int AS_SIZE;
32 extern const CapturemodeMap modemap[];
33 extern const unsigned int MODESCNT;
34
35 static short *min_av96_zoom_point_tbl = NULL;
36
37
38 #define PHOTO_PARAM_TV_NONE 32767
39
40 typedef struct {
41 int subj_dist;
42 short av96;
43 short tv96;
44 short sv96;
45 short nd_filter;
46 } PHOTO_PARAM;
47
48 static PHOTO_PARAM photo_param_put_off;
49
50
51
52 static int iso_override_mode_save = 0;
53
54
55
56
57
58 static const double inv_log_2 = 1.44269504088906;
59
60
61
62 #ifdef OPT_VIEWPORT_DEBUG
63 char avb_history[32];
64 unsigned char avb_times[32];
65 static unsigned avb_hp = 0;
66 static long avb_pts = 0;
67 static char avb_pv = 0;
68 #endif
69
70
71 void shooting_update_state(void)
72 {
73
74
75
76
77 if (iso_override_mode_save && !shooting_in_progress()) {
78 shooting_set_iso_mode(iso_override_mode_save);
79 iso_override_mode_save = 0;
80 }
81
82 #ifdef OPT_VIEWPORT_DEBUG
83 extern volatile char active_viewport_buffer;
84 long avb_ts;
85 char avb_v;
86 avb_ts = get_tick_count();
87 avb_v = active_viewport_buffer;
88 if (avb_v != avb_pv) {
89 avb_history[avb_hp] = avb_v;
90 avb_times[avb_hp] = avb_ts - avb_pts;
91 avb_hp = (avb_hp+1) & 31;
92 avb_pts = avb_ts;
93 avb_pv = avb_v;
94 }
95 #endif
96
97 }
98
99
100
101
102 int shooting_get_prop(int id)
103 {
104 short vv;
105 get_property_case(id, &vv, sizeof(vv));
106 return vv;
107 }
108
109 static int shooting_get_prop_int(int id)
110 {
111 int vv;
112 get_property_case(id, &vv, sizeof(vv));
113 return vv;
114 }
115
116 void shooting_set_prop(int id, int v)
117 {
118 short vv = v;
119 set_property_case(id, &vv, sizeof(vv));
120 return;
121 }
122
123 short shooting_get_is_mode() { return shooting_get_prop(PROPCASE_IS_MODE); }
124 short shooting_get_bv96() { return shooting_get_prop(PROPCASE_BV); }
125 short shooting_get_canon_overexposure_value() { return shooting_get_prop(PROPCASE_OVEREXPOSURE); }
126 short shooting_get_flash_mode() { return shooting_get_prop(PROPCASE_FLASH_MODE); }
127 short shooting_get_focus_mode() { return shooting_get_prop(PROPCASE_FOCUS_MODE); }
128 short shooting_get_ev_correction1() { return shooting_get_prop(PROPCASE_EV_CORRECTION_1); }
129 short shooting_get_ev_correction2() { return shooting_get_prop(PROPCASE_EV_CORRECTION_2); }
130 short shooting_get_resolution() { return shooting_get_prop(PROPCASE_RESOLUTION); }
131 short shooting_get_display_mode() { return shooting_get_prop(PROPCASE_DISPLAY_MODE); }
132
133 int shooting_get_exif_subject_dist() { return shooting_get_prop_int(PROPCASE_SUBJECT_DIST1); }
134 int shooting_is_flash() { return shooting_get_prop_int(PROPCASE_IS_FLASH_READY); }
135 int shooting_in_progress() { return shooting_get_prop_int(PROPCASE_SHOOTING); }
136
137
138 int shooting_get_canon_image_format() {
139 #ifdef CAM_HAS_CANON_RAW
140 #ifdef PROPCASE_IMAGE_FORMAT
141 switch(shooting_get_prop(PROPCASE_IMAGE_FORMAT)) {
142 case 0:
143 return SHOOTING_CANON_FMT_RAW;
144 case 2:
145 return (SHOOTING_CANON_FMT_RAW | SHOOTING_CANON_FMT_JPG);
146 default:
147 return SHOOTING_CANON_FMT_JPG;
148 }
149 #else
150 if(shooting_get_prop(PROPCASE_RESOLUTION) == 5) {
151 if(shooting_get_prop(PROPCASE_JPEG_WITH_RAW) == 1) {
152 return (SHOOTING_CANON_FMT_RAW | SHOOTING_CANON_FMT_JPG);
153 }
154 return SHOOTING_CANON_FMT_RAW;
155 } else {
156 return SHOOTING_CANON_FMT_JPG;
157 }
158 #endif
159 #else
160 return SHOOTING_CANON_FMT_JPG;
161 #endif
162 }
163
164
165 int shooting_set_canon_image_format(int fmt) {
166 #ifdef CAM_HAS_CANON_RAW
167 #ifdef PROPCASE_IMAGE_FORMAT
168 int v;
169 switch(fmt) {
170 case SHOOTING_CANON_FMT_RAW:
171 v = 0;
172 break;
173 case (SHOOTING_CANON_FMT_RAW | SHOOTING_CANON_FMT_JPG):
174 v = 2;
175 break;
176 case SHOOTING_CANON_FMT_JPG:
177 v = 1;
178 break;
179 default:
180 return 0;
181 }
182 shooting_set_prop(PROPCASE_IMAGE_FORMAT,v);
183 return 1;
184 #else
185
186 static int saved_resolution = -1;
187
188
189 if(fmt < 1 || fmt > 3) {
190 return 0;
191 }
192 if(fmt & SHOOTING_CANON_FMT_RAW) {
193 int res = shooting_get_prop(PROPCASE_RESOLUTION);
194 if( res != 5) {
195 saved_resolution = res;
196 shooting_set_prop(PROPCASE_RESOLUTION,5);
197 }
198 if(fmt & SHOOTING_CANON_FMT_JPG) {
199 shooting_set_prop(PROPCASE_JPEG_WITH_RAW,1);
200 } else {
201 shooting_set_prop(PROPCASE_JPEG_WITH_RAW,0);
202 }
203 } else {
204 if(shooting_get_prop(PROPCASE_RESOLUTION) == 5) {
205 if(saved_resolution != -1) {
206 shooting_set_prop(PROPCASE_RESOLUTION,saved_resolution);
207 saved_resolution = -1;
208 } else {
209 shooting_set_prop(PROPCASE_RESOLUTION,0);
210 }
211 }
212 }
213 return 1;
214 #endif
215 #else
216 return fmt == SHOOTING_CANON_FMT_JPG;
217 #endif
218 }
219
220
221 int shooting_get_imager_active() {
222 extern int imager_active;
223 return imager_active;
224 }
225
226
227
228
229
230
231
232 int shooting_get_analog_video_standard(void)
233 {
234 #ifdef PROPCASE_LANGUAGE
235 int v=shooting_get_prop(PROPCASE_LANGUAGE);
236
237 v = (v&1) + 1;
238 return v;
239 #else
240 return 1;
241 #endif
242 }
243
244
245
246
247 #if CAM_PROPSET > 1
248 int shooting_get_digital_zoom_mode(void)
249 {
250 int x=shooting_get_prop(PROPCASE_DIGITAL_ZOOM_MODE);
251 #if CAM_PROPSET == 7 || CAM_PROPSET == 9 || CAM_PROPSET == 10|| CAM_PROPSET == 11 || CAM_PROPSET == 12 || CAM_PROPSET == 13
252 if(x==1) {
253 return 0;
254 }
255 #endif
256 return x;
257 }
258 #endif
259
260 int shooting_get_digital_zoom_state(void)
261 {
262 #if CAM_PROPSET == 7 || CAM_PROPSET == 9 || CAM_PROPSET == 10 || CAM_PROPSET == 11 || CAM_PROPSET == 12 || CAM_PROPSET == 13
263
264 int x=shooting_get_prop(PROPCASE_DIGITAL_ZOOM_MODE);
265 if(x==1) {
266 return 1;
267 }
268 return 0;
269 #else
270 return shooting_get_prop(PROPCASE_DIGITAL_ZOOM_STATE);
271 #endif
272 }
273
274
275
276
277
278
279
280
281 short shooting_get_real_focus_mode()
282 {
283 short f = shooting_get_focus_mode();
284 short m = shooting_get_prop(PROPCASE_REAL_FOCUS_MODE);
285 if (f==0 && m!=0) f=(m==1)?4:m;
286 return f;
287 }
288
289 short shooting_get_focus_state()
290 {
291 if (shooting_get_focus_mode()==1) return -1;
292 int m = shooting_get_prop_int(PROPCASE_FOCUS_STATE);
293 return (short) m;
294 }
295
296 short shooting_get_focus_ok()
297 {
298 return ((shooting_get_focus_state()!=0) && shooting_in_progress());
299 }
300
301 short shooting_get_drive_mode()
302 {
303
304
305 #if defined (CAM_DRIVE_MODE_FROM_TIMER_MODE)
306 short m = shooting_get_prop(PROPCASE_TIMER_MODE);
307
308
309
310 if (m == 3)
311 return m;
312 #endif
313
314 return shooting_get_prop(PROPCASE_DRIVE_MODE);
315 }
316
317 int shooting_get_zoom()
318 {
319 return lens_get_zoom_point();
320 }
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378 extern const ISOTable iso_table[];
379 extern const unsigned int ISO_SIZE;
380
381 short shooting_get_canon_iso_mode() { return shooting_get_prop(PROPCASE_ISO_MODE); }
382 short shooting_get_sv96_market() { return shooting_get_prop(PROPCASE_SV_MARKET); }
383 short shooting_get_sv96_real() { return shooting_get_prop(PROPCASE_SV); }
384 short shooting_get_sv96_delta() { return shooting_get_prop(PROPCASE_DELTA_SV); }
385
386
387 static short canon_iso_base=0;
388 static short canon_sv96_base=0;
389
390 #if !defined(SV96_MARKET_OFFSET)
391
392 #define SV96_MARKET_OFFSET 69
393
394
395
396
397 #define ISO_MARKET_TO_REAL_MULT 9955
398 #define ISO_MARKET_TO_REAL_SHIFT 14
399 #define ISO_MARKET_TO_REAL_ROUND 8192
400 #define ISO_REAL_TO_MARKET_MULT 3371
401 #define ISO_REAL_TO_MARKET_SHIFT 11
402 #define ISO_REAL_TO_MARKET_ROUND 1024
403 #endif
404
405 #define ISO_MARKET_TO_REAL(x) (((int)x * ISO_MARKET_TO_REAL_MULT + ISO_MARKET_TO_REAL_ROUND) >> ISO_MARKET_TO_REAL_SHIFT)
406 #define ISO_REAL_TO_MARKET(x) (((int)x * ISO_REAL_TO_MARKET_MULT + ISO_REAL_TO_MARKET_ROUND) >> ISO_REAL_TO_MARKET_SHIFT)
407
408 short shooting_get_sv96_from_iso(short iso)
409 {
410
411 if (iso > 0)
412 return (short)( log((double)(iso)*32.0/100.0)*96.0*(inv_log_2)+0.5 );
413 return 0;
414 }
415
416 short shooting_get_iso_from_sv96(short sv96)
417 {
418
419 return (short)( (double)pow(2, (((double)sv96)/96.0))*100.0/32.0 + 0.5 );
420 }
421
422 short shooting_iso_market_to_real(short isom)
423 {
424 return ISO_MARKET_TO_REAL(isom);
425 }
426
427 short shooting_iso_real_to_market(short isor)
428 {
429 return ISO_REAL_TO_MARKET(isor);
430 }
431
432 short shooting_sv96_market_to_real(short sv96)
433 {
434 return sv96 - SV96_MARKET_OFFSET;
435 }
436
437 short shooting_sv96_real_to_market(short sv96)
438 {
439 return sv96 + SV96_MARKET_OFFSET;
440 }
441
442 short shooting_get_iso_override_value()
443 {
444 short iso = conf.iso_override_value;
445
446 #ifdef CAM_ISO_LIMIT_IN_HQ_BURST
447
448 if (camera_info.state.mode_shooting == MODE_HIGHSPEED_BURST)
449 if (iso > CAM_ISO_LIMIT_IN_HQ_BURST) iso = CAM_ISO_LIMIT_IN_HQ_BURST;
450 #endif
451 #ifdef CAM_MIN_ISO_OVERRIDE
452
453
454 if ((iso > 0) && (iso < CAM_MIN_ISO_OVERRIDE)) iso = CAM_MIN_ISO_OVERRIDE;
455 #endif
456 #ifdef CAM_MAX_ISO_OVERRIDE
457
458
459 if (iso > CAM_MAX_ISO_OVERRIDE) iso = CAM_MAX_ISO_OVERRIDE;
460 #endif
461 return shooting_iso_market_to_real(iso);
462 }
463
464 int shooting_get_iso_mode()
465 {
466 short isov = shooting_get_canon_iso_mode();
467 unsigned i;
468 for (i=0;i<ISO_SIZE;i++)
469 {
470 if (iso_table[i].prop_id == isov)
471 return iso_table[i].id;
472 }
473 return 0;
474 }
475
476 short shooting_get_iso_real()
477 {
478 short sv = shooting_get_sv96_real();
479 if (sv == 0)
480 return 0;
481 return shooting_get_iso_from_sv96(sv);
482 }
483
484
485 short shooting_get_iso_market()
486 {
487 short sv = shooting_get_sv96_market() + shooting_get_sv96_delta();
488 if (sv == 0)
489 return 0;
490 return shooting_get_iso_from_sv96(sv);
491 }
492
493 static void set_iso_mode(int i)
494 {
495 short vv = iso_table[i].prop_id;
496 set_property_case(PROPCASE_ISO_MODE, &vv, sizeof(vv));
497 }
498
499 void shooting_set_iso_mode(int v)
500 {
501 unsigned i;
502 if (v < 50)
503 {
504 for (i=0; i<ISO_SIZE; i++)
505 {
506 if (iso_table[i].id == v)
507 {
508 set_iso_mode(i);
509 return;
510 }
511 }
512 }
513 else
514 {
515 if (v <= iso_table[0].prop_id)
516 {
517 set_iso_mode(0);
518 return;
519 }
520 for (i=0; i<ISO_SIZE-1; i++)
521 {
522 if ((v > iso_table[i].prop_id) && (v <= iso_table[i+1].prop_id))
523 {
524 if ((v - iso_table[i].prop_id) < (iso_table[i+1].prop_id - v))
525 set_iso_mode(i);
526 else
527 set_iso_mode(i+1);
528 return;
529 }
530 }
531 set_iso_mode(ISO_SIZE-1);
532 }
533 }
534
535 void shooting_set_sv96(short sv96, short is_now)
536 {
537 if (!camera_info.state.mode_play)
538 {
539 if (is_now)
540 {
541 while ((shooting_is_flash_ready()!=1) || (focus_busy)) msleep(10);
542
543 short iso_mode = shooting_get_canon_iso_mode();
544 if (iso_mode >= 50) {
545
546
547 iso_override_mode_save = iso_mode;
548 shooting_set_iso_mode(0);
549 }
550
551 short dsv96 = sv96 + SV96_MARKET_OFFSET - canon_sv96_base;
552
553 set_property_case(PROPCASE_SV_MARKET, &canon_sv96_base, sizeof(canon_sv96_base));
554 set_property_case(PROPCASE_SV, &sv96, sizeof(sv96));
555 set_property_case(PROPCASE_DELTA_SV, &dsv96, sizeof(dsv96));
556 }
557 else
558 photo_param_put_off.sv96 = sv96;
559 }
560 }
561
562 void shooting_set_iso_real(short iso, short is_now)
563 {
564 if (!camera_info.state.mode_play)
565 {
566 if (iso > 0)
567 {
568 #ifdef CAM_ISO_LIMIT_IN_HQ_BURST
569
570 if (camera_info.state.mode_shooting == MODE_HIGHSPEED_BURST)
571 if (iso > ISO_MARKET_TO_REAL(CAM_ISO_LIMIT_IN_HQ_BURST)) iso = ISO_MARKET_TO_REAL(CAM_ISO_LIMIT_IN_HQ_BURST);
572 #endif
573 #ifdef CAM_MIN_ISO_OVERRIDE
574
575 if ((iso > 0) && (iso < ISO_MARKET_TO_REAL(CAM_MIN_ISO_OVERRIDE))) iso = ISO_MARKET_TO_REAL(CAM_MIN_ISO_OVERRIDE);
576 #endif
577 #ifdef CAM_MAX_ISO_OVERRIDE
578
579 if (iso > ISO_MARKET_TO_REAL(CAM_MAX_ISO_OVERRIDE)) iso = ISO_MARKET_TO_REAL(CAM_MAX_ISO_OVERRIDE);
580 #endif
581 shooting_set_sv96(shooting_get_sv96_from_iso(iso), is_now);
582 }
583 }
584 }
585
586 static void iso_init()
587 {
588
589 if (iso_table[1-iso_table[0].id].prop_id == 50)
590 canon_iso_base = 50;
591 else
592 canon_iso_base = CAM_MARKET_ISO_BASE;
593
594
595
596 canon_sv96_base = shooting_get_sv96_from_iso(canon_iso_base);
597 }
598
599
600
601
602
603
604
605
606 short shooting_get_tv96() { return shooting_get_prop(PROPCASE_TV); }
607
608
609
610 short shooting_get_tv96_from_shutter_speed(float t)
611 {
612 if (t > 0)
613 {
614 t = ((96.0 * -log(t)) * inv_log_2);
615 if (t < 0)
616 return (short)(t - 0.5);
617 return (short)(t + 0.5);
618 }
619 return SHOOTING_TV96_INVALID;
620 }
621
622 float shooting_get_shutter_speed_from_tv96(short tv96)
623 {
624 return pow(2,((float)(-tv96))/96.0);
625 }
626
627
628 #if CAM_EXT_TV_RANGE
629 #define tv_override_zero_shift (18+15)
630 #else
631 #define tv_override_zero_shift 18
632 #endif
633
634
635 static int shooting_get_tv96_override_value()
636 {
637
638 if (conf.tv_enum_type==TV_OVERRIDE_EV_STEP)
639 return 32*(conf.tv_override_value-tv_override_zero_shift);
640 else if (conf.tv_enum_type==TV_OVERRIDE_SHORT_EXP)
641 return shooting_get_tv96_from_shutter_speed(((float)conf.tv_override_short_exp)/100000.0);
642 else
643 return shooting_get_tv96_from_shutter_speed((float)conf.tv_override_long_exp);
644 }
645
646
647
648
649 static int find_nearest_shutter_speed_entry(short tv96)
650 {
651 if (tv96 <= shutter_speeds_table[0].prop_id)
652 return 0;
653
654 unsigned i;
655 for (i=0; i<SS_SIZE-1; i++)
656 {
657 if ((tv96 > shutter_speeds_table[i].prop_id) && (tv96 <= shutter_speeds_table[i+1].prop_id))
658 {
659 if ((tv96 - shutter_speeds_table[i].prop_id) < (shutter_speeds_table[i+1].prop_id - tv96))
660 return i;
661 else
662 return i+1;
663 }
664 }
665
666 return SS_SIZE-1;
667 }
668
669
670 static short find_canon_shutter_speed(short tv96)
671 {
672 return shutter_speeds_table[find_nearest_shutter_speed_entry(tv96)].prop_id;
673 }
674
675 void shooting_set_tv96_direct(short tv96, short is_now)
676 {
677 if (!camera_info.state.mode_play)
678 {
679 if(is_now)
680 {
681 set_property_case(PROPCASE_TV, &tv96, sizeof(tv96));
682 #ifdef PROPCASE_TV2
683 set_property_case(PROPCASE_TV2, &tv96, sizeof(tv96));
684 #endif
685 }
686 else
687 photo_param_put_off.tv96 = tv96;
688 }
689 }
690
691 void shooting_set_tv96(short tv96, short is_now)
692 {
693 if (!camera_info.state.mode_play)
694 shooting_set_tv96_direct(find_canon_shutter_speed(tv96), is_now);
695 }
696
697
698
699 short shooting_get_user_tv96()
700 {
701 #if CAM_HAS_USER_TV_MODES
702 return shooting_get_prop(PROPCASE_USER_TV);
703 #else
704 return 0;
705 #endif
706 }
707
708 int shooting_get_user_tv_id()
709 {
710 #if CAM_HAS_USER_TV_MODES
711 return shutter_speeds_table[find_nearest_shutter_speed_entry(shooting_get_user_tv96())].id;
712 #else
713 return 0;
714 #endif
715 }
716
717 void shooting_set_user_tv_by_id(int v)
718 {
719 #if CAM_HAS_USER_TV_MODES
720 if (!camera_info.state.mode_play)
721 {
722 unsigned i;
723 for (i=0;i<SS_SIZE;i++)
724 {
725 if (shutter_speeds_table[i].id == v)
726 {
727 short vv = shutter_speeds_table[i].prop_id;
728 set_property_case(PROPCASE_USER_TV, &vv, sizeof(vv));
729 return;
730 }
731 }
732 }
733 #else
734 (void)v;
735 #endif
736 }
737
738 void shooting_set_user_tv_by_id_rel(int v)
739 {
740 #if CAM_HAS_USER_TV_MODES
741 if (!camera_info.state.mode_play)
742 {
743 int cv = shooting_get_user_tv_id();
744 shooting_set_user_tv_by_id(cv+v);
745 }
746 #else
747 (void)v;
748 #endif
749 }
750
751 void shooting_set_user_tv96(short tv96)
752 {
753 #if CAM_HAS_USER_TV_MODES
754 if (!camera_info.state.mode_play)
755 {
756 tv96 = find_canon_shutter_speed(tv96);
757 set_property_case(PROPCASE_USER_TV, &tv96, sizeof(tv96));
758 }
759 #else
760 (void)tv96;
761 #endif
762 }
763
764
765 #if CAM_DRAW_EXPOSITION
766
767 char* shooting_get_tv_str()
768 {
769 return (char*)shutter_speeds_table[find_nearest_shutter_speed_entry(shooting_get_tv96())].name;
770 }
771 #endif
772
773
774
775
776
777
778
779
780
781 #define AV96_MIN (aperture_sizes_table[0].prop_id)
782 #define AV96_MAX (aperture_sizes_table[AS_SIZE-1].prop_id)
783
784 short shooting_get_av96() { return shooting_get_prop(PROPCASE_AV); }
785 short shooting_get_aperture_sizes_table_size() { return AS_SIZE; }
786
787
788
789 int shooting_get_aperture_from_av96(short av96)
790 {
791 if (av96)
792 return (short)((pow(2, ((double)av96)/192.0))*1000.0 + 0.5);
793 return -1;
794 }
795
796 short shooting_get_av96_from_aperture(int aperture)
797 {
798 return (int)((log((double)aperture/1000.0) * 192 * inv_log_2) + 0.5);
799 }
800
801
802 short shooting_get_av96_override_value()
803 {
804 if (conf.av_override_value<(int)AS_SIZE)
805 return (short) aperture_sizes_table[conf.av_override_value].prop_id;
806 return (short) (AV96_MAX+32*(conf.av_override_value-AS_SIZE+1));
807 }
808
809 int shooting_get_real_aperture()
810 {
811 return shooting_get_aperture_from_av96(shooting_get_current_av96());
812 }
813
814 static int shooting_get_min_real_aperture()
815 {
816 short av96;
817 get_property_case(PROPCASE_MIN_AV, &av96, sizeof(av96));
818 if (av96)
819 return shooting_get_aperture_from_av96(av96);
820 return shooting_get_real_aperture();
821 }
822
823
824
825
826 #if (CAM_HAS_IRIS_DIAPHRAGM || CAM_DRAW_EXPOSITION)
827 static int find_nearest_aperture_entry(short av96)
828 {
829 if (av96 <= aperture_sizes_table[0].prop_id)
830 return 0;
831
832 unsigned i;
833 for (i=0; i<AS_SIZE-1; i++)
834 {
835 if ((av96 > aperture_sizes_table[i].prop_id) && (av96 <= aperture_sizes_table[i+1].prop_id))
836 {
837 if ((av96 - aperture_sizes_table[i].prop_id) < (aperture_sizes_table[i+1].prop_id - av96))
838 return i;
839 else
840 return i+1;
841 }
842 }
843
844 return AS_SIZE-1;
845 }
846 #endif
847
848
849 #if CAM_HAS_IRIS_DIAPHRAGM
850 short find_canon_aperture(short av96)
851 {
852 return aperture_sizes_table[find_nearest_aperture_entry(av96)].prop_id;
853 }
854 #endif
855
856 void shooting_set_av96_direct(short av96, short is_now)
857 {
858 #if CAM_HAS_IRIS_DIAPHRAGM
859 if (!camera_info.state.mode_play)
860 {
861 if(is_now)
862 {
863 set_property_case(PROPCASE_AV, &av96, sizeof(av96));
864 #ifdef PROPCASE_AV2
865 set_property_case(PROPCASE_AV2, &av96, sizeof(av96));
866 #endif
867 }
868 else
869 photo_param_put_off.av96 = av96;
870 }
871 #else
872 (void)av96; (void)is_now;
873 #endif
874 }
875
876 void shooting_set_av96(short av96, short is_now)
877 {
878 #if CAM_HAS_IRIS_DIAPHRAGM
879 if (!camera_info.state.mode_play)
880 shooting_set_av96_direct(find_canon_aperture(av96), is_now);
881 #else
882 (void)av96; (void)is_now;
883 #endif
884 }
885
886
887
888 short shooting_get_user_av96()
889 {
890 #if CAM_HAS_IRIS_DIAPHRAGM
891 return shooting_get_prop(PROPCASE_USER_AV);
892 #else
893 return 0;
894 #endif
895 }
896
897 int shooting_get_user_av_id()
898 {
899 #if CAM_HAS_IRIS_DIAPHRAGM
900 return aperture_sizes_table[find_nearest_aperture_entry(shooting_get_user_av96())].id;
901 #else
902 return 0;
903 #endif
904 }
905
906 void shooting_set_user_av_by_id(int v)
907 {
908 #if CAM_HAS_IRIS_DIAPHRAGM
909 unsigned i;
910 if (!camera_info.state.mode_play)
911 {
912 for (i=0;i<AS_SIZE;i++)
913 {
914 if (aperture_sizes_table[i].id == v)
915 {
916 short vv = aperture_sizes_table[i].prop_id;
917 set_property_case(PROPCASE_USER_AV, &vv, sizeof(vv));
918 return;
919 }
920 }
921 }
922 #else
923 (void)v;
924 #endif
925 }
926
927 void shooting_set_user_av_by_id_rel(int v)
928 {
929 #if CAM_HAS_IRIS_DIAPHRAGM
930 if (!camera_info.state.mode_play)
931 {
932 int cv = shooting_get_user_av_id();
933 shooting_set_user_av_by_id(cv+v);
934 }
935 #else
936 (void)v;
937 #endif
938 }
939
940 void shooting_set_user_av96(short av96)
941 {
942 #if CAM_HAS_IRIS_DIAPHRAGM
943 if (!camera_info.state.mode_play)
944 {
945 av96 = find_canon_aperture(av96);
946 set_property_case(PROPCASE_USER_AV, &av96, sizeof(av96));
947 }
948 #else
949 (void)av96;
950 #endif
951 }
952
953
954 #if CAM_DRAW_EXPOSITION
955
956 char* shooting_get_av_str()
957 {
958 return (char*)aperture_sizes_table[find_nearest_aperture_entry(shooting_get_av96())].name;
959 }
960 #endif
961
962 void shooting_set_nd_filter_state(short v, short is_now)
963 {
964 #if CAM_HAS_ND_FILTER
965 if (!camera_info.state.mode_play)
966 {
967 if (is_now)
968 {
969 #if CAM_ND_SET_AV_VALUE == 1
970 short av;
971 get_property_case(PROPCASE_MIN_AV,&av,sizeof(av));
972 if(v==1) {
973 av += shooting_get_nd_value_ev96();
974 }
975 set_property_case(PROPCASE_AV, &av, sizeof(av));
976 #if defined(PROPCASE_AV2)
977 set_property_case(PROPCASE_AV2, &av, sizeof(av));
978 #endif
979 #endif
980 if (v==1) {
981 PutInNdFilter();
982 }
983 else if (v==2)
984 PutOutNdFilter();
985 #if defined(CAM_HAS_NATIVE_ND_FILTER) && defined(PROPCASE_ND_FILTER_STATE)
986 int n = (v==1) ? 1 : 0;
987 set_property_case(PROPCASE_ND_FILTER_STATE, &n, sizeof(n));
988 #endif
989 }
990 else
991 photo_param_put_off.nd_filter = v;
992 }
993 #else
994 (void)v; (void)is_now;
995 #endif
996 }
997
998
999
1000
1001
1002
1003 short shooting_get_min_av96()
1004 {
1005 #if CAM_HAS_IRIS_DIAPHRAGM
1006 extern short GetUsableMaxAv(void);
1007 if (camera_info.state.mode_play)
1008 {
1009 return -1;
1010 }
1011 return GetUsableMaxAv();
1012 #else
1013 return -1;
1014 #endif
1015 }
1016
1017 short shooting_get_max_av96()
1018 {
1019 #if CAM_HAS_IRIS_DIAPHRAGM
1020 extern short GetUsableMinAv(void);
1021 if (camera_info.state.mode_play)
1022 {
1023 return -1;
1024 }
1025 return GetUsableMinAv();
1026 #else
1027 return -1;
1028 #endif
1029 }
1030
1031
1032
1033
1034
1035
1036
1037
1038 void shooting_init()
1039 {
1040 photo_param_put_off.tv96 = PHOTO_PARAM_TV_NONE;
1041 iso_init();
1042 }
1043
1044
1045
1046
1047 #ifdef CAM_FILE_COUNTER_IS_VAR
1048 extern long file_counter_var;
1049 long get_file_counter()
1050 {
1051 return file_counter_var;
1052 }
1053 long get_exposure_counter()
1054 {
1055 long v = get_file_counter();
1056 v = ((v>>4)&0x3FFF);
1057 return v;
1058 }
1059 #else
1060 extern const unsigned int param_file_counter;
1061
1062 long get_file_counter()
1063 {
1064 long v = 0;
1065 get_parameter_data(param_file_counter, &v, 4);
1066 return v;
1067 }
1068
1069 long get_exposure_counter()
1070 {
1071 long v = 0;
1072 get_parameter_data(param_file_counter, &v, 4);
1073 v = ((v>>4)&0x3FFF);
1074 return v;
1075 }
1076 #endif
1077
1078 #ifndef CAM_DATE_FOLDER_NAMING
1079 void get_target_dir_name(char *dir) {
1080 extern long get_target_dir_num();
1081 sprintf(dir,"A/DCIM/%03dCANON",get_target_dir_num());
1082 }
1083 #endif
1084
1085
1086
1087
1088 static const double K = 12.5;
1089
1090 int shooting_get_luminance()
1091 {
1092 short bv = shooting_get_bv96();
1093 int b = (int)(100 * K * pow(2.0,((double)(bv-168)/96.0)));
1094 return b;
1095 }
1096
1097
1098
1099
1100 int shooting_get_subject_distance_override_value()
1101 {
1102 if (conf.subj_dist_override_koef != SD_OVERRIDE_INFINITY)
1103 return (conf.subj_dist_override_value < shooting_get_lens_to_focal_plane_width()?0:(conf.subj_dist_override_value - shooting_get_lens_to_focal_plane_width()));
1104 else
1105 return INFINITY_DIST;
1106 }
1107
1108
1109
1110
1111 int shooting_mode_canon2chdk(int canonmode)
1112 {
1113 unsigned i;
1114 for (i=0; i < MODESCNT; i++)
1115 {
1116 if (modemap[i].canonmode == canonmode)
1117 return modemap[i].hackmode;
1118 }
1119 return 0;
1120 }
1121
1122 int shooting_mode_chdk2canon(int hackmode)
1123 {
1124 unsigned i;
1125 for (i=0; i < MODESCNT; i++)
1126 {
1127 if (modemap[i].hackmode == hackmode)
1128 return modemap[i].canonmode;
1129 }
1130 return -1;
1131 }
1132
1133
1134
1135 int sd_over_modes()
1136 { return ( 0
1137 #ifdef CAM_SD_OVER_IN_AF
1138 + 1
1139 #endif
1140 #ifdef CAM_SD_OVER_IN_AFL
1141 + 2
1142 #endif
1143 #ifdef CAM_SD_OVER_IN_MF
1144 + 4
1145 #endif
1146 ); }
1147
1148 int shooting_get_lens_to_focal_plane_width()
1149 {
1150 return (int)(lens_get_focus_pos()-lens_get_focus_pos_from_lens());
1151 }
1152
1153 int shooting_get_hyperfocal_distance_1e3_f(int av, int fl)
1154 {
1155 if ((av>0) && (fl>0) && (camera_info.circle_of_confusion>0))
1156 return (int)(((((double)fl*fl)/(av*camera_info.circle_of_confusion)*1000)+fl)+0.5);
1157 else return (-1);
1158 }
1159
1160 int shooting_get_near_limit_f(int s, int av, int fl)
1161 {
1162 if (shooting_is_infinity_distance()) return (-1);
1163 int h_1e3 = shooting_get_hyperfocal_distance_1e3_f(av, fl);
1164 double m = ((double)(h_1e3 - fl)+500)/1000*s;
1165 int v = ((h_1e3 - 2*fl + 1000*s)+500)/1000;
1166 if ((m>0) && (v>0)) return (int)((2*m/v+1)/2);
1167 else return (-1);
1168 }
1169
1170 int shooting_get_far_limit_f(int s, int av, int fl)
1171 {
1172 if (shooting_is_infinity_distance()) return (-1);
1173 int h_1e3 = shooting_get_hyperfocal_distance_1e3_f(av, fl);
1174 double m = ((double)(h_1e3 - fl)+500)/1000*s;
1175 int v = ((h_1e3 - 1000*s)+500)/1000;
1176 if ((m>0) && (v>0)) return (int)((2*m/v+1)/2);
1177 else return (-1);
1178 }
1179
1180 short shooting_is_infinity_distance()
1181 {
1182 return (shooting_get_lens_to_focal_plane_width() == 0)?1:0;
1183 }
1184
1185 int shooting_get_canon_subject_distance()
1186 {
1187 if (conf.dof_use_exif_subj_dist)
1188 return shooting_get_exif_subject_dist();
1189 else
1190 return (lens_get_focus_pos_from_lens());
1191 }
1192
1193 int shooting_get_subject_distance_()
1194 {
1195 if (!conf.dof_subj_dist_as_near_limit) return shooting_get_canon_subject_distance();
1196 else return shooting_get_far_limit_f(shooting_get_canon_subject_distance(),
1197 shooting_get_min_real_aperture(),
1198 get_focal_length(lens_get_zoom_point()));
1199 }
1200
1201 void shooting_update_dof_values()
1202 {
1203 int hyp, hyp_1e3, av_1e3, v;
1204 int dist = shooting_get_subject_distance_();
1205 int zoom_point = lens_get_zoom_point();
1206 int fl = get_focal_length(zoom_point);
1207 short f_focus_ok = shooting_get_focus_ok();
1208 short f_hyp_calc = 0, f_dist_calc = 0;
1209 short min_av96_zoom_point = 0;
1210 short av96 = shooting_get_user_av96();
1211 short curr_av96 = shooting_get_current_av96();
1212 short prop_av96 = shooting_get_av96();
1213 short min_av96;
1214
1215 if (!min_av96_zoom_point_tbl) {
1216 min_av96_zoom_point_tbl = (short *) malloc(zoom_points * sizeof(short));
1217 if (min_av96_zoom_point_tbl) {
1218 memset(min_av96_zoom_point_tbl, 0, zoom_points * sizeof(short));
1219 }
1220 else {
1221 return;
1222 }
1223 } else min_av96_zoom_point = min_av96_zoom_point_tbl[zoom_point];
1224
1225 if (min_av96_zoom_point==0 && shooting_in_progress()) {
1226 get_property_case(PROPCASE_MIN_AV, &min_av96, sizeof(min_av96));
1227 min_av96_zoom_point_tbl[zoom_point] = min_av96;
1228 }
1229
1230 if ((camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_AV) && (av96>0) && !f_focus_ok) {
1231 if (av96 < min_av96_zoom_point) av96 = min_av96_zoom_point;
1232 }
1233 else av96 = (abs(curr_av96-prop_av96)<2)?prop_av96:curr_av96;
1234
1235 av_1e3 = shooting_get_aperture_from_av96(av96);
1236 hyp_1e3 = camera_info.dof_values.hyperfocal_distance_1e3;
1237 hyp = camera_info.dof_values.hyperfocal_distance;
1238
1239 if (camera_info.dof_values.aperture_value!=av_1e3 || camera_info.dof_values.focal_length!=fl || (hyp_1e3<0)) {
1240
1241 f_hyp_calc = 1;
1242 hyp_1e3 = -1;
1243 hyp = -1;
1244 camera_info.dof_values.aperture_value = av_1e3;
1245 camera_info.dof_values.focal_length = fl;
1246 hyp_1e3 = shooting_get_hyperfocal_distance_1e3_f(av_1e3, fl);
1247 if (hyp_1e3>0) {
1248 hyp = (hyp_1e3+500)/1000;
1249 camera_info.dof_values.min_stack_distance = CAMERA_MAX_DIST;
1250 v = ((hyp_1e3 - fl)/250 + 2 + 1)/2;
1251 if (v>0) {
1252 int m = ((fl*((fl - hyp_1e3)/1000 - 1)/500)/v + 1)/2;
1253 int m2 = (int)((((double)hyp*(2*fl - hyp_1e3)/1000))/v + 0.5);
1254 camera_info.dof_values.min_stack_distance = sqrt(m*m - m2) - m;
1255 }
1256 }
1257 }
1258
1259 if ((camera_info.dof_values.subject_distance!=dist || (camera_info.dof_values.hyperfocal_distance_1e3!=hyp_1e3)) && (hyp_1e3>0)) {
1260
1261 f_dist_calc = 1;
1262 camera_info.dof_values.subject_distance = dist;
1263 camera_info.dof_values.near_limit = -1;
1264 camera_info.dof_values.far_limit = -1;
1265 camera_info.dof_values.depth_of_field = -1;
1266 if ((av_1e3>0) && (fl>0) && (dist>0) && (shooting_is_infinity_distance()==0) && (hyp_1e3>0)) {
1267 double m = ((double)(hyp_1e3 - fl)/1000 * dist) + 0.5;
1268 if (conf.dof_subj_dist_as_near_limit) {
1269 camera_info.dof_values.near_limit = dist;
1270 } else {
1271 int v = ((((hyp_1e3 - 2*fl + 1000*dist)/500) + 1)/2);
1272 if (v>0) camera_info.dof_values.near_limit = (int)(m/v);
1273 }
1274 int v = ((((hyp_1e3 - 1000*dist)/500) + 1)/2);
1275 if (v>0) camera_info.dof_values.far_limit = (int)(m/v);
1276 if ((camera_info.dof_values.near_limit>0) && (camera_info.dof_values.far_limit>0)) {
1277 camera_info.dof_values.depth_of_field = camera_info.dof_values.far_limit - camera_info.dof_values.near_limit;
1278 }
1279 }
1280
1281
1282 if (shooting_is_infinity_distance()) {
1283 camera_info.dof_values.near_limit = hyp;
1284 }
1285 }
1286 camera_info.dof_values.hyperfocal_distance_1e3 = hyp_1e3;
1287 camera_info.dof_values.hyperfocal_distance = hyp;
1288 f_focus_ok = (f_focus_ok && shooting_get_focus_ok());
1289 camera_info.dof_values.hyperfocal_valid = (f_focus_ok || (camera_info.dof_values.hyperfocal_valid && !f_hyp_calc));
1290 camera_info.dof_values.distance_valid = (f_focus_ok || (camera_info.dof_values.distance_valid && !f_dist_calc)||(camera_info.dof_values.hyperfocal_valid && shooting_get_focus_mode()));
1291 return;
1292 }
1293
1294 int shooting_get_subject_distance()
1295 {
1296 shooting_update_dof_values();
1297 return camera_info.dof_values.subject_distance;
1298 }
1299
1300 int shooting_get_hyperfocal_distance()
1301 {
1302 shooting_update_dof_values();
1303 return camera_info.dof_values.hyperfocal_distance;
1304 }
1305
1306 static int focus_interlock_bypass = 0;
1307
1308 short shooting_can_focus()
1309 {
1310 if(camera_info.state.mode_play) return 0 ;
1311
1312 if(focus_interlock_bypass) return 1;
1313
1314 if( camera_info.state.mode_video == 1) return 1;
1315
1316 #ifdef CAM_SD_OVER_IN_AFL
1317 if (shooting_get_prop(PROPCASE_AF_LOCK)==1 ) return 1;
1318 #endif
1319 #ifdef CAM_SD_OVER_IN_MF
1320 if (shooting_get_prop(PROPCASE_FOCUS_MODE)==1 ) return 1;
1321 #endif
1322
1323 #ifdef CAM_SD_OVER_IN_AF
1324 #ifdef PROPCASE_CONTINUOUS_AF
1325 if (shooting_get_prop(PROPCASE_CONTINUOUS_AF)) return 0;
1326 #endif
1327 #ifdef PROPCASE_SERVO_AF
1328 if (shooting_get_prop(PROPCASE_SERVO_AF)) return 0;
1329 #endif
1330 if ( (shooting_get_prop(PROPCASE_AF_LOCK)==0)
1331 && (shooting_get_prop(PROPCASE_FOCUS_MODE)==0 )) return 1;
1332 #endif
1333 return 0;
1334 }
1335
1336 short shooting_get_common_focus_mode()
1337 {
1338 #if !CAM_HAS_MANUAL_FOCUS
1339 return conf.subj_dist_override_koef;
1340 #else
1341 return shooting_get_focus_mode();
1342 #endif
1343 }
1344
1345 int shooting_is_flash_ready()
1346 {
1347 int t = shooting_get_flash_mode();
1348 if ((t != 2) && (shooting_in_progress()))
1349 if (shooting_is_flash())
1350 return IsStrobeChargeCompleted();
1351 return 1;
1352 }
1353
1354
1355
1356
1357 #if CAM_QUALITY_OVERRIDE
1358 void shooting_set_image_quality(int imq)
1359 {
1360 if (imq != 3)
1361 {
1362 set_property_case(PROPCASE_QUALITY, &imq, sizeof(imq));
1363 }
1364 }
1365 #endif
1366
1367 #ifdef CAM_ILC
1368 void shooting_set_zoom(__attribute__ ((unused))int v) {}
1369 void shooting_set_zoom_rel(__attribute__ ((unused))int v) {}
1370 void shooting_set_zoom_speed(__attribute__ ((unused))int v) {}
1371 #else
1372 void shooting_set_zoom(int v)
1373 {
1374 if (!camera_info.state.mode_play)
1375 {
1376 #if CAM_REFOCUS_AFTER_ZOOM
1377 int dist = shooting_get_subject_distance();
1378 lens_set_zoom_point(v);
1379 #if defined(CAM_NEED_SET_ZOOM_DELAY)
1380 msleep(CAM_NEED_SET_ZOOM_DELAY);
1381 #endif
1382 shooting_set_focus(dist, SET_NOW);
1383 #else
1384 lens_set_zoom_point(v);
1385 #endif
1386 }
1387 }
1388
1389 void shooting_set_zoom_rel(int v)
1390 {
1391 int cv = shooting_get_zoom();
1392 if (!camera_info.state.mode_play)
1393 {
1394 shooting_set_zoom(cv+v);
1395 }
1396 }
1397
1398 void shooting_set_zoom_speed(int v) {
1399 if (!camera_info.state.mode_play)
1400 {
1401 lens_set_zoom_speed(v);
1402 }
1403 }
1404 #endif
1405
1406 void set_focus_bypass(int m)
1407 {
1408 focus_interlock_bypass = m ;
1409 }
1410
1411 void shooting_set_focus(int v, short is_now)
1412 {
1413 int s=v;
1414 if (!camera_info.state.mode_play)
1415 {
1416 if (is_now && shooting_can_focus())
1417 {
1418 if (conf.dof_subj_dist_as_near_limit)
1419 {
1420 s=shooting_get_near_limit_f(v,shooting_get_min_real_aperture(),get_focal_length(lens_get_zoom_point()));
1421 }
1422 if (!conf.dof_use_exif_subj_dist && (s != (int)INFINITY_DIST))
1423 s+=shooting_get_lens_to_focal_plane_width();
1424 lens_set_focus_pos(s);
1425 }
1426 else
1427 photo_param_put_off.subj_dist=v;
1428 }
1429 }
1430
1431 void shooting_video_bitrate_change(int v)
1432 {
1433 #if CAM_CHDK_HAS_EXT_VIDEO_MENU
1434 int m[]={1,2,3,4,5,6,7,8,10,12};
1435 if (v>=(int)((sizeof(m)/sizeof(m[0]))))
1436 v=(sizeof(m)/sizeof(m[0]))-1;
1437 change_video_tables(m[v],4);
1438 #else
1439 (void)v;
1440 #endif
1441 }
1442 #ifdef CAM_MOVIEREC_NEWSTYLE
1443 void shooting_video_minbitrate_change(int v)
1444 {
1445 char m[]={1,2,3,4,5,6,7,8,9,10};
1446 if (v>=(int)(sizeof(m)/sizeof(m[0])))
1447 v=(sizeof(m)/sizeof(m[0]))-1;
1448 change_video_minbitrate(m[v],10);
1449 }
1450 unsigned int shooting_get_video_recorded_size_kb()
1451 {
1452 return get_video_recorded_size_kb();
1453 }
1454 #endif
1455
1456
1457
1458 #if CAM_REAR_CURTAIN
1459 void shooting_set_flash_sync_curtain(int curtain)
1460 {
1461 set_property_case(PROPCASE_FLASH_SYNC_CURTAIN, &curtain, sizeof(curtain));
1462 }
1463 #endif
1464
1465 void unlock_optical_zoom(void)
1466 {
1467 #if CAM_CAN_UNLOCK_OPTICAL_ZOOM_IN_VIDEO
1468 extern void UnsetZoomForMovie();
1469 if (conf.unlock_optical_zoom_for_video)
1470 UnsetZoomForMovie();
1471 #endif
1472
1473 #if CAM_EV_IN_VIDEO
1474 set_ev_video_avail(0);
1475 #endif
1476 }
1477
1478 int shooting_set_mode_canon(int canonmode)
1479 {
1480 if (canonmode == -1 || !rec_mode_active())
1481 return 0;
1482 SetCurrentCaptureModeType(canonmode);
1483
1484 mode_get();
1485 return 1;
1486 }
1487
1488 int shooting_set_mode_chdk(int mode)
1489 {
1490 return shooting_set_mode_canon(shooting_mode_chdk2canon(mode));
1491 }
1492
1493
1494
1495
1496 EXPO_BRACKETING_VALUES bracketing;
1497
1498
1499 static int bracket_steps[4][2] = {
1500 { 1, -1 },
1501 { -1, -1 },
1502 { 1, 1 },
1503 { -1, 1 },
1504 };
1505 static int bracket_delta[4][2] = {
1506 { 1, 0 },
1507 { 1, 1 },
1508 { 1, 1 },
1509 { 1, 0 },
1510 };
1511
1512 static void shooting_tv_bracketing(int when)
1513 {
1514
1515 if (bracketing.shoot_counter == 0)
1516 {
1517
1518 if (is_tv_override_enabled)
1519 {
1520
1521 bracketing.tv96 = shooting_get_tv96_override_value();
1522 }
1523
1524 else
1525 {
1526 if (!(camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_TV || camera_info.state.mode_shooting==MODE_LONG_SHUTTER))
1527 bracketing.tv96=shooting_get_tv96();
1528 else
1529 bracketing.tv96=shooting_get_user_tv96();
1530 }
1531 bracketing.tv96_step = 32*conf.tv_bracket_value;
1532 }
1533
1534
1535 bracketing.dtv96 += (bracketing.tv96_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1536
1537 short value = bracketing.tv96 - (bracketing.dtv96 * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1538
1539
1540 bracketing.shoot_counter++;
1541
1542
1543 shooting_set_tv96_direct(value, when);
1544 }
1545
1546 static void shooting_av_bracketing(int when)
1547 {
1548
1549 if (bracketing.shoot_counter == 0)
1550 {
1551 if (!(camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_AV))
1552 bracketing.av96 = shooting_get_av96();
1553 else
1554 bracketing.av96 = shooting_get_user_av96();
1555 bracketing.av96_step = 32*conf.av_bracket_value;
1556 }
1557
1558
1559 bracketing.dav96 += (bracketing.av96_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1560
1561 short value = bracketing.av96 - (bracketing.dav96 * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1562
1563
1564 bracketing.shoot_counter++;
1565
1566
1567 if (value != bracketing.av96)
1568 {
1569 shooting_set_av96_direct(value, when);
1570 #ifdef CAM_AV_OVERRIDE_IRIS_FIX
1571 extern int MoveIrisWithAv(short*);
1572 MoveIrisWithAv(&value);
1573 #endif
1574 }
1575 }
1576
1577 static void shooting_iso_bracketing(int when)
1578 {
1579
1580 if (bracketing.shoot_counter == 0)
1581 {
1582 bracketing.iso = shooting_get_iso_real();
1583 bracketing.iso_step = shooting_iso_market_to_real(conf.iso_bracket_value);
1584 }
1585
1586
1587 bracketing.diso += (bracketing.iso_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1588
1589 short value = bracketing.iso + (bracketing.diso * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1590 if (value <= 0) value = 50;
1591
1592
1593 bracketing.shoot_counter++;
1594
1595
1596 shooting_set_iso_real(value, when);
1597 }
1598
1599 static void shooting_subject_distance_bracketing(int when)
1600 {
1601
1602 if (bracketing.shoot_counter == 0)
1603 {
1604 bracketing.subj_dist = shooting_get_subject_distance();
1605 bracketing.subj_dist_step = conf.subj_dist_bracket_value;
1606 }
1607
1608
1609 bracketing.dsubj_dist += (bracketing.subj_dist_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1610
1611 int value = bracketing.subj_dist + (bracketing.dsubj_dist * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1612 if (value < CAMERA_MIN_DIST) value = CAMERA_MIN_DIST;
1613 else if (value > CAMERA_MAX_DIST) value = CAMERA_MAX_DIST;
1614
1615
1616 bracketing.shoot_counter++;
1617
1618
1619 shooting_set_focus(value, when);
1620 }
1621
1622 void bracketing_reset()
1623 {
1624 memset(&bracketing,0,sizeof(bracketing));
1625 memset(&photo_param_put_off,0,sizeof(photo_param_put_off));
1626 photo_param_put_off.tv96=PHOTO_PARAM_TV_NONE;
1627 }
1628
1629 void bracketing_step(int when)
1630 {
1631 if (is_tv_bracketing_enabled) shooting_tv_bracketing(when);
1632 else if (is_av_bracketing_enabled) shooting_av_bracketing(when);
1633 else if (is_iso_bracketing_enabled) shooting_iso_bracketing(when);
1634 else if (is_sd_bracketing_enabled) shooting_subject_distance_bracketing(when);
1635 }
1636
1637 void shooting_bracketing(void)
1638 {
1639 if (shooting_get_drive_mode()!=0)
1640 {
1641 if (camera_info.state.mode_shooting!=MODE_STITCH && camera_info.state.mode_shooting!=MODE_BEST_IMAGE)
1642 {
1643 if (camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_PROCESSING)
1644 bracketing_reset() ;
1645 bracketing_step(SET_NOW) ;
1646 }
1647 }
1648 }
1649
1650
1651
1652
1653
1654
1655
1656
1657 int captseq_hack_override_active()
1658 {
1659 if (camera_info.state.state_kbd_script_run) {
1660 if ( photo_param_put_off.tv96 != PHOTO_PARAM_TV_NONE || photo_param_put_off.sv96 )
1661 return 1;
1662 #if CAM_HAS_IRIS_DIAPHRAGM
1663 if(photo_param_put_off.av96)
1664 return 1;
1665 #endif
1666 }
1667 if(conf.override_disable==1)
1668 return 0;
1669 if(is_iso_override_enabled)
1670 return 1;
1671 if(is_tv_override_enabled)
1672 return 1;
1673 #if CAM_HAS_IRIS_DIAPHRAGM
1674 if(is_av_override_enabled)
1675 return 1;
1676 #endif
1677 return 0;
1678 }
1679
1680 #ifdef CAM_SIMPLE_MOVIE_STATUS
1681 extern int simple_movie_status;
1682 #else
1683 extern int movie_status;
1684 #endif
1685
1686 void set_movie_status(int status)
1687 {
1688 #ifndef CAM_SIMPLE_MOVIE_STATUS
1689 switch(status)
1690 {
1691 case 1:
1692 if (movie_status == VIDEO_RECORD_IN_PROGRESS)
1693 {
1694 movie_status = VIDEO_RECORD_STOPPED;
1695 }
1696 break;
1697 case 2:
1698 if (movie_status == VIDEO_RECORD_STOPPED)
1699 {
1700 movie_status = VIDEO_RECORD_IN_PROGRESS;
1701 }
1702 break;
1703 case 3:
1704 if (movie_status == VIDEO_RECORD_STOPPED || movie_status == VIDEO_RECORD_IN_PROGRESS)
1705 {
1706 movie_status = VIDEO_RECORD_STOPPING;
1707 }
1708 break;
1709 }
1710 #else
1711
1712 (void)status;
1713 #endif
1714 }
1715
1716 int get_movie_status()
1717 {
1718 #ifndef CAM_SIMPLE_MOVIE_STATUS
1719 return movie_status;
1720 #else
1721
1722 return simple_movie_status?VIDEO_RECORD_IN_PROGRESS:VIDEO_RECORD_STOPPED;
1723 #endif
1724 }
1725
1726
1727 int is_video_recording()
1728 {
1729 #ifndef CAM_SIMPLE_MOVIE_STATUS
1730 #if defined(CAM_HAS_MOVIE_DIGEST_MODE)
1731
1732
1733
1734
1735
1736
1737
1738 return ((movie_status == VIDEO_RECORD_IN_PROGRESS) && (camera_info.state.mode_shooting != MODE_VIDEO_MOVIE_DIGEST));
1739 #else
1740
1741
1742
1743
1744
1745 return (movie_status > 1);
1746 #endif
1747 #else
1748 return (simple_movie_status!=0);
1749 #endif
1750 }
1751
1752
1753 int mode_is_video(int m)
1754 {
1755 m = m & MODE_SHOOTING_MASK;
1756 return (m==MODE_VIDEO_STD ||
1757 m==MODE_VIDEO_SPEED ||
1758 m==MODE_VIDEO_COMPACT ||
1759 m==MODE_VIDEO_MY_COLORS ||
1760 m==MODE_VIDEO_COLOR_ACCENT ||
1761 m==MODE_VIDEO_COLOR_SWAP ||
1762 m==MODE_VIDEO_MINIATURE ||
1763 m==MODE_VIDEO_TIME_LAPSE ||
1764 m==MODE_VIDEO_IFRAME_MOVIE ||
1765 m==MODE_VIDEO_M ||
1766 m==MODE_VIDEO_STAR_TIME_LAPSE ||
1767 m==MODE_VIDEO_SHORT_CLIP ||
1768 m==MODE_VIDEO_SUPER_SLOW
1769
1770
1771 );
1772 }
1773
1774
1775 int __attribute__((weak)) rec_mode_active(void)
1776 {
1777 return (playrec_mode==2 || playrec_mode==4 || playrec_mode==5);
1778 }
1779
1780 int mode_get(void)
1781 {
1782 int mode, t=0xFF;
1783
1784 mode = (rec_mode_active())?MODE_REC:MODE_PLAY;
1785
1786 #ifdef CAM_SWIVEL_SCREEN
1787 extern int screen_opened(void);
1788 extern int screen_rotated(void);
1789
1790 mode |= (screen_opened())?MODE_SCREEN_OPENED:0;
1791 mode |= (screen_rotated())?MODE_SCREEN_ROTATED:0;
1792 #endif
1793
1794 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
1795 extern void update_screen_dimensions();
1796 update_screen_dimensions();
1797 #endif
1798
1799 get_property_case(PROPCASE_SHOOTING_MODE, &t, 4);
1800 #ifdef CAM_MASK_VID_REC_ACTIVE
1801 mode |= shooting_mode_canon2chdk(t & (~CAM_MASK_VID_REC_ACTIVE));
1802 #else
1803 mode |= shooting_mode_canon2chdk(t);
1804 #endif
1805
1806
1807 camera_info.state.mode = mode;
1808 camera_info.state.mode_shooting = mode & MODE_SHOOTING_MASK;
1809 camera_info.state.mode_video = mode_is_video(mode);
1810 camera_info.state.mode_rec = ((mode & MODE_MASK) == MODE_REC);
1811 camera_info.state.mode_rec_or_review = camera_info.state.mode_rec && (recreview_hold==0 || conf.show_osd_in_review);
1812 camera_info.state.mode_play = ((mode & MODE_MASK) == MODE_PLAY);
1813 camera_info.state.mode_photo = (camera_info.state.mode_play || !(camera_info.state.mode_video || (mode&MODE_SHOOTING_MASK)==MODE_STITCH));
1814
1815 return (mode);
1816 }
1817
1818
1819
1820
1821 #if CAM_EV_IN_VIDEO
1822
1823 int ev_video_avail;
1824 int ev_video;
1825 int save_tv_video;
1826 int tv_min_video;
1827
1828 int get_ev_video_avail(void)
1829 {
1830 return ev_video_avail;
1831 }
1832
1833 int get_ev_video(void)
1834 {
1835 return ev_video;
1836 }
1837
1838 void set_ev_video_avail(int x)
1839 {
1840 extern void ExpCtrlTool_StartContiAE(int, int);
1841 extern void ExpCtrlTool_StopContiAE(int, int);
1842
1843 if (ev_video_avail==x) return;
1844 ev_video_avail=x;
1845 if (x)
1846 {
1847 ev_video=0;
1848 ExpCtrlTool_StopContiAE(0,0);
1849 get_property_case(PROPCASE_TV,&save_tv_video,2);
1850 if (camera_info.state.mode_shooting==MODE_VIDEO_SPEED)
1851 tv_min_video=577;
1852 else
1853 tv_min_video=480;
1854 }
1855 else
1856 ExpCtrlTool_StartContiAE(0,0);
1857 }
1858
1859 void set_ev_video(int x)
1860 {
1861 short ev, tv;
1862 if ((x<-4)||(x>4))
1863 return;
1864
1865 ev=48*x;
1866 tv=save_tv_video-ev;
1867 if (tv>=tv_min_video)
1868 {
1869 ev_video=x;
1870 extern short SetAE_ShutterSpeed(short* tv);
1871 SetAE_ShutterSpeed(&tv);
1872 }
1873 }
1874
1875 #endif
1876
1877
1878
1879
1880 static void shooting_set_flash_override()
1881 {
1882 int mode, flash, power;
1883 flash = 1;
1884
1885
1886 if ((conf.flash_video_override && is_video_recording()) || (!conf.flash_video_override))
1887 {
1888 if (conf.flash_manual_override)
1889 {
1890 mode = 1;
1891 power = conf.flash_video_override_power;
1892 set_property_case(PROPCASE_FLASH_ADJUST_MODE, &mode, sizeof(mode));
1893 set_property_case(PROPCASE_FLASH_FIRE, &flash, sizeof(flash));
1894 set_property_case(PROPCASE_FLASH_MANUAL_OUTPUT, &power, sizeof(power));
1895 }
1896 else if (conf.flash_enable_exp_comp)
1897 {
1898 mode = 0;
1899 power = (conf.flash_exp_comp - 9) * 32;
1900 set_property_case(PROPCASE_FLASH_ADJUST_MODE, &mode, sizeof(mode));
1901 set_property_case(PROPCASE_FLASH_FIRE, &flash, sizeof(flash));
1902 #if defined(PROPCASE_FLASH_EXP_COMP)
1903 set_property_case(PROPCASE_FLASH_EXP_COMP, &power, sizeof(power));
1904 #endif
1905 #if defined(PROPCASE_EXT_FLASH_EXP_COMP)
1906 set_property_case(PROPCASE_EXT_FLASH_EXP_COMP, &power, sizeof(power));
1907 #endif
1908 }
1909 }
1910 }
1911
1912 void shooting_expo_param_override_thumb(void)
1913 {
1914 if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.tv96 != PHOTO_PARAM_TV_NONE))
1915 {
1916 shooting_set_tv96_direct(photo_param_put_off.tv96, SET_NOW);
1917 photo_param_put_off.tv96=PHOTO_PARAM_TV_NONE;
1918 }
1919 else if (is_tv_override_enabled)
1920 {
1921 shooting_set_tv96_direct(shooting_get_tv96_override_value(),SET_NOW);
1922 }
1923
1924 if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.sv96))
1925 {
1926 shooting_set_sv96(photo_param_put_off.sv96, SET_NOW);
1927 photo_param_put_off.sv96=0;
1928 }
1929 else if (is_iso_override_enabled)
1930 shooting_set_iso_real(shooting_get_iso_override_value(), SET_NOW);
1931 else if (conf.autoiso_enable && shooting_get_flash_mode() && autoiso_and_bracketing_overrides_are_enabled)
1932 shooting_set_autoiso(shooting_get_iso_mode());
1933
1934 if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.av96))
1935 {
1936 shooting_set_av96_direct(photo_param_put_off.av96, SET_NOW);
1937 photo_param_put_off.av96=0;
1938 }
1939 else if (is_av_override_enabled)
1940 shooting_set_av96_direct(shooting_get_av96_override_value(), SET_NOW);
1941
1942 if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.subj_dist))
1943 {
1944 shooting_set_focus(photo_param_put_off.subj_dist, SET_NOW);
1945 photo_param_put_off.subj_dist=0;
1946 }
1947 else if (is_sd_override_enabled)
1948 shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);
1949
1950 #if CAM_HAS_ND_FILTER
1951 if ((camera_info.state.state_kbd_script_run) && (photo_param_put_off.nd_filter))
1952 {
1953 shooting_set_nd_filter_state(photo_param_put_off.nd_filter, SET_NOW);
1954 photo_param_put_off.nd_filter=0;
1955 }
1956 else if (conf.nd_filter_state && !(conf.override_disable==1))
1957 shooting_set_nd_filter_state(conf.nd_filter_state, SET_NOW);
1958 #endif
1959
1960 #if CAM_REAR_CURTAIN
1961 shooting_set_flash_sync_curtain(conf.flash_sync_curtain);
1962 #endif
1963
1964
1965 shooting_set_flash_override();
1966
1967 #if CAM_QUALITY_OVERRIDE
1968
1969
1970 shooting_set_image_quality(conf.fast_image_quality);
1971 #endif
1972
1973 libscriptapi->shoot_hook(SCRIPT_SHOOT_HOOK_PRESHOOT);
1974 }
1975
1976
1977
1978 void shooting_expo_iso_override_thumb(void)
1979 {
1980 if ((camera_info.state.state_kbd_script_run) && (photo_param_put_off.sv96))
1981 {
1982 shooting_set_sv96(photo_param_put_off.sv96, SET_NOW);
1983
1984 }
1985 else if (is_iso_override_enabled)
1986 shooting_set_iso_real(shooting_get_iso_override_value(), SET_NOW);
1987 else if (conf.autoiso_enable && shooting_get_flash_mode() && autoiso_and_bracketing_overrides_are_enabled)
1988 shooting_set_autoiso(shooting_get_iso_mode());
1989
1990 #if defined(CAM_HAS_ND_FILTER) && defined(CAM_HAS_NATIVE_ND_FILTER)
1991 if ((camera_info.state.state_kbd_script_run) && (photo_param_put_off.nd_filter))
1992 {
1993 shooting_set_nd_filter_state(photo_param_put_off.nd_filter, SET_NOW);
1994
1995 }
1996 else if (conf.nd_filter_state && !(conf.override_disable==1))
1997 shooting_set_nd_filter_state(conf.nd_filter_state, SET_NOW);
1998 #endif
1999
2000
2001 shooting_set_flash_override();
2002 }
2003
2004
2005
2006
2007
2008 void shooting_set_playrec_mode(int mode)
2009 {
2010
2011
2012 if (get_usb_bit_physw_mod())
2013 {
2014 switch_mode_usb(mode);
2015 return;
2016 }
2017 if(mode)
2018 levent_set_record();
2019 else
2020 levent_set_play();
2021 }