A question for the C gurus

Started by garry23, September 17, 2020, 10:53:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

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:

#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

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

@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

Sorry!  It's not much C, so you could learn it if you have the time.

garry23

@names_are_hard

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

names_are_hard

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

@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


garry23

@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

Quote from: garry23 on September 19, 2020, 07:24:19 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

@Danne

QuoteI 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

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

@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

@Danne @names_are_hard

Fully understood.

Cheers, and stay away from the pestilence and stupidity

Garry

garry23

@Danne

QuoteIf 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

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

QuoteIf you still don't see the oppurtunity

What!

Of course I do.

No more on this now.

Over and out.