Various comment fixes to tests.
[dcpomatic.git] / test / pixel_formats_test.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/pixel_formats_test.cc
21  *  @brief Make sure that Image::lines() and Image::bytes_per_pixel() return the right
22  *  things for various pixel formats.
23  *
24  *  @see test/image_test.cc
25  */
26
27 #include <boost/test/unit_test.hpp>
28 #include <list>
29 extern "C" {
30 #include <libavutil/pixfmt.h>
31 #include <libavcodec/avcodec.h>
32 }
33 #include "lib/image.h"
34
35 using std::list;
36 using std::cout;
37
38 struct Case
39 {
40         Case (AVPixelFormat f, int c, int l0, int l1, int l2, float b0, float b1, float b2)
41                 : format(f)
42                 , components(c)
43         {
44                 lines[0] = l0;
45                 lines[1] = l1;
46                 lines[2] = l2;
47                 bpp[0] = b0;
48                 bpp[1] = b1;
49                 bpp[2] = b2;
50         }
51         
52         AVPixelFormat format;
53         int components;
54         int lines[3];
55         float bpp[3];
56 };
57
58
59 BOOST_AUTO_TEST_CASE (pixel_formats_test)
60 {
61         list<Case> cases;
62         cases.push_back(Case(AV_PIX_FMT_RGB24,       1, 480, 480, 480, 3, 0,   0  ));
63         cases.push_back(Case(AV_PIX_FMT_RGBA,        1, 480, 480, 480, 4, 0,   0  ));
64         cases.push_back(Case(AV_PIX_FMT_YUV420P,     3, 480, 240, 240, 1, 0.5, 0.5));
65         cases.push_back(Case(AV_PIX_FMT_YUV422P,     3, 480, 480, 480, 1, 0.5, 0.5));
66         cases.push_back(Case(AV_PIX_FMT_YUV422P10LE, 3, 480, 480, 480, 2, 1,   1  ));
67         cases.push_back(Case(AV_PIX_FMT_YUV422P16LE, 3, 480, 480, 480, 2, 1,   1  ));
68         cases.push_back(Case(AV_PIX_FMT_UYVY422,     1, 480, 480, 480, 2, 0,   0  ));
69         cases.push_back(Case(AV_PIX_FMT_YUV444P,     3, 480, 480, 480, 1, 1,   1  ));
70         cases.push_back(Case(AV_PIX_FMT_YUV444P9BE,  3, 480, 480, 480, 2, 2,   2  ));
71         cases.push_back(Case(AV_PIX_FMT_YUV444P9LE,  3, 480, 480, 480, 2, 2,   2  ));
72         cases.push_back(Case(AV_PIX_FMT_YUV444P10BE, 3, 480, 480, 480, 2, 2,   2  ));
73         cases.push_back(Case(AV_PIX_FMT_YUV444P10LE, 3, 480, 480, 480, 2, 2,   2  ));
74
75         for (list<Case>::iterator i = cases.begin(); i != cases.end(); ++i) {
76                 AVFrame* f = av_frame_alloc ();
77                 f->width = 640;
78                 f->height = 480;
79                 f->format = static_cast<int> (i->format);
80                 av_frame_get_buffer (f, true);
81                 Image t (f);
82                 BOOST_CHECK_EQUAL(t.components(), i->components);
83                 BOOST_CHECK_EQUAL(t.lines(0), i->lines[0]);
84                 BOOST_CHECK_EQUAL(t.lines(1), i->lines[1]);
85                 BOOST_CHECK_EQUAL(t.lines(2), i->lines[2]);
86                 BOOST_CHECK_EQUAL(t.bytes_per_pixel(0), i->bpp[0]);
87                 BOOST_CHECK_EQUAL(t.bytes_per_pixel(1), i->bpp[1]);
88                 BOOST_CHECK_EQUAL(t.bytes_per_pixel(2), i->bpp[2]);
89         }
90 }