From: Carl Hetherington Date: Thu, 2 Aug 2012 11:25:15 +0000 (+0100) Subject: Tidy up equality options slightly. X-Git-Tag: v0.08~1 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=8d94e57248b7957d62350083a93aa479457f9385;p=libdcp.git Tidy up equality options slightly. --- diff --git a/src/asset.cc b/src/asset.cc index 38617e85..78686a17 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -96,11 +96,11 @@ Asset::mxf_path () const } list -Asset::equals (shared_ptr other, EqualityFlags flags, double, double) const +Asset::equals (shared_ptr other, EqualityOptions opt) const { list notes; - if (flags & LIBDCP_METADATA) { + if (opt.flags & LIBDCP_METADATA) { if (_mxf_name != other->_mxf_name) { notes.push_back ("MXF names differ"); } @@ -112,7 +112,7 @@ Asset::equals (shared_ptr other, EqualityFlags flags, double, doubl } } - if (flags & MXF_BITWISE) { + if (opt.flags & MXF_BITWISE) { if (digest() != other->digest()) { notes.push_back ("MXF digests differ"); diff --git a/src/asset.h b/src/asset.h index 51e5dc54..6c0a9803 100644 --- a/src/asset.h +++ b/src/asset.h @@ -66,7 +66,7 @@ public: */ void write_to_assetmap (std::ostream& s) const; - virtual std::list equals (boost::shared_ptr other, EqualityFlags flags, double max_mean, double max_std_dev) const; + virtual std::list equals (boost::shared_ptr other, EqualityOptions opt) const; protected: friend class PictureAsset; diff --git a/src/dcp.cc b/src/dcp.cc index cf37579f..53d6b55d 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -334,11 +334,11 @@ DCP::DCP (string directory) } list -DCP::equals (DCP const & other, EqualityFlags flags, double max_mean, double max_std_dev) const +DCP::equals (DCP const & other, EqualityOptions opt) const { list notes; - if (flags & LIBDCP_METADATA) { + if (opt.flags & LIBDCP_METADATA) { if (_name != other._name) { notes.push_back ("names differ"); } @@ -361,7 +361,7 @@ DCP::equals (DCP const & other, EqualityFlags flags, double max_mean, double max list >::const_iterator b = other._assets.begin (); while (a != _assets.end ()) { - list n = (*a)->equals (*b, flags, max_mean, max_std_dev); + list n = (*a)->equals (*b, opt); notes.merge (n); ++a; ++b; diff --git a/src/dcp.h b/src/dcp.h index 1ad56efc..477c1901 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -106,7 +106,7 @@ public: return _length; } - std::list equals (DCP const & other, EqualityFlags flags, double max_mean, double max_std_dev) const; + std::list equals (DCP const & other, EqualityOptions options) const; /** Emitted with a parameter between 0 and 1 to indicate progress * for long jobs. diff --git a/src/picture_asset.cc b/src/picture_asset.cc index 3386d6d4..f5c10ce3 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -143,11 +143,11 @@ PictureAsset::write_to_cpl (ostream& s) const } list -PictureAsset::equals (shared_ptr other, EqualityFlags flags, double max_mean, double max_std_dev) const +PictureAsset::equals (shared_ptr other, EqualityOptions opt) const { - list notes = Asset::equals (other, flags, max_mean, max_std_dev); + list notes = Asset::equals (other, opt); - if (flags & MXF_INSPECT) { + if (opt.flags & MXF_INSPECT) { ASDCP::JP2K::MXFReader reader_A; if (ASDCP_FAILURE (reader_A.OpenRead (mxf_path().string().c_str()))) { throw FileError ("could not open MXF file for reading", mxf_path().string()); @@ -221,6 +221,11 @@ PictureAsset::equals (shared_ptr other, EqualityFlags flags, double } if (!j2k_same) { + + if (opt.verbose) { + cout << "J2K images for " << i << " differ; checking by pixel\n"; + } + /* Decompress the images to bitmaps */ opj_image_t* image_A = decompress_j2k (const_cast (buffer_A.RoData()), buffer_A.Size ()); opj_image_t* image_B = decompress_j2k (const_cast (buffer_B.RoData()), buffer_B.Size ()); @@ -260,10 +265,14 @@ PictureAsset::equals (shared_ptr other, EqualityFlags flags, double double const std_dev = sqrt (double (total_squared_deviation) / abs_diffs.size()); - if (mean > max_mean || std_dev > max_std_dev) { + if (mean > opt.max_mean_pixel_error || std_dev > opt.max_std_dev_pixel_error) { notes.push_back ("mean or standard deviation out of range for " + lexical_cast(i)); } + if (opt.verbose) { + cout << "\tmean pixel error " << mean << ", standard deviation " << std_dev << "\n"; + } + opj_image_destroy (image_A); opj_image_destroy (image_B); } diff --git a/src/picture_asset.h b/src/picture_asset.h index 8a697f2c..41b09b58 100644 --- a/src/picture_asset.h +++ b/src/picture_asset.h @@ -82,7 +82,7 @@ public: */ void write_to_cpl (std::ostream& s) const; - std::list equals (boost::shared_ptr other, EqualityFlags flags, double max_mean, double max_std_dev) const; + std::list equals (boost::shared_ptr other, EqualityOptions opt) const; private: std::string path_from_list (int f, std::vector const & files) const; diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 2d834957..71d1d9ff 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -177,11 +177,11 @@ SoundAsset::write_to_cpl (ostream& s) const } list -SoundAsset::equals (shared_ptr other, EqualityFlags flags, double max_mean, double max_std_dev) const +SoundAsset::equals (shared_ptr other, EqualityOptions opt) const { - list notes = Asset::equals (other, flags, max_mean, max_std_dev); + list notes = Asset::equals (other, opt); - if (flags & MXF_INSPECT) { + if (opt.flags & MXF_INSPECT) { ASDCP::PCM::MXFReader reader_A; if (ASDCP_FAILURE (reader_A.OpenRead (mxf_path().string().c_str()))) { cout << "failed " << mxf_path() << "\n"; diff --git a/src/sound_asset.h b/src/sound_asset.h index 4b7c0967..e9faeb8b 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -84,7 +84,7 @@ public: */ void write_to_cpl (std::ostream& s) const; - std::list equals (boost::shared_ptr other, EqualityFlags flags, double max_mean, double max_std_dev) const; + std::list equals (boost::shared_ptr other, EqualityOptions opt) const; private: void construct (sigc::slot get_path); diff --git a/src/types.h b/src/types.h index ee3edaef..8c584579 100644 --- a/src/types.h +++ b/src/types.h @@ -68,6 +68,14 @@ enum EqualityFlags { MXF_INSPECT = 0x4 }; +struct EqualityOptions { + EqualityFlags flags; + bool verbose; + double max_mean_pixel_error; + double max_std_dev_pixel_error; +}; + + } #endif diff --git a/tools/dcpdiff.cc b/tools/dcpdiff.cc index 73097ccd..07bb6296 100644 --- a/tools/dcpdiff.cc +++ b/tools/dcpdiff.cc @@ -14,6 +14,7 @@ help (string n) cerr << "Syntax: " << n << " [OPTION] \n" << " -b, --bitwise bitwise check\n" << " -v, --version show libdcp version\n" + << " -d, --verbose be verbose\n" << " -h, --help show this help\n" << "\n" << "The s are the DCP directories to compare.\n" @@ -24,7 +25,9 @@ help (string n) int main (int argc, char* argv[]) { - bool bitwise = false; + EqualityOptions options; + options.flags = EqualityFlags (LIBDCP_METADATA | MXF_INSPECT); + options.verbose = false; int option_index = 0; while (1) { @@ -32,10 +35,11 @@ main (int argc, char* argv[]) { "bitwise", no_argument, 0, 'b'}, { "version", no_argument, 0, 'v'}, { "help", no_argument, 0, 'h'}, + { "verbose", no_argument, 0, 'd'}, { 0, 0, 0, 0 } }; - int c = getopt_long (argc, argv, "bvh", long_options, &option_index); + int c = getopt_long (argc, argv, "bvhd", long_options, &option_index); if (c == -1) { break; @@ -43,7 +47,7 @@ main (int argc, char* argv[]) switch (c) { case 'b': - bitwise = true; + options.flags = EqualityFlags (options.flags | MXF_BITWISE); break; case 'v': cout << "dcpdiff version " << LIBDCP_VERSION << "\n"; @@ -51,6 +55,9 @@ main (int argc, char* argv[]) case 'h': help (argv[0]); exit (EXIT_SUCCESS); + case 'd': + options.verbose = true; + break; } } @@ -85,14 +92,12 @@ main (int argc, char* argv[]) exit (EXIT_FAILURE); } - EqualityFlags flags = EqualityFlags (LIBDCP_METADATA | MXF_INSPECT); - if (bitwise) { - flags = EqualityFlags (flags | MXF_BITWISE); - } + options.max_mean_pixel_error = 5; + options.max_std_dev_pixel_error = 5; - list notes = a->equals (*b, flags, 5, 5); + list notes = a->equals (*b, options); if (notes.empty ()) { - cout << "DCPs identical\n"; + cout << "DCPs equal\n"; exit (EXIT_SUCCESS); }