2d783f52d72ae357d033ab70847902d98903333b
[dcpomatic.git] / test / video_decoder_fill_test.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include <boost/test/unit_test.hpp>
22 #include "lib/image_decoder.h"
23 #include "lib/image_content.h"
24 #include "lib/content_video.h"
25 #include "lib/video_decoder.h"
26 #include "lib/film.h"
27 #include "test.h"
28 #include <iostream>
29
30 using std::list;
31 using std::cout;
32 using boost::shared_ptr;
33
34 BOOST_AUTO_TEST_CASE (video_decoder_fill_test1)
35 {
36         shared_ptr<Film> film = new_test_film ("video_decoder_fill_test");
37         shared_ptr<ImageContent> c (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
38         ImageDecoder decoder (c, film->log());
39
40         decoder.video->fill_one_eye (0, 4, EYES_BOTH);
41         BOOST_CHECK_EQUAL (decoder.video->_decoded.size(), 4U);
42         list<ContentVideo>::iterator i = decoder.video->_decoded.begin();
43         for (int j = 0; j < 4; ++j) {
44                 BOOST_CHECK_EQUAL (i->frame.index(), j);
45                 ++i;
46         }
47
48         decoder.video->_decoded.clear ();
49
50         decoder.video->fill_one_eye (0, 7, EYES_BOTH);
51         BOOST_CHECK_EQUAL (decoder.video->_decoded.size(), 7);
52         i = decoder.video->_decoded.begin();
53         for (int j = 0; j < 7; ++j) {
54                 BOOST_CHECK_EQUAL (i->frame.index(), j);
55                 ++i;
56         }
57 }
58
59 BOOST_AUTO_TEST_CASE (video_decoder_fill_test2)
60 {
61         shared_ptr<Film> film = new_test_film ("video_decoder_fill_test");
62         shared_ptr<ImageContent> c (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
63         ImageDecoder decoder (c, film->log());
64
65         decoder.video->fill_both_eyes (VideoFrame (0, EYES_LEFT), VideoFrame (4, EYES_LEFT));
66         BOOST_CHECK_EQUAL (decoder.video->_decoded.size(), 8);
67         list<ContentVideo>::iterator i = decoder.video->_decoded.begin();
68         for (int j = 0; j < 8; ++j) {
69                 BOOST_CHECK_EQUAL (i->frame.index(), j / 2);
70                 BOOST_CHECK_EQUAL (i->frame.eyes(), (j % 2) == 0 ? EYES_LEFT : EYES_RIGHT);
71                 ++i;
72         }
73
74         decoder.video->_decoded.clear ();
75         decoder.video->fill_both_eyes (VideoFrame (0, EYES_LEFT), VideoFrame (7, EYES_RIGHT));
76         BOOST_CHECK_EQUAL (decoder.video->_decoded.size(), 15);
77         i = decoder.video->_decoded.begin();
78         for (int j = 0; j < 15; ++j) {
79                 BOOST_CHECK_EQUAL (i->frame.index(), j / 2);
80                 BOOST_CHECK_EQUAL (i->frame.eyes(), (j % 2) == 0 ? EYES_LEFT : EYES_RIGHT);
81                 ++i;
82         }
83
84         decoder.video->_decoded.clear ();
85         decoder.video->fill_both_eyes (VideoFrame (0, EYES_RIGHT), VideoFrame (7, EYES_RIGHT));
86         BOOST_CHECK_EQUAL (decoder.video->_decoded.size(), 14);
87         i = decoder.video->_decoded.begin();
88         for (int j = 0; j < 14; ++j) {
89                 BOOST_CHECK_EQUAL (i->frame.index(), (j + 1) / 2);
90                 BOOST_CHECK_EQUAL (i->frame.eyes(), (j % 2) == 0 ? EYES_RIGHT : EYES_LEFT);
91                 ++i;
92         }
93 }