diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-01-23 14:42:56 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-01-23 14:42:56 +0000 |
| commit | d58f9adc515ac0c0193a4998fed3605f4e2c6e11 (patch) | |
| tree | 8b9c48af8f50af93aa6dfd5e9852f4a6ffb21865 | |
| parent | 3886847e2dafdaec4ad780dac606802356beb31d (diff) | |
Fix and test Image::make_black().
| -rw-r--r-- | src/lib/image.cc | 18 | ||||
| -rw-r--r-- | test/test.cc | 62 |
2 files changed, 76 insertions, 4 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc index 4eed0e5b4..3afb6205e 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -245,13 +245,25 @@ Image::make_black () { switch (_pixel_format) { case PIX_FMT_YUV420P: - case PIX_FMT_YUV422P10LE: case PIX_FMT_YUV422P: memset (data()[0], 0, lines(0) * stride()[0]); - memset (data()[1], 0x80, lines(1) * stride()[1]); - memset (data()[2], 0x80, lines(2) * stride()[2]); + memset (data()[1], 0x7f, lines(1) * stride()[1]); + memset (data()[2], 0x7f, lines(2) * stride()[2]); break; + case PIX_FMT_YUV422P10LE: + memset (data()[0], 0, lines(0) * stride()[0]); + for (int i = 1; i < 3; ++i) { + int16_t* p = reinterpret_cast<int16_t*> (data()[i]); + for (int y = 0; y < size().height; ++y) { + for (int x = 0; x < line_size()[i] / 2; ++x) { + p[x] = (1 << 9) - 1; + } + p += stride()[i] / 2; + } + } + break; + case PIX_FMT_RGB24: memset (data()[0], 0, lines(0) * stride()[0]); break; diff --git a/test/test.cc b/test/test.cc index 7e1d92e06..13eb1f17f 100644 --- a/test/test.cc +++ b/test/test.cc @@ -69,9 +69,69 @@ new_test_film (string name) return shared_ptr<Film> (new Film (d, false)); } -BOOST_AUTO_TEST_CASE (film_metadata_test) + +/* Check that Image::make_black works, and doesn't use values which crash + sws_scale(). +*/ +BOOST_AUTO_TEST_CASE (make_black_test) { + /* This needs to happen in the first test */ dvdomatic_setup (); + + libdcp::Size in_size (512, 512); + libdcp::Size out_size (1024, 1024); + + { + /* Plain RGB input */ + boost::shared_ptr<Image> foo (new SimpleImage (AV_PIX_FMT_RGB24, in_size, true)); + foo->make_black (); + boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true); + + uint8_t* p = bar->data()[0]; + for (int y = 0; y < bar->size().height; ++y) { + uint8_t* q = p; + for (int x = 0; x < bar->line_size()[0]; ++x) { + BOOST_CHECK_EQUAL (*q++, 0); + } + p += bar->stride()[0]; + } + } + + { + /* YUV420P input */ + boost::shared_ptr<Image> foo (new SimpleImage (AV_PIX_FMT_YUV420P, in_size, true)); + foo->make_black (); + boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true); + + uint8_t* p = bar->data()[0]; + for (int y = 0; y < bar->size().height; ++y) { + uint8_t* q = p; + for (int x = 0; x < bar->line_size()[0]; ++x) { + BOOST_CHECK_EQUAL (*q++, 0); + } + p += bar->stride()[0]; + } + } + + { + /* YUV422P10LE input */ + boost::shared_ptr<Image> foo (new SimpleImage (AV_PIX_FMT_YUV422P10LE, in_size, true)); + foo->make_black (); + boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true); + + uint8_t* p = bar->data()[0]; + for (int y = 0; y < bar->size().height; ++y) { + uint8_t* q = p; + for (int x = 0; x < bar->line_size()[0]; ++x) { + BOOST_CHECK_EQUAL (*q++, 0); + } + p += bar->stride()[0]; + } + } +} + +BOOST_AUTO_TEST_CASE (film_metadata_test) +{ setup_test_config (); string const test_film = "build/test/film_metadata_test"; |
