| 1 | package Video::Pattern; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Pragmas. | ||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Modules. | ||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use English; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use File::Basename qw(fileparse); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Image::Random; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Video::Delay::Const; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # Constants. | ||||||||||||||||||||||||||||
| 18 | 4 | Readonly::Scalar our $EMPTY_STR => q{}; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Version. | ||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = 0.07; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # Constructor. | ||||||||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||||||||
| 25 | 12 | ▶ | my ($class, @params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Create object. | ||||||||||||||||||||||||||||
| 28 | 12 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Delay generator. | ||||||||||||||||||||||||||||
| 31 | 12 | $self->{'delay_generator'} = Video::Delay::Const->new( | |||||||||||||||||||||||||||
| 32 | 'const' => 1000, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # Duration. | ||||||||||||||||||||||||||||
| 36 | 12 | $self->{'duration'} = 10000; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Frame per second. | ||||||||||||||||||||||||||||
| 39 | 12 | $self->{'fps'} = 60; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Image generator. | ||||||||||||||||||||||||||||
| 42 | 12 | $self->{'image_generator'} = undef; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Image type. | ||||||||||||||||||||||||||||
| 45 | 12 | $self->{'image_type'} = 'bmp'; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Process params. | ||||||||||||||||||||||||||||
| 48 | 12 | set_params($self, @params); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Check fps value. | ||||||||||||||||||||||||||||
| 51 | 10 | ▶ | if (! defined $self->{'fps'} || $self->{'fps'} !~ m/^\d+$/ms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"fps"} and $self->{"fps"} =~ /^\d+$/ms
MC/DC100%2/2
defined $self->{"fps"} and $self->{"fps"} =~ /^\d+$/ms
defined $self->{"fps"}
$self->{"fps"} =~ /^\d+$/ms
Truth table100%3/3
A and B
A= defined $self->{"fps"}B= $self->{"fps"} =~ /^\d+$/ms
| |||||||||||||||||||||||||||||
| 52 | 2 | err "Parameter 'fps' must be numeric value."; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Check and process duration value. | ||||||||||||||||||||||||||||
| 56 | 8 | $self->_check_and_process_duration; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # Own image generator. | ||||||||||||||||||||||||||||
| 59 | 5 | ▶ | if (! defined $self->{'image_generator'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | $self->{'image_generator'} = Image::Random->new( | ||||||||||||||||||||||||||||
| 61 | 'height' => 1080, | ||||||||||||||||||||||||||||
| 62 | 4 | 'type' => $self->{'image_type'}, | |||||||||||||||||||||||||||
| 63 | 'width' => 1920, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||
| 66 | 1 | $self->{'image_type'} = $self->{'image_generator'}->type; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Object. | ||||||||||||||||||||||||||||
| 70 | 5 | return $self; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Create images to output directory. | ||||||||||||||||||||||||||||
| 74 | sub create { | ||||||||||||||||||||||||||||
| 75 | 1 | ▶ | my ($self, $output_dir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 1 | my $delay = 0; | |||||||||||||||||||||||||||
| 77 | 1 | my $image; | |||||||||||||||||||||||||||
| 78 | 1 | 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 | $self->{'image_type'}); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # Create new image. | ||||||||||||||||||||||||||||
| 86 | 601 | ▶ | if ($delay <= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 10 | $self->{'image_generator'}->create($image_path); | |||||||||||||||||||||||||||
| 88 | 10 | $image = $image_path; | |||||||||||||||||||||||||||
| 89 | 10 | $delay = $self->{'delay_generator'}->delay; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # Symlink to old image. | ||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||
| 93 | 591 | my ($image_filename) = fileparse($image); | |||||||||||||||||||||||||||
| 94 | 591 | $self->_symlink($image_filename, $image_path); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Decrement delay. | ||||||||||||||||||||||||||||
| 98 | 601 | $delay -= 1000 / $self->{'fps'}; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 1 | return; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # Check and process duration. | ||||||||||||||||||||||||||||
| 104 | sub _check_and_process_duration { | ||||||||||||||||||||||||||||
| 105 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_check_and_process_duration: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 106 | 8 | my $err = 0; | |||||||||||||||||||||||||||
| 107 | 8 | ▶ | if (! defined $self->{'duration'}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 108 | 1 | $err = 1; | |||||||||||||||||||||||||||
| 109 | } elsif ($self->{'duration'} =~ m/^(\d+)(\w*)$/ms) { | ||||||||||||||||||||||||||||
| 110 | 6 | my $duration_value = $1; | |||||||||||||||||||||||||||
| 111 | 6 | my $duration_suffix = $2; | |||||||||||||||||||||||||||
| 112 | 6 | ▶ | if ($duration_suffix ne $EMPTY_STR) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 3 | ▶ | if ($duration_suffix eq 's') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 114 | 1 | $self->{'duration'} = $duration_value * 1000; | |||||||||||||||||||||||||||
| 115 | } elsif ($duration_suffix eq 'ms') { | ||||||||||||||||||||||||||||
| 116 | 1 | $self->{'duration'} = $duration_value; | |||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||
| 118 | 1 | $err = 1; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||
| 122 | 1 | $err = 1; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 8 | ▶ | if ($err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 3 | err "Parameter 'duration' must be numeric value or numeric ". | |||||||||||||||||||||||||||
| 127 | "value with time suffix (s/ms)."; | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 5 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # Symlink. | ||||||||||||||||||||||||||||
| 133 | sub _symlink { | ||||||||||||||||||||||||||||
| 134 | 591 | ▶ | my ($self, $from, $to) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_symlink: called CC=4 SCAR=24.4
| |||||||||||||||||||||||||||||
| 135 | 591 | ▶ | if ($OSNAME eq 'MSWin32') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | eval { | |||||||||||||||||||||||||||
| 137 | 0 | require Win32::Symlink; | |||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||
| 139 | 0 | my $has_symlink; | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (! $EVAL_ERROR) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | $has_symlink = eval { | |||||||||||||||||||||||||||
| 142 | 0 | Win32::Symlink::symlink($from => $to); | |||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if (! $has_symlink) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | require File::Copy; | |||||||||||||||||||||||||||
| 147 | 0 | File::Copy::copy($from, $to); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||
| 150 | 591 | symlink $from, $to; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 4 | 1; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | __END__ | ||||||||||||||||||||||||||||