Tidy up equality options slightly.
authorCarl Hetherington <cth@carlh.net>
Thu, 2 Aug 2012 11:25:15 +0000 (12:25 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 2 Aug 2012 11:25:15 +0000 (12:25 +0100)
src/asset.cc
src/asset.h
src/dcp.cc
src/dcp.h
src/picture_asset.cc
src/picture_asset.h
src/sound_asset.cc
src/sound_asset.h
src/types.h
tools/dcpdiff.cc

index 38617e8584fc7e4c01c57c32c2622a219ff6977b..78686a17bf16ffe6ec59ef62c464f64a26042f0b 100644 (file)
@@ -96,11 +96,11 @@ Asset::mxf_path () const
 }
 
 list<string>
-Asset::equals (shared_ptr<const Asset> other, EqualityFlags flags, double, double) const
+Asset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
 {
        list<string> 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<const Asset> other, EqualityFlags flags, double, doubl
                }
        }
        
-       if (flags & MXF_BITWISE) {
+       if (opt.flags & MXF_BITWISE) {
 
                if (digest() != other->digest()) {
                        notes.push_back ("MXF digests differ");
index 51e5dc5426c7cf6db0a953bf5f91a9048a31c2cd..6c0a9803adb9e47ead40255e0aefc380a0f20c3f 100644 (file)
@@ -66,7 +66,7 @@ public:
         */
        void write_to_assetmap (std::ostream& s) const;
 
-       virtual std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const;
+       virtual std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
 
 protected:
        friend class PictureAsset;
index cf37579f716382d916857199249e97da053197f8..53d6b55dcc01ff3162a394318d0af322b5e66771 100644 (file)
@@ -334,11 +334,11 @@ DCP::DCP (string directory)
 }
 
 list<string>
-DCP::equals (DCP const & other, EqualityFlags flags, double max_mean, double max_std_dev) const
+DCP::equals (DCP const & other, EqualityOptions opt) const
 {
        list<string> 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<shared_ptr<Asset> >::const_iterator b = other._assets.begin ();
        
        while (a != _assets.end ()) {
-               list<string> n = (*a)->equals (*b, flags, max_mean, max_std_dev);
+               list<string> n = (*a)->equals (*b, opt);
                notes.merge (n);
                ++a;
                ++b;
index 1ad56efc1a9a0a89217d787a0d925ee16611b4ae..477c19011278fec98039663164649943875a620f 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -106,7 +106,7 @@ public:
                return _length;
        }
 
-       std::list<std::string> equals (DCP const & other, EqualityFlags flags, double max_mean, double max_std_dev) const;
+       std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
 
        /** Emitted with a parameter between 0 and 1 to indicate progress
         *  for long jobs.
index 3386d6d40c414fc473a4afb6c5b117ce15c37c94..f5c10ce3b4eef2ad7dba12d0d21f856100527c22 100644 (file)
@@ -143,11 +143,11 @@ PictureAsset::write_to_cpl (ostream& s) const
 }
 
 list<string>
-PictureAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const
+PictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
 {
-       list<string> notes = Asset::equals (other, flags, max_mean, max_std_dev);
+       list<string> 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<const Asset> 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<uint8_t*> (buffer_A.RoData()), buffer_A.Size ());
                                opj_image_t* image_B = decompress_j2k (const_cast<uint8_t*> (buffer_B.RoData()), buffer_B.Size ());
@@ -260,10 +265,14 @@ PictureAsset::equals (shared_ptr<const Asset> 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<string>(i));
                                }
 
+                               if (opt.verbose) {
+                                       cout << "\tmean pixel error " << mean << ", standard deviation " << std_dev << "\n";
+                               }
+
                                opj_image_destroy (image_A);
                                opj_image_destroy (image_B);
                        }
index 8a697f2cd3ca13ca6b579a02ee3933dcf67e720d..41b09b58c4b532529b37515e44d6fd429b9f9cdf 100644 (file)
@@ -82,7 +82,7 @@ public:
         */
        void write_to_cpl (std::ostream& s) const;
 
-       std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const;
+       std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
        
 private:
        std::string path_from_list (int f, std::vector<std::string> const & files) const;
index 2d8349579ccdacc171fab4cf176a5d79d5326832..71d1d9ff0a29e0f5185a98ea818e1c677da7cfb3 100644 (file)
@@ -177,11 +177,11 @@ SoundAsset::write_to_cpl (ostream& s) const
 }
 
 list<string>
-SoundAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const
+SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
 {
-       list<string> notes = Asset::equals (other, flags, max_mean, max_std_dev);
+       list<string> 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";
index 4b7c0967b85a6655b74e3ec1da2d9df900fe19cf..e9faeb8bb6d26c68f4fdcda46f2d6662a3f0c2ae 100644 (file)
@@ -84,7 +84,7 @@ public:
         */
        void write_to_cpl (std::ostream& s) const;
 
-       std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const;
+       std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
        
 private:
        void construct (sigc::slot<std::string, Channel> get_path);
index ee3edaef0c29fb4e320cab891e31c22f2523422d..8c58457995659e23fb60d53a2f3e7bc5a9d40f5e 100644 (file)
@@ -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
index 73097ccdd698f2890932f504b8834034b3cca953..07bb6296e47675827e8d78b242cd22ad3a842ba0 100644 (file)
@@ -14,6 +14,7 @@ help (string n)
        cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\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 <DCP>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<string> notes = a->equals (*b, flags, 5, 5);
+       list<string> notes = a->equals (*b, options);
        if (notes.empty ()) {
-               cout << "DCPs identical\n";
+               cout << "DCPs equal\n";
                exit (EXIT_SUCCESS);
        }