Author Topic: A question for the C gurus  (Read 844 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
A question for the C gurus
« on: September 17, 2020, 10:53:11 AM »
Things look really exciting over in ML videoland at the moment, but over in ML photoland some of us are 'struggling'.

What I've been trying to do is see if I can extend the Lua fix and expose more functionality, thus opening up Lua to greater things.

For example, at the moment the ML spotmeter, and in particular RAW form, remains 'hidden' in Lua.

In the main source, the spotmeter is in zebra.c:

Code: [Select]
#ifdef FEATURE_RAW_SPOTMETER
    int raw_luma = 0;
    int raw_ev = 0;
    if (can_use_raw_overlays() && raw_update_params())
    {
        const int xcr = BM2RAW_X(xcb);
        const int ycr = BM2RAW_Y(ycb);
        const int dxr = BM2RAW_DX(dxb);

        raw_luma = 0;
        int raw_count = 0;
        for( y = ycr - dxr ; y <= ycr + dxr ; y++ )
        {
            if (y < raw_info.active_area.y1 || y > raw_info.active_area.y2) continue;
            for( x = xcr - dxr ; x <= xcr + dxr ; x++ )
            {
                if (x < raw_info.active_area.x1 || x > raw_info.active_area.x2) continue;

                raw_luma += raw_get_pixel(x, y);
                raw_count++;
               
                /* define this to check if spotmeter reads from the right place;
                 * you should see some gibberish on raw zebras, right inside the spotmeter box */
                #ifdef RAW_SPOTMETER_TEST
                raw_set_pixel(raw_buf, x, y, rand());
                #endif
            }
        }
        if (!raw_count) return;
        raw_luma /= raw_count;
        raw_ev = (int) roundf(10.0 * raw_to_ev(raw_luma));
    }
    #endif

The relevant info here are the x and y values, ie giving the screen position of the spotmeter, and the raw EV value we see on the LV, ie raw_ev.

Having looked at the Lua module in the source, there are ways to access ML C and Canon variable, but this requires coding in C and compiling, which is a little bit beyond me at the moment.

So, does anyone know if it is possible to access variables that are in the main build, eg the spotmeter, but only via using Lua. I've read online that it should be possible, within Lua, to access functions in C, but I'm not sure if you can do this with variables and, of course, with ML Lua?

Obviously I'm only looking to read, not write, here.

I know there are lots of bright people out there and thus I would welcome any thoughts on the above, ie is it possible, using only, Lua, to read a C variable from ML, eg raw_ev above.


names_are_hard

  • Contributor
  • Senior
  • *****
  • Posts: 294
  • 200D idiot
Re: A question for the C gurus
« Reply #1 on: September 17, 2020, 07:21:49 PM »
You definitely can't read raw_ev because the scope is wrong.  You could make relatively small changes to the ML source to fix the scope, although this is a bad idea (it would get very messy if you want to expose more than a few variables).  A better approach would be a function like get_raw_ev(), and make that do the work, while being visible to Lua.

From some quick reading I don't think you can access C variables directly from Lua even if they're externally visible, because Lua uses a stack abstraction to safely pass data between the two languages.

Not a Lua expert so could be wrong about the details.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #2 on: September 17, 2020, 08:04:28 PM »
@names_are_hard

Many thanks for the insight.

As a simple Lua scripter, I’m afraid I will need to wait for a core C coder to tweak the Lua fix to uncover the spotmeter.

Cheers

Garry

names_are_hard

  • Contributor
  • Senior
  • *****
  • Posts: 294
  • 200D idiot
Re: A question for the C gurus
« Reply #3 on: September 17, 2020, 09:46:25 PM »
Sorry!  It's not much C, so you could learn it if you have the time.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #4 on: September 17, 2020, 10:04:34 PM »
@names_are_hard

I should have been clearer, it’s more the compiling. I just haven’t got into that yet.

names_are_hard

  • Contributor
  • Senior
  • *****
  • Posts: 294
  • 200D idiot
Re: A question for the C gurus
« Reply #5 on: September 18, 2020, 12:27:29 AM »
Compiling ML?  That's pretty easy.  Pop in the Discord and I can walk you through it if you want.  Or there are guides on the forums.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #6 on: September 18, 2020, 10:52:34 AM »
@names_are_hard

I appreciate your offer of support.

I have tried before and partially succeeded once, but a while ago.

However, I got turned off because of all the errors that kept came up.

Time has moved on and maybe I should look at compiling again, assuming things are more stable now.

BTW I’m Win10 based.

Cheers

Garry

names_are_hard

  • Contributor
  • Senior
  • *****
  • Posts: 294
  • 200D idiot
Re: A question for the C gurus
« Reply #7 on: September 19, 2020, 02:38:57 AM »

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #8 on: September 19, 2020, 07:24:19 AM »
@names_are_hard

Thanks for the pointers, however, reading those posts just reinforces the fragility of trying to compile, when you really don’t understand things.

Every post tries to fix problems.

Time has now moved on and we have moved to foss.hepapod, and I know if I started compiling I would get loads of ‘errors’.

IMHO we need someone who Really knows what they are doing to definitively create a master post, with working links, on how to carry out compiling on a PC and Mac.

But, of course, we don’t live in a perfect world, and everyone has their own priorities/interests and only so much ‘spare’ time to ‘donate’ to ML. My ‘spare’ time is Lua scripting focused ;-)

Anyway, once again, thanks for trying to help me.

Danne

  • Contributor
  • Hero Member
  • *****
  • Posts: 6968
Re: A question for the C gurus
« Reply #9 on: September 19, 2020, 08:14:03 AM »
@names_are_hard
IMHO we need someone who Really knows what they are doing to definitively create a master post, with working links, on how to carry out compiling on a PC and Mac.
In general what´s needed are two active parties to solve existing blocks to get the compiling environment working. I see one person with helping hands and I see active rejection based on a fixed mindset on the other side. The result. No compiling, no development.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #10 on: September 19, 2020, 08:57:35 AM »
@Danne

Quote
I see one person with helping hands and I see active rejection based on a fixed mindset on the other side. The result. No compiling, no development.

Not fully sure what you are saying here regarding ‘rejection’.

As a contributor to ML, albeit restricted to Lua scripting, I’m simply out of my depth when it comes to compiling, especially when ‘errors’ keep popping up.

I want to have a go at extending the Lua module, eg access other functionality, like the spotmeter, but this requires two things.

First, and the one I can do, is simply learn C and start coding.

Second, compile stuff, is not within my grasp at the moment, so I remain stalled.

Cheers

Garry

Danne

  • Contributor
  • Hero Member
  • *****
  • Posts: 6968
Re: A question for the C gurus
« Reply #11 on: September 19, 2020, 09:11:16 AM »
What I mean is your lua scripting is heavily centred around your own personal usage. Therefore, compiling and basic allround ml knowledge is mandatory imo. If you´re lucky maybe you get someone to do the dirty work for you but if you get tired of waiting it´s better to get the dirty prework done yourself ;).

names_are_hard

  • Contributor
  • Senior
  • *****
  • Posts: 294
  • 200D idiot
Re: A question for the C gurus
« Reply #12 on: September 19, 2020, 09:23:04 AM »
@garry23 - yup, you will need to work through some problems to get a working build environment.  But you only have to do that once.  This is doubly true if you do it inside a VM; should you break the environment, you can roll-back the VM (and then update the ML repo).  That's what I was offering to help with - fixing the problems.

I don't have a Mac or Windows, so I can't create the guide you want.  I did make a fully automated way to build ML, using Docker, but there was no interest in it so I didn't get it working well.  This could be improved.  There are significant tradeoffs to doing builds via Docker, but it's theoretically cross platform and handles making a working build environment for you.

ML build via Docker thread:
https://www.magiclantern.fm/forum/index.php?topic=24619.0

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #13 on: September 19, 2020, 09:25:42 AM »
@Danne @names_are_hard

Fully understood.

Cheers, and stay away from the pestilence and stupidity

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #14 on: September 19, 2020, 11:35:37 AM »
@Danne

Quote
If you´re lucky maybe you get someone to do the dirty work for you

Just to be clear, I was never looking or expecting anyone to compile for me. I’m looking for a tutorial that lays out the steps on how I can compile, today, on a Win 10 PC.

Cheers

Garry

Danne

  • Contributor
  • Hero Member
  • *****
  • Posts: 6968
Re: A question for the C gurus
« Reply #15 on: September 19, 2020, 11:58:02 AM »
There are no 10 fullproof steps that will achieve what you want. You were lucky enough to get @names_are_hard helping you through which imo is as good as it gets. If you still don't see the oppurtunity given that's more likely the problem not being able to compile yet.
Good luck though!

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2072
Re: A question for the C gurus
« Reply #16 on: September 19, 2020, 12:16:51 PM »
Quote
If you still don't see the oppurtunity

What!

Of course I do.

No more on this now.

Over and out.