Author Topic: Where and why is lens_info.focal_len assigned to 50mm with manual lenses  (Read 2826 times)

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3751
Is there a reason that it isn't assigned to "0" with manual lenses? I'd like to have the focal length tag in MLV files default to "0" when using manual lenses instead of 50mm.

I looked all over the code and can't figure out where lens_info.focal_len is assigned a value of 50 when a manual non-cpu lens is attached to the body. I did find a place where it is reassigned "0" but it seems like it is there in case a chipped lens reports bogus values:

lens.c line 1533
Code: [Select]
    if (lens_info.focal_len > 1000) // bogus values
        lens_info.focal_len = 0;

Am I'm missing something obvious somewhere?
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1989
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #1 on: November 19, 2016, 09:40:42 AM »
Even better, IMHO, have an ML menu that allows you to input a FL and, maybe, even an aperture value for use when a manual lens is detected.

I often use manual lenses and tend to use these at a 'sweet spot' aperture, i.e. I don't vary the aperture much when shooting.

Just a thought.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12422
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #2 on: November 19, 2016, 10:31:31 AM »
Line 1530:
Code: [Select]
    lens_info.focal_len     = bswap16( lv_lens->focal_len );

Try printing this info, e.g. like this:
Code: [Select]
    printf("FL %d\n", lens_info.focal_len);

And you'll see what values you get from Canon firmware (see Properties on the wiki) and how often they are refreshed. In this case, Canon firmware sends 50 when the lens is disconnected, and it does so either a few times in the first seconds after enabling LiveView or changing the video mode, or - sometimes - continuously a few times per second (5D3). The behavior is inconsistent, no idea why. This property contains other fields as well (it's not just a simple scalar value), so when those other fields change, focal_len is refreshed as well.

To see what's the reason for that bogus value check, use hg blame to look at lens.c, and this will point you to this issue.

The status displays in ML simply ignore this value for non-CPU lenses (checked using lens_info.name[0]). The best way would be probably to reassign focal_len to 0 in PROP_LV_LENS (which will affect all other parts of the code that use it).

This quirk went unnoticed because, in ML status indicators, the code was checking for valid lens_info.name[0] or aperture before using the focal_len field (so at first, I thought it must be MLV code writing a nonzero focal length by default for some reason).

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3751
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #3 on: November 19, 2016, 05:38:33 PM »
Thanks for the detailed explanation. I feel better that it wasn't something obvious.

...Canon firmware sends 50 when the lens is disconnected...The behavior is inconsistent, no idea why...

That's what I suspected too but EXIF tags on CR2 and MOV files show a lens of 0.0mm when no lens is attached. I probably wrote off that idea too quickly.

Interesting that one of your comments on issue 1460 was:

Quote
Another option is to enter focus distance manually.

That's what we're trying to do to get this interesting lua script working.

@garry23 - We could really use your lua scripting skills with it.
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

Lars Steenhoff

  • Senior
  • ****
  • Posts: 460
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #4 on: November 19, 2016, 07:02:15 PM »
Even better, IMHO, have an ML menu that allows you to input a FL and, maybe, even an aperture value for use when a manual lens is detected.

I often use manual lenses and tend to use these at a 'sweet spot' aperture, i.e. I don't vary the aperture much when shooting.

Just a thought.

Excatly the usecase that I also have, If you could have a look at the topic dfort pointed to you will see that we already have the name working  :)

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3751
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #5 on: November 20, 2016, 10:15:33 PM »
Looks like this is going to be trickier than I originally thought--seems like it always is.

Found this interesting:

lens.c line 82
Code: [Select]
struct lens_info lens_info = {
    .name        = "NO LENS NAME"
};

Though it seems that "NO LENS NAME" is never tested.

I can assign a value to lens_info.focal_len through lua by making it writeable to lua and commenting this out:

lens.c line 1530
Code: [Select]
    // lens_info.focal_len    = bswap16( lv_lens->focal_len );

This also seems to solve the issue with non-cpu lenses reporting a focal length of 50mm.

The status displays in ML simply ignore this value for non-CPU lenses (checked using lens_info.name[0]). The best way would be probably to reassign focal_len to 0 in PROP_LV_LENS (which will affect all other parts of the code that use it).

What I'm seeing is that the status display shows the focal_len assigned through lua and ignores focal_len if it is not assigned a value so there shouldn't be a need to reassign focal_len to 0 and start a domino effect in other parts of the code.

So everything is working great for manual lenses but of course it doesn't work with cpu (chipped) lenses. I'm looking for a way to make skipping that line through a conditional statement that checks if a non-cpu lens is attached. Note that checking if lens_info.name is empty doesn't work because the lua script is also assigning a value to the lens name.
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #6 on: November 21, 2016, 03:15:02 AM »
Since you can't use the name anymore to tell if it's manual, you'll simply need a new variable to track that state. Perhaps an is_manual field in the lens_info struct, or just a new global variable (changing struct definition can have far reaching and unexpected consequences)

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3751
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #7 on: November 21, 2016, 09:25:42 AM »
...you'll simply need a new variable to track that state...

Good to know I was on the right track. Almost working, just a few more kinks to iron out.
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3751
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #8 on: November 21, 2016, 04:32:01 PM »
Got it working.

I'm using this with the lua_fix branch because this is for a lua script that allows the user to set the lens name and focal length. A side benefit is that manual lenses no longer default to 50mm on the MLV metadata.

Thanks!
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 3394
  • 5D3 | M1 | 7D | 70D | SL1 | M2 | 50D
Re: Where and why is lens_info.focal_len assigned to 50mm with manual lenses
« Reply #9 on: November 21, 2016, 07:24:16 PM »
Excellent work @dfort and Thanks for sharing your pointers @dmilligan as usual!
5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109