summaryrefslogtreecommitdiff
path: root/test/video_content_scale_test.cc
blob: 73feb7dc66460dbaebd87e1158f687aaeb8f7acf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#include "lib/ratio.h"
#include "lib/video_content.h"
#include "test.h"
#include <boost/test/unit_test.hpp>


static dcp::Size const FOUR_TO_THREE(1436, 1080);
static dcp::Size const FLAT(1998, 1080);
static dcp::Size const SCOPE(2048, 858);


/* Test VideoContent::scaled_size() without any legacy stuff */
BOOST_AUTO_TEST_CASE (scaled_size_test1)
{
	VideoContent vc (0);

	/* Images at full size and in DCP-approved sizes that will not be scaled */
	// Flat/scope content into flat/scope container
	vc._size = FLAT;
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
	vc._size = SCOPE;
	BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
	// 1.33:1 into flat container
	vc._size = FOUR_TO_THREE;
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
	// Scope into flat container
	vc._size = SCOPE;
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 837));

	/* Smaller images but in the same ratios */
	vc._size = dcp::Size(185, 100);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
	vc._size = dcp::Size(955, 400);
	BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
	// 1.33:1 into flat container
	vc._size = dcp::Size(133, 100);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
	// Scope into flat container
	vc._size = dcp::Size(239, 100);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 836));

	/* Images at full size that are not DCP-approved but will still remain unscaled */
	vc._size = dcp::Size(600, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(600, 1080));
	vc._size = dcp::Size(1700, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1700, 1080));

	/* Image at full size that is too big for the container and will be shrunk */
	vc._size = dcp::Size(3000, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 719));
}


/* Same as scaled_size_test1 but with a non-unity sample aspect ratio */
BOOST_AUTO_TEST_CASE (scaled_size_test2)
{
	VideoContent vc (0);

	vc._sample_aspect_ratio = 2;

	/* Images at full size and in DCP-approved sizes that will not be scaled */
	// Flat/scope content into flat/scope container
	vc._size = dcp::Size (1998 / 2, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
	vc._size = dcp::Size (2048 / 2, 858);
	BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
	// 1.33:1 into flat container
	vc._size = dcp::Size (1436 / 2, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
	// Scope into flat container
	vc._size = dcp::Size (2048 / 2, 858);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 837));

	/* Smaller images but in the same ratios */
	vc._size = dcp::Size(185, 200);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
	vc._size = dcp::Size(955, 800);
	BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
	// 4:3 into flat container
	vc._size = dcp::Size(133, 200);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
	// Scope into flat container
	vc._size = dcp::Size(239, 200);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 836));

	/* Images at full size that are not DCP-approved but will still remain unscaled */
	vc._size = dcp::Size(600 / 2, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(600, 1080));
	vc._size = dcp::Size(1700 / 2, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1700, 1080));

	/* Image at full size that is too big for the container and will be shrunk */
	vc._size = dcp::Size(3000 / 2, 1080);
	BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 719));
}


/* Test VideoContent::scaled_size() with some legacy stuff */
BOOST_AUTO_TEST_CASE (scaled_size_legacy_test)
{
	{
		/* 640x480 content that the user had asked to be stretched to 1.85:1 */
		VideoContent vc (0);
		vc._size = dcp::Size(640, 480);
		vc._legacy_ratio = Ratio::from_id("185")->ratio();
		BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
	}

	{
		/* 640x480 content that the user had asked to be scaled to fit the container, without stretch */
		VideoContent vc (0);
		vc._size = dcp::Size(640, 480);
		vc._legacy_ratio = 1.33;
		BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FOUR_TO_THREE);
	}

	{
		/* 640x480 content that the user had asked to be kept the same size */
		VideoContent vc (0);
		vc._size = dcp::Size(640, 480);
		vc._custom_size = dcp::Size(640, 480);
		BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(640, 480));
	}
}