Revision 5157b47f
Added by david.sorber 8 months ago
| software/photo_compress_archiver/src/PhotoCompressArchiver.cc | ||
|---|---|---|
|
#include <chrono>
|
||
|
#include <climits>
|
||
|
#include <cmath>
|
||
|
#include <cstdio>
|
||
|
#include <fstream>
|
||
|
#include <iomanip>
|
||
|
#include <iostream>
|
||
|
#include <limits.h>
|
||
|
#include <thread>
|
||
|
#include <sstream>
|
||
|
#include <vector>
|
||
|
|
||
|
#include <sys/stat.h>
|
||
|
#include <sys/wait.h>
|
||
|
#include <unistd.h>
|
||
|
#include <vector>
|
||
|
|
||
|
|
||
|
#include <packjpg.h>
|
||
|
|
||
| ... | ... | |
|
// Helper function
|
||
|
std::string _format_num_bytes(uint64_t num_bytes)
|
||
|
{
|
||
|
const uint64_t tera = (1024 * 1024 * 1024 * 1024L);
|
||
|
const uint64_t giga = (1024 * 1024 * 1024L);
|
||
|
const uint64_t mega = (1024 * 1024L);
|
||
|
const uint64_t kilo = 1024L;
|
||
|
constexpr uint64_t tera(1024 * 1024 * 1024 * 1024L);
|
||
|
constexpr uint64_t giga(1024 * 1024 * 1024L);
|
||
|
constexpr uint64_t mega(1024 * 1024L);
|
||
|
constexpr uint64_t kilo(1024L);
|
||
|
|
||
|
double fractional;
|
||
|
std::ostringstream output;
|
||
| ... | ... | |
|
if (num_bytes >= tera)
|
||
|
{
|
||
|
// Tera
|
||
|
fractional = ((double)num_bytes) / tera;
|
||
|
fractional = static_cast<double>(num_bytes) / tera;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " TB";
|
||
|
}
|
||
|
else if (num_bytes >= giga)
|
||
|
{
|
||
|
// Giga
|
||
|
fractional = ((double)num_bytes) / giga;
|
||
|
fractional = static_cast<double>(num_bytes) / giga;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " GB";
|
||
|
}
|
||
|
else if (num_bytes >= mega)
|
||
|
{
|
||
|
// Mega
|
||
|
fractional = ((double)num_bytes) / mega;
|
||
|
fractional = static_cast<double>(num_bytes) / mega;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " MB";
|
||
|
}
|
||
|
else if (num_bytes >= kilo)
|
||
|
{
|
||
|
// Kilo
|
||
|
fractional = ((double)num_bytes) / kilo;
|
||
|
fractional = static_cast<double>(num_bytes) / kilo;
|
||
|
output << std::fixed << std::setprecision(2) << fractional;
|
||
|
output << " KB";
|
||
|
}
|
||
| ... | ... | |
|
auto diff = current - start;
|
||
|
double duration = std::chrono::duration<double>(diff).count();
|
||
|
|
||
|
double ratio = ((double)m_total_compressed_size /
|
||
|
double ratio = (static_cast<double>(m_total_compressed_size) /
|
||
|
m_running_compressed_size) * 100;
|
||
|
// This looks odd but in fact checks for NaN which we don't want to
|
||
|
// display in the status
|
||
| ... | ... | |
|
double duration = std::chrono::duration<double>(diff).count();
|
||
|
|
||
|
// Print out message if any errors were found
|
||
|
if (m_errors.size() > 0)
|
||
|
if (! m_errors.empty())
|
||
|
{
|
||
|
std::cout << BOLD << RED << "\n\nNOTE: errors were encountered "
|
||
|
<< "processing the following " << m_errors.size()
|
||
| ... | ... | |
|
<< _format_num_bytes(m_total_compressed_size) << std::endl;
|
||
|
|
||
|
// Calculate and display ratio
|
||
|
double ratio = (double)m_total_compressed_size / m_total_uncompressed_size;
|
||
|
double ratio = static_cast<double>(m_total_compressed_size) / m_total_uncompressed_size;
|
||
|
std::cout << " Compression ratio: " << std::fixed
|
||
|
<< std::setprecision(2) << (ratio * 100) << "%" << std::endl;
|
||
|
}
|
||
| ... | ... | |
|
continue;
|
||
|
}
|
||
|
|
||
|
input_stream.read((char*)file_buffer->data(), work_unit->m_file_size);
|
||
|
input_stream.read(reinterpret_cast<char*>(file_buffer->data()), work_unit->m_file_size);
|
||
|
input_stream.close();
|
||
|
|
||
|
// Determine input, and therefore output, filetype / extension based
|
||
| ... | ... | |
|
m_errors.push_back(work_unit);
|
||
|
continue;
|
||
|
}
|
||
|
output_stream.write((const char*)out_buffer, out_size);
|
||
|
output_stream.write(reinterpret_cast<const char*>(out_buffer), out_size);
|
||
|
output_stream.close();
|
||
|
|
||
|
// Delete original file if so instructed
|
||
| ... | ... | |
|
}
|
||
|
else
|
||
|
{
|
||
|
double percent = ((double)out_size) / work_unit->m_file_size;
|
||
|
double percent = static_cast<double>(out_size) / work_unit->m_file_size;
|
||
|
percent *= 100;
|
||
|
WRKR_OUT_REG(" -- (" << std::fixed << std::setprecision(2)
|
||
|
<< get_global_percent_done()
|
||
| ... | ... | |
|
|
||
|
double PhotoCompressArchiver::get_global_percent_done()
|
||
|
{
|
||
|
return ((double)(m_files_processed + m_errors.size())
|
||
|
return (static_cast<double>(m_files_processed + m_errors.size())
|
||
|
/ m_num_input_files) * 100;
|
||
|
}
|
||
|
|
||
| software/photo_compress_archiver/src/PhotoCompressArchiver.hh | ||
|---|---|---|
|
#define PHOTOCOMPRESSARCHIVER_H
|
||
|
|
||
|
#include <atomic>
|
||
|
#include <condition_variable>
|
||
|
#include <cstdint>
|
||
|
#include <deque>
|
||
|
#include <filesystem>
|
||
|
#include <mutex>
|
||
|
#include <sstream>
|
||
| ... | ... | |
|
const std::string UP_ONE = "\033[1A";
|
||
|
const std::string DOWN_ONE = "\033[1B";
|
||
|
|
||
|
const std::string version("v0.5.0");
|
||
|
const std::string version("v0.5.1");
|
||
|
|
||
|
const boost::regex JPEG_REGEX("^.+\\.((jpg)|(jpeg))$", boost::regex::icase);
|
||
|
const boost::regex PJG_REGEX("^.+\\.pjg$", boost::regex::icase);
|
||
| ... | ... | |
|
const std::string JPG_EXTENSION(".jpg");
|
||
|
const std::string PJG_EXTENSION(".pjg");
|
||
|
|
||
|
const uint32_t PROGRESS_BAR_WIDTH = 80;
|
||
|
constexpr uint32_t PROGRESS_BAR_WIDTH(80);
|
||
|
const std::string LINE(100, '-');
|
||
|
|
||
|
class WorkUnit
|
||
Minor code cleanup. Bump version to v0.5.1.