root/core/shooting.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. shooting_get_prop
  2. shooting_get_prop_int
  3. shooting_set_prop
  4. shooting_get_is_mode
  5. shooting_get_bv96
  6. shooting_get_canon_overexposure_value
  7. shooting_get_flash_mode
  8. shooting_get_focus_mode
  9. shooting_get_ev_correction1
  10. shooting_get_ev_correction2
  11. shooting_get_resolution
  12. shooting_get_display_mode
  13. shooting_get_exif_subject_dist
  14. shooting_is_flash
  15. shooting_in_progress
  16. shooting_get_canon_raw_enabled
  17. shooting_get_imager_active
  18. shooting_get_digital_zoom_mode
  19. shooting_get_digital_zoom_state
  20. shooting_get_real_focus_mode
  21. shooting_get_focus_state
  22. shooting_get_focus_ok
  23. shooting_get_drive_mode
  24. shooting_get_zoom
  25. shooting_get_canon_iso_mode
  26. shooting_get_sv96_market
  27. shooting_get_sv96_real
  28. shooting_get_sv96_delta
  29. shooting_get_sv96_from_iso
  30. shooting_get_iso_from_sv96
  31. shooting_iso_market_to_real
  32. shooting_iso_real_to_market
  33. shooting_sv96_market_to_real
  34. shooting_sv96_real_to_market
  35. shooting_get_iso_override_value
  36. shooting_get_iso_mode
  37. shooting_get_iso_real
  38. shooting_get_iso_market
  39. set_iso_mode
  40. shooting_set_iso_mode
  41. shooting_set_sv96
  42. shooting_set_iso_real
  43. iso_init
  44. shooting_get_tv96
  45. shooting_get_tv96_from_shutter_speed
  46. shooting_get_shutter_speed_from_tv96
  47. shooting_get_tv96_override_value
  48. find_nearest_shutter_speed_entry
  49. find_canon_shutter_speed
  50. shooting_set_tv96_direct
  51. shooting_set_tv96
  52. shooting_get_user_tv96
  53. shooting_get_user_tv_id
  54. shooting_set_user_tv_by_id
  55. shooting_set_user_tv_by_id_rel
  56. shooting_set_user_tv96
  57. shooting_get_tv_str
  58. shooting_get_av96
  59. shooting_get_aperture_sizes_table_size
  60. shooting_get_aperture_from_av96
  61. shooting_get_av96_from_aperture
  62. shooting_get_av96_override_value
  63. shooting_get_real_aperture
  64. shooting_get_min_real_aperture
  65. find_nearest_aperture_entry
  66. find_canon_aperture
  67. shooting_set_av96_direct
  68. shooting_set_av96
  69. shooting_get_user_av96
  70. shooting_get_user_av_id
  71. shooting_set_user_av_by_id
  72. shooting_set_user_av_by_id_rel
  73. shooting_set_user_av96
  74. shooting_get_av_str
  75. shooting_set_nd_filter_state
  76. shooting_get_min_av96
  77. shooting_get_max_av96
  78. shooting_init
  79. get_file_counter
  80. get_exposure_counter
  81. get_file_counter
  82. get_exposure_counter
  83. get_target_dir_name
  84. shooting_get_luminance
  85. shooting_get_subject_distance_override_value
  86. shooting_mode_canon2chdk
  87. shooting_mode_chdk2canon
  88. sd_over_modes
  89. shooting_get_lens_to_focal_plane_width
  90. shooting_get_hyperfocal_distance_1e3_f
  91. shooting_get_near_limit_f
  92. shooting_get_far_limit_f
  93. shooting_is_infinity_distance
  94. shooting_get_canon_subject_distance
  95. shooting_get_subject_distance_
  96. shooting_update_dof_values
  97. shooting_get_subject_distance
  98. shooting_get_hyperfocal_distance
  99. shooting_can_focus
  100. shooting_get_common_focus_mode
  101. shooting_is_flash_ready
  102. shooting_set_image_quality
  103. shooting_set_zoom
  104. shooting_set_zoom_rel
  105. shooting_set_zoom_speed
  106. set_focus_bypass
  107. shooting_set_focus
  108. shooting_video_bitrate_change
  109. shooting_video_minbitrate_change
  110. shooting_get_video_recorded_size_kb
  111. shooting_set_flash_sync_curtain
  112. unlock_optical_zoom
  113. shooting_set_mode_canon
  114. shooting_set_mode_chdk
  115. shooting_tv_bracketing
  116. shooting_av_bracketing
  117. shooting_iso_bracketing
  118. shooting_subject_distance_bracketing
  119. bracketing_reset
  120. bracketing_step
  121. shooting_bracketing
  122. captseq_hack_override_active
  123. set_movie_status
  124. get_movie_status
  125. is_video_recording
  126. mode_is_video
  127. rec_mode_active
  128. mode_get
  129. get_ev_video_avail
  130. get_ev_video
  131. set_ev_video_avail
  132. set_ev_video
  133. shooting_set_flash_override
  134. shooting_expo_param_override_thumb
  135. shooting_expo_iso_override_thumb
  136. shooting_set_playrec_mode

   1 #include "platform.h"
   2 #include "keyboard.h"
   3 #include "math.h"
   4 #include "stdlib.h"
   5 #include "conf.h"
   6 #include "histogram.h"
   7 #include "usb_remote.h"
   8 #include "autoiso.h"
   9 #include "levent.h"
  10 #include "script_api.h"
  11 
  12 // Shooting function that don't need to be ARM code
  13 // ARM code shooting functions are in platform/generic/shooting.c
  14 
  15 // This file needs more comments / documentation !!!!
  16 
  17 //-------------------------------------------------------------------
  18 // Forward references
  19 
  20 // returns 0 if in play, nonzero if rec
  21 int rec_mode_active(void); 
  22 
  23 //-------------------------------------------------------------------
  24 // From lolevel.h
  25 extern volatile long focus_busy;
  26 extern long playrec_mode;
  27 
  28 // Array & sizes stored in platform/generic/shooting.c
  29 extern const ShutterSpeed shutter_speeds_table[];
  30 extern const unsigned int SS_SIZE;
  31 extern const ApertureSize aperture_sizes_table[];
  32 extern const unsigned int AS_SIZE;
  33 extern const CapturemodeMap modemap[];
  34 extern const unsigned int MODESCNT;
  35 
  36 static short *min_av96_zoom_point_tbl = NULL;
  37 
  38 // Storage for delayed shooting overrides
  39 #define PHOTO_PARAM_TV_NONE 32767 // ~ 1/(2^341) seconds, safe marker for "no value"
  40 
  41 typedef struct {
  42     int subj_dist;
  43     short av96;
  44     short tv96;
  45     short sv96;
  46     short nd_filter;
  47 } PHOTO_PARAM;
  48 
  49 static PHOTO_PARAM photo_param_put_off;
  50 
  51 //-------------------------------------------------------------------
  52 // Convert values to/from APEX 96
  53 
  54 //static const double log_2 = 0.6931471805599;      // natural logarithm of 2
  55 static const double inv_log_2 = 1.44269504088906;   // 1 / log_2
  56 
  57 //-------------------------------------------------------------------
  58 // Functions to access Canon properties
  59 
  60 int shooting_get_prop(int id)
  61 {
  62     short vv;
  63     get_property_case(id, &vv, sizeof(vv));
  64     return vv;
  65 }
  66 
  67 static int shooting_get_prop_int(int id)
  68 {
  69     int vv;
  70     get_property_case(id, &vv, sizeof(vv));
  71     return vv;
  72 }
  73 
  74 void shooting_set_prop(int id, int v)
  75 {
  76     short vv = v;
  77     set_property_case(id, &vv, sizeof(vv));
  78     return;
  79 }
  80 
  81 short shooting_get_is_mode()                    { return shooting_get_prop(PROPCASE_IS_MODE); }
  82 short shooting_get_bv96()                       { return shooting_get_prop(PROPCASE_BV); }
  83 short shooting_get_canon_overexposure_value()   { return shooting_get_prop(PROPCASE_OVEREXPOSURE); }
  84 short shooting_get_flash_mode()                 { return shooting_get_prop(PROPCASE_FLASH_MODE); }
  85 short shooting_get_focus_mode()                 { return shooting_get_prop(PROPCASE_FOCUS_MODE); }
  86 short shooting_get_ev_correction1()             { return shooting_get_prop(PROPCASE_EV_CORRECTION_1); }
  87 short shooting_get_ev_correction2()             { return shooting_get_prop(PROPCASE_EV_CORRECTION_2); }
  88 short shooting_get_resolution()                 { return shooting_get_prop(PROPCASE_RESOLUTION); }
  89 short shooting_get_display_mode()               { return shooting_get_prop(PROPCASE_DISPLAY_MODE); }
  90 
  91 int   shooting_get_exif_subject_dist()          { return shooting_get_prop_int(PROPCASE_SUBJECT_DIST1); }
  92 int   shooting_is_flash()                       { return shooting_get_prop_int(PROPCASE_IS_FLASH_READY); }
  93 int   shooting_in_progress()                    { return shooting_get_prop_int(PROPCASE_SHOOTING); }
  94 
  95 // TODO should maybe jpeg, raw, raw+jpeg?
  96 int shooting_get_canon_raw_enabled() {
  97 #ifdef CAM_HAS_CANON_RAW
  98 #ifdef PROPCASE_IMAGE_FORMAT
  99     return (shooting_get_prop(PROPCASE_IMAGE_FORMAT) != 1); // 0 = raw, 2 = raw+jpeg
 100 #else
 101     return (shooting_get_prop(PROPCASE_RESOLUTION) == 5); // resolution 5 = raw, jpeg controlled with another prop
 102 #endif
 103 #else
 104     return 0;
 105 #endif
 106 }
 107 
 108 int shooting_get_imager_active() {
 109   extern int imager_active;
 110   return imager_active;
 111 }
 112 
 113 // translate digital zoom propcase values to match pre-propset 7 values
 114 // mode: 0 = off or standard digital zoom, 2 or 3 digital tele
 115 // PROPCASE_DIGITAL_ZOOM_MODE not defined for propset 1, ports configured to not need these functions
 116 #if CAM_PROPSET > 1
 117 int shooting_get_digital_zoom_mode(void)
 118 {
 119     int x=shooting_get_prop(PROPCASE_DIGITAL_ZOOM_MODE);
 120 #if CAM_PROPSET == 7 || CAM_PROPSET == 9 || CAM_PROPSET == 10|| CAM_PROPSET == 11
 121     if(x==1) {
 122         return 0;
 123     }
 124 #endif
 125     return x;
 126 }
 127 #endif // CAM_PROPSET > 1
 128 // state: 0 = off or digital tele, 1 = standard
 129 int shooting_get_digital_zoom_state(void)
 130 {
 131 #if CAM_PROPSET == 7 || CAM_PROPSET == 9 || CAM_PROPSET == 10 || CAM_PROPSET == 11 || CAM_PROPSET == 12
 132     // PS7 doesn't have _STATE, combines values
 133     int x=shooting_get_prop(PROPCASE_DIGITAL_ZOOM_MODE);
 134     if(x==1) {
 135         return 1;
 136     }
 137     return 0;
 138 #else
 139     return shooting_get_prop(PROPCASE_DIGITAL_ZOOM_STATE);
 140 #endif
 141 }
 142 /*
 143 get focus mode as used in script
 144 essentially returns PROPCASE_REAL_FOCUS_MODE,
 145 except MF and Macro values are swapped (presumably for backward compatiblity)
 146 resulting in:
 147 0=auto, 1=MF, 3=inf., 4=macro, 5=supermacro
 148 CHDK set_mf is correctly reported as MF, because set_mf overrides PROPCASE_FOCUS_MODE if needed
 149 */
 150 short shooting_get_real_focus_mode()
 151 {
 152     short f = shooting_get_focus_mode();
 153     short m = shooting_get_prop(PROPCASE_REAL_FOCUS_MODE);
 154     if (f==0 && m!=0) f=(m==1)?4:m;
 155     return f;
 156 }
 157 
 158 short shooting_get_focus_state()
 159 {
 160     if (shooting_get_focus_mode()==1) return -1;
 161     int m = shooting_get_prop_int(PROPCASE_FOCUS_STATE);
 162     return (short) m;
 163 }
 164  
 165 short shooting_get_focus_ok()
 166 {
 167     return ((shooting_get_focus_state()!=0) && shooting_in_progress());
 168 }
 169 
 170 short shooting_get_drive_mode()
 171 {
 172     // these cameras do not set PROPCASE_DRIVE_MODE when in custom timer mode
 173     // SX 200 IS 0,1,2,3,4=Off, 2 Second, Custom, Face Detection
 174 #if defined (CAM_DRIVE_MODE_FROM_TIMER_MODE)
 175     short m = shooting_get_prop(PROPCASE_TIMER_MODE);
 176     // note we return this only in custom mode.
 177     // Other cameras would return 3 if any timer mode is set (?) even if it doesn't do multiple exposures
 178     // note that face detect does multiple exposure
 179     if (m == 3)
 180         return m;
 181 #endif
 182 
 183     return shooting_get_prop(PROPCASE_DRIVE_MODE);
 184 }
 185 
 186 int shooting_get_zoom()
 187 {
 188     return lens_get_zoom_point();
 189 }
 190 
 191 //-------------------------------------------------------------------
 192 // ISO section - start
 193 //-------------------------------------------------------------------
 194 
 195 /*
 196     Notes on Canon ISO & CHDK ISO overrides.
 197     ========================================
 198     (philmoz Aug 2013)
 199 
 200     Canon P&S cameras use two different values for ISO in the firmware.
 201         - the ISO value displayed on screen & stored in the image EXIF, generally referred to as the 'market' ISO
 202         - the value used to program the sensitivity of the sensor and/or set the image tone curve, the 'real' ISO
 203 
 204     The firmware uses the APEX system for ISO (as well as aperture, shutter speed and luminance).
 205     See - http://dougkerr.net/pumpkin/#Optics - APEX - The Additive System of Photographic Exposure.
 206     The Canon firmware scales the Sv (speed value) by multiplying values by 96 - referred to as Sv96 below.
 207 
 208     Conversion of ISO to/from Sv96 (from the above linked PDF)
 209     ----------------------------------------------------------
 210         Sv = log2(ISO / 3.125)      ==>     Sv96 = log2(ISO / 3.125) * 96
 211         ISO = pow(2, Sv * 3.125)    ==>     ISO = pow(2, Sv96 / 96 * 3.125)
 212 
 213     In the implementation below 3.125 is represented as 100/32, 
 214     and log2(x) is calculated as log(x)/log(2), where log is the natural log function found in the firmware.
 215 
 216     Relationship of 'real' to 'market' values.
 217     ------------------------------------------
 218     In most cases the following equation holds:
 219         Sv96_real = Sv96_market - 69
 220     In other words the 'real' value is approx. 1/3 stop lower than the market value.
 221     On some cameras, when the lowest ISO is set manually on the camera, the equation is:
 222         Sv96_real = Sv96_market - 78
 223     The difference is less than 1/10th of a stop, so the value 69 is used in the CHDK override code.
 224 
 225     Note: some cameras have a different offset (e.g. IXUS700 uses 'real = market - 20')
 226           in this case override the conversion values in the platform_camera.h file
 227 
 228     Based on the above equations we can determine that:
 229         ISO_real = ISO_market * pow(2, -69/96) ~= ISO_market * 1.65
 230     and ISO_market = ISO_real * pow(2,  69/96) ~= ISO_real * 0.61
 231     The derivation of this equation is left as an exercise for the reader :)
 232 
 233     Setting ISO on the camera.
 234     --------------------------
 235     Four PROPCASES are used for ISO settings
 236         PROPCASE_ISO_MODE       = ISO value when ISO set manually, 0 for AUTO ISO
 237         PROPCASE_SV             = 'real' Sv96 value for ISO
 238         PROPCASE_SV_MARKET      = 'market' Sv96 value when ISO set manually
 239                                 = Sv96 value for camera 'base' ISO (50,100 or 200) when using AUTO ISO
 240         PROPCASE_DELTA_SV       = 0 when ISO set manually
 241                                 = 'market' Sv96 - PROPCASE_SV_MARKET when using AUTO ISO
 242 
 243     From the above:
 244         'market' Sv96 = PROPCASE_SV_MARKET + PROPCASE_DELTA_SV
 245  */
 246 
 247 extern const ISOTable iso_table[];
 248 extern const unsigned int ISO_SIZE;
 249 
 250 short shooting_get_canon_iso_mode()             { return shooting_get_prop(PROPCASE_ISO_MODE); }
 251 short shooting_get_sv96_market()                { return shooting_get_prop(PROPCASE_SV_MARKET); }
 252 short shooting_get_sv96_real()                  { return shooting_get_prop(PROPCASE_SV); }
 253 short shooting_get_sv96_delta()                 { return shooting_get_prop(PROPCASE_DELTA_SV); }
 254 
 255 // Local shooting calculation variables
 256 static short canon_iso_base=0;
 257 static short canon_sv96_base=0;
 258 
 259 #if !defined(SV96_MARKET_OFFSET)                // Can be overriden in platform_camera.h (see IXUS700 for example)
 260 // "real" to "market" conversion definitions
 261 #define SV96_MARKET_OFFSET          69          // market-real sv96 conversion value
 262 
 263 // Conversion values for pow(2,-69/96) 'market' to 'real', and pow(2,69/96) 'real' to 'market'
 264 // Uses integer arithmetic to avoid floating point calculations. Values chosen to get as close
 265 // to the desired multiplication factor as possible within normal ISO range.
 266 #define ISO_MARKET_TO_REAL_MULT     9955
 267 #define ISO_MARKET_TO_REAL_SHIFT    14
 268 #define ISO_MARKET_TO_REAL_ROUND    8192
 269 #define ISO_REAL_TO_MARKET_MULT     3371
 270 #define ISO_REAL_TO_MARKET_SHIFT    11
 271 #define ISO_REAL_TO_MARKET_ROUND    1024
 272 #endif
 273 
 274 #define ISO_MARKET_TO_REAL(x)       (((int)x * ISO_MARKET_TO_REAL_MULT + ISO_MARKET_TO_REAL_ROUND) >> ISO_MARKET_TO_REAL_SHIFT)
 275 #define ISO_REAL_TO_MARKET(x)       (((int)x * ISO_REAL_TO_MARKET_MULT + ISO_REAL_TO_MARKET_ROUND) >> ISO_REAL_TO_MARKET_SHIFT)
 276 
 277 short shooting_get_sv96_from_iso(short iso)
 278 {
 279     // Equivalent to (short)(log2(iso/3.125)*96+0.5) [APEX equation]
 280     if (iso > 0)
 281         return (short)( log((double)(iso)*32.0/100.0)*96.0*(inv_log_2)+0.5 );
 282     return 0;
 283 }
 284 
 285 short shooting_get_iso_from_sv96(short sv96)
 286 {
 287     // APEX equation --> (int)(POWER(2,(iso/96)) * 3.125) + 0.5)
 288     return (short)( (double)pow(2, (((double)sv96)/96.0))*100.0/32.0 + 0.5 );
 289 }
 290 
 291 short shooting_iso_market_to_real(short isom)
 292 {
 293    return ISO_MARKET_TO_REAL(isom);
 294 }
 295 
 296 short shooting_iso_real_to_market(short isor)
 297 {
 298    return ISO_REAL_TO_MARKET(isor);
 299 }
 300 
 301 short shooting_sv96_market_to_real(short sv96)
 302 {
 303    return sv96 - SV96_MARKET_OFFSET;
 304 }
 305 
 306 short shooting_sv96_real_to_market(short sv96)
 307 {
 308    return sv96 + SV96_MARKET_OFFSET;
 309 }
 310 
 311 short shooting_get_iso_override_value()
 312 {
 313     short iso = conf.iso_override_value;        // Start with market value
 314     // Apply limits if needed
 315 #ifdef CAM_ISO_LIMIT_IN_HQ_BURST
 316     // Limit max ISO in HQ burst mode (also done in shooting_set_iso_real; but done here so OSD display value is correct)
 317     if (camera_info.state.mode_shooting == MODE_HIGHSPEED_BURST)
 318         if (iso > CAM_ISO_LIMIT_IN_HQ_BURST) iso = CAM_ISO_LIMIT_IN_HQ_BURST;
 319 #endif
 320 #ifdef CAM_MIN_ISO_OVERRIDE
 321     // Limit min (non-zero) ISO
 322     // Some cameras will crash if flash used and ISO set lower than this value (most easily tested in AUTO mode)
 323     if ((iso > 0) && (iso < CAM_MIN_ISO_OVERRIDE)) iso = CAM_MIN_ISO_OVERRIDE;
 324 #endif
 325 #ifdef CAM_MAX_ISO_OVERRIDE
 326     // Limit max ISO
 327     // Some cameras will crash if ISO set higher than this value (dependence on flash is unclear)
 328     if (iso > CAM_MAX_ISO_OVERRIDE) iso = CAM_MAX_ISO_OVERRIDE;
 329 #endif
 330     return shooting_iso_market_to_real(iso);    // return real value (after limits applied)
 331 }
 332 
 333 int shooting_get_iso_mode()
 334 {
 335     short isov = shooting_get_canon_iso_mode();
 336     long i;
 337     for (i=0;i<ISO_SIZE;i++)
 338     {
 339         if (iso_table[i].prop_id == isov)
 340             return iso_table[i].id;
 341     }
 342     return 0;
 343 }
 344 
 345 short shooting_get_iso_real()
 346 {
 347     short sv = shooting_get_sv96_real();
 348     if (sv == 0)
 349         return 0;
 350     return shooting_get_iso_from_sv96(sv);
 351 }
 352 
 353 // AUTOISO:EXIF
 354 short shooting_get_iso_market()
 355 {
 356     short sv = shooting_get_sv96_market() + shooting_get_sv96_delta();
 357     if (sv == 0)
 358         return 0;
 359     return shooting_get_iso_from_sv96(sv);
 360 }
 361 
 362 static void set_iso_mode(int i)
 363 {
 364     short vv = iso_table[i].prop_id;
 365     set_property_case(PROPCASE_ISO_MODE, &vv, sizeof(vv));
 366 }
 367 
 368 void shooting_set_iso_mode(int v)
 369 {
 370     int i;
 371     if (v < 50) // CHDK ID
 372     {
 373         for (i=0; i<ISO_SIZE; i++)
 374         {
 375             if (iso_table[i].id == v)
 376             {
 377                 set_iso_mode(i);
 378                 return;
 379             }
 380         }
 381     }
 382     else        // ISO value - find nearest entry in iso_table and set iso mode to that value
 383     {
 384         if (v <= iso_table[0].prop_id)    // In case no AUTO (0) entry
 385         {
 386             set_iso_mode(0);
 387             return;
 388         }
 389         for (i=0; i<ISO_SIZE-1; i++)
 390         {
 391             if ((v > iso_table[i].prop_id) && (v <= iso_table[i+1].prop_id))
 392             {
 393                 if ((v - iso_table[i].prop_id) < (iso_table[i+1].prop_id - v))
 394                     set_iso_mode(i);
 395                 else
 396                     set_iso_mode(i+1);
 397                 return;
 398             }
 399         }
 400         set_iso_mode(ISO_SIZE-1);
 401     }
 402 }
 403 
 404 void shooting_set_sv96(short sv96, short is_now)
 405 {
 406     if (!camera_info.state.mode_play)
 407     {
 408         if (is_now)
 409         {
 410             while ((shooting_is_flash_ready()!=1) || (focus_busy)) msleep(10);
 411 
 412             short iso_mode = shooting_get_canon_iso_mode();
 413             if (iso_mode >= 50)
 414                 shooting_set_iso_mode(0);   // Force AUTO mode on camera
 415 
 416             short dsv96 = sv96 + SV96_MARKET_OFFSET - canon_sv96_base;
 417 
 418             set_property_case(PROPCASE_SV_MARKET, &canon_sv96_base, sizeof(canon_sv96_base));
 419             set_property_case(PROPCASE_SV,        &sv96, sizeof(sv96));
 420             set_property_case(PROPCASE_DELTA_SV,  &dsv96, sizeof(dsv96));
 421         }
 422         else   
 423             photo_param_put_off.sv96 = sv96;
 424     }
 425 }
 426 
 427 void shooting_set_iso_real(short iso, short is_now)
 428 {
 429     if (!camera_info.state.mode_play)
 430     {
 431         if (iso > 0)
 432         {
 433 #ifdef CAM_ISO_LIMIT_IN_HQ_BURST
 434             // Limit max ISO in HQ burst mode
 435             if (camera_info.state.mode_shooting == MODE_HIGHSPEED_BURST)
 436                 if (iso > ISO_MARKET_TO_REAL(CAM_ISO_LIMIT_IN_HQ_BURST)) iso = ISO_MARKET_TO_REAL(CAM_ISO_LIMIT_IN_HQ_BURST);
 437 #endif
 438 #ifdef CAM_MIN_ISO_OVERRIDE
 439             // Limit min (non-zero) ISO
 440             if ((iso > 0) && (iso < ISO_MARKET_TO_REAL(CAM_MIN_ISO_OVERRIDE))) iso = ISO_MARKET_TO_REAL(CAM_MIN_ISO_OVERRIDE);
 441 #endif
 442 #ifdef CAM_MAX_ISO_OVERRIDE
 443             // Limit max ISO
 444             if (iso > ISO_MARKET_TO_REAL(CAM_MAX_ISO_OVERRIDE)) iso = ISO_MARKET_TO_REAL(CAM_MAX_ISO_OVERRIDE);
 445 #endif
 446             shooting_set_sv96(shooting_get_sv96_from_iso(iso), is_now);
 447         }
 448     }
 449 }
 450 
 451 static void iso_init()
 452 {
 453     // Get the camera ISO base value, store in global variable 'canon_iso_base'
 454     if (iso_table[1-iso_table[0].id].prop_id == 50)
 455         canon_iso_base = 50;
 456     else
 457         canon_iso_base = CAM_MARKET_ISO_BASE;
 458 
 459     // Get the SV96 value corresponding to the base Canon ISO for the camera
 460     // Store in global variable 'canon_sv96_base'
 461     canon_sv96_base = shooting_get_sv96_from_iso(canon_iso_base);
 462 }
 463 //-------------------------------------------------------------------
 464 // ISO section - end
 465 //-------------------------------------------------------------------
 466 
 467 //-------------------------------------------------------------------
 468 // Tv section - start
 469 //-------------------------------------------------------------------
 470 
 471 short shooting_get_tv96()                       { return shooting_get_prop(PROPCASE_TV); }
 472 
 473 // APEX96 conversion
 474 
 475 short shooting_get_tv96_from_shutter_speed(float t)
 476 {
 477     if (t > 0)
 478     {
 479         t = ((96.0 * -log(t)) * inv_log_2);
 480         if (t < 0)
 481             return (short)(t - 0.5);
 482         return (short)(t + 0.5);
 483     }
 484     return SHOOTING_TV96_INVALID;
 485 }
 486 
 487 float shooting_get_shutter_speed_from_tv96(short tv96)
 488 {
 489     return pow(2,((float)(-tv96))/96.0);
 490 }
 491 
 492 // Index of '0' entry in the tv_override array (1 sec) (see gui.c for tv_override array)
 493 #if CAM_EXT_TV_RANGE
 494 #define tv_override_zero_shift  (18+15)
 495 #else
 496 #define tv_override_zero_shift  18
 497 #endif
 498 
 499 // Get Tv override value (APEX96)
 500 static int shooting_get_tv96_override_value()
 501 {
 502     // Calculate the tv96 value for the tv override
 503     if (conf.tv_enum_type==TV_OVERRIDE_EV_STEP)
 504         return 32*(conf.tv_override_value-tv_override_zero_shift);
 505     else if (conf.tv_enum_type==TV_OVERRIDE_SHORT_EXP)
 506         return shooting_get_tv96_from_shutter_speed(((float)conf.tv_override_short_exp)/100000.0);
 507     else
 508         return shooting_get_tv96_from_shutter_speed((float)conf.tv_override_long_exp);
 509 }
 510 
 511 // Overrides
 512 
 513 // Find nearest entry in 'shutter_speeds_table' to the given 'tv96' value
 514 static int find_nearest_shutter_speed_entry(short tv96)
 515 {
 516     if (tv96 <= shutter_speeds_table[0].prop_id)
 517         return 0;
 518 
 519     int i;
 520     for (i=0; i<SS_SIZE-1; i++)
 521     {
 522         if ((tv96 > shutter_speeds_table[i].prop_id) && (tv96 <= shutter_speeds_table[i+1].prop_id))
 523         {
 524             if ((tv96 - shutter_speeds_table[i].prop_id) < (shutter_speeds_table[i+1].prop_id - tv96))
 525                 return i;
 526             else
 527                 return i+1;
 528         }
 529     }
 530 
 531     return SS_SIZE-1;
 532 }
 533 
 534 // Convert 'tv96' value to nearest Canon value from shutter_speeds_table
 535 static short find_canon_shutter_speed(short tv96)
 536 {
 537     return shutter_speeds_table[find_nearest_shutter_speed_entry(tv96)].prop_id;
 538 }
 539 
 540 void shooting_set_tv96_direct(short tv96, short is_now)
 541 {
 542     if (!camera_info.state.mode_play)
 543     {
 544         if(is_now)
 545         {
 546             set_property_case(PROPCASE_TV, &tv96, sizeof(tv96));
 547 #ifdef PROPCASE_TV2
 548             set_property_case(PROPCASE_TV2, &tv96, sizeof(tv96));   // Save override to property that will update JPEG header & Canon OSD
 549 #endif
 550         }
 551         else
 552             photo_param_put_off.tv96 = tv96;
 553     }
 554 }
 555 
 556 void shooting_set_tv96(short tv96, short is_now)
 557 {
 558     if (!camera_info.state.mode_play)
 559         shooting_set_tv96_direct(find_canon_shutter_speed(tv96), is_now);
 560 }
 561 
 562 // User Tv
 563 
 564 short shooting_get_user_tv96()
 565 {
 566 #if CAM_HAS_USER_TV_MODES
 567     return shooting_get_prop(PROPCASE_USER_TV);
 568 #else
 569     return 0;
 570 #endif
 571 }
 572 
 573 int shooting_get_user_tv_id()
 574 {
 575 #if CAM_HAS_USER_TV_MODES
 576     return shutter_speeds_table[find_nearest_shutter_speed_entry(shooting_get_user_tv96())].id;
 577 #else
 578     return 0;
 579 #endif
 580 }
 581 
 582 void shooting_set_user_tv_by_id(int v)
 583 {
 584 #if CAM_HAS_USER_TV_MODES
 585     if (!camera_info.state.mode_play)
 586     {
 587         long i;
 588         for (i=0;i<SS_SIZE;i++)
 589         {
 590             if (shutter_speeds_table[i].id == v)
 591             {
 592                 short vv = shutter_speeds_table[i].prop_id;
 593                 set_property_case(PROPCASE_USER_TV, &vv, sizeof(vv));
 594                 return;
 595             }
 596         }
 597     }
 598 #endif
 599 }
 600 
 601 void shooting_set_user_tv_by_id_rel(int v)
 602 {
 603 #if CAM_HAS_USER_TV_MODES
 604     if (!camera_info.state.mode_play)
 605     {
 606         int cv = shooting_get_user_tv_id();
 607         shooting_set_user_tv_by_id(cv+v);
 608     }
 609 #endif
 610 }
 611 
 612 void shooting_set_user_tv96(short tv96)
 613 {
 614 #if CAM_HAS_USER_TV_MODES
 615     if (!camera_info.state.mode_play)
 616     {
 617         tv96 = find_canon_shutter_speed(tv96);
 618         set_property_case(PROPCASE_USER_TV, &tv96, sizeof(tv96));
 619     }
 620 #endif
 621 }
 622 
 623 // Only needed on VxWorks
 624 #if CAM_DRAW_EXPOSITION
 625 // compare PROPCASE_TV with shutter_speeds_table
 626 char* shooting_get_tv_str()
 627 {
 628     return (char*)shutter_speeds_table[find_nearest_shutter_speed_entry(shooting_get_tv96())].name;
 629 }
 630 #endif
 631 
 632 //-------------------------------------------------------------------
 633 // Tv section - end
 634 //-------------------------------------------------------------------
 635 
 636 //-------------------------------------------------------------------
 637 // Av section - start
 638 //-------------------------------------------------------------------
 639 
 640 #define AV96_MIN (aperture_sizes_table[0].prop_id)
 641 #define AV96_MAX (aperture_sizes_table[AS_SIZE-1].prop_id)
 642 
 643 short shooting_get_av96()                       { return shooting_get_prop(PROPCASE_AV); }
 644 short shooting_get_aperture_sizes_table_size()  { return AS_SIZE; }
 645 
 646 // APEX96 conversion
 647 
 648 int shooting_get_aperture_from_av96(short av96)
 649 {
 650     if (av96)
 651         return (short)((pow(2, ((double)av96)/192.0))*1000.0 + 0.5);
 652     return -1;
 653 }
 654 
 655 short shooting_get_av96_from_aperture(int aperture)
 656 {
 657     return (int)((log((double)aperture/1000.0) * 192 * inv_log_2) + 0.5);
 658 }
 659 
 660 // Get Av override value (APEX96)
 661 short shooting_get_av96_override_value()
 662 {
 663     if (conf.av_override_value<AS_SIZE)
 664         return (short) aperture_sizes_table[conf.av_override_value].prop_id;
 665     return (short) (AV96_MAX+32*(conf.av_override_value-AS_SIZE+1));
 666 }
 667 
 668 int shooting_get_real_aperture()
 669 {
 670     return shooting_get_aperture_from_av96(shooting_get_current_av96());
 671 }
 672 
 673 static int shooting_get_min_real_aperture()
 674 {
 675     short av96;
 676     get_property_case(PROPCASE_MIN_AV, &av96, sizeof(av96));
 677     if (av96)
 678         return shooting_get_aperture_from_av96(av96);
 679     return shooting_get_real_aperture();
 680 }
 681 
 682 // Overrides
 683 
 684 // Find nearest entry in 'aperture_sizes_table' to the given 'av96' value
 685 #if (CAM_HAS_IRIS_DIAPHRAGM || CAM_DRAW_EXPOSITION)
 686 static int find_nearest_aperture_entry(short av96)
 687 {
 688     if (av96 <= aperture_sizes_table[0].prop_id)
 689         return 0;
 690 
 691     int i;
 692     for (i=0; i<AS_SIZE-1; i++)
 693     {
 694         if ((av96 > aperture_sizes_table[i].prop_id) && (av96 <= aperture_sizes_table[i+1].prop_id))
 695         {
 696             if ((av96 - aperture_sizes_table[i].prop_id) < (aperture_sizes_table[i+1].prop_id - av96))
 697                 return i;
 698             else
 699                 return i+1;
 700         }
 701     }
 702 
 703     return AS_SIZE-1;
 704 }
 705 #endif
 706 
 707 // Convert 'av96' value to nearest Canon value from aperture_sizes_table
 708 #if CAM_HAS_IRIS_DIAPHRAGM
 709 short find_canon_aperture(short av96)
 710 {
 711     return aperture_sizes_table[find_nearest_aperture_entry(av96)].prop_id;
 712 }
 713 #endif
 714 
 715 void shooting_set_av96_direct(short av96, short is_now)
 716 {
 717 #if CAM_HAS_IRIS_DIAPHRAGM
 718     if (!camera_info.state.mode_play)
 719     {
 720         if(is_now)
 721         {
 722             set_property_case(PROPCASE_AV, &av96, sizeof(av96));
 723 #ifdef PROPCASE_AV2
 724             set_property_case(PROPCASE_AV2, &av96, sizeof(av96));   // Save override to property that will update JPEG header & Canon OSD
 725 #endif
 726         }
 727         else
 728             photo_param_put_off.av96 = av96;
 729     }
 730 #endif
 731 }
 732 
 733 void shooting_set_av96(short av96, short is_now)
 734 {
 735 #if CAM_HAS_IRIS_DIAPHRAGM
 736     if (!camera_info.state.mode_play)
 737         shooting_set_av96_direct(find_canon_aperture(av96), is_now);
 738 #endif
 739 }
 740 
 741 // User Av
 742 
 743 short shooting_get_user_av96()
 744 {
 745 #if CAM_HAS_IRIS_DIAPHRAGM
 746     return shooting_get_prop(PROPCASE_USER_AV);
 747 #else
 748     return 0;
 749 #endif
 750 }
 751 
 752 int shooting_get_user_av_id()
 753 {
 754 #if CAM_HAS_IRIS_DIAPHRAGM
 755     return aperture_sizes_table[find_nearest_aperture_entry(shooting_get_user_av96())].prop_id;
 756 #else
 757     return 0;
 758 #endif
 759 }
 760 
 761 void shooting_set_user_av_by_id(int v)
 762 {
 763 #if CAM_HAS_IRIS_DIAPHRAGM
 764     long i;
 765     if (!camera_info.state.mode_play)
 766     {
 767         for (i=0;i<AS_SIZE;i++)
 768         {
 769             if (aperture_sizes_table[i].id == v)
 770             {
 771                 short vv = aperture_sizes_table[i].prop_id;
 772                 set_property_case(PROPCASE_USER_AV, &vv, sizeof(vv));
 773                 return;
 774             }
 775         }
 776     }
 777 #endif
 778 }
 779 
 780 void shooting_set_user_av_by_id_rel(int v)
 781 {
 782 #if CAM_HAS_IRIS_DIAPHRAGM
 783     if (!camera_info.state.mode_play)
 784     {
 785         int cv = shooting_get_user_av_id();
 786         shooting_set_user_av_by_id(cv+v);
 787     }
 788 #endif
 789 }
 790 
 791 void shooting_set_user_av96(short av96)
 792 {
 793 #if CAM_HAS_IRIS_DIAPHRAGM
 794     if (!camera_info.state.mode_play)
 795     {
 796         av96 = find_canon_aperture(av96);
 797         set_property_case(PROPCASE_USER_AV, &av96, sizeof(av96));
 798     }
 799 #endif
 800 }
 801 
 802 // Only needed on VxWorks
 803 #if CAM_DRAW_EXPOSITION
 804 // compare PROPCASE_AV with aperture_sizes_table
 805 char* shooting_get_av_str()
 806 {
 807     return (char*)aperture_sizes_table[find_nearest_aperture_entry(shooting_get_av96())].name;
 808 }
 809 #endif
 810 
 811 void shooting_set_nd_filter_state(short v, short is_now)
 812 {
 813 #if CAM_HAS_ND_FILTER
 814     if (!camera_info.state.mode_play)
 815     {
 816         if (is_now)
 817         {
 818 #if defined(CAM_ND_SET_AV_VALUE)
 819             short av;
 820             get_property_case(PROPCASE_MIN_AV,&av,sizeof(av));
 821             if(v==1) {
 822                 av += shooting_get_nd_value_ev96();
 823             }
 824             set_property_case(PROPCASE_AV, &av, sizeof(av));
 825 #if defined(PROPCASE_AV2)
 826             set_property_case(PROPCASE_AV2, &av, sizeof(av));
 827 #endif
 828 #endif
 829             if (v==1) {
 830                 PutInNdFilter();
 831             }
 832             else if (v==2)
 833                 PutOutNdFilter();
 834 #if defined(CAM_HAS_NATIVE_ND_FILTER) && defined(PROPCASE_ND_FILTER_STATE)
 835             int n = (v==1) ? 1 : 0;
 836             set_property_case(PROPCASE_ND_FILTER_STATE, &n, sizeof(n));
 837 #endif
 838         }
 839         else
 840             photo_param_put_off.nd_filter = v;
 841     }
 842 #endif
 843 }
 844 
 845 
 846 // get usable Av range (iris only)
 847 // Appears to be the full range, including smaller (higher F/ number) than available in Canon UI.
 848 // NOTE canon functions Min and Max refer to aperture size, CHDK refer to av96 values
 849 // returns -1 if unavailable (0 is a valid Av = F/1.0)
 850 short shooting_get_min_av96()
 851 {
 852 #if CAM_HAS_IRIS_DIAPHRAGM
 853     extern short GetUsableMaxAv(void);
 854     if (camera_info.state.mode_play)
 855     {
 856         return -1;
 857     }
 858     return GetUsableMaxAv();
 859 #else
 860     return -1;
 861 #endif
 862 }
 863 
 864 short shooting_get_max_av96()
 865 {
 866 #if CAM_HAS_IRIS_DIAPHRAGM
 867     extern short GetUsableMinAv(void);
 868     if (camera_info.state.mode_play)
 869     {
 870         return -1;
 871     }
 872     return GetUsableMinAv();
 873 #else
 874     return -1;
 875 #endif
 876 }
 877 
 878 //-------------------------------------------------------------------
 879 // Av section - end
 880 //-------------------------------------------------------------------
 881 
 882 //-------------------------------------------------------------------
 883 // Init
 884 
 885 void shooting_init()
 886 {
 887     photo_param_put_off.tv96 = PHOTO_PARAM_TV_NONE;
 888     iso_init();
 889 }
 890 
 891 //-------------------------------------------------------------------
 892 // Get file related info
 893 
 894 #ifdef CAM_FILE_COUNTER_IS_VAR
 895 extern long file_counter_var;
 896 long get_file_counter()
 897 {
 898     return file_counter_var;
 899 }
 900 long get_exposure_counter()
 901 {
 902     long v = get_file_counter();
 903     v = ((v>>4)&0x3FFF);
 904     return v;
 905 }
 906 #else
 907 extern const unsigned int param_file_counter;
 908 
 909 long get_file_counter()
 910 {
 911     long v = 0;
 912     get_parameter_data(param_file_counter, &v, 4);
 913     return v;
 914 }
 915 
 916 long get_exposure_counter()
 917 {
 918     long v = 0;
 919     get_parameter_data(param_file_counter, &v, 4);
 920     v = ((v>>4)&0x3FFF);
 921     return v;
 922 }
 923 #endif
 924 
 925 #ifndef CAM_DATE_FOLDER_NAMING
 926 void get_target_dir_name(char *dir) {
 927     extern long get_target_dir_num();
 928     sprintf(dir,"A/DCIM/%03dCANON",get_target_dir_num());
 929 }
 930 #endif
 931 
 932 //-------------------------------------------------------------------
 933 // Convert values to/from APEX 96
 934 
 935 static const double K = 12.5;               // K is the reflected-light meter calibration constant
 936 
 937 int shooting_get_luminance()                // http://en.wikipedia.org/wiki/APEX_system
 938 {
 939     short bv = shooting_get_bv96();
 940     int b = (int)(100 * K * pow(2.0,((double)(bv-168)/96.0)));
 941     return b;
 942 }
 943 
 944 //-------------------------------------------------------------------
 945 // Get override values
 946 
 947 int shooting_get_subject_distance_override_value()
 948 {
 949     if (conf.subj_dist_override_koef != SD_OVERRIDE_INFINITY)
 950         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()));
 951     else
 952         return INFINITY_DIST;
 953 }
 954 
 955 //-------------------------------------------------------------------
 956 // Get shooting value, with conversion / calculation
 957 
 958 int shooting_mode_canon2chdk(int canonmode)
 959 {
 960         int i;
 961         for (i=0; i < MODESCNT; i++)
 962     {
 963                 if (modemap[i].canonmode == canonmode)
 964                         return modemap[i].hackmode;
 965         }
 966         return 0;
 967 }
 968 
 969 int shooting_mode_chdk2canon(int hackmode)
 970 {
 971         int i;
 972         for (i=0; i < MODESCNT; i++)
 973     {
 974                 if (modemap[i].hackmode == hackmode)
 975                         return modemap[i].canonmode;
 976         }
 977         return -1; // 0 is a valid mode on old cameras!
 978 }
 979 
 980 
 981 
 982 int sd_over_modes()
 983 {  return ( 0
 984 #ifdef CAM_SD_OVER_IN_AF 
 985           + 1
 986 #endif
 987 #ifdef CAM_SD_OVER_IN_AFL
 988           + 2 
 989 #endif
 990 #ifdef CAM_SD_OVER_IN_MF
 991           + 4
 992 #endif
 993 );  }
 994 
 995 int shooting_get_lens_to_focal_plane_width()
 996 {
 997     return (int)(lens_get_focus_pos()-lens_get_focus_pos_from_lens());
 998 }
 999 
1000 int shooting_get_hyperfocal_distance_1e3_f(int av, int fl)
1001 {
1002   if ((av>0) && (fl>0) && (camera_info.circle_of_confusion>0))
1003     return (int)(((((double)fl*fl)/(av*camera_info.circle_of_confusion)*1000)+fl)+0.5);
1004   else return (-1);
1005 }
1006 
1007 int shooting_get_near_limit_f(int s, int av, int fl)
1008 {
1009   if (shooting_is_infinity_distance()) return (-1);
1010   int h_1e3 = shooting_get_hyperfocal_distance_1e3_f(av, fl);
1011   double m = ((double)(h_1e3 - fl)+500)/1000*s;
1012   int v = ((h_1e3 - 2*fl + 1000*s)+500)/1000;
1013   if ((m>0) && (v>0)) return (int)((2*m/v+1)/2);
1014   else return (-1);
1015 }
1016 
1017 int shooting_get_far_limit_f(int s, int av, int fl)
1018 {
1019   if (shooting_is_infinity_distance()) return (-1);
1020   int h_1e3 = shooting_get_hyperfocal_distance_1e3_f(av, fl);
1021   double m = ((double)(h_1e3 - fl)+500)/1000*s;
1022   int v = ((h_1e3 - 1000*s)+500)/1000;
1023   if ((m>0) && (v>0)) return (int)((2*m/v+1)/2);
1024   else return (-1); 
1025 }
1026 
1027 short shooting_is_infinity_distance()
1028 {
1029   return (shooting_get_lens_to_focal_plane_width() == 0)?1:0;
1030 }
1031 
1032 int shooting_get_canon_subject_distance()
1033 {
1034         if (conf.dof_use_exif_subj_dist) 
1035           return shooting_get_exif_subject_dist();
1036         else
1037           return (lens_get_focus_pos_from_lens());
1038 }
1039 
1040 int shooting_get_subject_distance_()
1041 {
1042    if (!conf.dof_subj_dist_as_near_limit) return shooting_get_canon_subject_distance();
1043    else return shooting_get_far_limit_f(shooting_get_canon_subject_distance(),
1044                                          shooting_get_min_real_aperture(), 
1045                                          get_focal_length(lens_get_zoom_point()));
1046 }
1047 
1048 void shooting_update_dof_values()
1049 {
1050   int hyp, hyp_1e3, av_1e3, v;
1051   int dist = shooting_get_subject_distance_();
1052   int zoom_point = lens_get_zoom_point();
1053   int fl = get_focal_length(zoom_point);
1054   short f_focus_ok = shooting_get_focus_ok();
1055   short f_hyp_calc = 0, f_dist_calc = 0;
1056   short min_av96_zoom_point = 0;
1057   short av96 = shooting_get_user_av96();
1058   short curr_av96 = shooting_get_current_av96();
1059   short prop_av96 = shooting_get_av96();
1060   short min_av96;
1061 
1062   if (!min_av96_zoom_point_tbl) {
1063     min_av96_zoom_point_tbl = (short *) malloc(zoom_points * sizeof(short));
1064     if (min_av96_zoom_point_tbl) {
1065       memset(min_av96_zoom_point_tbl, 0, zoom_points * sizeof(short));
1066     }
1067     else {
1068         return;
1069     }
1070   } else min_av96_zoom_point = min_av96_zoom_point_tbl[zoom_point]; 
1071 
1072   if (min_av96_zoom_point==0 && shooting_in_progress()) { 
1073     get_property_case(PROPCASE_MIN_AV, &min_av96, sizeof(min_av96));
1074     min_av96_zoom_point_tbl[zoom_point] = min_av96;
1075   }
1076 
1077   if ((camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_AV) && (av96>0) && !f_focus_ok) { 
1078     if (av96 < min_av96_zoom_point) av96 = min_av96_zoom_point;
1079   }
1080   else av96 = (abs(curr_av96-prop_av96)<2)?prop_av96:curr_av96;
1081 
1082   av_1e3 = shooting_get_aperture_from_av96(av96);
1083   hyp_1e3 = camera_info.dof_values.hyperfocal_distance_1e3;
1084   hyp = camera_info.dof_values.hyperfocal_distance;
1085   
1086   if (camera_info.dof_values.aperture_value!=av_1e3 || camera_info.dof_values.focal_length!=fl || (hyp_1e3<0)) {
1087     //calc new hyperfocal distance and min stack distance
1088     f_hyp_calc = 1;
1089     hyp_1e3 = -1;
1090     hyp = -1;
1091     camera_info.dof_values.aperture_value = av_1e3;
1092     camera_info.dof_values.focal_length = fl;
1093     hyp_1e3 = shooting_get_hyperfocal_distance_1e3_f(av_1e3, fl);
1094     if (hyp_1e3>0) {
1095       hyp = (hyp_1e3+500)/1000;
1096       camera_info.dof_values.min_stack_distance = CAMERA_MAX_DIST;
1097       v = ((hyp_1e3 - fl)/250 + 2 + 1)/2;
1098       if (v>0) {
1099         int m = ((fl*((fl - hyp_1e3)/1000 - 1)/500)/v + 1)/2;
1100         int m2 = (int)((((double)hyp*(2*fl - hyp_1e3)/1000))/v + 0.5);
1101         camera_info.dof_values.min_stack_distance = sqrt(m*m - m2) - m;
1102       }  
1103     }
1104   }
1105 
1106   if ((camera_info.dof_values.subject_distance!=dist || (camera_info.dof_values.hyperfocal_distance_1e3!=hyp_1e3)) && (hyp_1e3>0)) {
1107     //calc new NEAR, FAR, DOF values
1108     f_dist_calc = 1;
1109     camera_info.dof_values.subject_distance = dist;
1110     camera_info.dof_values.near_limit = -1;
1111     camera_info.dof_values.far_limit = -1;
1112     camera_info.dof_values.depth_of_field = -1;
1113     if ((av_1e3>0) && (fl>0) && (dist>0) && (shooting_is_infinity_distance()==0) && (hyp_1e3>0)) {
1114       double m = ((double)(hyp_1e3 - fl)/1000 * dist) + 0.5;
1115       if (conf.dof_subj_dist_as_near_limit) { 
1116           camera_info.dof_values.near_limit = dist;
1117       } else {
1118         int v = ((((hyp_1e3 - 2*fl + 1000*dist)/500) + 1)/2);
1119             if (v>0) camera_info.dof_values.near_limit = (int)(m/v);
1120           }
1121       int v = ((((hyp_1e3 - 1000*dist)/500) + 1)/2);
1122       if (v>0) camera_info.dof_values.far_limit = (int)(m/v);
1123       if ((camera_info.dof_values.near_limit>0) && (camera_info.dof_values.far_limit>0)) {
1124           camera_info.dof_values.depth_of_field = camera_info.dof_values.far_limit - camera_info.dof_values.near_limit;
1125       }
1126     }
1127   }
1128   camera_info.dof_values.hyperfocal_distance_1e3 = hyp_1e3;
1129   camera_info.dof_values.hyperfocal_distance = hyp;
1130   f_focus_ok = (f_focus_ok && shooting_get_focus_ok());
1131   camera_info.dof_values.hyperfocal_valid = (f_focus_ok || (camera_info.dof_values.hyperfocal_valid && !f_hyp_calc));
1132   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()));
1133   return;
1134 }
1135 
1136 int shooting_get_subject_distance()
1137 {
1138   shooting_update_dof_values();
1139   return camera_info.dof_values.subject_distance;
1140 }
1141 
1142 int shooting_get_hyperfocal_distance()
1143 {
1144   shooting_update_dof_values();
1145   return camera_info.dof_values.hyperfocal_distance;
1146 }
1147 
1148 static int focus_interlock_bypass = 0;
1149 
1150 short shooting_can_focus()
1151 {
1152     if(camera_info.state.mode_play) return 0 ;                 // don't focus in playback mode
1153 
1154     if(focus_interlock_bypass) return 1;                       // checks disabled, allow
1155 
1156     if( camera_info.state.mode_video == 1) return 1;           // FIXME : default to MF enabled in video mode for now
1157 
1158 #ifdef CAM_SD_OVER_IN_AFL
1159     if (shooting_get_prop(PROPCASE_AF_LOCK)==1 ) return 1;     // allow focus if AFL enabled and camera can focus that way?
1160 #endif
1161 #ifdef CAM_SD_OVER_IN_MF
1162     if (shooting_get_prop(PROPCASE_FOCUS_MODE)==1 ) return 1;  // allow focus if MF enabled and camera can focus that way?
1163 #endif
1164 
1165 #ifdef CAM_SD_OVER_IN_AF 
1166 #ifdef PROPCASE_CONTINUOUS_AF
1167     if (shooting_get_prop(PROPCASE_CONTINUOUS_AF)) return 0;   // don't focus in continuous AF mode,
1168 #endif
1169 #ifdef PROPCASE_SERVO_AF
1170     if (shooting_get_prop(PROPCASE_SERVO_AF)) return 0;        // don't focus in servo AF mode
1171 #endif
1172     if (    (shooting_get_prop(PROPCASE_AF_LOCK)==0)           // allow focus when in AF mode (i.e AFL or MF not enabled)?
1173          && (shooting_get_prop(PROPCASE_FOCUS_MODE)==0 )) return 1;
1174 #endif
1175     return 0;
1176 }
1177 
1178 short shooting_get_common_focus_mode()
1179 {
1180 #if !CAM_HAS_MANUAL_FOCUS
1181     return conf.subj_dist_override_koef;         // SD override state 0=OFF, 1=ON, 2=Infinity if camera has no native MF mode
1182 #else
1183     return shooting_get_focus_mode();            // 0=Auto, 1=manual
1184 #endif
1185 }
1186 
1187 int shooting_is_flash_ready()
1188 {
1189     int t = shooting_get_flash_mode();
1190     if ((t != 2) && (shooting_in_progress()))
1191         if (shooting_is_flash()) 
1192             return IsStrobeChargeCompleted();
1193     return 1;
1194 }
1195 
1196 //-------------------------------------------------------------------
1197 // Overrides for camera settings
1198 
1199 #if CAM_QUALITY_OVERRIDE
1200 void shooting_set_image_quality(int imq)
1201 {
1202     if (imq != 3)
1203     {
1204         set_property_case(PROPCASE_QUALITY, &imq, sizeof(imq));
1205     }
1206 }
1207 #endif
1208 
1209 void shooting_set_zoom(int v)
1210 {
1211     if (!camera_info.state.mode_play)
1212     {
1213 #if CAM_REFOCUS_AFTER_ZOOM
1214         int dist = shooting_get_subject_distance();
1215         lens_set_zoom_point(v);
1216 #if defined(CAM_NEED_SET_ZOOM_DELAY)
1217         msleep(CAM_NEED_SET_ZOOM_DELAY);
1218 #endif
1219         shooting_set_focus(dist, SET_NOW);
1220 #else // CAM_REFOCUS_AFTER_ZOOM
1221         lens_set_zoom_point(v);
1222 #endif // CAM_REFOCUS_AFTER_ZOOM
1223     }
1224 }
1225 
1226 void shooting_set_zoom_rel(int v)
1227 {
1228     int cv = shooting_get_zoom();
1229     if (!camera_info.state.mode_play)
1230     {
1231         shooting_set_zoom(cv+v);
1232     }
1233 }
1234 
1235 void shooting_set_zoom_speed(int v) {
1236     if (!camera_info.state.mode_play)
1237     {
1238         lens_set_zoom_speed(v);
1239     }
1240 }
1241 
1242 void set_focus_bypass(int m)
1243 {
1244         focus_interlock_bypass = m ;
1245 }
1246 
1247 void shooting_set_focus(int v, short is_now)
1248 {
1249     int s=v;
1250     if (!camera_info.state.mode_play)
1251     {
1252         if (is_now && shooting_can_focus()) 
1253         {
1254             if (conf.dof_subj_dist_as_near_limit)
1255             {
1256                 s=shooting_get_near_limit_f(v,shooting_get_min_real_aperture(),get_focal_length(lens_get_zoom_point()));
1257             }
1258             if (!conf.dof_use_exif_subj_dist && (s != INFINITY_DIST)) 
1259                 s+=shooting_get_lens_to_focal_plane_width();
1260             lens_set_focus_pos(s); 
1261         }
1262         else
1263             photo_param_put_off.subj_dist=v;
1264     }
1265 }
1266 
1267 void shooting_video_bitrate_change(int v)
1268 {
1269 #if CAM_CHDK_HAS_EXT_VIDEO_MENU
1270     int m[]={1,2,3,4,5,6,7,8,10,12};  // m[v]/4 = bitrate*1x
1271     if (v>=(sizeof(m)/sizeof(m[0])))
1272         v=(sizeof(m)/sizeof(m[0]))-1;
1273     change_video_tables(m[v],4);
1274 #endif
1275 }
1276 #ifdef CAM_MOVIEREC_NEWSTYLE
1277 void shooting_video_minbitrate_change(int v)
1278 {
1279     char m[]={1,2,3,4,5,6,7,8,9,10};  // m[v]/10 = bitrate*1x
1280     if (v>=(sizeof(m)/sizeof(m[0])))
1281         v=(sizeof(m)/sizeof(m[0]))-1;
1282     change_video_minbitrate(m[v],10);
1283 }
1284 unsigned int shooting_get_video_recorded_size_kb()
1285 {
1286     return get_video_recorded_size_kb();
1287 }
1288 #endif
1289 
1290 //-------------------------------------------------------------------
1291 
1292 #if CAM_REAR_CURTAIN
1293 void shooting_set_flash_sync_curtain(int curtain)
1294 {
1295     set_property_case(PROPCASE_FLASH_SYNC_CURTAIN, &curtain, sizeof(curtain));
1296 }
1297 #endif
1298 
1299 void unlock_optical_zoom(void)
1300 {
1301 #if CAM_CAN_UNLOCK_OPTICAL_ZOOM_IN_VIDEO
1302     extern void UnsetZoomForMovie();
1303     if (conf.unlock_optical_zoom_for_video)
1304         UnsetZoomForMovie();
1305 #endif
1306 
1307 #if CAM_EV_IN_VIDEO
1308     set_ev_video_avail(0);
1309 #endif
1310 }
1311 
1312 int shooting_set_mode_canon(int canonmode)
1313 {
1314     if (canonmode == -1 || !rec_mode_active())
1315         return 0;
1316     SetCurrentCaptureModeType(canonmode);
1317     // updated cached mode information immediately
1318     mode_get();
1319     return 1;
1320 }
1321 
1322 int shooting_set_mode_chdk(int mode)
1323 {
1324     return shooting_set_mode_canon(shooting_mode_chdk2canon(mode));
1325 }
1326 
1327 //-------------------------------------------------------------------
1328 // Bracketing functions
1329 
1330 EXPO_BRACKETING_VALUES bracketing;
1331 
1332 // Adjustment multipliers for bracketing types
1333 static int bracket_steps[4][2] = {
1334     {  1, -1 },     // +/- option - shoot at 0, +1, -1
1335     { -1, -1 },     // -   option - shoot at 0, -1, -2
1336     {  1,  1 },     // +   option - shoot at 0, +1, +2
1337     { -1,  1 },     // -/+ option - shoot at 0, -1, +1
1338 };
1339 static int bracket_delta[4][2] = {
1340     {  1,  0 },     // +/- option - shoot at 0, +1, -1
1341     {  1,  1 },     // -   option - shoot at 0, -1, -2
1342     {  1,  1 },     // +   option - shoot at 0, +1, +2
1343     {  1,  0 },     // -/+ option - shoot at 0, -1, +1
1344 };
1345 
1346 static void shooting_tv_bracketing(int when)
1347 {
1348     // first shot? (actually this is called just after the first shot has been taken)
1349     if (bracketing.shoot_counter == 0)
1350     {
1351         // if Tv override is enabled... (this was adapted from function shooting_expo_param_override() )
1352         if (is_tv_override_enabled)
1353         {
1354             // ...use Tv override value as seed for bracketing:
1355             bracketing.tv96 = shooting_get_tv96_override_value();
1356         }
1357         // Tv override is disabled, use camera's opinion of Tv for bracketing seed value.
1358         else 
1359         {
1360             if (!(camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_TV || camera_info.state.mode_shooting==MODE_LONG_SHUTTER))
1361                 bracketing.tv96=shooting_get_tv96();
1362             else
1363                 bracketing.tv96=shooting_get_user_tv96();
1364         }
1365         bracketing.tv96_step = 32*conf.tv_bracket_value;
1366     }
1367 
1368     // Adjust delta TV value for shot based on shot number
1369     bracketing.dtv96 += (bracketing.tv96_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1370     // Calculate new TV (note, need to subtract delta because higher values are shorter shutter speeds / darker images)
1371     short value = bracketing.tv96 - (bracketing.dtv96 * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1372 
1373     // Inc for next shot
1374     bracketing.shoot_counter++;
1375 
1376     // Apply value for next shot to be taken
1377     shooting_set_tv96_direct(value, when);
1378 }
1379 
1380 static void shooting_av_bracketing(int when)
1381 {
1382     // first shot? (actually this is called just after the first shot has been taken)
1383     if (bracketing.shoot_counter == 0)
1384     {
1385         if (!(camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_AV))
1386             bracketing.av96 = shooting_get_av96();
1387         else
1388             bracketing.av96 = shooting_get_user_av96();
1389         bracketing.av96_step = 32*conf.av_bracket_value;
1390     }
1391 
1392     // Adjust delta AV value for shot based on shot number
1393     bracketing.dav96 += (bracketing.av96_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1394     // Calculate new AV (note, need to subtract delta because higher values are smaller apertures / darker images)
1395     short value = bracketing.av96 - (bracketing.dav96 * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1396 
1397     // Inc for next shot
1398     bracketing.shoot_counter++;
1399 
1400     // Apply value for next shot to be taken
1401     if (value != bracketing.av96)
1402     {
1403         shooting_set_av96_direct(value, when);
1404 #ifdef CAM_AV_OVERRIDE_IRIS_FIX
1405         extern int MoveIrisWithAv(short*);
1406         MoveIrisWithAv(&value);
1407 #endif
1408     }
1409 }
1410 
1411 static void shooting_iso_bracketing(int when)
1412 {
1413     // first shot? (actually this is called just after the first shot has been taken)
1414     if (bracketing.shoot_counter == 0)
1415     {
1416         bracketing.iso = shooting_get_iso_real();
1417         bracketing.iso_step = shooting_iso_market_to_real(conf.iso_bracket_value);
1418     }
1419 
1420     // Adjust delta ISO value for shot based on shot number
1421     bracketing.diso += (bracketing.iso_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1422     // Calculate new ISO (higher ISO = brighter image)
1423     short value = bracketing.iso + (bracketing.diso * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1424     if (value <= 0) value = 50;
1425 
1426     // Inc for next shot
1427     bracketing.shoot_counter++;
1428 
1429     // Apply value for next shot to be taken
1430     shooting_set_iso_real(value, when);
1431 }
1432 
1433 static void shooting_subject_distance_bracketing(int when)
1434 {
1435     // first shot? (actually this is called just after the first shot has been taken)
1436     if (bracketing.shoot_counter == 0)
1437     {
1438         bracketing.subj_dist = shooting_get_subject_distance();
1439         bracketing.subj_dist_step = conf.subj_dist_bracket_value;
1440     }
1441 
1442     // Adjust delta SD value for shot based on shot number
1443     bracketing.dsubj_dist += (bracketing.subj_dist_step * bracket_delta[conf.bracket_type][bracketing.shoot_counter&1]);
1444     // Calculate new SD
1445     int value = bracketing.subj_dist + (bracketing.dsubj_dist * bracket_steps[conf.bracket_type][bracketing.shoot_counter&1]);
1446     if (value < CAMERA_MIN_DIST) value = CAMERA_MIN_DIST;
1447     else if (value > CAMERA_MAX_DIST) value = CAMERA_MAX_DIST;
1448 
1449     // Inc for next shot
1450     bracketing.shoot_counter++;
1451 
1452     // Apply value for next shot to be taken
1453     shooting_set_focus(value, when);
1454 }
1455 
1456 void bracketing_reset()
1457 {
1458     memset(&bracketing,0,sizeof(bracketing));
1459     memset(&photo_param_put_off,0,sizeof(photo_param_put_off));
1460     photo_param_put_off.tv96=PHOTO_PARAM_TV_NONE;
1461 }
1462 
1463 void bracketing_step(int when)
1464 {
1465     if (is_tv_bracketing_enabled)       shooting_tv_bracketing(when);
1466     else if (is_av_bracketing_enabled)  shooting_av_bracketing(when);
1467     else if (is_iso_bracketing_enabled) shooting_iso_bracketing(when);
1468     else if (is_sd_bracketing_enabled)  shooting_subject_distance_bracketing(when);           
1469 }
1470 
1471 void shooting_bracketing(void)
1472 {  
1473     if (shooting_get_drive_mode()!=0)  
1474     {
1475         if (camera_info.state.mode_shooting!=MODE_STITCH && camera_info.state.mode_shooting!=MODE_BEST_IMAGE)
1476         {
1477             if (camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_PROCESSING)
1478                 bracketing_reset() ;
1479             bracketing_step(SET_NOW) ;
1480         }
1481     }
1482 }
1483 
1484 //-------------------------------------------------------------------
1485 // Other state test functions. 
1486 // Not strictly shooting related; but somehow ended up here.
1487 
1488 // Check if any shutter, aperture or ISO overrides active, for cameras
1489 // that require capt seq hack to override canon "quick press" behavior
1490 // caller must save regs
1491 int captseq_hack_override_active()
1492 {
1493     if (camera_info.state.state_kbd_script_run) {
1494         if ( photo_param_put_off.tv96 != PHOTO_PARAM_TV_NONE || photo_param_put_off.sv96 )
1495             return 1;
1496 #if CAM_HAS_IRIS_DIAPHRAGM
1497         if(photo_param_put_off.av96)
1498             return 1;
1499 #endif
1500     }
1501     if(conf.override_disable==1)
1502         return 0;
1503     if(is_iso_override_enabled)
1504         return 1;
1505     if(is_tv_override_enabled)
1506         return 1;
1507 #if CAM_HAS_IRIS_DIAPHRAGM
1508     if(is_av_override_enabled)
1509         return 1;
1510 #endif
1511     return 0;
1512 }
1513 
1514 #ifdef CAM_SIMPLE_MOVIE_STATUS
1515 extern int simple_movie_status;
1516 #else
1517 extern int movie_status;
1518 #endif
1519 
1520 void set_movie_status(int status)
1521 {
1522 #ifndef CAM_SIMPLE_MOVIE_STATUS
1523     switch(status)
1524     {
1525         case 1:
1526             if (movie_status == VIDEO_RECORD_IN_PROGRESS)
1527             {
1528                 movie_status = VIDEO_RECORD_STOPPED;
1529             }
1530             break;
1531         case 2:
1532             if (movie_status == VIDEO_RECORD_STOPPED)
1533             {
1534                 movie_status = VIDEO_RECORD_IN_PROGRESS;
1535             }
1536             break;
1537         case 3:
1538             if (movie_status == VIDEO_RECORD_STOPPED || movie_status == VIDEO_RECORD_IN_PROGRESS)
1539             {
1540                 movie_status = VIDEO_RECORD_STOPPING;
1541             }
1542             break;
1543     }
1544 #else // CAM_SIMPLE_MOVIE_STATUS
1545       // no known way to control the recording process
1546 #endif
1547 }
1548 
1549 int get_movie_status()
1550 {
1551 #ifndef CAM_SIMPLE_MOVIE_STATUS
1552     return movie_status;
1553 #else
1554     // firmware movie_status interpreted as: zero - not recording, nonzero - recording
1555     return simple_movie_status?VIDEO_RECORD_IN_PROGRESS:VIDEO_RECORD_STOPPED;
1556 #endif
1557 }
1558 
1559 // Return whether video is being recorded
1560 int is_video_recording()
1561 {
1562 #ifndef CAM_SIMPLE_MOVIE_STATUS
1563 #if defined(CAM_HAS_MOVIE_DIGEST_MODE)
1564     // If camera has movie digest mode then movie_status values are different than previous models
1565     // 'movie_status' values
1566     //      0 - after startup
1567     //      1 - movie recording stopped
1568     //      4 - movie recording in progress, or in 'movie digest' scene mode
1569     //      5 - movie recording stopping
1570     //      6 - in video mode, not recording
1571     return ((movie_status == VIDEO_RECORD_IN_PROGRESS) && (camera_info.state.mode_shooting != MODE_VIDEO_MOVIE_DIGEST));
1572 #else
1573     // 'movie_status' values
1574     //      0 - after startup
1575     //      1 - movie recording stopped
1576     //      4 - movie recording in progress
1577     //      5 - movie recording stopping
1578     return (movie_status > 1);
1579 #endif
1580 #else // CAM_SIMPLE_MOVIE_STATUS
1581     return (simple_movie_status!=0);
1582 #endif
1583 }
1584 
1585 // Converted from MODE_IS_VIDEO macro (philmoz July 2011)
1586 int mode_is_video(int m)
1587 {
1588     m = m & MODE_SHOOTING_MASK;
1589     return (m==MODE_VIDEO_STD ||
1590             m==MODE_VIDEO_SPEED ||
1591             m==MODE_VIDEO_COMPACT ||
1592             m==MODE_VIDEO_MY_COLORS ||
1593             m==MODE_VIDEO_COLOR_ACCENT ||
1594             m==MODE_VIDEO_COLOR_SWAP ||
1595             m==MODE_VIDEO_MINIATURE ||
1596             m==MODE_VIDEO_TIME_LAPSE ||
1597             m==MODE_VIDEO_IFRAME_MOVIE ||
1598             m==MODE_VIDEO_M ||
1599             m==MODE_VIDEO_STAR_TIME_LAPSE ||
1600             m==MODE_VIDEO_SHORT_CLIP
1601         // not clear if this should be considered a video mode ?
1602         //  m==MODE_VIDEO_MOVIE_DIGEST
1603         );
1604 }
1605 
1606 // override in platform/<cam>/main.c if playrec_mode is not found or different
1607 int __attribute__((weak)) rec_mode_active(void)
1608 {
1609     return (playrec_mode==2 || playrec_mode==4 || playrec_mode==5);
1610 }
1611 
1612 int mode_get(void)
1613 {
1614     int mode, t=0xFF;
1615 
1616     mode = (rec_mode_active())?MODE_REC:MODE_PLAY;
1617 
1618 #ifdef CAM_SWIVEL_SCREEN
1619     extern int screen_opened(void);     // 0 not open, non-zero open
1620     extern int screen_rotated(void);    // 0 not rotated, non-zero rotated
1621 
1622     mode |= (screen_opened())?MODE_SCREEN_OPENED:0;
1623     mode |= (screen_rotated())?MODE_SCREEN_ROTATED:0;
1624 #endif
1625 
1626 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
1627     extern void update_screen_dimensions();
1628     update_screen_dimensions();
1629 #endif
1630 
1631     get_property_case(PROPCASE_SHOOTING_MODE, &t, 4);
1632 #ifdef CAM_MASK_VID_REC_ACTIVE
1633     mode |= shooting_mode_canon2chdk(t & (~CAM_MASK_VID_REC_ACTIVE));
1634 #else
1635     mode |= shooting_mode_canon2chdk(t);
1636 #endif
1637 
1638     // Set camera state variables from mode info
1639     camera_info.state.mode = mode;
1640     camera_info.state.mode_shooting = mode & MODE_SHOOTING_MASK;
1641     camera_info.state.mode_video = mode_is_video(mode);
1642     camera_info.state.mode_rec = ((mode & MODE_MASK) == MODE_REC);
1643     camera_info.state.mode_rec_or_review = camera_info.state.mode_rec && (recreview_hold==0 || conf.show_osd_in_review);
1644     camera_info.state.mode_play = ((mode & MODE_MASK) == MODE_PLAY);
1645     camera_info.state.mode_photo = (camera_info.state.mode_play || !(camera_info.state.mode_video || (mode&MODE_SHOOTING_MASK)==MODE_STITCH));
1646 
1647 #ifdef CAM_CLEAN_OVERLAY
1648     extern void handle_clean_overlay();
1649     handle_clean_overlay();
1650 #endif
1651 
1652     return (mode);
1653 }
1654 
1655 //-------------------------------------------------------------------
1656 // Exposure control in video
1657 
1658 #if CAM_EV_IN_VIDEO
1659 
1660 int ev_video_avail;
1661 int ev_video;
1662 int save_tv_video;
1663 int tv_min_video;
1664 
1665 int get_ev_video_avail(void)
1666 {
1667     return ev_video_avail;
1668 }
1669 
1670 int get_ev_video(void)
1671 {
1672     return ev_video;
1673 }
1674 
1675 void set_ev_video_avail(int x)
1676 {
1677     extern void ExpCtrlTool_StartContiAE(int, int);
1678     extern void ExpCtrlTool_StopContiAE(int, int);
1679 
1680     if (ev_video_avail==x) return;
1681     ev_video_avail=x;
1682     if (x)
1683     {
1684         ev_video=0;
1685         ExpCtrlTool_StopContiAE(0,0);
1686         get_property_case(PROPCASE_TV,&save_tv_video,2);
1687         if (camera_info.state.mode_shooting==MODE_VIDEO_SPEED)
1688             tv_min_video=577;   // 1/60
1689         else
1690             tv_min_video=480;   //1/30
1691     }
1692     else
1693         ExpCtrlTool_StartContiAE(0,0);
1694 }
1695 
1696 void set_ev_video(int x)
1697 {
1698     short ev, tv;
1699     if ((x<-4)||(x>4))
1700         return;
1701 
1702     ev=48*x;
1703     tv=save_tv_video-ev;
1704     if (tv>=tv_min_video)
1705     {
1706         ev_video=x;
1707         extern short SetAE_ShutterSpeed(short* tv);
1708         SetAE_ShutterSpeed(&tv);
1709     }
1710 }
1711 
1712 #endif
1713 
1714 //-------------------------------------------------------------------
1715 // Main exposure override function called from capt_seq_task()
1716 
1717 static void shooting_set_flash_override()
1718 {
1719     int mode, flash, power;
1720     flash = 1;
1721 
1722     // Set flash mode & override
1723     if ((conf.flash_video_override && is_video_recording()) || (!conf.flash_video_override))
1724     {
1725         if (conf.flash_manual_override)
1726         {
1727             mode = 1;   // Manual flash
1728             power = conf.flash_video_override_power;
1729             set_property_case(PROPCASE_FLASH_ADJUST_MODE, &mode, sizeof(mode));
1730             set_property_case(PROPCASE_FLASH_FIRE, &flash, sizeof(flash));
1731             set_property_case(PROPCASE_FLASH_MANUAL_OUTPUT, &power, sizeof(power));
1732         }
1733         else if (conf.flash_enable_exp_comp)
1734         {
1735             mode = 0;   // Auto flash
1736             power = (conf.flash_exp_comp - 9) * 32;
1737             set_property_case(PROPCASE_FLASH_ADJUST_MODE, &mode, sizeof(mode));
1738             set_property_case(PROPCASE_FLASH_FIRE, &flash, sizeof(flash));
1739 #if defined(PROPCASE_FLASH_EXP_COMP)
1740             set_property_case(PROPCASE_FLASH_EXP_COMP, &power, sizeof(power));
1741 #endif
1742 #if defined(PROPCASE_EXT_FLASH_EXP_COMP)
1743             set_property_case(PROPCASE_EXT_FLASH_EXP_COMP, &power, sizeof(power));
1744 #endif
1745         }
1746     }
1747 }
1748 
1749 void shooting_expo_param_override_thumb(void)
1750 {
1751     if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.tv96 != PHOTO_PARAM_TV_NONE))
1752     {
1753         shooting_set_tv96_direct(photo_param_put_off.tv96, SET_NOW);
1754         photo_param_put_off.tv96=PHOTO_PARAM_TV_NONE;
1755     }
1756     else if (is_tv_override_enabled)
1757     {
1758         shooting_set_tv96_direct(shooting_get_tv96_override_value(),SET_NOW);
1759     }
1760 
1761     if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.sv96))
1762     {
1763         shooting_set_sv96(photo_param_put_off.sv96, SET_NOW);
1764         photo_param_put_off.sv96=0;
1765     }
1766     else if (is_iso_override_enabled)
1767         shooting_set_iso_real(shooting_get_iso_override_value(), SET_NOW);
1768     else if (conf.autoiso_enable && shooting_get_flash_mode()/*NOT FOR FLASH AUTO MODE*/ && autoiso_and_bracketing_overrides_are_enabled)
1769         shooting_set_autoiso(shooting_get_iso_mode());
1770 
1771     if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.av96))
1772     {
1773         shooting_set_av96_direct(photo_param_put_off.av96, SET_NOW);
1774         photo_param_put_off.av96=0;
1775     }
1776     else if (is_av_override_enabled)
1777         shooting_set_av96_direct(shooting_get_av96_override_value(), SET_NOW);
1778 
1779     if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.subj_dist))
1780     {
1781         shooting_set_focus(photo_param_put_off.subj_dist, SET_NOW);
1782         photo_param_put_off.subj_dist=0;
1783     }
1784     else if (is_sd_override_enabled)
1785         shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);
1786 
1787 #if CAM_HAS_ND_FILTER
1788     if ((camera_info.state.state_kbd_script_run) && (photo_param_put_off.nd_filter))
1789     {
1790         shooting_set_nd_filter_state(photo_param_put_off.nd_filter, SET_NOW);
1791         photo_param_put_off.nd_filter=0;
1792     }
1793     else if (conf.nd_filter_state && !(conf.override_disable==1))
1794         shooting_set_nd_filter_state(conf.nd_filter_state, SET_NOW);
1795 #endif
1796 
1797 #if CAM_REAR_CURTAIN
1798     shooting_set_flash_sync_curtain(conf.flash_sync_curtain);
1799 #endif
1800 
1801     // Set flash mode & override
1802     shooting_set_flash_override();
1803 
1804 #if CAM_QUALITY_OVERRIDE
1805     // this doesn't really need to be set in the override hook.
1806     // should only need to be set once if the users doesn't change back, but doing it here ensures it is set
1807     shooting_set_image_quality(conf.fast_image_quality);
1808 #endif
1809 
1810     libscriptapi->shoot_hook(SCRIPT_SHOOT_HOOK_PRESHOOT);
1811 }
1812 
1813 // Override ISO settings only
1814 // need to do this before exposure calc for ISO, as well as after on some cameras
1815 void shooting_expo_iso_override_thumb(void)
1816 {
1817     if ((camera_info.state.state_kbd_script_run) && (photo_param_put_off.sv96))
1818     {
1819         shooting_set_sv96(photo_param_put_off.sv96, SET_NOW);
1820         // photo_param_put_off.sv96 is not reset here, it will be reset in next call to shooting_expo_param_override
1821     }
1822     else if (is_iso_override_enabled)
1823         shooting_set_iso_real(shooting_get_iso_override_value(), SET_NOW);
1824     else if (conf.autoiso_enable && shooting_get_flash_mode()/*NOT FOR FLASH AUTO MODE*/ && autoiso_and_bracketing_overrides_are_enabled)
1825         shooting_set_autoiso(shooting_get_iso_mode());
1826 
1827 #if defined(CAM_HAS_ND_FILTER) && defined(CAM_HAS_NATIVE_ND_FILTER)
1828     if ((camera_info.state.state_kbd_script_run) && (photo_param_put_off.nd_filter))
1829     {
1830         shooting_set_nd_filter_state(photo_param_put_off.nd_filter, SET_NOW);
1831         //photo_param_put_off.nd_filter=0;
1832     }
1833     else if (conf.nd_filter_state && !(conf.override_disable==1))
1834         shooting_set_nd_filter_state(conf.nd_filter_state, SET_NOW);
1835 #endif
1836 
1837     // Set flash mode & override
1838     shooting_set_flash_override();
1839 }
1840 
1841 /*
1842 switch camera between playback (0) and record(1)
1843 uses switch_mode_usb if a usb connection is present
1844 */
1845 void shooting_set_playrec_mode(int mode)
1846 {
1847     // use PTP compatible switch if usb bit power detected, and USB remote not configured to use USB
1848     // TODO should just check the USB bit seen by canon firmware (after masking)
1849     if (get_usb_bit() && !(conf.remote_enable == 1 && conf.remote_input_channel == REMOTE_INPUT_USB))
1850     {
1851         switch_mode_usb(mode);
1852         return;
1853     }
1854     if(mode)
1855         levent_set_record();
1856     else
1857         levent_set_play();
1858 }

/* [<][>][^][v][top][bottom][index][help] */