doc/web: Use repo.or.cz terminology for the summary page.
[Ale.git] / ale
blobdc98514e6ca871679df830d3497e9b929d05047c
1 #!/usr/bin/perl -w
3 # ALE wrapper script
4 #
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`);
22 %defaults = (
23 "ALE_BIN" => "$ale_exec_dir/ale-bin",
24 "DCRAW" => "dcraw",
25 "EXIF_UTILITY" => "exiftool",
28 %devices = (
29 "Canon EOS 5D" => "canon_300d",
30 "Canon EOS DIGITAL REBEL" => "canon_300d",
33 for $default (keys %defaults) {
34 if (!defined $ENV{$default}) {
35 $ENV{$default} = $defaults{$default};
40 # Perform metadata extraction and conversion
43 $started_conversion = 0;
44 undef $global_device;
45 for ($i = 0; $i < @ARGV; $i++) {
46 $arg = $ARGV[$i];
48 $i += 10 if $arg =~ /^-?-3dvp$/;
49 $i += 10 if $arg =~ /^-?-3dpp$/;
50 $i += 2 if $arg =~ /^-?-3dp$/;
51 $i += 2 if $arg =~ /^-?-3dv$/;
52 $i += 2 if $arg =~ /^-?-ochain$/;
53 $i += 3 if $arg =~ /^-?-wm$/;
54 $i += 3 if $arg =~ /^-?-wmx$/;
56 next if (!-e $arg);
58 if (defined $ENV{"EXIF_UTILITY"} && `which $ENV{"EXIF_UTILITY"}`) {
59 if (`$ENV{"EXIF_UTILITY"} $arg | grep '^EV'` =~ /([0-9\.]+)/) {
60 $ev = $1;
61 if (`$ENV{"EXIF_UTILITY"} $arg | grep '^ISO'` =~ /([0-9\.]+)/) {
62 $ev = $ev - log($1 / 100) / log(2);
64 @ARGV = (@ARGV[0..$i - 1], "--ev", "$ev", @ARGV[$i..$#ARGV]);
65 $i += 2;
69 if (defined $ENV{"DCRAW"} && `which $ENV{"DCRAW"}`) {
70 $device_info = `$ENV{"DCRAW"} -i $arg 2> /dev/null`;
72 next if ($?);
74 if (!$started_conversion) {
75 print "Extracting frame data";
76 $started_conversion = 1;
79 # Make a temporary directory for conversion
82 use File::Temp qw/ tempdir /;
84 $tempdir = tempdir("ale.XXXXXXXXX",
85 CLEANUP => 1,
86 DIR => File::Spec->tmpdir());
90 # Get device information
93 undef $device;
94 foreach $device_string (keys %devices) {
95 if ($device_info =~ /$device_string/) {
96 $device = $devices{$device_string};
97 last;
100 if (!defined $device) {
101 $device = "canon_300d";
105 # Currently, devices must be global.
108 if (defined $global_device && $global_device ne $device) {
109 die "Multiple device types not yet supported.\n";
110 } else {
111 $global_device = $device;
114 # @ARGV = (@ARGV[0..$i - 1], "--device", "$device", @ARGV[$i..$#ARGV]);
115 @ARGV = ("--device", "$device", @ARGV);
117 $i += 2;
120 # Convert
123 $converted_frame = $arg;
124 $converted_frame =~ s/(?:\.[^.]*)?$/.pgm/;
125 $converted_frame =~ s/.*\///;
126 $converted_frame = $tempdir . "/" . $converted_frame;
128 `$ENV{"DCRAW"} -t 0 -d -4 -k 0 -r 1 1 1 1 -c $arg > $converted_frame`;
130 $ARGV[$i] = $converted_frame;
133 # Try to get black level information
136 # XXX: The following approach is not obviously correct.
138 if (`$ENV{"DCRAW"} -d -v -c $arg 2>&1 1>/dev/null` =~ /black=(\d+)/) {
139 $black_unscaled = $1;
140 `$ENV{"DCRAW"} -D -4 -c $arg | pgmhist | tail -1` =~ /(\d+)/;
141 $maxval_unscaled = $1;
142 `pgmhist $converted_frame | tail -1` =~ /(\d+)/;
143 $maxval_scaled = $1;
145 $black_scaled = $black_unscaled
146 * ($maxval_scaled / $maxval_unscaled)
147 / 65535;
149 @ARGV = (@ARGV[0..$i - 1], "--black", "$black_scaled", @ARGV[$i..$#ARGV]);
150 $i += 2;
153 print ".";
157 if ($started_conversion) {
158 print "\n";
161 @ARGV = ($0, @ARGV);
162 system { $ENV{"ALE_BIN"} } @ARGV;