summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-05-24 23:07:42 +0100
committerCarl Hetherington <cth@carlh.net>2017-05-24 23:07:42 +0100
commitf1d209319f90adc50e0f3d2a853216052f290bd5 (patch)
tree9d6fd3118b76ff265808b14ce42e3f703c3b3ebd /test
parentf5291ad8e2e0dd8b342a62b4086577094944d700 (diff)
Implement alpha_blend for YUV420P and YUV420P10. Improve unit test.
Diffstat (limited to 'test')
-rw-r--r--test/image_test.cc77
-rw-r--r--test/test.cc20
-rw-r--r--test/test.h3
3 files changed, 57 insertions, 43 deletions
diff --git a/test/image_test.cc b/test/image_test.cc
index 5a39bb066..6a35be07f 100644
--- a/test/image_test.cc
+++ b/test/image_test.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -24,9 +24,11 @@
* @see test/make_black_test.cc, test/pixel_formats_test.cc
*/
-#include <boost/test/unit_test.hpp>
-#include <Magick++.h>
#include "lib/image.h"
+#include "lib/magick_image_proxy.h"
+#include "test.h"
+#include <Magick++.h>
+#include <boost/test/unit_test.hpp>
#include <iostream>
using std::string;
@@ -133,58 +135,53 @@ BOOST_AUTO_TEST_CASE (compact_image_test)
delete u;
}
-/** Test Image::alpha_blend */
-BOOST_AUTO_TEST_CASE (alpha_blend_test)
+void
+alpha_blend_test_one (AVPixelFormat format, string suffix)
{
- int const stride = 48 * 4;
+ shared_ptr<MagickImageProxy> proxy (new MagickImageProxy (private_data / "prophet_frame.tiff"));
+ shared_ptr<Image> raw = proxy->image();
+ shared_ptr<Image> background = raw->scale (raw->size(), dcp::YUV_TO_RGB_REC709, format, true, false);
- shared_ptr<Image> A (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 48), false));
- A->make_black ();
- uint8_t* a = A->data()[0];
+ shared_ptr<Image> overlay (new Image (AV_PIX_FMT_RGBA, raw->size(), true));
+ overlay->make_transparent ();
- for (int y = 0; y < 48; ++y) {
- uint8_t* p = a + y * stride;
- for (int x = 0; x < 16; ++x) {
+ for (int y = 0; y < 128; ++y) {
+ uint8_t* p = overlay->data()[0] + y * overlay->stride()[0];
+ for (int x = 0; x < 128; ++x) {
p[x * 4] = 255;
- p[(x + 16) * 4 + 1] = 255;
- p[(x + 32) * 4 + 2] = 255;
+ p[x * 4 + 3] = 255;
}
}
- shared_ptr<Image> B (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 48), true));
- B->make_transparent ();
- uint8_t* b = B->data()[0];
-
- for (int y = 32; y < 48; ++y) {
- uint8_t* p = b + y * stride;
- for (int x = 0; x < 48; ++x) {
- p[x * 4] = 255;
+ for (int y = 128; y < 256; ++y) {
+ uint8_t* p = overlay->data()[0] + y * overlay->stride()[0];
+ for (int x = 0; x < 128; ++x) {
p[x * 4 + 1] = 255;
- p[x * 4 + 2] = 255;
p[x * 4 + 3] = 255;
}
}
- A->alpha_blend (B, Position<int> (0, 0));
-
- for (int y = 0; y < 32; ++y) {
- uint8_t* p = a + y * stride;
- for (int x = 0; x < 16; ++x) {
- BOOST_CHECK_EQUAL (p[x * 4], 255);
- BOOST_CHECK_EQUAL (p[(x + 16) * 4 + 1], 255);
- BOOST_CHECK_EQUAL (p[(x + 32) * 4 + 2], 255);
+ for (int y = 256; y < 384; ++y) {
+ uint8_t* p = overlay->data()[0] + y * overlay->stride()[0];
+ for (int x = 0; x < 128; ++x) {
+ p[x * 4 + 2] = 255;
+ p[x * 4 + 3] = 255;
}
}
- for (int y = 32; y < 48; ++y) {
- uint8_t* p = a + y * stride;
- for (int x = 0; x < 48; ++x) {
- BOOST_CHECK_EQUAL (p[x * 4], 255);
- BOOST_CHECK_EQUAL (p[x * 4 + 1], 255);
- BOOST_CHECK_EQUAL (p[x * 4 + 2], 255);
- BOOST_CHECK_EQUAL (p[x * 4 + 3], 255);
- }
- }
+ background->alpha_blend (overlay, Position<int> (0, 0));
+
+ shared_ptr<Image> save = background->scale (background->size(), dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false, false);
+
+ write_image (save, "build/test/image_test_" + suffix + ".png", "RGB");
+ check_image ("build/test/image_test_" + suffix + ".png", private_data / ("image_test_" + suffix + ".png"));
+}
+
+/** Test Image::alpha_blend */
+BOOST_AUTO_TEST_CASE (alpha_blend_test)
+{
+ alpha_blend_test_one (AV_PIX_FMT_RGBA, "rgba");
+ alpha_blend_test_one (AV_PIX_FMT_YUV420P, "yuv420p");
}
/** Test merge (list<PositionImage>) with a single image */
diff --git a/test/test.cc b/test/test.cc
index b8d7070f8..85c36c16c 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -163,6 +163,22 @@ check_audio_file (boost::filesystem::path ref, boost::filesystem::path check)
}
void
+check_image (boost::filesystem::path ref, boost::filesystem::path check)
+{
+#ifdef DCPOMATIC_IMAGE_MAGICK
+ using namespace MagickCore;
+#else
+ using namespace MagickLib;
+#endif
+
+ Magick::Image ref_image;
+ ref_image.read (ref.string ());
+ Magick::Image check_image;
+ check_image.read (check.string ());
+ DCPOMATIC_ASSERT (ref_image.compare (check_image));
+}
+
+void
check_file (boost::filesystem::path ref, boost::filesystem::path check)
{
uintmax_t N = boost::filesystem::file_size (ref);
@@ -333,7 +349,7 @@ wait_for_jobs ()
}
void
-write_image (shared_ptr<const Image> image, boost::filesystem::path file)
+write_image (shared_ptr<const Image> image, boost::filesystem::path file, string format)
{
#ifdef DCPOMATIC_IMAGE_MAGICK
using namespace MagickCore;
@@ -341,6 +357,6 @@ write_image (shared_ptr<const Image> image, boost::filesystem::path file)
using namespace MagickLib;
#endif
- Magick::Image m (image->size().width, image->size().height, "ARGB", CharPixel, (void *) image->data()[0]);
+ Magick::Image m (image->size().width, image->size().height, format.c_str(), CharPixel, (void *) image->data()[0]);
m.write (file.string ());
}
diff --git a/test/test.h b/test/test.h
index 1593b3a03..8ac026e66 100644
--- a/test/test.h
+++ b/test/test.h
@@ -32,5 +32,6 @@ extern void check_file (boost::filesystem::path ref, boost::filesystem::path che
extern void check_audio_file (boost::filesystem::path ref, boost::filesystem::path check);
extern void check_xml (boost::filesystem::path, boost::filesystem::path, std::list<std::string>);
extern void check_file (boost::filesystem::path, boost::filesystem::path);
+extern void check_image (boost::filesystem::path, boost::filesystem::path);
extern boost::filesystem::path test_film_dir (std::string);
-extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem::path file);
+extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem::path file, std::string format);