Missed update to private test repo version.
[dcpomatic.git] / test / pixel_formats_test.cc
1 /*
2     Copyright (C) 2013-2021 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 /** @file  src/pixel_formats_test.cc
23  *  @brief Make sure that Image::sample_size() and Image::bytes_per_pixel() return the right
24  *  things for various pixel formats.
25  *  @ingroup selfcontained
26  *  @see test/image_test.cc
27  */
28
29
30 #include <boost/test/unit_test.hpp>
31 #include <list>
32 extern "C" {
33 #include <libavutil/pixfmt.h>
34 #include <libavcodec/avcodec.h>
35 }
36 #include "lib/image.h"
37 #include <iostream>
38
39
40 using std::list;
41 using std::cout;
42
43
44 /** @struct Case
45  *  @brief  A test case for pixel_formats_test.
46  */
47 struct Case
48 {
49         Case (AVPixelFormat f, int c, int l0, int l1, int l2, float b0, float b1, float b2)
50                 : format(f)
51                 , planes(c)
52         {
53                 lines[0] = l0;
54                 lines[1] = l1;
55                 lines[2] = l2;
56                 bpp[0] = b0;
57                 bpp[1] = b1;
58                 bpp[2] = b2;
59         }
60
61         AVPixelFormat format;
62         int planes;
63         int lines[3];
64         float bpp[3];
65 };
66
67
68 BOOST_AUTO_TEST_CASE (pixel_formats_test)
69 {
70         list<Case> cases = {
71                 { AV_PIX_FMT_RGB24,       1, 480, 480, 480, 3, 0,   0  },
72                 { AV_PIX_FMT_RGBA,        1, 480, 480, 480, 4, 0,   0  },
73                 { AV_PIX_FMT_YUV420P,     3, 480, 240, 240, 1, 0.5, 0.5},
74                 { AV_PIX_FMT_YUV422P,     3, 480, 480, 480, 1, 0.5, 0.5},
75                 { AV_PIX_FMT_YUV422P10LE, 3, 480, 480, 480, 2, 1,   1  },
76                 { AV_PIX_FMT_YUV422P16LE, 3, 480, 480, 480, 2, 1,   1  },
77                 { AV_PIX_FMT_UYVY422,     1, 480, 480, 480, 2, 0,   0  },
78                 { AV_PIX_FMT_YUV444P,     3, 480, 480, 480, 1, 1,   1  },
79                 { AV_PIX_FMT_YUV444P9BE,  3, 480, 480, 480, 2, 2,   2  },
80                 { AV_PIX_FMT_YUV444P9LE,  3, 480, 480, 480, 2, 2,   2  },
81                 { AV_PIX_FMT_YUV444P10BE, 3, 480, 480, 480, 2, 2,   2  },
82                 { AV_PIX_FMT_YUV444P10LE, 3, 480, 480, 480, 2, 2,   2  }
83         };
84
85         for (auto const& i: cases) {
86                 auto f = av_frame_alloc ();
87                 f->width = 640;
88                 f->height = 480;
89                 f->format = static_cast<int> (i.format);
90                 av_frame_get_buffer (f, true);
91                 Image t (f, Image::Alignment::COMPACT);
92                 BOOST_CHECK_EQUAL(t.planes(), i.planes);
93                 BOOST_CHECK_EQUAL(t.sample_size(0).height, i.lines[0]);
94                 BOOST_CHECK_EQUAL(t.sample_size(1).height, i.lines[1]);
95                 BOOST_CHECK_EQUAL(t.sample_size(2).height, i.lines[2]);
96                 BOOST_CHECK_EQUAL(t.bytes_per_pixel(0), i.bpp[0]);
97                 BOOST_CHECK_EQUAL(t.bytes_per_pixel(1), i.bpp[1]);
98                 BOOST_CHECK_EQUAL(t.bytes_per_pixel(2), i.bpp[2]);
99         }
100 }