supplierdeeply

Add function get_luminance() in LUA scripting

  • 18 Replies
  • 3596 Views
*

nosebleed

Add function get_luminance() in LUA scripting
« on: 14 / April / 2012, 04:06:17 »
Advertisements
The following LUA function prints the Bv value.

Code: [Select]
function get_bv()
press("shoot_half")
sleep(500)
Bv = get_prop(34)
printf("%d.%02d", Bv/100, math.abs(Bv) % 100)
release("shoot_half")
end

But this isn't what I actually wanted. What I want is luminance (cd/m^2).
In core/shooting.c luminance is calculated using floating point numbers.
However, LUA scripts do not support floating point numbers.
The only way to provide the end user with luminance is to export the native c++ function into a lua function.
This can be done easily by adding the following code in core/luascript.c. Thanks to user jgrahamc from #highaltitude on freenode.

Code: [Select]
   
core/luascript.c:
    -----------------
    static int luaCB_get_luminance( lua_State* L )
    {
      lua_pushnumber( L, shooting_get_luminance() );
      return 1;
    }
     
    Further down
    ------------
     
    FUNC(get_luminance)

I wish to hear that the next revision will support this :)

Re: Add function get_luminance() in LUA scripting
« Reply #1 on: 14 / April / 2012, 09:51:44 »
The change look simple - just giving Lua the ability to access the function shooting_get_luminance() in platform/generic/shooting.c . 

As a small note to keep things tidy,  if you feel that you need to cross post something,  please add a comment in the new thread with a pointer to the old tread rather than just cutting & pasting the whole thing over.

http://chdk.setepontos.com/index.php?topic=5051.msg84197#msg84197
http://chdk.setepontos.com/index.php?topic=7988.msg84217#msg84217

Thanks - those of us who watch all the updates will appreciate it.
« Last Edit: 14 / April / 2012, 09:59:49 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Add function get_luminance() in LUA scripting
« Reply #2 on: 14 / April / 2012, 11:31:39 »
Attached is a patch file to implement this in the stable branch rev 1807.

Tested with this script   (luminance.lua) :
Code: [Select]
--[[
@title Luminance
--]]
i=0
repeat
      press("shoot_half")
      repeat sleep(100) until get_shooting() == true
      release("shoot_half")
      repeat sleep(100) until get_shooting() == false
      sleep(500)
       i=i+1
       L=get_luminance()
       print(i, "luminance:", L )
until false

In a simple test, values on my G10 range from 116 in a dimly lit room to 77163 through a window to a bright outdoor scene.
Ported :   A1200    SD940   G10    Powershot N    G16

*

nosebleed

Re: Add function get_luminance() in LUA scripting
« Reply #3 on: 14 / April / 2012, 12:03:33 »
Man you are great! I can't believe you responded soooooo fast!
Going to test it when the new revision is up.

Awesome thanks! And sorry for the cross posting... I'm posting infrequently and Iam not used in those rules.
But now I learned this as well !!!!

Thanks again !
« Last Edit: 14 / April / 2012, 12:05:11 by nosebleed »


Re: Add function get_luminance() in LUA scripting
« Reply #4 on: 14 / April / 2012, 12:26:51 »
Don't get too excited yet.  I just posted the patch and tested it.  I don't have svn commit access so one of the devs will have to look and decide whether to accept the patch.
Ported :   A1200    SD940   G10    Powershot N    G16

*

nosebleed

Re: Add function get_luminance() in LUA scripting
« Reply #5 on: 14 / April / 2012, 12:42:13 »
I believe in open source!

*

Offline reyalp

  • ******
  • 11583
Re: Add function get_luminance() in LUA scripting
« Reply #6 on: 14 / April / 2012, 17:22:31 »
Why do you want Bv in these units ? If you are doing any sort of calculation on them, you'd be much better off just working in native APEX96 units.

Edit: Or APEX, if you aren't doing the calculation on the camera.

Edit:
Looking at doug kerrs apex doc http://dougkerr.net/pumpkin/#APEX it seems like you should be able to approximate it in lua something like this
Quote
luminance_x10 = bit_shl(1, get_bv96()/96) * 34
You'd have to be a bit more sophisticated if you wanted fractional stops, but at that point a very rough approximation should be fine.

Note that Kerr's definition appears to disagree with what shooting_get_luminance is doing

Kerr defines Bv (with L in candelas/m^2) as
Bv = log2(L/0.3K)
=>
L = 0.3K*2Bv
Which matches the table on page 5.

shooting_get_luminance appears to be doing
L = 100 * k * 2(bv96-168)/96

with K = 12.5 rather than the 11.4 Kerr uses, the 0.3 factor dropped, and an unexplained - 168 (=1 3/4 stops) subtracted from Bv ?
« Last Edit: 14 / April / 2012, 18:14:07 by reyalp »
Don't forget what the H stands for.

*

nosebleed

Re: Add function get_luminance() in LUA scripting
« Reply #7 on: 15 / April / 2012, 03:02:30 »
Hello reyalp and thanks for your long post..
I actually need luminance so I can control the shutter speed dynamically while the camera works.
For example, depending on the luminance my shutter should close fast or slow..
I am writing on LUA. I tried
luminance_x10 = bit_shl(1, get_bv96()/96) * 34, however it tells me "calling a global function with a nil value"
My code is this
Code: [Select]
Bv = get_prop(34)
luminance_x10 = bit_shl(1, Bv/96) * 34


*

Offline fe50

  • ******
  • 3094
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: Add function get_luminance() in LUA scripting
« Reply #8 on: 15 / April / 2012, 03:32:04 »
I am writing on LUA. I tried
luminance_x10 = bit_shl(1, get_bv96()/96) * 34, however it tells me "calling a global function with a nil value"
My code is this
Code: [Select]
Bv = get_prop(34)
luminance_x10 = bit_shl(1, Bv/96) * 34
...bit_shl - there's no such lua command, use bitshl instead ;)

* http://chdk.wikia.com/wiki/Lua/Lua_Reference#bitwise_operations

*

nosebleed

Re: Add function get_luminance() in LUA scripting
« Reply #9 on: 15 / April / 2012, 05:56:12 »
Ok, scripts runs without error.
However the resulting values are not good.
I use as reference the OSD misc values.
Those say
Bv: 3.60
B: 47.8

Mine say
Bv: 3.53 [CORRECT]
B: 272 [WRONG]

 

Related Topics