diff options
author | U. Artie Eoff <ullysses.a.eoff@intel.com> | 2016-09-28 13:36:10 -0700 |
---|---|---|
committer | Sean V Kelley <seanvk@posteo.de> | 2016-10-03 11:31:18 -0700 |
commit | 2d0bb8fbdc15c0323fdbee2dfb5f10e7226fcb1b (patch) | |
tree | edbc33a2f193679ec64fcd2bb1b6dab5642ec33b | |
parent | 9dd60d7fc73e35207d629519102afdc4f6ff668d (diff) |
test: jpeg/enc: add tests for YUY2 and UYVY inputs
...plus optimize TestInput::toOutputFourcc()
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Reviewed-by: Sean V Kelley <seanvk@posteo.de>
-rw-r--r-- | test/i965_jpeg_encode_test.cpp | 18 | ||||
-rw-r--r-- | test/i965_jpeg_test_data.cpp | 97 | ||||
-rw-r--r-- | test/i965_jpeg_test_data.h | 8 |
3 files changed, 104 insertions, 19 deletions
diff --git a/test/i965_jpeg_encode_test.cpp b/test/i965_jpeg_encode_test.cpp index b454484..789d4f3 100644 --- a/test/i965_jpeg_encode_test.cpp +++ b/test/i965_jpeg_encode_test.cpp @@ -278,7 +278,7 @@ protected: ASSERT_INVALID_ID(coded); unsigned size = std::accumulate(input->sizes.begin(), input->sizes.end(), 8192u); - size *= input->planes; + size *= 2; coded = createBuffer(context, VAEncCodedBufferType, size); } @@ -349,8 +349,6 @@ protected: void VerifyOutput() { - // VerifyOutput only supports VA_FOURCC_IMC3 output, currently - ASSERT_EQ(unsigned(VA_FOURCC_IMC3), input->fourcc_output); TestInput::SharedConst expect = input->toOutputFourcc(); ASSERT_PTR(expect.get()); @@ -414,6 +412,10 @@ protected: VAImage image; ASSERT_NO_FAILURE(deriveImage(osurfaces.front(), image)); + ASSERT_EQ(expect->planes, image.num_planes); + ASSERT_GT(image.data_size, 0u); + ASSERT_EQ(expect->width(), image.width); + ASSERT_EQ(expect->height(), image.height); ASSERT_NO_FAILURE(uint8_t *data = mapBuffer<uint8_t>(image.buf)); auto isClose = [](const uint8_t& a, const uint8_t& b) { @@ -479,7 +481,7 @@ INSTANTIATE_TEST_CASE_P( ::testing::ValuesIn( std::vector<TestInputCreator::SharedConst>( 5, TestInputCreator::SharedConst(new RandomSizeCreator))), - ::testing::Values("I420", "NV12") + ::testing::Values("I420", "NV12", "UYVY", "YUY2") ) ); @@ -513,7 +515,7 @@ INSTANTIATE_TEST_CASE_P( Common, JPEGEncodeInputTest, ::testing::Combine( ::testing::ValuesIn(generateCommonInputs()), - ::testing::Values("I420", "NV12") + ::testing::Values("I420", "NV12", "UYVY", "YUY2") ) ); @@ -523,7 +525,7 @@ INSTANTIATE_TEST_CASE_P( ::testing::Values( TestInputCreator::Shared(new FixedSizeCreator({8192, 8192})) ), - ::testing::Values("I420", "NV12") + ::testing::Values("I420", "NV12", "UYVY", "YUY2") ) ); @@ -560,7 +562,7 @@ INSTANTIATE_TEST_CASE_P( Edge, JPEGEncodeInputTest, ::testing::Combine( ::testing::ValuesIn(generateEdgeCaseInputs()), - ::testing::Values("I420", "NV12") + ::testing::Values("I420", "NV12", "UYVY", "YUY2") ) ); @@ -578,7 +580,7 @@ INSTANTIATE_TEST_CASE_P( Misc, JPEGEncodeInputTest, ::testing::Combine( ::testing::ValuesIn(generateMiscInputs()), - ::testing::Values("I420", "NV12") + ::testing::Values("I420", "NV12", "UYVY", "YUY2") ) ); diff --git a/test/i965_jpeg_test_data.cpp b/test/i965_jpeg_test_data.cpp index da7d440..6ca2d27 100644 --- a/test/i965_jpeg_test_data.cpp +++ b/test/i965_jpeg_test_data.cpp @@ -794,6 +794,21 @@ namespace Encode { t->format = VA_RT_FORMAT_YUV420; t->fourcc_output = VA_FOURCC_IMC3; break; + case VA_FOURCC_UYVY: + case VA_FOURCC_YUY2: + t->planes = 1; + t->widths = {(w + (w & 1)) << 1, 0, 0}; + t->heights = {h + (h & 1), 0, 0}; + t->format = VA_RT_FORMAT_YUV422; + t->fourcc_output = VA_FOURCC_422H; + break; + case VA_FOURCC_422H: + t->planes = 3; + t->widths = {w + (w & 1), (w + 1) >> 1, (w + 1) >> 1}; + t->heights = {h + (h & 1), h + (h & 1), h + (h & 1)}; + t->format = VA_RT_FORMAT_YUV422; + t->fourcc_output = VA_FOURCC_422H; + break; default: return Shared(); // fourcc is unsupported } @@ -849,28 +864,88 @@ namespace Encode { return bytes.data() + offsets[i]; } + uint8_t* TestInput::begin(const size_t i) + { + return bytes.data() + offsets[i]; + } + + const uint8_t* TestInput::begin(const size_t i) const + { + return bytes.data() + offsets[i]; + } + + uint8_t* TestInput::end(const size_t i) + { + return begin(i) + sizes[i]; + } + + const uint8_t* TestInput::end(const size_t i) const + { + return begin(i) + sizes[i]; + } + const TestInput::SharedConst TestInput::toOutputFourcc() const { TestInput::Shared result; + + struct IsEvenIndex + { + IsEvenIndex():i(0){} + inline const bool operator()(const uint8_t&) + { + const bool r = (i % 2) != 1; + ++i; + return r; + } + size_t i; + }; + + struct IsOddIndex + { + IsOddIndex():i(0){} + inline const bool operator()(const uint8_t&) + { + const bool r = (i % 2) == 1; + ++i; + return r; + } + size_t i; + }; + if (fourcc_output == VA_FOURCC_IMC3) { if (fourcc == VA_FOURCC_I420) { return shared_from_this(); } else if (fourcc == VA_FOURCC_NV12) { result = create(VA_FOURCC_I420, width(), height()); - std::copy( - std::begin(bytes), std::end(bytes), - std::begin(result->bytes)); - size_t i(0); - auto predicate = [&i](const ByteData::value_type&) { - bool isu = ((i % 2) == 0) or (i == 0); - ++i; - return isu; - }; + // copy Y to plane 0 + std::copy(begin(0), end(0), result->begin(0)); + // copy U to plane 1 + std::copy_if(begin(1), end(1), result->begin(1), IsEvenIndex()); + // copy V to plane 2 + std::copy_if(begin(1), end(1), result->begin(2), IsOddIndex()); + } + } else if (fourcc_output == VA_FOURCC_422H) { + if (fourcc == VA_FOURCC_UYVY) { + result = create(VA_FOURCC_422H, width(), height()); + // copy Y to plane 0 + std::copy_if(begin(0), end(0), result->begin(0), IsOddIndex()); + // copy UV across plane 1 and 2 + std::copy_if(begin(0), end(0), result->begin(1), IsEvenIndex()); + // partition U into plane 1 and V into plane 2 + std::stable_partition( + result->begin(1), result->end(2), IsEvenIndex()); + } else if (fourcc == VA_FOURCC_YUY2) { + result = create(VA_FOURCC_422H, width(), height()); + // copy Y to plane 0 + std::copy_if(begin(0), end(0), result->begin(0), IsEvenIndex()); + // copy UV across plane 1 and 2 + std::copy_if(begin(0), end(0), result->begin(1), IsOddIndex()); + // partition U into plane 1 and V into plane 2 std::stable_partition( - std::begin(result->bytes) + result->offsets[1], - std::end(result->bytes), predicate); + result->begin(1), result->end(2), IsEvenIndex()); } } + return result; } diff --git a/test/i965_jpeg_test_data.h b/test/i965_jpeg_test_data.h index f29e579..f3113f5 100644 --- a/test/i965_jpeg_test_data.h +++ b/test/i965_jpeg_test_data.h @@ -425,6 +425,14 @@ namespace Encode { private: TestInput(); + + /** get pointer to beginning of plane @param i **/ + uint8_t* begin(const size_t i); + const uint8_t* begin(const size_t i) const; + + /** get pointer to end of plane @param i **/ + uint8_t* end(const size_t i); + const uint8_t* end(const size_t i) const; }; class TestInputCreator |