line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Video::Pattern; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
289664
|
use strict; |
|
4
|
|
|
|
|
30
|
|
|
4
|
|
|
|
|
108
|
|
4
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
103
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1317
|
use Class::Utils qw(set_params); |
|
4
|
|
|
|
|
75116
|
|
|
4
|
|
|
|
|
92
|
|
7
|
4
|
|
|
4
|
|
209
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
144
|
|
8
|
4
|
|
|
4
|
|
21
|
use English; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
23
|
|
9
|
4
|
|
|
4
|
|
1758
|
use File::Basename qw(fileparse); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
291
|
|
10
|
4
|
|
|
4
|
|
1754
|
use File::Spec::Functions qw(catfile); |
|
4
|
|
|
|
|
3244
|
|
|
4
|
|
|
|
|
228
|
|
11
|
4
|
|
|
4
|
|
1271
|
use Image::Random; |
|
4
|
|
|
|
|
122107
|
|
|
4
|
|
|
|
|
131
|
|
12
|
4
|
|
|
4
|
|
35
|
use Readonly; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
169
|
|
13
|
4
|
|
|
4
|
|
1896
|
use Video::Delay::Const; |
|
4
|
|
|
|
|
908
|
|
|
4
|
|
|
|
|
3248
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constants. |
16
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY_STR => q{}; |
17
|
|
|
|
|
|
|
Readonly::Scalar our $MILISECONDS_IN_SECOND => 1000; |
18
|
|
|
|
|
|
|
Readonly::Scalar our $MINUTS_IN_HOUR => 60; |
19
|
|
|
|
|
|
|
Readonly::Scalar our $SECONDS_IN_MINUTE => 60; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = 0.09; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Constructor. |
24
|
|
|
|
|
|
|
sub new { |
25
|
12
|
|
|
12
|
1
|
18544
|
my ($class, @params) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Create object. |
28
|
12
|
|
|
|
|
45
|
my $self = bless {}, $class; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Delay generator. |
31
|
12
|
|
|
|
|
41
|
$self->{'delay_generator'} = Video::Delay::Const->new( |
32
|
|
|
|
|
|
|
'const' => 1000, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Duration. |
36
|
12
|
|
|
|
|
277
|
$self->{'duration'} = 10000; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Frame per second. |
39
|
12
|
|
|
|
|
24
|
$self->{'fps'} = 60; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Image generator. |
42
|
12
|
|
|
|
|
14
|
$self->{'image_generator'} = undef; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Image type. |
45
|
12
|
|
|
|
|
25
|
$self->{'image_type'} = 'bmp'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Process params. |
48
|
12
|
|
|
|
|
27
|
set_params($self, @params); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Check fps value. |
51
|
10
|
100
|
100
|
|
|
169
|
if (! defined $self->{'fps'} || $self->{'fps'} !~ m/^\d+$/ms) { |
52
|
2
|
|
|
|
|
8
|
err "Parameter 'fps' must be numeric value."; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Check and process duration value. |
56
|
8
|
|
|
|
|
26
|
$self->_check_and_process_duration; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Own image generator. |
59
|
5
|
100
|
|
|
|
14
|
if (! defined $self->{'image_generator'}) { |
60
|
|
|
|
|
|
|
$self->{'image_generator'} = Image::Random->new( |
61
|
|
|
|
|
|
|
'height' => 1080, |
62
|
4
|
|
|
|
|
23
|
'type' => $self->{'image_type'}, |
63
|
|
|
|
|
|
|
'width' => 1920, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} else { |
66
|
1
|
|
|
|
|
6
|
$self->{'image_type'} = $self->{'image_generator'}->type; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Object. |
70
|
5
|
|
|
|
|
21187
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Create images to output directory. |
74
|
|
|
|
|
|
|
sub create { |
75
|
1
|
|
|
1
|
1
|
627
|
my ($self, $output_dir) = @_; |
76
|
1
|
|
|
|
|
2
|
my $delay = 0; |
77
|
1
|
|
|
|
|
2
|
my $image; |
78
|
1
|
|
|
|
|
7
|
foreach my $frame_num (0 .. $self->{'duration'} / 1000 |
79
|
|
|
|
|
|
|
* $self->{'fps'}) { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $image_path = catfile($output_dir, |
82
|
|
|
|
|
|
|
(sprintf '%03d', $frame_num).'.'. |
83
|
601
|
|
|
|
|
3400
|
$self->{'image_type'}); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Create new image. |
86
|
601
|
100
|
|
|
|
1403
|
if ($delay <= 0) { |
87
|
10
|
|
|
|
|
71
|
$self->{'image_generator'}->create($image_path); |
88
|
10
|
|
|
|
|
299810
|
$image = $image_path; |
89
|
10
|
|
|
|
|
88
|
$delay = $self->{'delay_generator'}->delay; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Symlink to old image. |
92
|
|
|
|
|
|
|
} else { |
93
|
591
|
|
|
|
|
6081
|
my ($image_filename) = fileparse($image); |
94
|
591
|
|
|
|
|
1358
|
$self->_symlink($image_filename, $image_path); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Decrement delay. |
98
|
601
|
|
|
|
|
1960
|
$delay -= 1000 / $self->{'fps'}; |
99
|
|
|
|
|
|
|
} |
100
|
1
|
|
|
|
|
7
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Check and process duration. |
104
|
|
|
|
|
|
|
sub _check_and_process_duration { |
105
|
8
|
|
|
8
|
|
12
|
my $self = shift; |
106
|
8
|
|
|
|
|
15
|
my $err = 0; |
107
|
8
|
100
|
|
|
|
46
|
if (! defined $self->{'duration'}) { |
|
|
100
|
|
|
|
|
|
108
|
1
|
|
|
|
|
2
|
$err = 1; |
109
|
|
|
|
|
|
|
} elsif ($self->{'duration'} =~ m/^(\d+)(\w*)$/ms) { |
110
|
6
|
|
|
|
|
15
|
my $duration_value = $1; |
111
|
6
|
|
|
|
|
13
|
my $duration_suffix = $2; |
112
|
6
|
100
|
|
|
|
18
|
if ($duration_suffix ne $EMPTY_STR) { |
113
|
3
|
100
|
|
|
|
11
|
if ($duration_suffix eq 's') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
114
|
1
|
|
|
|
|
5
|
$self->{'duration'} = $duration_value |
115
|
|
|
|
|
|
|
* $MILISECONDS_IN_SECOND; |
116
|
|
|
|
|
|
|
} elsif ($duration_suffix eq 'ms') { |
117
|
1
|
|
|
|
|
4
|
$self->{'duration'} = $duration_value; |
118
|
|
|
|
|
|
|
} elsif ($duration_suffix eq 'min') { |
119
|
0
|
|
|
|
|
0
|
$self->{'duration'} = $duration_value |
120
|
|
|
|
|
|
|
* $MILISECONDS_IN_SECOND |
121
|
|
|
|
|
|
|
* $SECONDS_IN_MINUTE; |
122
|
|
|
|
|
|
|
} elsif ($duration_suffix eq 'h') { |
123
|
0
|
|
|
|
|
0
|
$self->{'duration'} = $duration_value |
124
|
|
|
|
|
|
|
* $MILISECONDS_IN_SECOND |
125
|
|
|
|
|
|
|
* $SECONDS_IN_MINUTE |
126
|
|
|
|
|
|
|
* $MINUTS_IN_HOUR; |
127
|
|
|
|
|
|
|
} else { |
128
|
1
|
|
|
|
|
3
|
$err = 1; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} else { |
132
|
1
|
|
|
|
|
3
|
$err = 1; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
8
|
100
|
|
|
|
18
|
if ($err) { |
136
|
3
|
|
|
|
|
10
|
err "Parameter 'duration' must be numeric value or numeric ". |
137
|
|
|
|
|
|
|
"value with time suffix."; |
138
|
|
|
|
|
|
|
} |
139
|
5
|
|
|
|
|
8
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Symlink. |
143
|
|
|
|
|
|
|
sub _symlink { |
144
|
591
|
|
|
591
|
|
847
|
my ($self, $from, $to) = @_; |
145
|
591
|
50
|
|
|
|
1328
|
if ($OSNAME eq 'MSWin32') { |
146
|
0
|
|
|
|
|
0
|
eval { |
147
|
0
|
|
|
|
|
0
|
require Win32::Symlink; |
148
|
|
|
|
|
|
|
}; |
149
|
0
|
|
|
|
|
0
|
my $has_symlink; |
150
|
0
|
0
|
|
|
|
0
|
if (! $EVAL_ERROR) { |
151
|
0
|
|
|
|
|
0
|
$has_symlink = eval { |
152
|
0
|
|
|
|
|
0
|
Win32::Symlink::symlink($from => $to); |
153
|
|
|
|
|
|
|
}; |
154
|
|
|
|
|
|
|
} |
155
|
0
|
0
|
|
|
|
0
|
if (! $has_symlink) { |
156
|
0
|
|
|
|
|
0
|
require File::Copy; |
157
|
0
|
|
|
|
|
0
|
File::Copy::copy($from, $to); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} else { |
160
|
591
|
|
|
|
|
16327
|
symlink $from, $to; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |