Revision ddd2cb4a
Added by David Sorber almost 8 years ago
| software/photo_compress_archiver/PhotoCompressArchiver.cc | ||
|---|---|---|
|
<< "ERROR: " << msg << std::endl; \
|
||
|
}
|
||
|
|
||
|
// Helper functions
|
||
|
std::string _format_num_bytes(uint64_t num_bytes)
|
||
|
{
|
||
|
const uint64_t tera = (1024 * 1024 * 1024L);
|
||
|
const uint64_t giga = (1024 * 1024 * 1024L);
|
||
|
const uint64_t mega = (1024 * 1024L);
|
||
|
const uint64_t kilo = 1024L;
|
||
|
|
||
|
double fractional;
|
||
|
std::ostringstream output;
|
||
|
|
||
|
if (num_bytes >= tera)
|
||
|
{
|
||
|
// Tera
|
||
|
fractional = ((double)num_bytes) / tera;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " TB";
|
||
|
}
|
||
|
else if (num_bytes >= giga)
|
||
|
{
|
||
|
// Giga
|
||
|
fractional = ((double)num_bytes) / giga;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " GB";
|
||
|
}
|
||
|
else if (num_bytes >= mega)
|
||
|
{
|
||
|
// Mega
|
||
|
fractional = ((double)num_bytes) / mega;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " MB";
|
||
|
}
|
||
|
else if (num_bytes >= kilo)
|
||
|
{
|
||
|
// Kilo
|
||
|
fractional = ((double)num_bytes) / kilo;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " KB";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Bytes
|
||
|
output << num_bytes << " b";
|
||
|
}
|
||
|
|
||
|
return output.str();
|
||
|
}
|
||
|
|
||
|
PhotoCompressArchiver::PhotoCompressArchiver(
|
||
|
const std::string& path,
|
||
|
uint32_t num_threads,
|
||
| ... | ... | |
|
if (! m_decompress)
|
||
|
{
|
||
|
std::cout << " Total uncompressed bytes: "
|
||
|
<< m_total_uncompressed_size << "\n" << std::endl;
|
||
|
<< _format_num_bytes(m_total_uncompressed_size) << "\n"
|
||
|
<< std::endl;
|
||
|
}
|
||
|
|
||
|
// Add terminator for each worker thread
|
||
| ... | ... | |
|
if (! m_decompress)
|
||
|
{
|
||
|
std::cout << "\n Total uncompressed bytes: "
|
||
|
<< m_total_uncompressed_size << std::endl;
|
||
|
std::cout << " Total compressed bytes: " << m_total_compressed_size
|
||
|
<< std::endl;
|
||
|
<< _format_num_bytes(m_total_uncompressed_size) << std::endl;
|
||
|
std::cout << " Total compressed bytes: "
|
||
|
<< _format_num_bytes(m_total_compressed_size) << std::endl;
|
||
|
|
||
|
// Calculate and display ratio
|
||
|
double ratio = (double)m_total_compressed_size / m_total_uncompressed_size;
|
||
|
std::cout << " Compression ratio: " << std::fixed
|
||
|
<< std::setprecision(4) << (ratio * 100) << "%" << std::endl;
|
||
|
std::cout << " Compression ratio: " << std::fixed
|
||
|
<< std::setprecision(2) << (ratio * 100) << "%" << std::endl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
// Display execution duration
|
||
|
std::cout << " Total time: " << duration << " s\n" << std::endl;
|
||
|
std::cout << " Total time: " << duration << " s\n" << std::endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
| software/photo_compress_archiver/PhotoCompressArchiver.hh | ||
|---|---|---|
|
#ifndef PHOTOCOMPRESSARCHIVER_H
|
||
|
#define PHOTOCOMPRESSARCHIVER_H
|
||
|
|
||
|
#include <atomic>
|
||
|
#include <condition_variable>
|
||
|
#include <cstdint>
|
||
|
#include <deque>
|
||
|
#include <mutex>
|
||
|
#include <sstream>
|
||
|
#include <string>
|
||
|
#include <thread>
|
||
|
#include <vector>
|
||
| ... | ... | |
|
const std::string YELLOW("\033[33m");
|
||
|
const std::string PURPLE("\033[35m");
|
||
|
|
||
|
const std::string version("v0.3.0");
|
||
|
const std::string version("v0.3.1");
|
||
|
|
||
|
const boost::regex JPEG_REGEX("^.+\\.(jpg)|(jpeg)$", boost::regex::icase);
|
||
|
const boost::regex PJG_REGEX("^.+\\.pjg$", boost::regex::icase);
|
||
| ... | ... | |
|
|
||
|
std::mutex m_output_mutex; // output mutex
|
||
|
|
||
|
std::atomic<uint32_t> m_files_processed; // number of input files processed
|
||
|
uint32_t m_num_input_files; // total number of input files found
|
||
|
std::atomic<uint64_t> m_total_uncompressed_size;// total uncompressed size of all images
|
||
|
std::atomic<uint64_t> m_total_compressed_size; // total compressed size of all images
|
||
|
std::atomic<uint32_t> m_files_processed; // number of input files processed
|
||
|
uint32_t m_num_input_files; // total number of input files found
|
||
|
uint64_t m_total_uncompressed_size; // total uncompressed size of all images
|
||
|
uint64_t m_total_compressed_size; // total compressed size of all images
|
||
|
|
||
|
// input file list (either images or compressed images)
|
||
|
ProtectedAndSynchronizedQueue<WorkUnit*> m_file_list;
|
||
Improve PCA post processing output message formatting.