diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-07-17 23:36:04 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-07-17 23:36:04 +0000 |
| commit | 8964feb6151ac79ef7429878f29534c5f9a58505 (patch) | |
| tree | 688486fbb425f01c73533b195c88c5a975633632 /test/test.cc | |
| parent | 46d89e9f754c50712e8983ae5c86bbb0a6cf4362 (diff) | |
Be more lenient when comparing JPEG2000 frames in tests.
Diffstat (limited to 'test/test.cc')
| -rw-r--r-- | test/test.cc | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/test/test.cc b/test/test.cc index b0bd0bda7..e68413ecd 100644 --- a/test/test.cc +++ b/test/test.cc @@ -34,6 +34,7 @@ #include "lib/ratio.h" #include "lib/dcp_content_type.h" #include "lib/log_entry.h" +#include "lib/j2k_image_proxy.h" #include "lib/compose.hpp" #include "test.h" #include <dcp/dcp.h> @@ -68,6 +69,7 @@ using std::abs; using boost::shared_ptr; using boost::scoped_array; using boost::dynamic_pointer_cast; +using boost::optional; boost::filesystem::path private_data = boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private"); @@ -445,7 +447,7 @@ check_ffmpeg (boost::filesystem::path ref, boost::filesystem::path check, int au } void -check_one_frame (boost::filesystem::path dcp_dir, int64_t index, boost::filesystem::path ref) +check_one_frame (boost::filesystem::path dcp_dir, int64_t index, dcp::Size dcp_size, boost::filesystem::path ref, dcp::Size ref_size) { dcp::DCP dcp (dcp_dir); dcp.read (); @@ -453,18 +455,30 @@ check_one_frame (boost::filesystem::path dcp_dir, int64_t index, boost::filesyst BOOST_REQUIRE (asset); shared_ptr<const dcp::MonoPictureFrame> frame = asset->start_read()->get_frame(index); - boost::uintmax_t const ref_size = boost::filesystem::file_size(ref); - BOOST_CHECK_EQUAL (frame->j2k_size(), ref_size); + J2KImageProxy dcp_proxy (frame, dcp_size, AV_PIX_FMT_RGB48, optional<int>()); + J2KImageProxy ref_proxy (ref, ref_size, AV_PIX_FMT_RGB48); - FILE* ref_file = fopen_boost(ref, "rb"); - BOOST_REQUIRE (ref_file); + shared_ptr<Image> dcp_image = dcp_proxy.image().first->convert_pixel_format (dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false); + shared_ptr<Image> ref_image = ref_proxy.image().first->convert_pixel_format (dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false); - uint8_t* ref_data = new uint8_t[ref_size]; - fread (ref_data, ref_size, 1, ref_file); - fclose (ref_file); +#ifdef DCPOMATIC_IMAGE_MAGICK + using namespace MagickCore; +#else + using namespace MagickLib; +#endif + + Magick::Image dcp_magick (dcp_image->size().width, dcp_image->size().height, "RGB", CharPixel, (void *) dcp_image->data()[0]); + Magick::Image ref_magick (ref_image->size().width, ref_image->size().height, "RGB", CharPixel, (void *) ref_image->data()[0]); - BOOST_CHECK (memcmp(ref_data, frame->j2k_data(), ref_size) == 0); - delete[] ref_data; + /* XXX: this is a hack; we really want the ImageMagick call but GraphicsMagick doesn't have it; + this may cause random test failures on platforms that use GraphicsMagick. + */ +#ifdef DCPOMATIC_ADVANCED_MAGICK_COMPARE + double const dist = ref_magick.compare(dcp_magick, Magick::RootMeanSquaredErrorMetric); + BOOST_CHECK_MESSAGE (dist < 0.001, ref << " differs from " << dcp_dir << ":" << index << " " << dist); +#else + BOOST_CHECK_MESSAGE (!ref_magick.compare(dcp_magick), ref << " differs from " << check); +#endif } boost::filesystem::path |
