I just found this discussion, so let me add my thoughts.
I wrote up some documentation and posted it in the Histogram Request thread. Here's the part on the Apex96 functions:
==========
*** Apex Conversion Functions ***
==========
tv96=shutter_to_tv96(shutter_time[,scale]) (default scale is 1000 for msec)
shutter_time>0 means msec (if scale=1000 default)
For microseconds, set scale=1000000
shutter_time<0 means function uses 1/-shutter_time
Example:
@param t Shutter Max (sec)
@default t 10
@param u Shutter Min (1/sec)
@default u 3200
tvmax=shutter_to_tv96(-u*1000)
tvmin=shutter_to_tv96(t*1000)
Note: You could also do this with
tvmax=shutter_to_tv96(-u,1)
tvmin=shutter_to_tv96(t,1)
shutter=tv96_to_shutter(tv96,scale) note: default scale=1000
converts tv96 to shutter time in msec
if tv96>0, you can use a scale of 1000000 for microseconds or...
you can use -tv96 and print out 1/seconds instead of msec
Example: This Lua function returns a string with the time
function seconds(tv) -- tv96 to time string i.e. print(seconds(tv))
pre=""
if(tv>0)then
tv=-tv
pre="1/"
end
tv=tv96_to_shutter(tv) -- tv96 to msec
ti=tv/1000 -- integer part
ts=string.format("%s%u.%03u",pre,ti,tv%1000) -- xx.xxx or 1/xx.xxx
if(ti>1)then -- truncate digits to reflect decimal precision
if(ti>149)then ti=-5
elseif(ti>14)then ti=-3
else ti=-2 end
ts=string.sub(ts,1,ti)
end
return ts
end
sv96=iso_to_sv96(iso[,scale]) note: default scale=1
converts iso to sv96.
iso=sv96_to_iso(sv96[,scale]) note: default scale=1
converts sv96 to iso
av96=aperture_to_av96(aperture[,scale]) default scale=1000
converts aperture to av96. f/2.0 is aperture=2000
aperture=av96_to_aperture(av96[,scale]) default scale=1000
converts av96 to aperture
The ISO conversion is using the old CHDK equation for 'real' ISO. It needs to be updated to use the 1.3 conversion.
I need to change the constant in the conversion, since I used the Wikipedia equation, but I don't think this function should be modified to include "Market" ISO. To do that, you would need a Real to Market conversion function.
I need to research this a little more, but in my Tlasper.lua script I just add a constant to the Real sv96 to get Market sv96. This is based on the assumption that adding 96 to real or market sv96 should double the ISO (Real or Market). This shows how I do it in my script so I can input Market ISO:
@param z ISO Max
@default z 400
@param s ISO Min
@default s 100
--(in half_shoot)
sv=get_sv96()
svdiff=iso_to_sv96(get_iso_market())-sv -- real to market difference
svmin=iso_to_sv96(s)-svdiff -- min sv ISO 100 market default
svmax=iso_to_sv96(z)-svdiff
--Now, to print Market ISO you do this
print(sv96_to_iso(sv+svdiff))
This works perfectly up to Market ISO 800 on my cameras. Above that, I think Canon may be cheating a little by making Market ISO more sensitive than it really is. I need to test this some more.
Not sure I see the need for the optional 'scale' parameter in all of the functions - the level of inaccuracy in the integer conversion means you're not going to get much better than using a default value of 1000.
This would also simplify the code.
This is not true. As Tv96 gets larger, the shutter times go below 1/1000 second (0.001 second). You need a scale of 1000000 to
output in microseconds.
The idea is that within the normal range of shutter times, ISO, and Aperture values, a change of 1 tv96, sv96, and av96 should
always be able to show a change in the resulting Shutter Time, ISO or Aperture value. This is important when displaying
converted Shutter, ISO, and Aperture values so you can see that they are changing.
If you don't like the scale parameter, you don't have to use it since the default is a scale of 1000. But if you take it out, you won't be able to accurately input or output accurate fast shutter times in microseconds, and your other conversions may have less precision than desired for certain applications.
Edit2: The other option here is to use the imath library fixed point type for shutter speed and aperture (instead of multiplying everything by 1000 / 'scale').
Personally I would also lose the convert96 function and move the conversion code into the calling functions.
Edit: I also don't like the way the 'shutter_to_tv96' treats negative numbers as a special case so that -2000 and 500 both mean 1/2 second shutter speed.
The imath library doesn't have the capability to do microsecond precision, and it adds complexity to the scripts in that you have to do a lot of multiplying and dividing by 1000, plus rounding. My functions are much simpler to use, and will take up much less overall memory by reducing a lot of Lua code.
I originally had a single Lua function called "convert96", and I never moved the code to the new, multiple calling functions. That's on my to do list.
Again, if you don't like the negative shutter time feature, you don't have to use it. But for me, it's very useful for inputting and displaying fast shutter times in a standard, 1/t format instead of in microseconds (the only other option). I'd rather input my maximum shutter speed as -4000 (1/4000) than have to figure out that it's 250 microseconds (although you can do that if you want using a scale of 1000000).
I'm open to simplifying code and making it faster and more accurate, but please don't take out important and very useful features because you don't "like" them. Others will want to use them, and probably think of new, innovative ways to use them that we can't imagine right now.