Zoom to focal length - General Help and Assistance on using CHDK stable releases - CHDK Forum

Zoom to focal length

  • 20 Replies
  • 3502 Views
Zoom to focal length
« on: 15 / March / 2023, 03:03:09 »
Advertisements
Other than scripting it, ie zooming in a loop and checking focal lemgth, does amyone know if there is a way in Lua to zoom_to_focal_length?

*

Offline Caefix

  • *****
  • 947
  • Sorry, busy deleting test shots...
Re: Zoom to focal length
« Reply #1 on: 15 / March / 2023, 11:52:03 »
 ??? Probably not without a prepared cam-specific table
dof.eff_focal_length [x 1000 mm] - 35mm equivalent focal length
https://chdk.fandom.com/wiki/Script_commands#get_dofinfo

and the matching zoompoint.
https://chdk.fandom.com/wiki/CHDK_scripting#set_zoom_.2F_set_zoom_rel_.2F_get_zoom_.2F_set_zoom_speed
All lifetime is a loan from eternity.

Re: Zoom to focal length
« Reply #2 on: 15 / March / 2023, 12:28:09 »
??? Probably not without a prepared cam-specific table
dof.eff_focal_length [x 1000 mm] - 35mm equivalent focal length
https://chdk.fandom.com/wiki/Script_commands#get_dofinfo

and the matching zoompoint.
https://chdk.fandom.com/wiki/CHDK_scripting#set_zoom_.2F_set_zoom_rel_.2F_get_zoom_.2F_set_zoom_speed

I thought there might be something hidden from me ;-)

Thanks for replying.

*

Offline reyalp

  • ******
  • 14114
Re: Zoom to focal length
« Reply #3 on: 15 / March / 2023, 12:36:51 »
Other than scripting it, ie zooming in a loop and checking focal lemgth, does amyone know if there is a way in Lua to zoom_to_focal_length?
There isn't currently.

CHDK internally has functions to convert zoom point to FL or EFL, and most ports use a firmware table mapping between the two, but they aren't exposed to script. This is something that's been on my list to add to add for a long time, so I'll take a look in the next few days to see if it can be done stragiht forwardly. I would probably add functions like (names TBD)
get_fl_for_zoom_step(zp) and get_zoom_step_for_fl(fl)

then you could do set_zoom(get_zoom_step_for_fl(5000))

If you don't want to wait, you could use peek to access the firmware table focus_len_table found in stubs_entry.S on most ports. Note that the format and number of entries varies between cameras.

There are presumably also firmware functions which do similar things, but not eventprocs that I  know of.
Don't forget what the H stands for.


Re: Zoom to focal length
« Reply #4 on: 15 / March / 2023, 13:08:30 »
Other than scripting it, ie zooming in a loop and checking focal lemgth, does amyone know if there is a way in Lua to zoom_to_focal_length?
There isn't currently.

CHDK internally has functions to convert zoom point to FL or EFL, and most ports use a firmware table mapping between the two, but they aren't exposed to script. This is something that's been on my list to add to add for a long time, so I'll take a look in the next few days to see if it can be done stragiht forwardly. I would probably add functions like (names TBD)
get_fl_for_zoom_step(zp) and get_zoom_step_for_fl(fl)

then you could do set_zoom(get_zoom_step_for_fl(5000))

If you don't want to wait, you could use peek to access the firmware table focus_len_table found in stubs_entry.S on most ports. Note that the format and number of entries varies between cameras.

There are presumably also firmware functions which do similar things, but not eventprocs that I  know of.

@reyalp

Many thanks for insight and I would welcome the additional scripting functionality.

I’m scripting a simple script that lets you use a Cam, say the g7x, as a medium format 617 simulator, ie using the CHDK camera as a hand held viewfinder.

Once I’ve coded it up, I’ll write about on my blog and post a link here.

Bottom line: I’ll wait for your tweak  ;)

Cheers

Garry

*

Offline Caefix

  • *****
  • 947
  • Sorry, busy deleting test shots...
Re: Zoom to focal length
« Reply #5 on: 15 / March / 2023, 13:14:58 »
then you could do set_zoom(get_zoom_step_for_fl(5000))
Maybe get_zoom_step_for_efl to avoid   :blink:
A step for ubasic was
Code: [Select]
  case TOKENIZER_GET_EFF_FOCAL_LENGTH:
    r = get_effective_focal_length(shooting_get_zoom());
    r = r * conf.zoom_scale / 100; // from gui_osd.c
break;
All lifetime is a loan from eternity.

Re: Zoom to focal length
« Reply #6 on: 15 / March / 2023, 13:58:09 »
then you could do set_zoom(get_zoom_step_for_fl(5000))
Maybe get_zoom_step_for_efl to avoid   :blink:
A step for ubasic was
Code: [Select]
  case TOKENIZER_GET_EFF_FOCAL_LENGTH:
    r = get_effective_focal_length(shooting_get_zoom());
    r = r * conf.zoom_scale / 100; // from gui_osd.c
   break;


In fact it’s more nuanced than you think. I’m simulating a shifted MF lens, ie shifted 31mm in total.


BTW I know how and what I want to do, I am ‘just’ lacking the function to zoom to the right focal length, ie can easily do it by manually changing zoom until I hit where I need to be, ie the specific MF focal length I’m simulating.


Cheers


Garry

*

Offline reyalp

  • ******
  • 14114
Re: Zoom to focal length
« Reply #7 on: 16 / March / 2023, 01:51:33 »
@pigeonhill here's a preliminary patch. I can provide a build if you tell me which camera and firmware version.

The patch adds two functions to Lua:
Code: [Select]
fl = get_focal_length(zoom_pos)
zoom_pos is the zoom position to get the focal length of. Out of range zoom_pos values are clamped to the closest valid value. If zoom_pos is omitted, the focal length for the current zoom position is returned.

The return value fl is the focal length, in the usual CHDK mm*1000 units.
Code: [Select]
efl = get_eff_focal_length(zoom_pos)
as above, but the 35mm equivalent focal length

But wait, you say, that's not what I asked for at all?!  :D

The rest is in Lua module, zoomutil.lua. As usual, import the module like
Code: [Select]
zu = require'zoomutil'

The module provides
Code: [Select]
pos = zu.get_zoom_for_fl(focal_length)
where focal_length: desired focal length, expressed as mm*1000
pos: zoom position with focal length closest to specified value

zu.get_zoom_for_efl is the same, but 35mm equivalent.

zu.set_zoom_for_fl and zu.set_zoom_for_efl set the zoom position from fl/efl values using the functions above.

Additional functions allow converting between fl and efl, as well as getting the minimum and maximum. Note the actual fl/efl conversion in CHDK is per platform and only available for specific zoom steps, so it's possible the conversion functions will give slightly different values than get_focal_length and get_eff_focal_length in some instances. In other words, if you do
Code: [Select]
f=get_focal_length(10)
ef=get_eff_focal_length(10)
zu.fl_to_efl(f) == ef
might not be true, although the values should be very close.


Other notes:
ubasic already has get_focal_length, which returns the focal length for the current zoom step (In Lua, this was previously available through get_dofinfo only). I'm not sure if ubasic can support optional arguments. AFAIK it does not have a way to get efl. I'm not inclined to add the new functionality to ubasic, but it will make the documentation for get_focal_length somewhat confusing.

The no-argument variants of get_focal_length and get_eff_focal_length are somewhat redundant with get_dofinfo, but they are trivial to implement, and seemed convenient. I though about allowing passing a zoom pos to get_dofinfo, but that seemed ugly, since some dofinfo values are dependent on other settings.


Any feedback anyone has before I check this in is welcome.
Don't forget what the H stands for.


Re: Zoom to focal length
« Reply #8 on: 16 / March / 2023, 02:22:50 »
@reyalp

Fantastic, many thanks.

My test camera is a 100d G7x


*

Offline reyalp

  • ******
  • 14114
Re: Zoom to focal length
« Reply #9 on: 16 / March / 2023, 02:30:51 »
Here's a g7x 100d test build
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal