1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
|
$infile = 'data.txt';
#$infile = $batOutput;
## Output File Handles (open)
open(OUT1,"> \!".$state.$status."INFO.txt") or die "Can't open \!".$state.$status."INFO.txt: $!";
open(OUT2,"> \!".$state.$status."INFOspdsht.txt") or die "Can't open \!".$state.$status."INFO.txt $!";
open(ERRLOG,"> \!errors.log") or die "Can't open !errors.log $!";
## Print Headers To spdsht file
print OUT2 ";;;;Whitespace;;DPI ReSize;;;\n";
print OUT2 "Filename;Comp;AlphCnl;Foto;Wid;Len;Res 0;x0;;;MB\n";
## Configuration Data for masking data output
my %config = (
'LZW' => 'colors',
'Lempel-Ziv & Welch encoding' => 'colors',
'CCITT Group 4' => 'bkwhts',
'CCITT Group 4 facsimile encoding' => 'bkwhts',
'None' => 'none',
'none' => 'none',
'RGB color' => 'colors',
'min-is-white' => 'bkwhts',
'min-is-black' => 'bkwhts',
'palette color (RGB from colormap)' => 'colors',
'Resolution' => sub {
my @r = split(/, /, shift);
$r[0] =~ s/\D//g;
$r[1] =~ s/\D//g;
return @r[0,1];
},
);
my @config = keys %config;
my $file = $infile; # set this as needed.
open my $fh, '<', $file or die "can't open <$file> for reading $!";
$/ = "TYPE:\n";
while ( my $record = <$fh> ) {
chomp $record;
next if $record eq '';
$record =~ s/(TIFF Directory at offset .+)\n//;
## Future use, for incrementing errors
$errorCount = 0;
my ($fullpath, $data) = split(/\n/, $record, 2);
$fullpath =~ s/:$//;
my ($drv, $path, $file) = File::Spec->splitpath($fullpath);
## Get Compression Scheme data
$cs = $config{$1} if ($data =~ s/\s{2}Compression Scheme:\s+(.*?)\n//);
if (!defined $cs) {
print "[ERROR]: Compression Scheme for $file not found.\n";
print ERRLOG "[ERROR]: Compression Scheme for $file not found.\n";
$errorCount++;
#next;
}
## Get Photometric Interpretation data
$pi = $config{$1} if ($data =~ s/\s{2}Photometric Interpretation:\s+(.*?)\n//);
if (!defined $pi) {
print "[ERROR]: Photometric Interpretation for $file not found.\n";
print ERRLOG "[ERROR]: Photometric Interpretation for $file not found.\n";
$errorCount++;
#next;
}
## Get Bits/Sample data
$bits = $1 if ($data =~ s/\s{2}Bits\/Sample:\s+(.*?)\n//);
if (!defined $bits) {
print "[ERROR]: Bits/Sample data for $file not found.\n";
print ERRLOG "[ERROR]: Bits/Sample data for $file not found.\n";
$errorCount++;
#next;
}
## Get Samples/Pixel data
$pixels = $1 if ($data =~ s/\s{2}Samples\/Pixel:\s+(.*?)\n//);
if (!defined $pixels) {
print "[ERROR]: Samples/Pixel data for $file not found.\n";
print ERRLOG "[ERROR]: Samples/Pixel data for $file not found.\n";
$errorCount++;
#next;
}
## Get AlphaChnl Value (bits * pixels)
$alphachnl = $bits * $pixels;
if ($alphachnl == 1) {
$alphachnl = "bkwhts";
}
elsif ($alphachnl == 8) {
$alphachnl = "colors";
}
elsif ($alphachnl == 24) {
$alphachnl = "doLOGO";
}
else {
$alphachnl = "unknwn";
}
## Get Resolution data
my @r = $config{'Resolution'}->($1) if ($data =~ s/\s{2}Resolution:\s+(.*?)\n//);
## Get Width/Length data
my ($w, $l) = ($1, $2) if ($data =~ s/\s{2}Image Width: (\d+) Image Length: (\d+)\n//);
## Width
if (!defined $w) {
print "[ERROR]: Width for $file not found.\n";
print ERRLOG "[ERROR]: Width for $file not found.\n";
$errorCount++;
#next;
}
## Length
if (!defined $l) {
print "[ERROR]: Length for $file not found.\n";
print ERRLOG "[ERROR]: Length for $file not found.\n";
$errorCount++;
#next;
}
## Resolution
if (!defined $r[0] || !defined $r[1]) {
print "[ERROR]: Resolution for $file not found.\n";
print ERRLOG "[ERROR]: Resolution for $file not found.\n";
$errorCount++;
#next;
}
## Get Size of TIF(F) file(s)
my $filesize = (-s $fullpath) / (1024 * 1024);
my $size_in_mb = sprintf "%.2f", $filesize;
## Error Check
if ($errorCount > 0) {
print "[INFO]: $file was not processed, too many errors.\n";
next;
}
$data =~ s/\n$//;
## ** For Debugging - Prints To Screen **
## print $/, join(':', $file, $cs, $bits, $pi, $w, $l, @r, $size_in_mb, "\n"), $data, "\n";
print "Processing $file\n";
print OUT1 $/, join(';', $file, $cs, $bits, $pixels, $pi, $w, $l, @r, $size_in_mb, "\n"), $data, "\n";
## LA Output
if ($state eq "LA") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];;;", "$size_in_mb;;","\'$batch;;;;","start;","$file;;;;;;;;;;","$size_in_mb;","move;","$file;","$dir_root\\done;", "\n";
}
## NM Output
elsif ($state eq "NM") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];;;", "$size_in_mb;;","\'$batch;;;;","start;","$file;","$size_in_mb;","move;","$file;","$dir_root\\done;", "\n";
next;
}
## OK/UT Output
elsif ($state eq "OK" || $state eq "UT") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];;;", "$size_in_mb;;","\'$batch;;;;","start;","$file;","$size_in_mb;","move;","$file;","$dir_root\\done;","start;",$file."f;","move;",$file."f;","$dir_root\\done\\TEMPdone;", "\n";
next;
}
## TX/WY Output
elsif ($state eq "TX" || $state eq "WY") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];", "move $dir_root\\$file $dir_root\\$cs\\$file;;", "$size_in_mb;;", "\'$batch;;;","start;", "$dir_root\\$cs\\$file;", "$file;","$size_in_mb;","move;", "$dir_root\\$cs\\$file;", "$dir_root\\done;","start;", $file."f;", "move;", $file."f;", "$dir_root\\done\\TEMPdone;", "\n";
next;
}
elsif ($state eq "NONE" || $state eq "--" || $state eq "OTHER") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];", "$size_in_mb\n";
next;
}
}
close (OUT1) or die "Can't close out1: $!";
close (OUT2) or die "Can't close out2: $!";
close (ERRLOG) or die "Can't close error log: $!";
close ($fh) or die "Can't close $fh: $!";
|