diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-02 00:59:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-02 00:59:36 +0100 |
| commit | 4f6b9809ed4c9291e2577ee8e0f3bebf15ca2629 (patch) | |
| tree | afd8890b4b0a0c850ed8dad19e5815a90be83ac8 /src | |
| parent | 12fe692248cfd7f604b8ac7d596bf796c0bf420a (diff) | |
Compare using maximum mean absolute difference and standard deviation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset.cc | 2 | ||||
| -rw-r--r-- | src/asset.h | 2 | ||||
| -rw-r--r-- | src/dcp.cc | 4 | ||||
| -rw-r--r-- | src/dcp.h | 2 | ||||
| -rw-r--r-- | src/picture_asset.cc | 46 | ||||
| -rw-r--r-- | src/picture_asset.h | 2 | ||||
| -rw-r--r-- | src/sound_asset.cc | 4 | ||||
| -rw-r--r-- | src/sound_asset.h | 2 |
8 files changed, 39 insertions, 25 deletions
diff --git a/src/asset.cc b/src/asset.cc index f8362c8b..38617e85 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -96,7 +96,7 @@ Asset::mxf_path () const } list<string> -Asset::equals (shared_ptr<const Asset> other, EqualityFlags flags) const +Asset::equals (shared_ptr<const Asset> other, EqualityFlags flags, double, double) const { list<string> notes; diff --git a/src/asset.h b/src/asset.h index cf161104..51e5dc54 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<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags) const; + virtual std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const; protected: friend class PictureAsset; @@ -334,7 +334,7 @@ DCP::DCP (string directory) } list<string> -DCP::equals (DCP const & other, EqualityFlags flags) const +DCP::equals (DCP const & other, EqualityFlags flags, double max_mean, double max_std_dev) const { list<string> notes; @@ -361,7 +361,7 @@ DCP::equals (DCP const & other, EqualityFlags flags) const list<shared_ptr<Asset> >::const_iterator b = other._assets.begin (); while (a != _assets.end ()) { - list<string> n = (*a)->equals (*b, flags); + list<string> n = (*a)->equals (*b, flags, max_mean, max_std_dev); notes.merge (n); ++a; ++b; @@ -106,7 +106,7 @@ public: return _length; } - std::list<std::string> equals (DCP const & other, EqualityFlags flags) const; + std::list<std::string> equals (DCP const & other, EqualityFlags flags, double max_mean, double max_std_dev) 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 969a5523..3386d6d4 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -25,6 +25,7 @@ #include <stdexcept> #include <iostream> #include <sstream> +#include <fstream> #include <boost/filesystem.hpp> #include <boost/lexical_cast.hpp> #include <openjpeg.h> @@ -142,9 +143,9 @@ PictureAsset::write_to_cpl (ostream& s) const } list<string> -PictureAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags) const +PictureAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const { - list<string> notes = Asset::equals (other, flags); + list<string> notes = Asset::equals (other, flags, max_mean, max_std_dev); if (flags & MXF_INSPECT) { ASDCP::JP2K::MXFReader reader_A; @@ -214,13 +215,9 @@ PictureAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags) const if (buffer_A.Size() != buffer_B.Size()) { notes.push_back ("sizes of video data for frame " + lexical_cast<string>(i) + " differ"); j2k_same = false; - continue; - } - - if (memcmp (buffer_A.RoData(), buffer_B.RoData(), buffer_A.Size()) != 0) { + } else if (memcmp (buffer_A.RoData(), buffer_B.RoData(), buffer_A.Size()) != 0) { notes.push_back ("J2K data for frame " + lexical_cast<string>(i) + " differ"); j2k_same = false; - continue; } if (!j2k_same) { @@ -234,21 +231,38 @@ PictureAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags) const notes.push_back ("image component counts for frame " + lexical_cast<string>(i) + " differ"); } + vector<int> abs_diffs (image_A->comps[0].w * image_A->comps[0].h * image_A->numcomps); + int d = 0; + for (int c = 0; c < image_A->numcomps; ++c) { + if (image_A->comps[c].w != image_B->comps[c].w || image_A->comps[c].h != image_B->comps[c].h) { notes.push_back ("image sizes for frame " + lexical_cast<string>(i) + " differ"); } - - cout << "comp " << c << " of " << image_A->numcomps << "\n"; - cout << "bpp " << image_A->comps[c].bpp << "\n"; - - for (int x = 0; x < image_A->comps[c].w; ++x) { - for (int y = 0; y < image_A->comps[c].h; ++y) { - - } + + int const pixels = image_A->comps[c].w * image_A->comps[c].h; + for (int j = 0; j < pixels; ++j) { + abs_diffs[d++] = abs (image_A->comps[c].data[j] - image_B->comps[c].data[j]); } } - + + uint64_t total = 0; + for (vector<int>::iterator j = abs_diffs.begin(); j != abs_diffs.end(); ++j) { + total += *j; + } + + double const mean = double (total) / abs_diffs.size (); + + uint64_t total_squared_deviation = 0; + for (vector<int>::iterator j = abs_diffs.begin(); j != abs_diffs.end(); ++j) { + total_squared_deviation += pow (*j - mean, 2); + } + + double const std_dev = sqrt (double (total_squared_deviation) / abs_diffs.size()); + + if (mean > max_mean || std_dev > max_std_dev) { + notes.push_back ("mean or standard deviation out of range for " + lexical_cast<string>(i)); + } opj_image_destroy (image_A); opj_image_destroy (image_B); diff --git a/src/picture_asset.h b/src/picture_asset.h index 3980794a..8a697f2c 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<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags) const; + std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const; private: std::string path_from_list (int f, std::vector<std::string> const & files) const; diff --git a/src/sound_asset.cc b/src/sound_asset.cc index ed815eda..2d834957 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -177,9 +177,9 @@ SoundAsset::write_to_cpl (ostream& s) const } list<string> -SoundAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags) const +SoundAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const { - list<string> notes = Asset::equals (other, flags); + list<string> notes = Asset::equals (other, flags, max_mean, max_std_dev); if (flags & MXF_INSPECT) { ASDCP::PCM::MXFReader reader_A; diff --git a/src/sound_asset.h b/src/sound_asset.h index 2d797998..4b7c0967 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<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags) const; + std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityFlags flags, double max_mean, double max_std_dev) const; private: void construct (sigc::slot<std::string, Channel> get_path); |
