Don't overlap simultaneous video content in the timeline. Fix keep-aligned for separ...
[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 #include <boost/test/unit_test.hpp>
21 #include <libdcp/util.h>
22 extern "C" {
23 #include <libavutil/pixfmt.h>
24 }
25 #include "lib/image.h"
26 #include "lib/scaler.h"
27
28 using std::list;
29
30 /* Check that Image::make_black works, and doesn't use values which crash
31    sws_scale().
32 */
33 BOOST_AUTO_TEST_CASE (make_black_test)
34 {
35         libdcp::Size in_size (512, 512);
36         libdcp::Size out_size (1024, 1024);
37
38         list<AVPixelFormat> pix_fmts;
39         pix_fmts.push_back (AV_PIX_FMT_RGB24);
40         pix_fmts.push_back (AV_PIX_FMT_ARGB);
41         pix_fmts.push_back (AV_PIX_FMT_RGBA);
42         pix_fmts.push_back (AV_PIX_FMT_ABGR);
43         pix_fmts.push_back (AV_PIX_FMT_BGRA);
44         pix_fmts.push_back (AV_PIX_FMT_YUV420P);
45         pix_fmts.push_back (AV_PIX_FMT_YUV411P);
46         pix_fmts.push_back (AV_PIX_FMT_YUV422P10LE);
47         pix_fmts.push_back (AV_PIX_FMT_YUV422P16LE);
48         pix_fmts.push_back (AV_PIX_FMT_YUV444P9LE);
49         pix_fmts.push_back (AV_PIX_FMT_YUV444P9BE);
50         pix_fmts.push_back (AV_PIX_FMT_YUV444P10LE);
51         pix_fmts.push_back (AV_PIX_FMT_YUV444P10BE);
52         pix_fmts.push_back (AV_PIX_FMT_UYVY422);
53         pix_fmts.push_back (AV_PIX_FMT_YUVJ420P);
54         pix_fmts.push_back (AV_PIX_FMT_YUVJ422P);
55         pix_fmts.push_back (AV_PIX_FMT_YUVJ444P);
56         pix_fmts.push_back (AV_PIX_FMT_YUVA420P9BE);
57         pix_fmts.push_back (AV_PIX_FMT_YUVA422P9BE);
58         pix_fmts.push_back (AV_PIX_FMT_YUVA444P9BE);
59         pix_fmts.push_back (AV_PIX_FMT_YUVA420P9LE);
60         pix_fmts.push_back (AV_PIX_FMT_YUVA422P9LE);
61         pix_fmts.push_back (AV_PIX_FMT_YUVA444P9LE);
62         pix_fmts.push_back (AV_PIX_FMT_YUVA420P10BE);
63         pix_fmts.push_back (AV_PIX_FMT_YUVA422P10BE);
64         pix_fmts.push_back (AV_PIX_FMT_YUVA444P10BE);
65         pix_fmts.push_back (AV_PIX_FMT_YUVA420P10LE);
66         pix_fmts.push_back (AV_PIX_FMT_YUVA422P10LE);
67         pix_fmts.push_back (AV_PIX_FMT_YUVA444P10LE);
68         pix_fmts.push_back (AV_PIX_FMT_YUVA420P16BE);
69         pix_fmts.push_back (AV_PIX_FMT_YUVA422P16BE);
70         pix_fmts.push_back (AV_PIX_FMT_YUVA444P16BE);
71         pix_fmts.push_back (AV_PIX_FMT_YUVA420P16LE);
72         pix_fmts.push_back (AV_PIX_FMT_YUVA422P16LE);
73         pix_fmts.push_back (AV_PIX_FMT_YUVA444P16LE);
74
75         int N = 0;
76         for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) {
77                 boost::shared_ptr<Image> foo (new Image (*i, in_size, true));
78                 foo->make_black ();
79                 boost::shared_ptr<Image> bar = foo->scale (out_size, Scaler::from_id ("bicubic"), PIX_FMT_RGB24, true);
80                 
81                 uint8_t* p = bar->data()[0];
82                 for (int y = 0; y < bar->size().height; ++y) {
83                         uint8_t* q = p;
84                         for (int x = 0; x < bar->line_size()[0]; ++x) {
85                                 if (*q != 0) {
86                                         std::cerr << "x=" << x << ", (x%3)=" << (x%3) << "\n";
87                                 }
88                                 BOOST_CHECK_EQUAL (*q++, 0);
89                         }
90                         p += bar->stride()[0];
91                 }
92
93                 ++N;
94         }
95 }