Where and why is lens_info.focal_len assigned to 50mm with manual lenses

Started by dfort, November 19, 2016, 07:37:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dfort

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
    if (lens_info.focal_len > 1000) // bogus values
        lens_info.focal_len = 0;


Am I'm missing something obvious somewhere?

garry23

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

Line 1530:

    lens_info.focal_len     = bswap16( lv_lens->focal_len );


Try printing this info, e.g. like this:

    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

Thanks for the detailed explanation. I feel better that it wasn't something obvious.

Quote from: a1ex on November 19, 2016, 10:31:31 AM
...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:

QuoteAnother 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.

Lars Steenhoff

Quote from: garry23 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.

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

Looks like this is going to be trickier than I originally thought--seems like it always is.

Found this interesting:

lens.c line 82
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
    // 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.

Quote from: a1ex on November 19, 2016, 10:31:31 AM
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.

dmilligan

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

Quote from: dmilligan on November 21, 2016, 03:15:02 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.

dfort

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!

DeafEyeJedi

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