X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=b8bc1fc9e467680646f924c2ab3385d195911efb;hb=373f010a7f04add1f49169cbaa60cb7ae5f508d4;hp=7e7e579a4b5ac4d20bef402c43bec455ea05021d;hpb=3e56e4126ec8199f15e03c213b37f39d72c27cc3;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index 7e7e579a4..b8bc1fc9e 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -45,6 +45,7 @@ #include #include #include +#include extern "C" { #include #include @@ -61,6 +62,7 @@ extern "C" { #include "sound_processor.h" #include "config.h" #include "ratio.h" +#include "job.h" #ifdef DCPOMATIC_WINDOWS #include "stack.hpp" #endif @@ -407,6 +409,58 @@ md5_digest (boost::filesystem::path file) return s.str (); } +/** @param job Optional job for which to report progress */ +string +md5_digest_directory (boost::filesystem::path directory, shared_ptr job) +{ + int const buffer_size = 64 * 1024; + char buffer[buffer_size]; + + MD5_CTX md5_context; + MD5_Init (&md5_context); + + int files = 0; + if (job) { + for (boost::filesystem::directory_iterator i(directory); i != boost::filesystem::directory_iterator(); ++i) { + ++files; + } + } + + int j = 0; + for (boost::filesystem::directory_iterator i(directory); i != boost::filesystem::directory_iterator(); ++i) { + ifstream f (i->path().string().c_str(), std::ios::binary); + if (!f.good ()) { + throw OpenFileError (i->path().string()); + } + + f.seekg (0, std::ios::end); + int bytes = f.tellg (); + f.seekg (0, std::ios::beg); + + while (bytes > 0) { + int const t = min (bytes, buffer_size); + f.read (buffer, t); + MD5_Update (&md5_context, buffer, t); + bytes -= t; + } + + if (job) { + job->set_progress (float (j) / files); + ++j; + } + } + + unsigned char digest[MD5_DIGEST_LENGTH]; + MD5_Final (digest, &md5_context); + + stringstream s; + for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { + s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]); + } + + return s.str (); +} + static bool about_equal (float a, float b) { @@ -704,17 +758,17 @@ FrameRateConversion::FrameRateConversion (float source, int dcp) change_speed = !about_equal (source * factor(), dcp); if (!skip && !repeat && !change_speed) { - description = _("DCP and source have the same rate.\n"); + description = _("Content and DCP have the same rate.\n"); } else { if (skip) { - description = _("DCP will use every other frame of the source.\n"); + description = _("DCP will use every other frame of the content.\n"); } else if (repeat) { - description = _("Each source frame will be doubled in the DCP.\n"); + description = _("Each content frame will be doubled in the DCP.\n"); } if (change_speed) { float const pc = dcp * 100 / (source * factor()); - description += String::compose (_("DCP will run at %1%% of the source speed.\n"), pc); + description += String::compose (_("DCP will run at %1%% of the content speed.\n"), pc); } } } @@ -737,3 +791,12 @@ LocaleGuard::~LocaleGuard () setlocale (LC_NUMERIC, _old); free (_old); } + +bool +valid_image_file (boost::filesystem::path f) +{ + string ext = f.extension().string(); + transform (ext.begin(), ext.end(), ext.begin(), ::tolower); + return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp" || ext == ".tga"); +} +