Get C value from the core code - Script Writing - CHDK Forum

Get C value from the core code

  • 4 Replies
  • 1875 Views
Get C value from the core code
« on: 15 / May / 2022, 06:10:19 »
Advertisements
@reyalp @philmoz

Out of ignorance, is there a way to extract a variable from the core, to use in Lua.

Or does one need to code/compile in the transfer.

For example the following is in the histogram.c

Code: [Select]

over_exposed  = (histogram_proc[HISTO_RGB][HISTO_WIDTH-3]
                                +histogram_proc[HISTO_RGB][HISTO_WIDTH-2]*4
                                +histogram_proc[HISTO_RGB][HISTO_WIDTH-1]*8) > exposition_thresh;


Thus is there a way to ‘peek’ at the variable over_exposed?

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Get C value from the core code
« Reply #1 on: 15 / May / 2022, 06:31:12 »
Not easily.


You could get the address for a variable in the core C code by building yourself and then inspecting the main.bin.dump file to find the variable & address. You would need to update the address value whenever the core CHDK changed.


However the histogram code is a module so it is only loaded when needed. The memory address where the histogram code gets loaded is not known until run time and could be different each time you use it.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: Get C value from the core code
« Reply #2 on: 15 / May / 2022, 06:44:47 »
@philmoz

Thanks for the insight, I won’t go down that rabbit hole ;-)

Cheers

Garry

*

Offline Caefix

  • *****
  • 947
  • Sorry, busy deleting test shots...
Re: Get C value from the core code
« Reply #3 on: 16 / May / 2022, 11:53:22 »
@reyalp @philmoz

Out of ignorance, is there a way to extract a variable from the core, to use in Lua.

Or does one need to code/compile in the transfer.

For example the following is in the histogram.c

Code: [Select]

over_exposed  = (histogram_proc[HISTO_RGB][HISTO_WIDTH-3]
                                +histogram_proc[HISTO_RGB][HISTO_WIDTH-2]*4
                                +histogram_proc[HISTO_RGB][HISTO_WIDTH-1]*8) > exposition_thresh;


Thus is there a way to ‘peek’ at the variable over_exposed?
There may be ways to make a low level value more global and give it a token for scripting...  :-X

Edit: A first attempt for some research, ...
Edit2: & a little improvement, if need for more precision than than 1 or 0...  :D
Code: [Select]
luascript.c:

static int luaCB_over_exposed( lua_State* L )
{
  lua_pushnumber(L, histo_over_exposed);
  return 1;
}

static int luaCB_under_exposed( lua_State* L )
{
  lua_pushnumber(L, histo_under_exposed);
  return 1;
}

//...
    FUNC(under_exposed)
    FUNC(over_exposed)


// histogram.h:

static int histo_under_exposed;
static int histo_over_exposed;

// histogram.c:

            if (histo_max[HISTO_RGB] > 0) { // over- / under- exposed
                under_exposed = (histogram_proc[HISTO_RGB][0]*8
                                +histogram_proc[HISTO_RGB][1]*4
                                +histogram_proc[HISTO_RGB][2]);
                over_exposed  = (histogram_proc[HISTO_RGB][HISTO_WIDTH-3]
                                +histogram_proc[HISTO_RGB][HISTO_WIDTH-2]*4
                                +histogram_proc[HISTO_RGB][HISTO_WIDTH-1]*8);
            } else {
                over_exposed = 0;
                under_exposed = 1;
            }
            histo_over_exposed  = over_exposed;
            histo_under_exposed = under_exposed;
            under_exposed = under_exposed> exposition_thresh;
            over_exposed  = over_exposed > exposition_thresh;
            histogram_stage = 5;
            break;
« Last Edit: 16 / May / 2022, 15:45:22 by Caefix »
All lifetime is a loan from eternity.


*

Offline reyalp

  • ******
  • 14110
Re: Get C value from the core code
« Reply #4 on: 16 / May / 2022, 17:43:36 »
There may be ways to make a low level value more global and give it a token for scripting...  :-X

Edit: A first attempt for some research, ...
Edit2: & a little improvement, if need for more precision than than 1 or 0...  :D
If you want to analyze live histogram from script, I would suggest using get_live_histo instead. It's not entirely equivalent since it uses Y values rather than RGB, but that should be no worse for detecting over or under exposure.

If there is a reason to use other color channels, exposing them them through get_live_histo would IMO be a better approach than exposing the over/under flags, since it would be far more flexible.
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal