Skip to content

Instantly share code, notes, and snippets.

@pigeonhill
Last active March 23, 2023 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigeonhill/d2031eeb79eb3d417664cf88a33dcf0b to your computer and use it in GitHub Desktop.
Save pigeonhill/d2031eeb79eb3d417664cf88a33dcf0b to your computer and use it in GitHub Desktop.
Cropped XPAN Simulator
--[[
@title CPAN
@chdk_version 1.7
#sleep_time = 0 "Delay (s)" [0 10]
#title = 1 "Title Line" {Off Full Exit}
Notes:
* This script (Cropped XPAN) simulates the look of a Hasselblad XPan (65mmx24mm) on the G7X or G5X with CHDK 1.7 or later
* You may need to tweak the function check_buttons_etc() for other CHDK cameras, ie if the buttons are different, and change line 42 test
* The script is designed as an aid to exploring XPAN composition and 'practicing' XPAN capture with 45mm and 90mm lenses, plus a non-XPAN 150mm
* XPAN 30mm emulation is not possible, ie it's too wide to emulate on the G5/7X
* Pressing the RIGHT button will toggle through the XPan focal lengths that the camera can cover: 45mm, 90mm and 150mm
* Pressing the zoom-in or zoom-out will put the camera in 'digital' XPan simulation mode, where all camera focal lengths are accessible...
* and the script displays actual and 35mm effective focal lengths
* Pressing SET button captures an image, with or without a delay (adjustable in the script's menu)
* Pressing the LEFT button will toggle the CHDK histogram on and
* Pressing the UP button will toggle between transparent and dark modes
* Feel free to adjust the CHDK histogram position in the script
* For an uncluttered display you can adjust the CHDK title bar display to your liking in the menu, ie off, full or exit
* Press DOWN button to exit the script
* NOTE: the script is good for LCD viewing, (G5X) EVF or HDMI out viewing...
* For HDMI out viewing set the camera's aspect ration to 16:9. Also G5X EVF viewing will exhibit a gap on the right - a quirk of the CHDK
Release 1.09
March 2023
Garry George
--]]
props=require'propcase'
zu = require'zoomutil'
require "drawings"
bi = get_buildinfo()
fl_state = 0
tg = 242
top = draw.add("rectf", 0, 0, 0, 0, tg,tg)
bottom = draw.add("rectf", 0, 0, 0, 0, tg,tg)
fl_text = draw.add("string",0,0,"",tg,tg)
finished = false
toggle = 1
screen_test = 0
dirty_screen = false
vx = 0
vy = 0
vc = 0
if not (bi.platform == "g7x" or bi.platform == "g5x") then -- for now ;-)
print("Doesn't run on this Cam")
sleep(3000)
return
end
set_config_value(2020,10,95) -- histogram position, adjust to your liking
set_draw_title_line(title) -- switch off CHDK info according to the menu request
function check_screen()
dirty_screen = false
if get_gui_screen_width() == 360 and get_gui_screen_height() == 240 then -- using the LCD
vx = 360
vy = 240
elseif get_gui_screen_width() == 480 and get_gui_screen_height() == 270 then -- using the HDMI out
vx = 480
vy = 270
elseif get_gui_screen_width() == 344 and get_gui_screen_height() == 270 then -- using the EVF (at least on a G5X). Note there will be a gap on the right ;-)
vx = 360
vy = 270
end
if screen_test ~= vx+vy then dirty_screen = true end
screen_test = vx+vy
vc = (vy-((vx*24)/65))/2
end
function check_buttons_etc()
wait_click(50)
do
if is_key("down") and get_alt_mode() then -- exit script
finished = true
elseif is_key("zoom_in") and get_alt_mode() then
press("zoom_in")
repeat
sleep(10)
until not is_pressed("zoom_in")
release("zoom_in")
text = (get_focal_length(zoom_pos)/1000).."mm ("..(get_eff_focal_length(zoom_pos)/1000).."mm)"
draw.replace(fl_text,"string",vx/2-847*string.len(text)/200,20,text,"white",tg)
draw.overdraw()
elseif is_key("zoom_out") and get_alt_mode() then
press("zoom_out")
repeat
sleep(10)
until not is_pressed("zoom_out")
release("zoom_out")
text = (get_focal_length(zoom_pos)/1000).."mm ("..(get_eff_focal_length(zoom_pos)/1000).."mm)"
draw.replace(fl_text,"string",vx/2-847*string.len(text)/200,20,text,"white",tg)
draw.overdraw()
elseif is_key("right") and get_alt_mode() then
fl_state = fl_state + 1
if fl_state > 2 then fl_state = 0 end
if fl_state == 0 then
zu.set_zoom_fl((45000*132)/650)
text = "45 mm"
elseif fl_state == 1 then
zu.set_zoom_fl((90000*132)/650)
text = "90 mm"
elseif fl_state == 2 then
zu.set_zoom_fl((150000*132)/650)
text = "150mm"
end
draw.replace(top,"rectf", 0, 0, vx, vc,tg,tg)
draw.replace(bottom,"rectf", 0, vy-vc, vx, vy,tg,tg)
draw.replace(fl_text,"string",vx/2-20,20,text,"white",tg)
draw.overdraw()
elseif is_key("shoot_half") or is_key("erase") then
press("shoot_half")
repeat
sleep(100)
until not is_pressed("shoot_half")
release("shoot_half")
elseif is_key("set") then
sleep(sleep_time*1000)
shoot()
elseif is_key("left") then
sleep(100)
set_config_value(1060,1-get_config_value(1060,0))
elseif is_key("up") then
check_screen()
toggle = (1-toggle)
if toggle == 0 then tg = 242 else tg = "black" end
draw.replace(top,"rectf", 0, 0, vx, vc,tg,tg)
draw.replace(bottom,"rectf", 0, vy-vc, vx, vy,tg,tg)
draw.replace(fl_text,"string",vx/2-20,20,text,"white",tg)
draw.overdraw()
end
end
end
-- Main Section
check_screen()
sleep(1000) -- then set focal length to a simulated 45mm
zu.set_zoom_fl((45000*132)/650)
tg = "black"
draw.replace(top,"rectf", 0, 0, vx, vc,tg,tg)
draw.replace(bottom,"rectf", 0, vy-vc, vx, vy,tg,tg)
text = "45 mm"
draw.replace(fl_text,"string",vx/2-20,20,text,"white","black")
draw.overdraw()
repeat -- stay here until exit requested
check_screen()
check_buttons_etc()
if dirty_screen then
draw.replace(top,"rectf", 0, 0, vx, vc,tg,tg)
draw.replace(bottom,"rectf", 0, vy-vc, vx, vy,tg,tg)
draw.overdraw()
end
sleep(300)
until finished
exit_alt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment