Revision 4f6113f8
Added by David Sorber almost 8 years ago
| software/photo_compress_archiver/PhotoCompressArchiver.hh | ||
|---|---|---|
|
#include <boost/filesystem.hpp>
|
||
|
#include <boost/regex.hpp>
|
||
|
|
||
|
#include "ProtectedAndSynchronizedQueue.h"
|
||
|
|
||
|
// Alias the boost fs namespace to keep the code readable
|
||
|
namespace bfs = boost::filesystem;
|
||
|
|
||
| ... | ... | |
|
const std::string YELLOW("\033[33m");
|
||
|
const std::string PURPLE("\033[35m");
|
||
|
|
||
|
const std::string version("v0.1.0");
|
||
|
const std::string version("v0.2.0");
|
||
|
|
||
|
const boost::regex JPEG_REGEX("^.+\\.(jpg)|(jpeg)$", boost::regex::icase);
|
||
|
const boost::regex PJG_REGEX("^.+\\.pjg$", boost::regex::icase);
|
||
|
|
||
|
struct work_unit_t {
|
||
|
std::vector<const char*> exec_argv;
|
||
|
std::vector<std::string*> output_filenames;
|
||
|
const std::string JPG_EXTENSION(".jpg");
|
||
|
const std::string PJG_EXTENSION(".pjg");
|
||
|
|
||
|
class WorkUnit
|
||
|
{
|
||
|
public:
|
||
|
bfs::path m_path;
|
||
|
uint32_t m_file_size;
|
||
|
|
||
|
WorkUnit(const bfs::path& path)
|
||
|
: m_path(path),
|
||
|
m_file_size(0)
|
||
|
{
|
||
|
m_file_size = bfs::file_size(path);
|
||
|
};
|
||
|
};
|
||
|
typedef struct work_unit_t WorkUnit;
|
||
|
|
||
|
class PhotoCompressArchiver
|
||
|
{
|
||
| ... | ... | |
|
const boost::regex& file_regex);
|
||
|
|
||
|
/**
|
||
|
* Fork and wait
|
||
|
* Compress/decompress worker thread body
|
||
|
*/
|
||
|
void fork_worker(uint32_t tid);
|
||
|
void worker_thread_body(uint32_t tid);
|
||
|
|
||
|
/**
|
||
|
* Calculate the return the "global" percent done as determined by the
|
||
| ... | ... | |
|
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::vector<bfs::path> m_file_list; // input file list (either images or compressed images)
|
||
|
// input file list (either images or compressed images)
|
||
|
ProtectedAndSynchronizedQueue<WorkUnit*> m_file_list;
|
||
|
|
||
|
std::thread* p_finder_thread; // file finder thread
|
||
|
std::vector<std::thread*> m_worker_threads; // worker threads
|
||
|
|
||
|
std::deque<WorkUnit*> m_work_unit_queue;
|
||
|
std::mutex m_work_unit_mtx;
|
||
|
std::condition_variable m_work_unit_cv;
|
||
|
|
||
|
bool m_filter_empty; // is the filter regex empty
|
||
|
boost::regex& m_filter_regex; // filter regular expression
|
||
|
};
|
||
Converted PCA to be multithreaded and use libpackjpg instead of calling
the old packjpg executable. This works much better! Need to handle a few
error conditions and do some more testing with decompress.