--[[ ******************************** Licence: GPL thx fudgey, mattkime ******************************** @param a Schrittweite [x*1/3Ev] @default a 3 @param b Anzahl Bilder [n] @default b 3 @param c Entwicklung? [0=nein][1=ja] @default c 1 @param d Bildmischung [0=sum] [1=ds] @default d 1 @param e RAWs löschen [0=nein][1=ja] @default e 1 @param f WAV löschen [0=nein][1=ja] @default f 1 @param g Tonwertkurve [0=nein] [1-4] @default g 0 @param h nur Entwickl.[0=nein][1=ja] @default h 0 @param i Shoot-Pause [0=nein][1=ja] @default i 0 @param j Kurven setzen[0=nein][1=ja] @default j 0 @param k #Kurvenverz. [0 bis 99] @default k 0 @param l Kurve in Exif eintr. [1=ja] @default l 0 @param m Startbildnummer [keine=<1] @default m 0 ]] ---///////// derived from br_dev02.lua from msl ---///////// these lines are changes for curve-bracketing by naddel ver 0.1 ---///////// other functionality unchanged ---wrap///// these lines may also enhance standard behavior ---wrap///// by skipping merging if only 1 picture to develop debug=false -- functions function log(...) ---/// logfile=io.open(log_name,"a") logfile:write(...) logfile:write("\n") logfile:close() ---//// ---/// io.write(...) ---/// io.write("\n") end function fastshoot() press("shoot_half") repeat sleep(1) until get_shooting() == true press("shoot_full") release("shoot_full") release("shoot_half") repeat sleep(1) until get_shooting() ~= true end function wait() repeat print("weiter mit [SET]") wait_click() until is_pressed "set" print("Start in 2 Sekunden...") sleep (2000) end function ev_display(nn) local s,i,f="" if nn < 0 then s="-" nn=nn*-1 end i,f=tostring(nn/3),tostring(nn%3) if nn ==0 then s="0" elseif nn>2 then s=s..i.." " end if f~="0" then s=s..f.."/3" end return s.." Ev" end function getImageDirs() local dcimList = os.listdir("A/DCIM", false) local i=1 if(dcimList) then table.sort(dcimList) while i<=#dcimList do if string.upper(string.sub(dcimList[i],4))~="CANON" then table.remove(dcimList,i) else i=i+1 end end end return dcimList end function getImageList() local imgTable = {} local dcimList = getImageDirs() local dirCount = table.getn(dcimList) local i = 0 while ( dirCount ~= i) do i = i + 1 local imgDirList = os.listdir("A/DCIM/"..dcimList[i], false) local imgCount = table.getn(imgDirList) table.sort(imgDirList) local a = 0 while (imgCount ~= a) do a = a + 1 table.insert(imgTable,"A/DCIM/"..dcimList[i].."/"..imgDirList[a]) end end return imgTable end function filter(searchString,PICList) --print(searchString,PICList) --wait_click() local imageList={} if PICList ~= nil then for i=1,#PICList do imageList[i] = PICList[i] end else imageList = getImageList() end local count = table.getn(imageList) local i = 0 while i ~= count do i = i + 1 if(string.find(imageList[i],searchString,17, true) == nil) then table.remove(imageList,i) i = i - 1 count = count - 1 end end ------------ -- for i,count in ipairs(imageList) do log(count) end --------------- return imageList end -----///////////////////////////////// -- set curve file function copy_to_std(name,from_name) local f,buffer,testbuffer if from_name==nil then f,buffer=io.open(name,"rb") buffer=f:read("*all") f:close() else buffer=string.rep("\0\16",4*1024) end f=io.open("A/CHDK/CURVES/STD.CVF","wb") f:write(buffer) f:close() if false then f=io.open("A/CHDK/CURVES/STD.CVF","rb") testbuffer=f:read("*all") f:close() print("std.cvf ok=",buffer==testbuffer,#buffer,#testbuffer) end end function set_manufacturer_to_filter(image,curve) --print(image,curve) --wait_click() local ss,se,act_param -- returns -2 if params invalid -- -1 if image not found -- 0 if "Canon" not found -- 1 success if image==nil or curve==nil then return -2 end local filter=string.sub(curve,1,-5) filter=string.sub(filter,1,1)..string.sub(filter,-4) local i,retVal=0 -- mostly the filesystem is to lazy repeat sleep(100) i=i+1 if not exists_file(image) then retVal = -1 else local f,buffer=io.open(image,"r") buffer=f:read(500) f:close() ss,se=string.find(buffer,"Canon") if ss~=nil then f=io.open(image,"r+") f:write(string.sub(buffer,1,ss-1),filter) f:close() retVal = 1 else retVal = 0 end end until retVal>=0 or i > 10 return retVal end function isdng(bildname) -- DNG_Format testen: Tiff-Signatur II* testfile=io.open(bildname,"r") testsig=testfile:read(3) testfile:close() return testsig=="II*" end function exists_file(name) local state_is=get_state(name) if state_is.attrib==nil then return false end -- .. wird wohl tlw emuliert und liefert keine korrekten Werte return bitand(state_is.attrib,0x30) == 0x20 -- return state_is.is_file == true end function get_state(file_name) state_is = {} local r = os.stat(file_name) if r then local keys={ "dev", "mode", "size", "atime", "mtime", "ctime", "blksize", "blocks", "attrib","is_dir","is_file",} for k,v in ipairs(keys) do state_is[v] = r[v] end end return state_is end --////////////////////////////////// --start script ---///////////////// if not get_mode() then print(" Schalte auf FotoModus") print(" und starte nochmal ") sleep(2000) else -------//////////////////// if a<0 then a=0 end if a>6 then a=6 end if b<0 then b=3 end if a<2 then if b>7 then b=7 end else if b>5 then b=5 end end if c~=1 then c=0 end if d~=1 then d=0 end if e~=1 then e=0 end if f~=1 then f=0 end if g<0 or g>4 then g=0 end if h~=1 then h = 0 end i = i == 1 ----//////////// if j<0 or j>1 then j=0 end if k<0 then k=0 end if k>99 then k=99 end if l~=1 then l=0 end if m <0 then m=m*-1 end m = m % 10000 ----//////////// step =a num =b dev =c operation =d del_raw =e del_wav =f curve =g only_dev =h==1 pause =i use_pic =m ----/////////// switch_curve = j == 1 curveFolder="A/CHDK/CURVES/BRACKT"..string.sub("00"..tostring(k),-2) if switch_curve then writeExif = l==1 num =1 dev =1 curve =1 -- operation =1 del_raw =0 del_wav =0 -- only_dev =1 else writeExif= false end ----////////////// -- nothing usable defined there -- prop_cases=require("propcase") raw_state = get_raw() ev_state = get_ev() dev_string = {"develop : off","develop : on"} op_string = {"sum","average"} del_raw_string = {"RAW delete : off","RAW delete : on"} del_wav_string = {"WAV delete : off","WAV delete : on"} raw_string = {"RAW: off","RAW: on"} curve_string = {"NONE","CUSTOM","+1EV","+2EV","AutoDR"} only_dev_string = {"shoot and develop" , "only develop"} ---/// --- note sx10 returns Flash as 7 custom as 8 else custom is 7 whiteBal_string = {"Auto","Day Light","Cloudy","Tungsten","Fluorescent","Fluorescent H","Custom","Custom_"} ---/// log_path = "A/CHDK/LOGS/" log_file_name = "log.log" log_name = log_path..log_file_name logfile=io.open(log_name,"wb") ---/// logfile:close() ---/// ---///io.output(logfile) propset=get_propset() log(os.date("%x - %X"), " raw merge\n") log("cam status: ", raw_string[raw_state + 1], " | ", ev_display(ev_state/32), "\n") log("number of pics : ", num, " step wide *1/3Ev: ", step) log(dev_string[dev + 1], " ", op_string[operation + 1]) if propset == 1 then WB_MODE=5 if debug then property=get_prop(100) log("pc100 -"..property.."-") property=get_prop(101) log("pc101 -"..property.."-") end else WB_MODE=268 end log("white-balance : ", whiteBal_string[get_prop(WB_MODE) + 1]) log(del_raw_string[del_raw + 1]) log(del_wav_string[del_wav + 1]) if switch_curve then log("use curves from: ",curveFolder) end log("curve : ", curve_string[curve + 1]) log("mode : ",only_dev_string[h+1], "\n") --//////////// print("Start") if not only_dev then ---/////////////// --///////////print("Start in 2 Sekunden...") ---////////// print("in 2 Sekunden...") ---/////////// sleep(2000) ------//////// end ----//////////// -- bracketing shooting if not only_dev then set_raw(1) n=1 for i=1, num do ev = (i/2 * n) * step print("Bild", i, "von", num, ev_display(ev_state/32+ev), ev_display(ev)) log("pic ", i, " of ", num, " ",ev_display(ev_state/32+ev), ev_display(ev)) set_ev(ev*32+ev_state) if pause then wait() end fastshoot() if n==1 then n=-1 else n=1 end end set_ev(ev_state) set_raw(raw_state) end function printlist(list) print() for i=1,#list do print(list[i]) wait_click() end end -- search for last raw files log("\nsearch for the last ", num, " files\n") search = "CRW" list_crw = filter(search) count_crw = table.getn(list_crw) if count_crw < num then log("Found only ", count_crw, " files.\n") num = count_crw end if use_pic > 0 then result_crw=filter("_"..string.sub("00000"..tostring(use_pic),-4),list_crw) local loci,li,lj,lk if #result_crw >0 then for loci=1,count_crw do li=loci if list_crw[loci]==result_crw[1] then break end end lk=1 for lj=li,li+(num-1) do if list_crw[lj] == nil then break end result_crw[lk]=list_crw[lj] lk=lk+1 end else print("crw nr ",use_pic," nicht gefunden2") log("search for raw ",tostring(use_pic)," ...fail") result_crw=list_crw use_pic=0 end end if use_pic == 0 then local li result_crw = {} for li=1, num do if count_crw - li+1 < 1 then break end result_crw[li] = list_crw[count_crw - li+1] end table.sort(result_crw) end for i=1, #result_crw do log(result_crw[i]) end if switch_curve then curveList = os.listdir(curveFolder, false) if curveList~=nil then i=tostring(#curveList) else switch_curve=false i="no" end log(i," curves found in folder ",curveFolder) end -- merge if result_crw[1] ~= nil then ---wrap////////////////// if num==1 then list_wav=result_crw count_wav=1 else curveList={} ----wrap////////////////////// log("\nmerge: ",op_string[operation + 1], "\n") merge_start(operation) for i=1, num do print("lade:", string.sub(result_crw[i], 17)) log("load: ", result_crw[i]) raw_merge_add_file(result_crw[i]) end print("erzeuge WAV-Datei") log("\ncreate WAV file") raw_merge_end() ----wrap//////////// end ----wrap////////////// else print("Keine RAW-Dateien!") log("No RAW files for merging found!") end -- search last wav file ------////////////// if num~=1 then ------/////////////// log("\nsearch for the last wav file\n") search = "WAV" list_wav = filter(search) count_wav = table.getn(list_wav) if list_wav[1] ~= nil then log(list_wav[count_wav]) else log("No WAV file found!") end ----////////////// end -----///////////// -- develop if dev == 1 then if list_wav[1] ~= nil then set_ev(0) ----///////////////// use_curve=1 repeat --- set_curve_state(0) if curveList~=nil and curveList[use_curve]~=nil then copy_to_std(curveFolder.."/"..curveList[use_curve]) log("\ndevelop: ",list_wav[count_wav]) log( "using : ",curveList[use_curve]) log( "to pic : ",tostring((1+get_exp_count()) % 10000)) print("lade",string.sub(list_wav[count_wav],-20)) print("setze Kurve:",curveList[use_curve]) else log("\nmake JPG ",tostring((1+get_exp_count()) % 10000)) end ---/////////////////////// set_curve_state(curve) --//// log("\nmake JPG\n") --///// if isdng(list_wav[count_wav]) then log(list_wav[count_wav]," is DNG and will not be used\n") print("! Eingabedatei ist DNG") end ---/// set_raw_develop(list_wav[count_wav]) fastshoot() if debug then search = "JPG" list_jpg = filter(search) --printlist(list_jpg) listcount = table.getn(list_jpg) log("\n",list_jpg[listcount]) -----///////////////// -- print(string.sub(list_jpg[listcount],1,-14)) -- wait_click() tst=os.listdir(string.sub(list_jpg[listcount],1,-14)) table.sort(tst) log("last in last dir: ",tst[#tst]) log("Expcount :",tostring((get_exp_count())%10000)) end if writeExif and curveList~=nil and curveList[use_curve]~=nil then tst=getImageDirs() act_image="A/DCIM/"..tst[#tst].."/IMG_"..string.sub("0000"..tostring((get_exp_count())%10000),-4)..".JPG" set_manufacturer_to_filter(act_image,curveList[use_curve]) end use_curve=use_curve+1 until curveList==nil or curveList[use_curve]==nil -----/////////////// set_ev(ev_state) set_curve_state(0) else print("Keine WAV-Datei!") log("No file for development!") end end -- search last jpg number search = "JPG" list_jpg = filter(search) count_jpg = table.getn(list_jpg) last_jpg = string.sub(list_jpg[count_jpg], 21, -5) log("\nlast pic number: ", last_jpg, "\n") -- delete raw files if del_raw == 1 then print("RAWs löschen.") log("delete RAW files\n") if result_crw[1] ~= nil then for i=1, num do log("delete: ", result_crw[i]) os.remove(result_crw[i]) end else print("keine RAW-Dateien!") log("No RAW files found!\n") end end -- delete wav file or rename to *.cr2 if list_wav[1] ~= nil then if del_wav == 1 then print("WAV löschen.") log("delete: ", list_wav[count_wav]) os.remove(list_wav[count_wav]) else ----///////////// if not only_dev then ---///////////// print("WAV in CR2 umbenennen.") new_name = string.sub(list_wav[count_wav], 1, string.len(list_wav[count_wav])-8)..last_jpg..".CR2" log("\nrename: ", list_wav[count_wav], "\nto: ", new_name) os.rename(list_wav[count_wav], new_name) ------//// end ------//// end else print("keine WAV-Datei!") log("No WAV file for deleting or renaming!") end -- ready print("-------fertig--------") log("\nready -> ", os.date("%X")) ---////logfile:close() play_sound(0) -- rename logfile log_num = 1 while os.stat(log_path..last_jpg.."_"..log_num..".log") do log_num = log_num + 1 end os.rename(log_name, log_path..last_jpg.."_"..log_num..".log") ----////////////// end ----//////////////