Be more lenient when comparing JPEG2000 frames in tests.
authorCarl Hetherington <cth@carlh.net>
Tue, 17 Jul 2018 23:36:04 +0000 (23:36 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 17 Jul 2018 23:36:04 +0000 (23:36 +0000)
test/remake_with_subtitle_test.cc
test/test.cc
test/test.h

index bc6d4179866af71799a77de035912232e9a34bab..9cc57662c8aadb2ee6683cd85caab4ed72820faf 100644 (file)
@@ -48,5 +48,5 @@ BOOST_AUTO_TEST_CASE (remake_with_subtitle_test)
        film->make_dcp ();
        BOOST_REQUIRE (!wait_for_jobs ());
 
-       check_one_frame (film->dir(film->dcp_name()), 325, private_data / "prophet_frame_325_no_subs.j2c");
+       check_one_frame (film->dir(film->dcp_name()), 325, dcp::Size(1998, 1080), private_data / "prophet_frame_325_no_subs.j2c", dcp::Size(1998, 1080));
 }
index b0bd0bda7e6404026d677590e2fcd85cbd8090e2..e68413ecdfd792a6264ed96aedda48ee5c52a687 100644 (file)
@@ -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
index 2f206269299acae14c7b447f0a6951879ead4a56..8ed7cf7e01fdec965f5ee14e3feb38d6f1eb04ef 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -18,6 +18,7 @@
 
 */
 
+#include <dcp/types.h>
 #include <boost/filesystem.hpp>
 
 class Film;
@@ -40,4 +41,4 @@ extern void check_image (boost::filesystem::path, boost::filesystem::path, doubl
 extern boost::filesystem::path test_film_dir (std::string);
 extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem::path file, std::string format);
 boost::filesystem::path dcp_file (boost::shared_ptr<const Film> film, std::string prefix);
-void check_one_frame (boost::filesystem::path dcp, int64_t index, boost::filesystem::path ref);
+void check_one_frame (boost::filesystem::path dcp, int64_t index, dcp::Size dcp_size, boost::filesystem::path ref, dcp::Size ref_size);