line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Images::To::DjVu; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
60552
|
use strict; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
95
|
|
4
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
86
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1610
|
use Class::Utils qw(set_params); |
|
4
|
|
|
|
|
97400
|
|
|
4
|
|
|
|
|
67
|
|
7
|
4
|
|
|
4
|
|
248
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
123
|
|
8
|
4
|
|
|
4
|
|
20
|
use File::Basename; |
|
4
|
|
|
|
|
37
|
|
|
4
|
|
|
|
|
353
|
|
9
|
4
|
|
|
4
|
|
6639
|
use Getopt::Std; |
|
4
|
|
|
|
|
169
|
|
|
4
|
|
|
|
|
199
|
|
10
|
4
|
|
|
4
|
|
1557
|
use Perl6::Slurp qw(slurp); |
|
4
|
|
|
|
|
5183
|
|
|
4
|
|
|
|
|
19
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.02; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constructor. |
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
1523
|
my ($class, @params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Create object. |
19
|
2
|
|
|
|
|
7
|
my $self = bless {}, $class; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Process parameters. |
22
|
2
|
|
|
|
|
16
|
set_params($self, @params); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Object. |
25
|
2
|
|
|
|
|
16
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Run. |
29
|
|
|
|
|
|
|
sub run { |
30
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Process arguments. |
33
|
1
|
|
|
|
|
9
|
$self->{'_opts'} = { |
34
|
|
|
|
|
|
|
'e' => 'c44', |
35
|
|
|
|
|
|
|
'h' => 0, |
36
|
|
|
|
|
|
|
'o' => 'output.djvu', |
37
|
|
|
|
|
|
|
'q' => 0, |
38
|
|
|
|
|
|
|
}; |
39
|
1
|
50
|
33
|
|
|
7
|
if (! getopts('e:ho:q', $self->{'_opts'}) || @ARGV < 1 |
|
|
|
33
|
|
|
|
|
40
|
|
|
|
|
|
|
|| $self->{'_opts'}->{'h'}) { |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
118
|
print STDERR "Usage: $0 [-e encoder] [-h] [-o out_file] [-q] ". |
43
|
|
|
|
|
|
|
"[--version] images_list_file\n"; |
44
|
1
|
|
|
|
|
13
|
print STDERR "\t-e encoder\t\tEncoder (default value is 'c44').\n"; |
45
|
1
|
|
|
|
|
10
|
print STDERR "\t-h\t\t\tPrint help.\n"; |
46
|
1
|
|
|
|
|
9
|
print STDERR "\t-o out_file\t\tOutput file (default value is ". |
47
|
|
|
|
|
|
|
"'output.djvu').\n"; |
48
|
1
|
|
|
|
|
10
|
print STDERR "\t-q\t\t\tQuiet mode.\n"; |
49
|
1
|
|
|
|
|
8
|
print STDERR "\t--version\t\tPrint version.\n"; |
50
|
1
|
|
|
|
|
20
|
print STDERR "\timages_list_file\tText file with images list.\n"; |
51
|
1
|
|
|
|
|
13
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
my $images_list_file = $ARGV[0]; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Get images. |
56
|
0
|
|
|
|
|
|
my @images = slurp($images_list_file, { 'chomp' => 1 }); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Create djvu file for each file. |
59
|
0
|
|
|
|
|
|
my @djvu; |
60
|
0
|
|
|
|
|
|
foreach my $image (@images) { |
61
|
0
|
|
|
|
|
|
my ($image_base, undef, $suffix) = fileparse($image, qr{\.[^.]+$}); |
62
|
0
|
|
|
|
|
|
$suffix =~ s/^\.//ms; |
63
|
0
|
|
|
|
|
|
my $djvu = $image_base.'.djvu'; |
64
|
0
|
|
|
|
|
|
push @djvu, $djvu; |
65
|
0
|
0
|
0
|
|
|
|
if ($image ne $djvu && ! -r $djvu) { |
66
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'e'} eq 'c44') { |
67
|
0
|
0
|
|
|
|
|
if ($suffix eq 'png') { |
68
|
0
|
|
|
|
|
|
system "convert $image $image_base.jpg"; |
69
|
0
|
|
|
|
|
|
$image = "$image_base.jpg"; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
system "c44 $image $djvu"; |
72
|
0
|
0
|
|
|
|
|
if (! $self->{'_opts'}->{'q'}) { |
73
|
0
|
|
|
|
|
|
print "$djvu\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
err "Unsupported encoder '$self->{'_opts'}->{'e'}'."; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Create djvu file. |
82
|
0
|
0
|
|
|
|
|
if (! -r $self->{'_opts'}->{'o'}) { |
83
|
0
|
|
|
|
|
|
system "djvm -c $self->{'_opts'}->{'o'} ".(join ' ', @djvu); |
84
|
0
|
0
|
|
|
|
|
if (! $self->{'_opts'}->{'q'}) { |
85
|
0
|
|
|
|
|
|
print "$self->{'_opts'}->{'o'}\n"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding utf8 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
App::Images::To::DjVu - Base class for images2djvu script. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
use App::Images::To::DjVu; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $app = App::Images::To::DjVu->new; |
107
|
|
|
|
|
|
|
my $exit_code = $app->run; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 C |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $app = App::Images::To::DjVu->new; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Constructor. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Returns instance of object. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 C |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $exit_code = $app->run; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Run. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns 1 for error, 0 for success. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 ERRORS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
new(): |
130
|
|
|
|
|
|
|
From Class::Utils::set_params(): |
131
|
|
|
|
|
|
|
Unknown parameter '%s'. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
run(): |
134
|
|
|
|
|
|
|
Unsupported encoder '%s'. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 EXAMPLE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
use strict; |
139
|
|
|
|
|
|
|
use warnings; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
use App::Images::To::DjVu; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Arguments. |
144
|
|
|
|
|
|
|
@ARGV = ( |
145
|
|
|
|
|
|
|
'-h', |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Run. |
149
|
|
|
|
|
|
|
exit App::Images::To::DjVu->new->run; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Output like: |
152
|
|
|
|
|
|
|
# Usage: ./ex1.pl [-e encoder] [-h] [-o out_file] [-q] [--version] images_list_file |
153
|
|
|
|
|
|
|
# -e encoder Encoder (default value is 'c44'). |
154
|
|
|
|
|
|
|
# -h Print help. |
155
|
|
|
|
|
|
|
# -o out_file Output file (default value is 'output.djvu'). |
156
|
|
|
|
|
|
|
# -q Quiet mode. |
157
|
|
|
|
|
|
|
# --version Print version. |
158
|
|
|
|
|
|
|
# images_list_file Text file with images list. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L, |
163
|
|
|
|
|
|
|
L, |
164
|
|
|
|
|
|
|
L, |
165
|
|
|
|
|
|
|
L, |
166
|
|
|
|
|
|
|
L. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 REPOSITORY |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Michal Josef Špaček L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
© 2021-2022 Michal Josef Špaček |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
BSD 2-Clause License |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 VERSION |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
0.02 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |