5 # Copyright (C) 2007 David Hilvert
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 chomp ($ale_exec_dir = `dirname $0`);
26 if (!defined $ENV{"ALE_SOFT_GPU"} && `which glxinfo` && `glxinfo | grep "direct rendering: No"`) {
27 $ENV{"ALE_SOFT_GPU"} = "1";
28 } elsif (!defined $ENV{"ALE_SOFT_GPU"}) {
29 $ENV{"ALE_SOFT_GPU"} = "0";
33 # Determine whether to use GPU acceleration by default
36 if (!defined $ENV{"ALE_GPU_ACCEL_DEFAULT"}
37 && ($ENV{"ALE_SOFT_GPU"}
39 $ENV{"ALE_GPU_ACCEL_DEFAULT"} = 0;
41 $ENV{"ALE_GPU_ACCEL_DEFAULT"} = 1;
45 # Determine whether to use GL interface by default
50 if (!defined $ENV{"ALE_GL_UI_DEFAULT"}
51 && ($ENV{"ALE_SOFT_GPU"}
53 $ENV{"ALE_GL_UI_DEFAULT"} = 0;
58 if (!defined $ENV{"ALE_GL_UI_DEFAULT"}
59 && (`uname -a | grep Linux`)) {
60 $ENV{"ALE_GL_UI_DEFAULT"} = 1;
63 # Make GL UI non-default if neither blacklisted nor whitelisted
65 if (!defined $ENV{"ALE_GL_UI_DEFAULT"}) {
66 $ENV{"ALE_GL_UI_DEFAULT"} = 0;
70 # Environment variable defaults
74 "ALE_BIN" => "$ale_exec_dir/ale-bin",
76 "EXIF_UTILITY" => "exiftool",
77 "ALE_COUNT_THREADS" => "0",
78 "PAGER" => "/usr/bin/less",
82 "Canon EOS 5D" => "canon_300d",
83 "Canon EOS DIGITAL REBEL" => "canon_300d",
86 for $default (keys %defaults) {
87 if (!defined $ENV{$default}) {
88 $ENV{$default} = $defaults{$default};
93 # Wrap help page requests
96 if (!defined @ARGV || @ARGV == 0 || $ARGV[0] =~ /^--h[a-zA-Z0-9]$/) {
97 $ale_bin = $ENV{"ALE_BIN"};
104 if (-x
"$ENV{PAGER}") {
105 $pager = $ENV{"PAGER"};
106 } elsif (`which $ENV{"PAGER"}`) {
107 $pager = `which $ENV{"PAGER"}`;
108 } elsif (`which pager`) {
109 $pager = `which pager`;
110 } elsif (`which less`) {
111 $pager = `which less`;
112 } elsif (`which more`) {
113 $pager = `which more`;
114 } elsif (-x
'/usr/bin/less') {
115 $pager = '/usr/bin/less';
116 } elsif (-x
'/bin/more') {
117 $pager = '/bin/more';
124 $ENV{"LESS"} = "-X -F";
130 if (defined $pager) {
131 exec "exec -a $0 $ale_bin @ARGV | $pager";
133 exec "exec -a $0 $ale_bin @ARGV";
140 # Perform metadata extraction and conversion
143 $started_conversion = 0;
144 undef $global_device;
147 if ("@ARGV" =~ /exp-meta-only/ && defined $ENV{"EXIF_UTILITY"} && `which $ENV{"EXIF_UTILITY"}`) {
150 if (defined $ENV{"DCRAW"} && `which $ENV{"DCRAW"}`) {
153 for ($i = 0; $i < @ARGV; $i++) {
156 $i += 10 if $arg =~ /^-?-3dvp$/;
157 $i += 10 if $arg =~ /^-?-3dpp$/;
158 $i += 2 if $arg =~ /^-?-3dp$/;
159 $i += 2 if $arg =~ /^-?-3dv$/;
160 $i += 2 if $arg =~ /^-?-ochain$/;
161 $i += 3 if $arg =~ /^-?-wm$/;
162 $i += 3 if $arg =~ /^-?-wmx$/;
163 $i += 1 if $arg =~ /^-?-trans-load$/;
164 $i += 1 if $arg =~ /^-?-trans-save$/;
169 if (`$ENV{"EXIF_UTILITY"} $arg | grep '^EV'` =~ /([0-9\.]+)/) {
171 if (`$ENV{"EXIF_UTILITY"} $arg | grep '^ISO'` =~ /([0-9\.]+)/) {
172 $ev = $ev - log($1 / 100) / log(2);
174 @ARGV = (@ARGV[0..$i - 1], "--ev", "$ev", @ARGV[$i..$#ARGV]);
180 $device_info = `$ENV{"DCRAW"} -i $arg 2> /dev/null`;
184 if (!$started_conversion) {
185 print "Extracting frame data";
186 $started_conversion = 1;
189 # Make a temporary directory for conversion
192 use File
::Temp qw
/ tempdir /;
194 $tempdir = tempdir
("ale.XXXXXXXXX",
196 DIR
=> File
::Spec
->tmpdir());
200 # Get device information
204 foreach $device_string (keys %devices) {
205 if ($device_info =~ /$device_string/) {
206 $device = $devices{$device_string};
210 if (!defined $device) {
211 $device = "canon_300d";
215 # Currently, devices must be global.
218 if (defined $global_device && $global_device ne $device) {
219 die "Multiple device types not yet supported.\n";
221 $global_device = $device;
224 # @ARGV = (@ARGV[0..$i - 1], "--device", "$device", @ARGV[$i..$#ARGV]);
225 @ARGV = ("--device", "$device", @ARGV);
233 $converted_frame = $arg;
234 $converted_frame =~ s/(?:\.[^.]*)?$/.pgm/;
235 $converted_frame =~ s/.*\///;
236 $converted_frame = $tempdir . "/" . $converted_frame;
238 `$ENV{"DCRAW"} -t 0 -d -4 -k 0 -r 1 1 1 1 -c $arg > $converted_frame`;
240 $ARGV[$i] = $converted_frame;
243 # Try to get black level information
246 # XXX: The following approach is not obviously correct.
248 if (`$ENV{"DCRAW"} -d -v -c $arg 2>&1 1>/dev/null` =~ /black=(\d+)/) {
249 $black_unscaled = $1;
250 `$ENV{"DCRAW"} -D -4 -c $arg | pgmhist | tail -1` =~ /(\d+)/;
251 $maxval_unscaled = $1;
252 `pgmhist $converted_frame | tail -1` =~ /(\d+)/;
255 $black_scaled = $black_unscaled
256 * ($maxval_scaled / $maxval_unscaled)
259 @ARGV = (@ARGV[0..$i - 1], "--black", "$black_scaled", @ARGV[$i..$#ARGV]);
267 if ($started_conversion) {
273 if ($ENV{"ALE_COUNT_THREADS"} == 0) {
274 system { $ENV{"ALE_BIN"} } @ARGV;
279 exec { $ENV{"ALE_BIN"} } @ARGV;
283 $status_file = "/proc/$fork1/status";
284 while (-r
$status_file && `cat $status_file 2> /dev/null | grep Threads` =~ /(\d+)/) {
285 if (defined $threads{$1}) {
292 foreach $count (sort keys %threads) {
293 print("$count thread(s): $threads{$count} tick(s)\n");
298 while (wait() != -1) {}