summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-05-03 01:38:11 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-06 21:59:56 +0200
commit52f6790026040e17237ba8d7865cda3e0e239b62 (patch)
tree9c52eb35b48c1b012e8056709177c0f3d5e32acd
parent29ad9ebaba113f0300b0c94fd1fa29f67e9f24a6 (diff)
Add pixel format 0 (AV_PIX_FMT_YUV420P) to make_part_black().v2.14.51
Remainder of fix for #1984. Backported-from-commit: 0aabe4060ea4bad7c7caac633aef0737fccff8c2 Backported-from-branch: 2.15.x
-rw-r--r--src/lib/image.cc47
-rw-r--r--test/make_black_test.cc1
2 files changed, 37 insertions, 11 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 7da2edef9..c82db59ee 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -385,6 +385,23 @@ Image::swap_16 (uint16_t v)
return ((v >> 8) & 0xff) | ((v & 0xff) << 8);
}
+
+/* This was a lambda in the original code */
+static
+void
+y_part (Image* image, int start, int width)
+{
+ int const bpp = image->bytes_per_pixel(0);
+ int const h = image->sample_size(0).height;
+ int const s = image->stride()[0];
+ uint8_t* p = image->data()[0];
+ for (int y = 0; y < h; ++y) {
+ memset (p + start * bpp, 0, width * bpp);
+ p += s;
+ }
+}
+
+
void
Image::make_part_black (int const start, int const width)
{
@@ -409,20 +426,28 @@ Image::make_part_black (int const start, int const width)
}
break;
}
- case AV_PIX_FMT_YUV422P10LE:
+ case AV_PIX_FMT_YUV420P:
{
- int const bpp_0 = bytes_per_pixel(0);
- int const h_0 = sample_size(0).height;
- int const stride_0 = stride()[0];
- auto p = data()[0];
- for (int y = 0; y < h_0; ++y) {
- memset (p + start * bpp_0, 0xff, width * bpp_0);
- p += stride_0;
+ y_part (this, start, width);
+ for (int i = 1; i < 3; ++i) {
+ uint8_t* p = data()[i];
+ int const h = sample_size(i).height;
+ for (int y = 0; y < h; ++y) {
+ for (int x = start / 2; x < (start + width) / 2; ++x) {
+ p[x] = eight_bit_uv;
+ }
+ p += stride()[i];
+ }
}
+ break;
+ }
+ case AV_PIX_FMT_YUV422P10LE:
+ {
+ y_part (this, start, width);
for (int i = 1; i < 3; ++i) {
- auto p = reinterpret_cast<int16_t*>(data()[i]);
- int const lines = sample_size(i).height;
- for (int y = 0; y < lines; ++y) {
+ int16_t* p = reinterpret_cast<int16_t*>(data()[i]);
+ int const h = sample_size(i).height;
+ for (int y = 0; y < h; ++y) {
for (int x = start / 2; x < (start + width) / 2; ++x) {
p[x] = ten_bit_uv;
}
diff --git a/test/make_black_test.cc b/test/make_black_test.cc
index a639e079e..ee9903109 100644
--- a/test/make_black_test.cc
+++ b/test/make_black_test.cc
@@ -113,6 +113,7 @@ BOOST_AUTO_TEST_CASE (make_part_black_test)
AV_PIX_FMT_RGBA,
AV_PIX_FMT_ABGR,
AV_PIX_FMT_BGRA,
+ AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUV422P10LE,
};