More test fixes after changes in c2c6fbdd8dddbb6ccba0a6ae49a13d5364122df7
[dcpomatic.git] / test / remake_video_test.cc
1 /*
2     Copyright (C) 2024 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
22 #include "lib/content_factory.h"
23 #include "lib/film.h"
24 #include "lib/video_content.h"
25 #include "test.h"
26 #include <dcp/colour_conversion.h>
27 #include <dcp/cpl.h>
28 #include <dcp/dcp.h>
29 #include <dcp/mono_picture_asset_reader.h>
30 #include <dcp/reel.h>
31 #include <dcp/reel_mono_picture_asset.h>
32 #include <boost/test/unit_test.hpp>
33
34
35 using std::dynamic_pointer_cast;
36 using std::shared_ptr;
37 using std::string;
38 using std::vector;
39
40
41 BOOST_AUTO_TEST_CASE(remake_video_after_yub_rgb_matrix_changed)
42 {
43         auto content = content_factory("test/data/rgb_grey_testcard.mp4")[0];
44         auto film = new_test_film2("remake_video_after_yub_rgb_matrix_changed", { content });
45
46         auto conversion = content->video->colour_conversion();
47         BOOST_REQUIRE(static_cast<bool>(conversion));
48         conversion->set_yuv_to_rgb(dcp::YUVToRGB::REC709);
49         content->video->set_colour_conversion(*conversion);
50
51         auto calculate_picture_hashes = [](shared_ptr<Film> film) {
52                 make_and_verify_dcp(film);
53                 dcp::DCP dcp(film->dir(film->dcp_name()));
54                 dcp.read();
55                 BOOST_REQUIRE(!dcp.cpls().empty());
56                 auto cpl = dcp.cpls()[0];
57                 BOOST_REQUIRE(!cpl->reels().empty());
58                 auto reel = cpl->reels()[0];
59                 BOOST_REQUIRE(reel->main_picture());
60                 auto mono = dynamic_pointer_cast<dcp::MonoPictureAsset>(reel->main_picture()->asset());
61                 BOOST_REQUIRE(mono);
62                 auto reader = mono->start_read();
63
64                 vector<string> hashes;
65                 for (auto i = 0; i < reel->main_picture()->intrinsic_duration(); ++i) {
66                         auto frame = reader->get_frame(i);
67                         hashes.push_back(dcp::make_digest(dcp::ArrayData(frame->data(), frame->size())));
68                 }
69                 return hashes;
70         };
71
72         auto before = calculate_picture_hashes(film);
73         conversion->set_yuv_to_rgb(dcp::YUVToRGB::REC601);
74         content->video->set_colour_conversion(*conversion);
75         auto after = calculate_picture_hashes(film);
76
77         BOOST_CHECK(before != after);
78 }
79