summaryrefslogtreecommitdiff
path: root/src/lib/image.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-05-25 00:03:51 +0100
committerCarl Hetherington <cth@carlh.net>2017-05-25 00:03:51 +0100
commit0f664dab81a835feebd5db92942413f91747481f (patch)
treeb0761612b7ca45c3ac4d7856dfc8e26e4f599295 /src/lib/image.cc
parentf1d209319f90adc50e0f3d2a853216052f290bd5 (diff)
More tests; fix blend for YUV420P10LE.
Diffstat (limited to 'src/lib/image.cc')
-rw-r--r--src/lib/image.cc39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 2511df73e..228685442 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -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);
}