#include "src/colour_parser.h"
#include "gtest/gtest.h"
#include "test_utils/element_parser_test.h"
#include "webm/id.h"
using webm::Colour;
using webm::ColourParser;
using webm::ElementParserTest;
using webm::Id;
using webm::MasteringMetadata;
using webm::MatrixCoefficients;
using webm::Primaries;
using webm::Range;
using webm::TransferCharacteristics;
namespace {
class ColourParserTest : public ElementParserTest<ColourParser, Id::kColour> {};
TEST_F(ColourParserTest, DefaultParse) {
ParseAndVerify();
const Colour colour = parser_.value();
EXPECT_FALSE(colour.matrix_coefficients.is_present());
EXPECT_EQ(MatrixCoefficients::kUnspecified,
colour.matrix_coefficients.value());
EXPECT_FALSE(colour.bits_per_channel.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.bits_per_channel.value());
EXPECT_FALSE(colour.chroma_subsampling_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_x.value());
EXPECT_FALSE(colour.chroma_subsampling_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_y.value());
EXPECT_FALSE(colour.cb_subsampling_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_x.value());
EXPECT_FALSE(colour.cb_subsampling_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_y.value());
EXPECT_FALSE(colour.chroma_siting_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_x.value());
EXPECT_FALSE(colour.chroma_siting_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_y.value());
EXPECT_FALSE(colour.range.is_present());
EXPECT_EQ(Range::kUnspecified, colour.range.value());
EXPECT_FALSE(colour.transfer_characteristics.is_present());
EXPECT_EQ(TransferCharacteristics::kUnspecified,
colour.transfer_characteristics.value());
EXPECT_FALSE(colour.primaries.is_present());
EXPECT_EQ(Primaries::kUnspecified, colour.primaries.value());
EXPECT_FALSE(colour.max_cll.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_cll.value());
EXPECT_FALSE(colour.max_fall.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_fall.value());
EXPECT_FALSE(colour.mastering_metadata.is_present());
EXPECT_EQ(MasteringMetadata{}, colour.mastering_metadata.value());
}
TEST_F(ColourParserTest, DefaultValues) {
SetReaderData({
0x55, 0xB1, 0x80,
0x55, 0xB2, 0x80,
0x55, 0xB3, 0x80,
0x55, 0xB4, 0x80,
0x55, 0xB5, 0x80,
0x55, 0xB6, 0x80,
0x55, 0xB7, 0x80,
0x55, 0xB8, 0x80,
0x55, 0xB9, 0x80,
0x55, 0xBA, 0x80,
0x55, 0xBB, 0x80,
0x55, 0xBC, 0x80,
0x55, 0xBD, 0x80,
0x55, 0xD0, 0x80, });
ParseAndVerify();
const Colour colour = parser_.value();
EXPECT_TRUE(colour.matrix_coefficients.is_present());
EXPECT_EQ(MatrixCoefficients::kUnspecified,
colour.matrix_coefficients.value());
EXPECT_TRUE(colour.bits_per_channel.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.bits_per_channel.value());
EXPECT_TRUE(colour.chroma_subsampling_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_x.value());
EXPECT_TRUE(colour.chroma_subsampling_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_y.value());
EXPECT_TRUE(colour.cb_subsampling_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_x.value());
EXPECT_TRUE(colour.cb_subsampling_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_y.value());
EXPECT_TRUE(colour.chroma_siting_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_x.value());
EXPECT_TRUE(colour.chroma_siting_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_y.value());
EXPECT_TRUE(colour.range.is_present());
EXPECT_EQ(Range::kUnspecified, colour.range.value());
EXPECT_TRUE(colour.transfer_characteristics.is_present());
EXPECT_EQ(TransferCharacteristics::kUnspecified,
colour.transfer_characteristics.value());
EXPECT_TRUE(colour.primaries.is_present());
EXPECT_EQ(Primaries::kUnspecified, colour.primaries.value());
EXPECT_TRUE(colour.max_cll.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_cll.value());
EXPECT_TRUE(colour.max_fall.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_fall.value());
EXPECT_TRUE(colour.mastering_metadata.is_present());
EXPECT_EQ(MasteringMetadata{}, colour.mastering_metadata.value());
}
TEST_F(ColourParserTest, CustomValues) {
SetReaderData({
0x55, 0xB1, 0x81, 0x01,
0x55, 0xB2, 0x81, 0x02,
0x55, 0xB3, 0x81, 0x03,
0x55, 0xB4, 0x81, 0x04,
0x55, 0xB5, 0x81, 0x05,
0x55, 0xB6, 0x81, 0x06,
0x55, 0xB7, 0x81, 0x01,
0x55, 0xB8, 0x81, 0x02,
0x55, 0xB9, 0x81, 0x03,
0x55, 0xBA, 0x81, 0x04,
0x55, 0xBB, 0x81, 0x05,
0x55, 0xBC, 0x81, 0x06,
0x55, 0xBD, 0x81, 0x07,
0x55, 0xD0, 0x87,
0x55, 0xD1, 0x84, 0x3F, 0x80, 0x00, 0x00, });
ParseAndVerify();
const Colour colour = parser_.value();
EXPECT_TRUE(colour.matrix_coefficients.is_present());
EXPECT_EQ(MatrixCoefficients::kBt709, colour.matrix_coefficients.value());
EXPECT_TRUE(colour.bits_per_channel.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(2), colour.bits_per_channel.value());
EXPECT_TRUE(colour.chroma_subsampling_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(3), colour.chroma_subsampling_x.value());
EXPECT_TRUE(colour.chroma_subsampling_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(4), colour.chroma_subsampling_y.value());
EXPECT_TRUE(colour.cb_subsampling_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(5), colour.cb_subsampling_x.value());
EXPECT_TRUE(colour.cb_subsampling_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(6), colour.cb_subsampling_y.value());
EXPECT_TRUE(colour.chroma_siting_x.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(1), colour.chroma_siting_x.value());
EXPECT_TRUE(colour.chroma_siting_y.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(2), colour.chroma_siting_y.value());
EXPECT_TRUE(colour.range.is_present());
EXPECT_EQ(Range::kDerived, colour.range.value());
EXPECT_TRUE(colour.transfer_characteristics.is_present());
EXPECT_EQ(TransferCharacteristics::kGamma22curve,
colour.transfer_characteristics.value());
EXPECT_TRUE(colour.primaries.is_present());
EXPECT_EQ(Primaries::kBt470Bg, colour.primaries.value());
EXPECT_TRUE(colour.max_cll.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(6), colour.max_cll.value());
EXPECT_TRUE(colour.max_fall.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(7), colour.max_fall.value());
MasteringMetadata mastering_metadata{};
mastering_metadata.primary_r_chromaticity_x.Set(1.0, true);
EXPECT_TRUE(colour.mastering_metadata.is_present());
EXPECT_EQ(mastering_metadata, colour.mastering_metadata.value());
}
}