More tests; fix blend for YUV420P10LE.
authorCarl Hetherington <cth@carlh.net>
Wed, 24 May 2017 23:03:51 +0000 (00:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 24 May 2017 23:03:51 +0000 (00:03 +0100)
src/lib/image.cc
src/lib/image.h
test/image_test.cc
test/test.cc

index 2511df73ea87bed9638df60e324ea77a0bc24557..228685442dd5016a3a614d63f010cf18e6171947 100644 (file)
@@ -429,6 +429,36 @@ Image::make_transparent ()
        memset (data()[0], 0, sample_size(0).height * stride()[0]);
 }
 
+template <class T>
+void
+component (
+       int n,
+       Image* base,
+       shared_ptr<const Image> other,
+       shared_ptr<const Image> rgba,
+       int start_base_x, int start_base_y,
+       int start_other_x, int start_other_y
+       )
+{
+       dcp::Size const base_size = base->sample_size(n);
+       dcp::Size const other_size = other->sample_size(n);
+       for (int by = start_base_y, oy = start_other_y; by < base_size.height && oy < other_size.height; ++by, ++oy) {
+               /* base image */
+               T* bp = ((T*) (base->data()[n] + by * base->stride()[n])) + start_base_x;
+               /* overlay image */
+               T* op = ((T*) (other->data()[n] + oy * other->stride()[n]));
+               /* original RGBA for alpha channel */
+               uint8_t* rp = rgba->data()[0] + oy * rgba->stride()[0];
+               for (int bx = start_base_x, ox = start_other_x; bx < base_size.width && ox < other_size.width; ++bx, ++ox) {
+                       float const alpha = float (rp[3]) / 255;
+                       *bp = *op * alpha + *bp * (1 - alpha);
+                       ++bp;
+                       ++op;
+                       rp += 4;
+               }
+       }
+}
+
 void
 Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
 {
@@ -547,7 +577,6 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                break;
        }
        case AV_PIX_FMT_YUV420P:
-       case AV_PIX_FMT_YUV420P10:
        {
                shared_ptr<Image> yuv = other->scale (other->size(), dcp::YUV_TO_RGB_REC709, _pixel_format, false, false);
 
@@ -579,6 +608,14 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                }
                break;
        }
+       case AV_PIX_FMT_YUV420P10:
+       {
+               shared_ptr<Image> yuv = other->scale (other->size(), dcp::YUV_TO_RGB_REC709, _pixel_format, false, false);
+               component<uint16_t> (0, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+               component<uint8_t> (1, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+               component<uint8_t> (2, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+               break;
+       }
        default:
                throw PixelFormatError ("alpha_blend()", _pixel_format);
        }
index dde42f1bc2add86b228e7d0847a42d50830c0956..fd5adb0762ea9071ce1cd831f7aba49c3bef0aab 100644 (file)
@@ -57,6 +57,7 @@ public:
        int vertical_factor (int) const;
        int horizontal_factor (int) const;
        dcp::Size sample_size (int) const;
+       float bytes_per_pixel (int) const;
 
        boost::shared_ptr<Image> scale (dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool aligned, bool fast) const;
        boost::shared_ptr<Image> crop_scale_window (
@@ -81,7 +82,6 @@ private:
 
        void allocate ();
        void swap (Image &);
-       float bytes_per_pixel (int) const;
        void yuv_16_black (uint16_t, bool);
        static uint16_t swap_16 (uint16_t);
 
index 6a35be07f315b369073073d13ae0ef61b4981f8f..59000918a0155722a3842324ec9ae72b52b2bcd6 100644 (file)
@@ -180,8 +180,12 @@ alpha_blend_test_one (AVPixelFormat format, string suffix)
 /** Test Image::alpha_blend */
 BOOST_AUTO_TEST_CASE (alpha_blend_test)
 {
+       alpha_blend_test_one (AV_PIX_FMT_RGB24, "rgb24");
+       alpha_blend_test_one (AV_PIX_FMT_BGRA, "bgra");
        alpha_blend_test_one (AV_PIX_FMT_RGBA, "rgba");
+       alpha_blend_test_one (AV_PIX_FMT_RGB48LE, "rgb48le");
        alpha_blend_test_one (AV_PIX_FMT_YUV420P, "yuv420p");
+       alpha_blend_test_one (AV_PIX_FMT_YUV420P10LE, "yuv420p10le");
 }
 
 /** Test merge (list<PositionImage>) with a single image */
index 85c36c16c0038910242def9a57ed7ed05ed71e84..b81d20134d7b9024c5d0e131c3c66a0795a56007 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -175,7 +175,7 @@ check_image (boost::filesystem::path ref, boost::filesystem::path check)
        ref_image.read (ref.string ());
        Magick::Image check_image;
        check_image.read (check.string ());
-       DCPOMATIC_ASSERT (ref_image.compare (check_image));
+       BOOST_CHECK_MESSAGE (ref_image.compare (check_image), ref << " differs from " << check);
 }
 
 void