X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=test%2Fpixel_formats_test.cc;h=12a95bd6939b11d751edc6dd8c4e565a0f05d3bf;hp=68d225e6efa36dc6b69a5b30f8319b7e6da74eaa;hb=6d686ea45f5cd01a0d11f92a903ac77779ad8562;hpb=8c7a308c03e4b4196b4e2379a26d432b100ae2b1 diff --git a/test/pixel_formats_test.cc b/test/pixel_formats_test.cc index 68d225e6e..12a95bd69 100644 --- a/test/pixel_formats_test.cc +++ b/test/pixel_formats_test.cc @@ -1,29 +1,32 @@ /* - Copyright (C) 2013-2014 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington - This program is free software; you can redistribute it and/or modify + 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. - This program is distributed in the hope that it will be useful, + 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ + /** @file src/pixel_formats_test.cc - * @brief Make sure that Image::lines() and Image::bytes_per_pixel() return the right + * @brief Make sure that Image::sample_size() and Image::bytes_per_pixel() return the right * things for various pixel formats. - * + * @ingroup selfcontained * @see test/image_test.cc */ + #include #include extern "C" { @@ -31,10 +34,13 @@ extern "C" { #include } #include "lib/image.h" +#include + using std::list; using std::cout; + /** @struct Case * @brief A test case for pixel_formats_test. */ @@ -42,7 +48,7 @@ struct Case { Case (AVPixelFormat f, int c, int l0, int l1, int l2, float b0, float b1, float b2) : format(f) - , components(c) + , planes(c) { lines[0] = l0; lines[1] = l1; @@ -51,9 +57,9 @@ struct Case bpp[1] = b1; bpp[2] = b2; } - + AVPixelFormat format; - int components; + int planes; int lines[3]; float bpp[3]; }; @@ -61,33 +67,34 @@ struct Case BOOST_AUTO_TEST_CASE (pixel_formats_test) { - list cases; - cases.push_back(Case(AV_PIX_FMT_RGB24, 1, 480, 480, 480, 3, 0, 0 )); - cases.push_back(Case(AV_PIX_FMT_RGBA, 1, 480, 480, 480, 4, 0, 0 )); - cases.push_back(Case(AV_PIX_FMT_YUV420P, 3, 480, 240, 240, 1, 0.5, 0.5)); - cases.push_back(Case(AV_PIX_FMT_YUV422P, 3, 480, 480, 480, 1, 0.5, 0.5)); - cases.push_back(Case(AV_PIX_FMT_YUV422P10LE, 3, 480, 480, 480, 2, 1, 1 )); - cases.push_back(Case(AV_PIX_FMT_YUV422P16LE, 3, 480, 480, 480, 2, 1, 1 )); - cases.push_back(Case(AV_PIX_FMT_UYVY422, 1, 480, 480, 480, 2, 0, 0 )); - cases.push_back(Case(AV_PIX_FMT_YUV444P, 3, 480, 480, 480, 1, 1, 1 )); - cases.push_back(Case(AV_PIX_FMT_YUV444P9BE, 3, 480, 480, 480, 2, 2, 2 )); - cases.push_back(Case(AV_PIX_FMT_YUV444P9LE, 3, 480, 480, 480, 2, 2, 2 )); - cases.push_back(Case(AV_PIX_FMT_YUV444P10BE, 3, 480, 480, 480, 2, 2, 2 )); - cases.push_back(Case(AV_PIX_FMT_YUV444P10LE, 3, 480, 480, 480, 2, 2, 2 )); - - for (list::iterator i = cases.begin(); i != cases.end(); ++i) { - AVFrame* f = av_frame_alloc (); + list cases = { + { AV_PIX_FMT_RGB24, 1, 480, 480, 480, 3, 0, 0 }, + { AV_PIX_FMT_RGBA, 1, 480, 480, 480, 4, 0, 0 }, + { AV_PIX_FMT_YUV420P, 3, 480, 240, 240, 1, 0.5, 0.5}, + { AV_PIX_FMT_YUV422P, 3, 480, 480, 480, 1, 0.5, 0.5}, + { AV_PIX_FMT_YUV422P10LE, 3, 480, 480, 480, 2, 1, 1 }, + { AV_PIX_FMT_YUV422P16LE, 3, 480, 480, 480, 2, 1, 1 }, + { AV_PIX_FMT_UYVY422, 1, 480, 480, 480, 2, 0, 0 }, + { AV_PIX_FMT_YUV444P, 3, 480, 480, 480, 1, 1, 1 }, + { AV_PIX_FMT_YUV444P9BE, 3, 480, 480, 480, 2, 2, 2 }, + { AV_PIX_FMT_YUV444P9LE, 3, 480, 480, 480, 2, 2, 2 }, + { AV_PIX_FMT_YUV444P10BE, 3, 480, 480, 480, 2, 2, 2 }, + { AV_PIX_FMT_YUV444P10LE, 3, 480, 480, 480, 2, 2, 2 } + }; + + for (auto const& i: cases) { + auto f = av_frame_alloc (); f->width = 640; f->height = 480; - f->format = static_cast (i->format); + f->format = static_cast (i.format); av_frame_get_buffer (f, true); - Image t (f); - BOOST_CHECK_EQUAL(t.components(), i->components); - BOOST_CHECK_EQUAL(t.lines(0), i->lines[0]); - BOOST_CHECK_EQUAL(t.lines(1), i->lines[1]); - BOOST_CHECK_EQUAL(t.lines(2), i->lines[2]); - BOOST_CHECK_EQUAL(t.bytes_per_pixel(0), i->bpp[0]); - BOOST_CHECK_EQUAL(t.bytes_per_pixel(1), i->bpp[1]); - BOOST_CHECK_EQUAL(t.bytes_per_pixel(2), i->bpp[2]); + Image t (f, Image::Alignment::COMPACT); + BOOST_CHECK_EQUAL(t.planes(), i.planes); + BOOST_CHECK_EQUAL(t.sample_size(0).height, i.lines[0]); + BOOST_CHECK_EQUAL(t.sample_size(1).height, i.lines[1]); + BOOST_CHECK_EQUAL(t.sample_size(2).height, i.lines[2]); + BOOST_CHECK_EQUAL(t.bytes_per_pixel(0), i.bpp[0]); + BOOST_CHECK_EQUAL(t.bytes_per_pixel(1), i.bpp[1]); + BOOST_CHECK_EQUAL(t.bytes_per_pixel(2), i.bpp[2]); } }