Merge master.
[dcpomatic.git] / test / make_black_test.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /* Check that Image::make_black works, and doesn't use values which crash
21    sws_scale().
22 */
23 BOOST_AUTO_TEST_CASE (make_black_test)
24 {
25         libdcp::Size in_size (512, 512);
26         libdcp::Size out_size (1024, 1024);
27
28         list<AVPixelFormat> pix_fmts;
29         pix_fmts.push_back (AV_PIX_FMT_RGB24);
30         pix_fmts.push_back (AV_PIX_FMT_YUV420P);
31         pix_fmts.push_back (AV_PIX_FMT_YUV422P10LE);
32         pix_fmts.push_back (AV_PIX_FMT_YUV422P16LE);
33         pix_fmts.push_back (AV_PIX_FMT_YUV444P9LE);
34         pix_fmts.push_back (AV_PIX_FMT_YUV444P9BE);
35         pix_fmts.push_back (AV_PIX_FMT_YUV444P10LE);
36         pix_fmts.push_back (AV_PIX_FMT_YUV444P10BE);
37         pix_fmts.push_back (AV_PIX_FMT_UYVY422);
38         pix_fmts.push_back (AV_PIX_FMT_YUVJ420P);
39         pix_fmts.push_back (AV_PIX_FMT_YUVJ422P);
40         pix_fmts.push_back (AV_PIX_FMT_YUVJ444P);
41
42         int N = 0;
43         for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) {
44                 boost::shared_ptr<Image> foo (new SimpleImage (*i, in_size, true));
45                 foo->make_black ();
46                 boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, Scaler::from_id ("bicubic"), true);
47                 
48                 uint8_t* p = bar->data()[0];
49                 for (int y = 0; y < bar->size().height; ++y) {
50                         uint8_t* q = p;
51                         for (int x = 0; x < bar->line_size()[0]; ++x) {
52                                 if (*q != 0) {
53                                         std::cerr << "x=" << x << ", (x%3)=" << (x%3) << "\n";
54                                 }
55                                 BOOST_CHECK_EQUAL (*q++, 0);
56                         }
57                         p += bar->stride()[0];
58                 }
59
60                 ++N;
61         }
62 }