Fix and test Image::make_black().
authorCarl Hetherington <cth@carlh.net>
Wed, 23 Jan 2013 14:42:56 +0000 (14:42 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 23 Jan 2013 14:42:56 +0000 (14:42 +0000)
src/lib/image.cc
test/test.cc

index 4eed0e5b4d8417dc2ad4f7f204fa673b47c5b8db..3afb6205eb21f11245ac8e3f3e41e48f8b2738d6 100644 (file)
@@ -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;
index 7e1d92e06bf911f8ea0a42557ab4d024125b0665..13eb1f17fec42802ac9ff7cc7cb7c5b625df759e 100644 (file)
@@ -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";