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
39         int N = 0;
40         for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) {
41                 boost::shared_ptr<Image> foo (new SimpleImage (*i, in_size, true));
42                 foo->make_black ();
43                 boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true);
44                 
45                 uint8_t* p = bar->data()[0];
46                 for (int y = 0; y < bar->size().height; ++y) {
47                         uint8_t* q = p;
48                         for (int x = 0; x < bar->line_size()[0]; ++x) {
49                                 BOOST_CHECK_EQUAL (*q++, 0);
50                         }
51                         p += bar->stride()[0];
52                 }
53
54                 ++N;
55         }
56 }