@title Sunset10rem Sunset and dawn time-lapsesrem v. 10, Fbonomi may 20th 2008rem Released under GPLrem incorporates feedback from previous shot: if more than 10% of pixelsrem are in the 100-800 range, decrease exposure@param a Delay (sec)@default a 5@param b Limit Tv @default b -414rem (-414=20 sec; -384=15 sec; -320=10 sec; -224=5 sec.)@param c Default Sv@default c 480rem (480=160)@param d Limit Sv @default d 776rem (776=1250 ISO; 960=5000)@param e Guess mode limit@default e -200@param f Slope in guess mode@default f 5print_screen 1print "Sunset Time Lapse"rem initialize guess mode valuex=erem get start Tvget_tv96 Nrem picture counter p=1rem exposure factor of previous shot h=0rem mark "FIFO BUFFER EMPTY"Z=-1:looprem measure luminance and aperturepress "shoot_half"sleep 500release "shoot_half"get_bv96 Bget_av96 Arem release "shoot_half"print "Measured: ",B ,Arem resulting Tv would be:N=B-AN=N+cprint "Calculated T: ", Nrem check Tv Valuesif N>e then rem normal mode, shoot with calculated Tv and default Sc M=N L=c print "Mode: Standard"else rem Guess mode, every shot will be 5/96th steps longer x=x-f rem but if last exposure was over-exposed, don't decrease, rem and instead increase if h>10 then print "Compensating ", h x=x+f+f endif rem x has now the desired exposure, we will now attempt rem to smooth its value (mobile average over 10 shots) rem the last 10 values of x are stored in a FIFO buffer rem made by variables Q to Z rem The first time we are here, the FIFO buffer will be empty rem let's initialize it if Z=-1 then Q=x R=x S=x T=x U=x V=x W=x X=x Y=x Z=x endif rem feed the buffer Z=Y Y=X X=W W=V V=U U=T T=S S=R R=Q Q=x rem calculate the average of values stored in FIFO buffer P= Q+Q+Q+Q+Q P=P +R+R+R+R P=P +S+S+S P=P +T+T P=P +U P=P/15 print "Smoothed ",x, " ", P rem P now contains a smoothed value of what was in x rem avoid overcompensating (guess mode climbing over guess mode limit) if P>e then P=e endif if P>b then print "Mode: Guess ", P ,b rem we are in dark, but exposure is not too long rem normal mode, shoot with guessed Tv and default Sc M=P L=c else print "Mode: Guess with High ISO", P ,b rem we are in very dark area, we want to avoid too long exposures rem shoot with maximum allowed time (b) and rem adjust Sv accordingly M=b L=c+b-P rem BUT check we don't go in too high ISO! if L>d then L=d endif endif endifrem we can now shootsleep 100set_sv96 Lsleep 100set_tv96_direct Msleep 100shootsleep 100rem let's read histogram of the shot that was just takenexp_get_info 100 800 hrem h contains the percentage of pixels that are between 100/1024 and 800/1024print "SHOOT ",p,M,L,hp=p+1sleep a*1000goto "loop"
#include "platform.h"#include "conf.h"#include "shot_histogram.h"#include "camera.h"#include "raw.h"#include "stdlib.h"#define RAW_TARGET_DIRECTORY "A/DCIM/%03dCANON"#define RAW_TARGET_FILENAME "%s_%04d.%s"unsigned short shot_histogram[1024];unsigned short shot_margin_left=0, shot_margin_top=0, shot_margin_right=0, shot_margin_bottom=0;void build_shot_histogram(){ // read samples fromRAW memory and build an histogram of its luminosity // actually, it' just reading pixels, ignoring difference between R, G and B, // we just need an estimate of luminance // SHOT_HISTOGRAM_MARGIN defines a margin around the sensor that will be ignored // (dead area) int x, y, x0, x1, y0, y1; int marginstep; short p; for (x = 0; x < 1024; x ++ ) { shot_histogram[x]=0; } marginstep= (CAM_RAW_ROWPIX - 2 * SHOT_HISTOGRAM_MARGIN)/10; // In future, support definition of a sort of "spot metering" x0 = SHOT_HISTOGRAM_MARGIN + shot_margin_left * marginstep; x1 = CAM_RAW_ROWPIX - SHOT_HISTOGRAM_MARGIN - shot_margin_right * marginstep; y0 = SHOT_HISTOGRAM_MARGIN + shot_margin_top * marginstep; y1 = CAM_RAW_ROWS - SHOT_HISTOGRAM_MARGIN - shot_margin_bottom * marginstep; //x0 = SHOT_HISTOGRAM_MARGIN ; //x1 = CAM_RAW_ROWPIX - SHOT_HISTOGRAM_MARGIN ; //y0 = SHOT_HISTOGRAM_MARGIN; //y1 = CAM_RAW_ROWS - SHOT_HISTOGRAM_MARGIN; // just read one pixel out of SHOT_HISTOGRAM_STEP, one line out of SHOT_HISTOGRAM_STEP for (y = y0 ; y < y1; y +=SHOT_HISTOGRAM_STEP ) for (x = x0 ; x < x1; x +=SHOT_HISTOGRAM_STEP ) { p=get_raw_pixel(x,y); shot_histogram[p]++; } // dump to file (just for debugging / logging purposes) // for each shoot, creates a HSTnnnnn.DAT file containing 2*1024 bytes char fn[64]; char dir[32]; sprintf(dir, RAW_TARGET_DIRECTORY, (conf.raw_in_dir)?get_target_dir_num():100); sprintf(fn, "%s/", dir); sprintf(fn+strlen(fn), RAW_TARGET_FILENAME, "HST", get_target_file_num(), "DAT"); char buf[64]; int fd = open(fn, O_WRONLY|O_CREAT, 0777); if (fd>=0) { write(fd, shot_histogram, 2048); close(fd); } }int shot_histogram_get_range(int histo_from, int histo_to)// Examines the histogram, and returns the percentage of pixels that // have luminance between histo_from and histo_to{ int x, tot, rng; tot=0; rng=0; for (x = 0 ; x < 1024; x ++ ) { tot += shot_histogram[x]; if (x>=histo_from && x <= histo_to) { rng += shot_histogram[x]; } } return (rng*100)/tot; }
#include "shot_histogram.h"
Line 28: // just after shooting, build shot histogram build_shot_histogram();
Line 1552:// Interface function for uBasicstatic void exp_get_info(){ int var; int histo_from; int histo_to; accept(TOKENIZER_EXP_GET_INFO); histo_from=expr(); histo_to=expr(); var = tokenizer_variable_num(); accept(TOKENIZER_VARIABLE); ubasic_set_variable(var, (unsigned short)shot_histogram_get_range(histo_from, histo_to)); accept_cr(); }
Line:1831 case TOKENIZER_EXP_GET_INFO: exp_get_info(); break;
{"exp_get_info", TOKENIZER_EXP_GET_INFO},
sleep 100set_sv96 Yset_tv96_direct Xsleep 100
sleep 100set_sv96 Ysleep 100set_tv96_direct Xsleep 100
So at least you should add an option in the menus to enable/disable this feature. You are probably better than me at this, I have never studied the menu and configuration system.
It's much better to have an uBasic command that enables/disalbes this feature.
Otherwise, where are the sources to your build?