1---------------------------------------------------------------- 2---------------------------------------------------------------- 3-- Enfuse droplet applescript 0.0.4 4-- Harry van der wolf 12 Aug 2008 5---------------------------------------------------------------- 6---------------------------------------------------------------- 7on FUNC_ABOUT() 8 display dialog "Enfuse droplet 0.0.4 by Harry van der Wolf" & return & return & � 9 "This (G)UI wrapper uses enfuse " & � 10 "to fuse your set of images with different exposure " & � 11 "settings to one fused image." & return & return & � 12 "You can use this GUI either by starting it " & � 13 "manually and then select your images" & � 14 return & return & "OR" & return & return & � 15 "drag and drop your images onto this little application." buttons {"Ok"} 16 17end FUNC_ABOUT 18---------------------------------------------------------------- 19---------------------------------------------------------------- 20on FUNC_ENF_PARAM() 21 display dialog "==== enfuse, version 3.1 ====" & return & � 22 "Common options:" & return & � 23 " -l number Number of levels to use (1 to 29)" & return & � 24 " -o filename Write output to file" & return & � 25 "-w Blend across -180/+180 boundary" & return & � 26 "--compression=COMP Set compression of the output image." & return & � 27 "Valid values for compression are:" & return & � 28 "For TIFF files: LZW, DEFLATE" & return & � 29 "For JPEG files: 0-100" & return & return & � 30 "Extended options:" & return & � 31 "-b kilobytes Image cache block size (default=2MiB)" & return & � 32 "-c Use CIECAM02 to blend colors" & return & � 33 "-g Associated alpha hack for Gimp (ver. < 2) and Cinepaint" & return & � 34 "-f WIDTHxHEIGHT+x0+y0 Manually set the size and position of the output image." & return & � 35 "Useful for cropped and shifted input TIFF images," & � 36 "such as those produced by Nona." & � 37 "-m megabytes Use this much memory before going to disk (default=1GiB)" & return & return & � 38 "Fusion options:" & return & � 39 "--wExposure=W Weight given to well-exposed pixels (from 0 to 1)." & return & � 40 "default value: 1.0" & return & � 41 "--wSaturation=W Weight given to highly-saturated pixels (from 0 to 1)." & return & � 42 "default value: 0.2" & return & � 43 "--wContrast=W Weight given to high-contrast pixels (from 0 to 1)." & return & � 44 "default value: 0" & return & � 45 "--HardMask Force hard blend masks (no averaging) on finest" & � 46 "scale. This is especially useful for focus" & � 47 "stacks with thin and high contrast features such" & � 48 "as insect hairs etc, but will lead to increased noise." & return & return & � 49 "Expert options:" & return & � 50 "--ContrastWindowSize=s Window size for local contrast analysis." & return & � 51 "Default: 5, (must be bigger than 3)." & return � 52 buttons {"Ok"} 53end FUNC_ENF_PARAM 54---------------------------------------------------------------- 55on FUNC_Initialize_BP_PGB(titlebarmsg, topmsg, bottommsg) 56 tell application "BP Progress Bar" 57 launch 58 set title of window 1 to titlebarmsg 59 activate 60 show window 1 61 tell window 1 of application "BP Progress Bar" 62 tell progress indicator 1 63 set indeterminate to true 64 start 65 end tell 66 end tell 67 tell window 1 of application "BP Progress Bar" to tell text field 1 to set content to topmsg 68 tell window 1 of application "BP Progress Bar" to tell text field 2 to set content to bottommsg 69 end tell 70end FUNC_Initialize_BP_PGB 71---------------------------------------------------------------- 72---------------------------------------------------------------- 73on FUNC_quit_BP_PGB() 74 tell application "BP Progress Bar" to quit 75end FUNC_quit_BP_PGB 76---------------------------------------------------------------- 77---------------------------------------------------------------- 78-- function enfuse 79on FUNC_ENFUSE(dropped_on, ImageList) 80 81 82 -- set enfuse_additional_parameters to "--wExposure=1 --wSaturation=1 --wContrast=1" 83 set enfuse_additional_parameters to "" 84 ---- start images selection if dropped_on is false 85 if not dropped_on then 86 set ImageList to "" 87 set theImages to � 88 choose file with prompt � 89 "Select the image files of your choice" default location (path to pictures folder) � 90 of type {"JPEG", "TIFF", "PNG"} with multiple selections allowed without invisibles 91 repeat with OneImage in theImages 92 set OneImage to quoted form of POSIX path of OneImage 93 set testname to POSIX path of OneImage 94 -- we need this extension later 95 if (testname as text) ends with ".TIF" or (testname as text) ends with ".TIFF" then 96 set ImgExt to ".tif" 97 else 98 set ImgExt to ".jpg" 99 end if 100 101 set ImagePath to quoted form of POSIX path of OneImage --should do it only once but who cares 102 set ImageList to ImageList & OneImage & " " 103 end repeat 104 ---- end of images selection 105 end if 106 107 -- Find the working dir of the program, otherwise it will default to $HOME where ais and enfuse are not available 108 tell application "Finder" to get folder of (path to me) as Unicode text 109 set workingDir to POSIX path of result 110 111 112 ---- start of requesting enfuse parameters 113 set get_going to "NOK" 114 repeat while get_going is "NOK" 115 display dialog "Enfuse additional parameters" & return & return & � 116 "Here you can specify your parameters." & return & � 117 "(Click Show Parameters to show possibilities)" & return & return � 118 default answer enfuse_additional_parameters buttons {"Show Parameters", "Quit", "Ok"} default button "Ok" 119 set dialogResult to result 120 set enfuse_additional_parameters to text returned of dialogResult 121 set choice to button returned of dialogResult 122 if choice = "Show Parameters" then FUNC_ENF_PARAM() 123 if choice = "Quit" then return -- exit script immediately 124 if choice = "Ok" then set get_going to "OK" 125 end repeat 126 --- end of requesting enfuse parameters 127 128 ----Ask filename of fused image and where it should be stored 129 set NewImgName to (choose file name with prompt "Specify the filename of your new fused image" default location (path to pictures folder)) 130 set NewImage to quoted form of POSIX path of NewImgName 131 set testname to POSIX path of NewImgName 132 -- file extensions are not treated case-sensitive within applescript 133 if (testname as text) ends with ".TIF" or (testname as text) ends with ".JPG" or (testname as text) ends with ".TIFF" or (testname as text) ends with ".JPEG" then 134 set NewImage to quoted form of POSIX path of testname 135 --display dialog NewImage 136 else 137 -- No image extension, so make it a tif 138 set testname to testname & ".tif" 139 set NewImage to quoted form of POSIX path of testname 140 --display dialog NewImage 141 end if 142 ---- kick off enfuse and set barber pole 143 FUNC_Initialize_BP_PGB("Running enfuse", "enfuse is merging your images", "This will take some time. Please wait....") 144 do shell script "cd " & workingDir & "; " & workingDir & "enfuse " & enfuse_additional_parameters & " -o " & NewImage & " " & ImageList 145 FUNC_quit_BP_PGB() 146 ---- enfuse finished. stop barber pole 147 148 ---- Show fused image to the public 149 -- Stupid preview application is not scriptable so we need to shell out. 150 -- Next to that there is another stupidity: It's called Preview.app on Tiger and preview.app on Leopard. 151 do shell script "open /Applications/Preview.app " & NewImage 152 do shell script "open /Applications/preview.app " & NewImage 153 154end FUNC_ENFUSE 155-- end of function enfuse 156---------------------------------------------------------------- 157---------------------------------------------------------------- 158 159 160-- Main part of script 161-- Here does it all start 162-- Define some (initial) variables/properties 163global ImageList 164set ImageList to "" 165 166-- "open" handler triggered by drag'n'drop launch. 167-- This parts starts when a user drops files on it 168on open of finderObjects 169 global HUGIN_PATH 170 --set HUGIN_PATH to "/Applications/Hugin.app" 171 set HUGIN_PATH to "" 172 set ImageList to "" 173 repeat with OneImage in (finderObjects) -- in case multiple objects dropped on applet 174 --set pipo to quoted form of POSIX path of i as text 175 --display dialog pipo -- show file/folder's info 176 if folder of (info for OneImage) is true then -- process folder's contents too 177 repeat with OneImage in finderObjects 178 set OneImage to quoted form of POSIX path of OneImage 179 set testname to POSIX path of NewImgName 180 -- we need this extension later 181 if (testname as text) ends with ".TIF" or (testname as text) ends with ".TIFF" then 182 set ImgExt to ".tif" 183 else 184 set ImgExt to ".jpg" 185 end if 186 set ImagePath to quoted form of POSIX path of OneImage --should do it only once but who cares 187 set ImageList to ImageList & OneImage & " " 188 end repeat 189 end if 190 -- repeat with OneImage in finderObjects 191 set OneImage to quoted form of POSIX path of OneImage 192 set ImagePath to quoted form of POSIX path of OneImage --should do it only once but who cares 193 set ImageList to ImageList & OneImage & " " 194 -- end repeat 195 end repeat 196 -- run function enfuse 197 set dropped_on to true 198 FUNC_ENFUSE(dropped_on, ImageList) 199end open 200-- end of drag'n'drop launch 201 202-- This is the part that starts when user opens application by double-clicking it 203 204set ImageList to "" 205-- ask user what he/she wants 206set quit_app to false 207repeat until quit_app is true 208 display dialog "Click Enfuse to get going!" buttons {"about", "quit", "Enfuse"} default button "Enfuse" 209 set choice to button returned of result 210 if choice = "Enfuse" then 211 set dropped_on to false 212 FUNC_ENFUSE(dropped_on, ImageList) 213 else if choice = "about" then 214 FUNC_ABOUT() 215 else 216 return --user has chosen quit so quit script 217 end if 218end repeat 219end run