File: quick.t

package info (click to toggle)
libepsilon 0.9.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,176 kB
  • sloc: ansic: 11,329; sh: 9,321; perl: 936; xml: 86; makefile: 85
file content (185 lines) | stat: -rw-r--r-- 5,104 bytes parent folder | download | duplicates (3)
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
181
182
183
184
185
#!/usr/bin/perl

#
# $Id: quick.t,v 1.2 2011/04/28 10:15:47 simakov Exp $
#
# EPSILON - wavelet image compression library.
# Copyright (C) 2006-2011 Alexander Simakov, <xander@entropyware.info>
#
# Quick verification test for generic EPSILON build.
# This file is part of EPSILON
#
# EPSILON is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# EPSILON is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with EPSILON.  If not, see <http://www.gnu.org/licenses/>.
#
# http://epsilon-project.sourceforge.net
#

use strict;
use warnings;

use Readonly;
Readonly our $VERSION => qw($Revision: 1.2 $) [1];

use English qw( -no_match_vars );
use File::Temp qw(tempdir tempfile);
use File::Spec::Functions;
use File::Basename;

#use Smart::Comments;

use FindBin qw($Bin);
FindBin::again();

use lib "$Bin/../lib";
use EPSILON::Utils qw(
    run_epsilon
    get_image_path
    get_rnd_string
);

use Test::More;
use Test::Exception;
use Test::PBM::PSNR;

Readonly my $TMP_DIR => tempdir( 'quick_XXXX', TMPDIR => 1, CLEANUP => 0 );
### TMP_DIR: $TMP_DIR

Readonly my $RND_SUFFIX_LENGTH => 4;
Readonly my $BUILD_TAG         => 'generic';

Readonly my $CHECKS_PER_IMAGE => 3;
Readonly my %TEST_IMAGES      => (
    'gray_dot.pgm'            => 60.00,
    'horizontal_gradient.pgm' => 49.50,
    'vertical_gradient.pgm'   => 49.80,
    'red_dot.ppm'             => {
        min_Y_psnr  => 58.60,
        min_Cb_psnr => 54.10,
        min_Cr_psnr => 63.50,
    },
    'horizontal_rainbow.ppm' => {
        min_Y_psnr  => 49.00,
        min_Cb_psnr => 40.00,
        min_Cr_psnr => 36.00,
    },

    'vertical_rainbow.ppm' => {
        min_Y_psnr  => 52.40,
        min_Cb_psnr => 31.50,
        min_Cr_psnr => 40.10,
    },
    'nirvana.ppm' => {
        min_Y_psnr  => 55.20,
        min_Cb_psnr => 44.50,
        min_Cr_psnr => 42.90,
    },
);

# Set to 0 if you want to check reconstructed files visually
Readonly my $CLEANUP_RECONSTRUCTED_FILES => 1;

sub set_test_plan {
    plan tests => $CHECKS_PER_IMAGE * keys %TEST_IMAGES;

    return;
}

sub quick_test {
    foreach my $image_ext ( keys %TEST_IMAGES ) {

        # Set minimal compression ratio to get hightest PSNR possible
        my $epsilon_encode_options
            = "--ratio 1.001 --output-dir '$TMP_DIR' --quiet";

        # Encode file
        lives_ok {
            run_epsilon(
                build_tag       => $BUILD_TAG,
                epsilon_options => $epsilon_encode_options,
                file            => get_image_path($image_ext),
            );
        }
        "[$BUILD_TAG] Encode '$image_ext' with epsilon options: "
            . "'$epsilon_encode_options'";

        my ( $image, undef, $ext )
            = fileparse( $image_ext, qr/[.](?:pgm|ppm)/xms );
        $ext =~ s/\A[.]//xms;    # remove leading dot

        my $reconstructed_image
            = $image . '_reconstructed_' . get_rnd_string($RND_SUFFIX_LENGTH);

        # Rename encoded file: add random suffix
        rename catfile( $TMP_DIR, "$image.psi" ),
            catfile( $TMP_DIR, "$reconstructed_image.psi" );

        my $epsilon_decode_options = '--decode-file --quiet';

        # Decode file
        lives_ok {
            run_epsilon(
                build_tag       => $BUILD_TAG,
                epsilon_options => $epsilon_decode_options,
                file => catfile( $TMP_DIR, "$reconstructed_image.psi" ),
            );
        }
        "[$BUILD_TAG] Decode '$reconstructed_image.psi' with epsilon options: "
            . "'$epsilon_decode_options'";

        # Check PSNR
        my $result;
        if ( $ext eq 'pgm' ) {
            $result = is_pgm_image_psnr(
                original_image => get_image_path($image_ext),
                reconstructed_image =>
                    catfile( $TMP_DIR, "$reconstructed_image.$ext" ),
                min_psnr => $TEST_IMAGES{$image_ext},
            );
        }
        else {
            $result = is_ppm_image_psnr(
                original_image => get_image_path($image_ext),
                reconstructed_image =>
                    catfile( $TMP_DIR, "$reconstructed_image.$ext" ),
                %{ $TEST_IMAGES{$image_ext} },
            );
        }

        if ($result) {

            # PSNR is ok, unlink temporary files
            unlink catfile( $TMP_DIR, "$reconstructed_image.psi" );
            if ($CLEANUP_RECONSTRUCTED_FILES) {
                unlink catfile( $TMP_DIR, "$reconstructed_image.$ext" );
            }
        }
    }

    return;
}

sub run_tests {
    set_test_plan();
    quick_test();

    return;
}

run_tests();

END {

    # Removes empty dir only
    rmdir $TMP_DIR;
}