Debian Codegraph @

src/SPERR/test_scripts/graveyard/compressor_2d.cpp

raw
1 #include "SPECK2D.h"
2 #include "CDF97.h"
3
4 #include <cstdlib>
5 #include <iostream>
6 #include <chrono>
7 #include <cstring>
8
9 #include "SpeckConfig.h"
10
11 extern "C" // C Function calls, and don't include the C header!
12 {
13 int sam_read_n_bytes( const char*, size_t, void* );
14 }
15
16 int main( int argc, char* argv[] )
17 {
18 if( argc != 6 )
19 {
20 std::cerr << "Usage: ./a.out input_filename dim_x dim_y "
21 << "output_filename bits_per_pixel " << std::endl;
22 return 1;
23 }
24
25 const char* input = argv[1];
26 const size_t dim_x = std::atol( argv[2] );
27 const size_t dim_y = std::atol( argv[3] );
28 const char* output = argv[4];
29 const float bpp = std::atof( argv[5] );
30 const size_t total_vals = dim_x * dim_y;
31
32 //
33 // Let's read in binaries as 4-byte floats
34 //
35 auto in_buf = speck::unique_malloc<float>( total_vals );
36 if( sam_read_n_bytes( input, sizeof(float) * total_vals, in_buf.get() ) )
37 {
38 std::cerr << "Input read error!" << std::endl;
39 return 1;
40 }
41
42 //
43 // Take input to go through DWT.
44 //
45 speck::CDF97 cdf;
46 cdf.set_dims( dim_x, dim_y );
47 cdf.copy_data( in_buf.get(), total_vals );
48
49 auto startT = std::chrono::high_resolution_clock::now();
50 cdf.dwt2d();
51 auto endT = std::chrono::high_resolution_clock::now();
52
53 std::chrono::duration<double> diffT = endT - startT;
54 std::cout << "# Encoding time in milliseconds: Bit-per-Pixel XForm_Time SPECK_Time"
55 << std::endl;
56 std::cout << bpp << " " << diffT.count() * 1000.0f << " ";
57
58 // Do a speck encoding
59 speck::SPECK2D encoder;
60 encoder.set_dims( dim_x, dim_y );
61 encoder.set_image_mean( cdf.get_mean() );
62 const size_t total_bits = size_t(bpp * total_vals);
63 encoder.set_bit_budget( total_bits );
64 encoder.take_coeffs( cdf.release_data(), total_vals );
65
66 startT = std::chrono::high_resolution_clock::now();
67 encoder.encode();
68 endT = std::chrono::high_resolution_clock::now();
69 diffT = endT - startT;
70 std::cout << diffT.count() * 1000.0f << std::endl;
71
72 if( encoder.write_to_disk( output ) )
73 {
74 std::cerr << "Output write error!" << std::endl;
75 return 1;
76 }
77
78 return 0;
79 }