More benchmarks.
[dcpomatic.git] / benchmark / scaling.cc
1 /*
2     Copyright (C) 2020 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/compose.hpp"
23 #include "lib/image.h"
24 #include "lib/timer.h"
25
26
27 using boost::shared_ptr;
28
29
30 #define ITERATIONS 500
31
32
33 static
34 shared_ptr<Image>
35 dummy_image(dcp::Size size, AVPixelFormat pixel)
36 {
37         shared_ptr<Image> image(new Image(pixel, size, true));
38         int v = 0;
39         for (int y = 0; y < size.height; ++y) {
40                 for (int c = 0; c < image->planes(); ++c) {
41                         uint8_t* p = image->data()[c] + y * image->stride()[c];
42                         int const line_size = image->line_size()[c];
43                         for (int x = 0; x < line_size; ++x) {
44                                 *p++ = v++ % 256;
45                         }
46                 }
47         }
48
49         return image;
50 }
51
52
53 static
54 void
55 test (dcp::Size from_size, AVPixelFormat from_pixel, dcp::Size to, bool fast)
56 {
57         shared_ptr<Image> image = dummy_image(from_size, from_pixel);
58         PeriodTimer pt (String::compose("%1:%2 -> %3:%4 %5 %6", from_size.width, from_size.height, to.width, to.height, static_cast<int>(from_pixel), fast ? "fast" : "slow"));
59         for (int i = 0; i < ITERATIONS; ++i) {
60                 image->scale (to, dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB48, true, fast);
61         }
62 }
63
64
65 int
66 main ()
67 {
68         test (dcp::Size(1998, 1080), AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), true);
69         test (dcp::Size(1998, 1080), AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), false);
70
71         test (dcp::Size(1998, 1080), AV_PIX_FMT_RGB24, dcp::Size(2006, 1088), true);
72         test (dcp::Size(1998, 1080), AV_PIX_FMT_RGB24, dcp::Size(2006, 1088), false);
73
74         test (dcp::Size(996, 540), AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), true);
75         test (dcp::Size(996, 540), AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), false);
76
77         test (dcp::Size(498, 270), AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), true);
78         test (dcp::Size(498, 270), AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), false);
79
80         test (dcp::Size(1998, 1080), AV_PIX_FMT_RGB24, dcp::Size(1720, 930), true);
81         test (dcp::Size(1998, 1080), AV_PIX_FMT_RGB24, dcp::Size(1720, 930), false);
82
83         test (dcp::Size(1998, 1080), AV_PIX_FMT_XYZ12LE, dcp::Size(1998, 1080), true);
84         test (dcp::Size(1998, 1080), AV_PIX_FMT_XYZ12LE, dcp::Size(1998, 1080), false);
85
86         test (dcp::Size(1998, 1080), AV_PIX_FMT_XYZ12LE, dcp::Size(2006, 1088), true);
87         test (dcp::Size(1998, 1080), AV_PIX_FMT_XYZ12LE, dcp::Size(2006, 1088), false);
88
89         test (dcp::Size(996, 540), AV_PIX_FMT_XYZ12LE, dcp::Size(1998, 1080), true);
90         test (dcp::Size(996, 540), AV_PIX_FMT_XYZ12LE, dcp::Size(1998, 1080), false);
91
92         test (dcp::Size(498, 270), AV_PIX_FMT_XYZ12LE, dcp::Size(1998, 1080), true);
93         test (dcp::Size(498, 270), AV_PIX_FMT_XYZ12LE, dcp::Size(1998, 1080), false);
94
95         test (dcp::Size(1998, 1080), AV_PIX_FMT_XYZ12LE, dcp::Size(1720, 930), true);
96         test (dcp::Size(1998, 1080), AV_PIX_FMT_XYZ12LE, dcp::Size(1720, 930), false);
97
98         return 0;
99 }
100