Last active
June 4, 2024 01:49
-
-
Save pigeonhill/600ce3c066c5f8f22b722a2a311b2c21 to your computer and use it in GitHub Desktop.
Depth Of Field Info script Chdk version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
@DOFIC | |
Rev 0.835 | |
Garry George | |
@chdk_version 1.5 | |
# show_DOFIC = 1 "Display DOFIC?" {No Yes} | |
# show_coc = 0 "Show Inf focus blurs?" {No Yes} | |
# time_2_show = 5 "Display timeout (s)" [3 30] | |
# pos = 1 "Vertical position" [0 14] | |
--]] | |
require('rawoplib') | |
set_config_value(2270,"Always") | |
set_config_value(2271,time_2_show) | |
set_config_value(2270,1) | |
set_config_value(2151,0) | |
set_config_value(2152,0) | |
function restore() | |
set_console_layout(0,0,45,14) | |
end | |
infinity = 999999 -- an acceptably large number that CHDK can handle and that is beyond Canon reporting | |
dof = get_dofinfo() | |
coc = dof.coc -- CHDK infinity blur (um) at the hyperfocal, ie the defocus Circle of Confusion, which the script uses as the overlap criterion | |
N, xx, x, ndof, fdof, f, last_x, last_fdof, last_ndof, last_f, last_N = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
last_step_x, last_step_f, last_step_N = 0, 0, 0 | |
ecnt = get_exp_count() | |
no_image = true | |
min = coc*36000/(15*rawop.get_jpeg_width()) -- estimate of 2 sensor pixels infinity focusing limit | |
function something_changed() | |
dof = get_dofinfo() | |
N = dof.aperture | |
f = dof.focal_length/1000 -- within a mm of the actual focal length, ie good enough | |
x = dof.focus -- CHDK estimate of focus 'from the lens' | |
ndof = dof.near -- note these are the defocus alone dofs, based on the CHDK CoC. That is no diffraction | |
fdof = dof.far | |
H = dof.hyp_dist | |
if x ~= last_step_x or f ~= last_step_f or N ~= last_step_N then | |
return true | |
else | |
return false | |
end | |
end | |
function update_info() | |
repeat sleep(10) until not get_shooting() -- make sure any capture taking place is completed | |
if ecnt ~= get_exp_count() then -- register captured image's focus info | |
last_ndof = ndof | |
last_fdof = fdof | |
last_x = x | |
last_f = f | |
last_N = N | |
last_step_N = -N -- to force a console refresh | |
ecnt = get_exp_count() | |
no_image = false | |
end | |
if (x < 0) then -- at infinity, so correct CHDK value for use by the script | |
ndof = H/2 -- note CHDK erroneously reports ndof, when focused at infinity, as infinity, ie -1 | |
x = infinity -- as CHDK reports infinity as -1, so can't use it directly | |
end | |
if (fdof == -1) then fdof = infinity end | |
if (x == infinity) or (x > H) then | |
num = 0 | |
else | |
num = (1 + (H/x))/2 -- estimate of number of focus brackets from current focus to H | |
end | |
-- Because we are using integer math Lua, we need to muck about a bit :-( | |
scale = imath.scale | |
diff_b = imath.mul(1342,N) -- diffraction blur diameter = 2.44*0.550*N = 1'342*N (at vis bands, ie change for IR converted cam) | |
inf_b = scale*coc -- infinity defocus blur, scaled from H definded blur, ie CHDK coc, around 30um/crop. Consider switching on show_coc, as this reminds you what the 'just acceptable' defocus blur is | |
temp = imath.div(scale*H,scale*x) | |
inf_b = imath.mul(inf_b,temp) | |
if x == infinity then | |
inf_b = 0 | |
tot_b = diff_b | |
else | |
tot_b = imath.mul(inf_b,inf_b) + imath.mul(diff_b,diff_b) | |
if tot_b < 16384000 then | |
tot_b = imath.sqrt(tot_b) | |
else | |
tot_b = inf_b | |
end | |
end | |
tot_b = imath.round(tot_b)/scale -- all blurs now converted to um | |
inf_b = imath.round(inf_b)/scale | |
diff_b = imath.round(diff_b)/scale | |
info = inf_b.."/"..diff_b.."/"..tot_b | |
if tot_b == inf_b then info = tot_b end | |
if x == infinity then | |
info = "oo: "..info | |
elseif (x < H) then | |
info = num.."<H: "..info | |
else | |
info = ">H: "..info | |
end | |
if no_image then | |
info = info.." [X]" | |
elseif x == last_x then | |
info = info.." [=]" | |
elseif ((fdof >= last_ndof) and (fdof <= last_fdof)) or ((ndof <= last_fdof) and (fdof >= last_fdof)) then | |
info = info.." [+]" | |
elseif (fdof < last_ndof) or (ndof > last_fdof) then | |
info = info.." [-]" | |
end | |
ls = info:len() -- character length of string | |
if show_coc == 1 then | |
info = " ["..coc..":"..min.."] "..info.." " | |
else | |
info = " "..info.." " | |
end | |
ls = info:len() | |
set_console_layout(0,pos,ls,pos+1) | |
end | |
-- Run in the background, in non Alt mode | |
exit_alt() | |
while show_DOFIC == 1 do | |
if something_changed() or is_pressed("shoot_half") then -- update console | |
update_info() | |
print(info) | |
last_step_N = N | |
last_step_x = x | |
last_step_f = f | |
end | |
sleep(100) -- free to adjust | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment