2 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "i965_test_fixture.h"
26 #include "i965_jpeg_test_data.h"
39 class JPEGDecodeTest : public I965TestFixture { };
41 TEST_F(JPEGDecodeTest, Entrypoint)
43 VAConfigID config = VA_INVALID_ID;
44 ConfigAttribs attributes;
45 struct i965_driver_data *i965(*this);
49 if (HAS_JPEG_DECODING(i965)) {
50 config = createConfig(profile, entrypoint, attributes);
52 VAStatus status = i965_CreateConfig(
53 *this, profile, entrypoint, attributes.data(), attributes.size(),
55 EXPECT_STATUS_EQ(VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT, status);
56 EXPECT_INVALID_ID(config);
59 if (config != VA_INVALID_ID)
60 destroyConfig(config);
64 : public JPEGDecodeTest
65 , public ::testing::WithParamInterface<
66 std::tuple<TestPattern::SharedConst, const char*> >
71 JPEGDecodeTest::SetUp();
74 std::tie(testPattern, sFourcc) = GetParam();
76 ASSERT_PTR(testPattern.get()) << "Invalid test pattern parameter";
78 ASSERT_EQ(4u, sFourcc.size())
79 << "Invalid fourcc parameter '" << sFourcc << "'";
81 unsigned fourcc = VA_FOURCC(
82 sFourcc[0], sFourcc[1], sFourcc[2], sFourcc[3]);
84 pd = testPattern->encoded(fourcc);
87 << "Unhandled fourcc parameter '" << sFourcc << "'"
88 << " = 0x" << std::hex << fourcc << std::dec;
90 ASSERT_EQ(fourcc, pd->fourcc);
93 void validateComponent(const uint8_t * const expect, const uint8_t * actual,
94 unsigned width, unsigned height, unsigned pitch, unsigned hsample = 1,
97 for (size_t row(0); row < (height / vsample); ++row) {
98 for (size_t col(0); col < (width / hsample); ++col) {
99 size_t aIdx = (row * pitch) + col;
100 size_t eIdx = (row * vsample * height) + (col * hsample);
102 std::vector<uint8_t> samples;
103 for (size_t i(0); i < vsample; ++i) {
104 for (size_t j(0); j < hsample; ++j) {
105 size_t sIdx = eIdx + (width * i) + j;
106 samples.push_back(expect[sIdx]);
111 std::accumulate(samples.begin(), samples.end(), 0x00)
114 const uint8_t aVal = actual[aIdx];
117 ::testing::Message() << std::endl
118 << "\tRow = " << row << std::endl
119 << "\tColumn = " << col << std::endl
121 << std::hex << std::setfill('0') << std::setw(2)
122 << (uint32_t)eVal << std::endl
124 << std::hex << std::setfill('0') << std::setw(2)
125 << (uint32_t)aVal << std::dec);
127 EXPECT_NEAR(eVal, aVal, 0x02);
132 void validateImageOutput(const VAImage& image, const uint8_t * const output)
135 SCOPED_TRACE("Y Component\n");
137 testPattern->decoded().data(), output + image.offsets[0],
138 image.width, image.height, image.pitches[0]);
142 SCOPED_TRACE("U Component\n");
144 testPattern->decoded().data() + (image.width * image.height),
145 output + image.offsets[1], image.width, image.height,
146 image.pitches[1], pd->pparam.components[0].h_sampling_factor,
147 pd->pparam.components[0].v_sampling_factor);
151 SCOPED_TRACE("V Component\n");
153 testPattern->decoded().data() + (image.width * image.height * 2),
154 output + image.offsets[2], image.width, image.height,
155 image.pitches[2], pd->pparam.components[0].h_sampling_factor,
156 pd->pparam.components[0].v_sampling_factor);
160 void printComponentDataTo(std::ostream& os, const uint8_t * const data,
161 unsigned w, unsigned h, unsigned pitch, unsigned hsample = 1,
162 unsigned vsample = 1)
164 const uint8_t *row = data;
165 for (unsigned i(0); i < (h/vsample); ++i) {
166 for (size_t j(0); j < (w/hsample); ++j) {
167 os << "0x" << std::hex << std::setfill('0') << std::setw(2)
168 << (uint32_t)row[j] << ",";
173 os << std::setw(0) << std::setfill(' ') << std::dec << std::endl;
176 void printImageOutputTo(std::ostream& os, const VAImage& image,
177 const uint8_t * const output)
179 printComponentDataTo(os, output + image.offsets[0], image.width,
180 image.height, image.pitches[0]); // Y
182 printComponentDataTo(os, output + image.offsets[1], image.width,
183 image.height, image.pitches[1],
184 pd->pparam.components[0].h_sampling_factor,
185 pd->pparam.components[0].v_sampling_factor); // U
187 printComponentDataTo(os, output + image.offsets[2], image.width,
188 image.height, image.pitches[2],
189 pd->pparam.components[0].h_sampling_factor,
190 pd->pparam.components[0].v_sampling_factor); // V
193 TestPattern::SharedConst testPattern;
194 PictureData::SharedConst pd;
197 TEST_P(FourCCTest, Decode)
199 struct i965_driver_data *i965(*this);
201 if (not HAS_JPEG_DECODING(i965)) {
202 RecordProperty("skipped", true);
203 std::cout << "[ SKIPPED ] " << getFullTestName()
204 << " is unsupported on this hardware" << std::endl;
208 VAConfigAttrib a = { type:VAConfigAttribRTFormat, value:pd->format };
209 ConfigAttribs attribs(1, a);
212 Surfaces surfaces = createSurfaces(
213 pd->pparam.picture_width, pd->pparam.picture_height, pd->format));
215 VAConfigID config = createConfig(profile, entrypoint, attribs));
217 VAContextID context = createContext(
218 config, pd->pparam.picture_width, pd->pparam.picture_height, 0,
221 VABufferID sliceDataBufId = createBuffer(
222 context, VASliceDataBufferType, pd->sparam.slice_data_size, 1,
225 VABufferID sliceParamBufId = createBuffer(
226 context, VASliceParameterBufferType, sizeof(pd->sparam), 1,
229 VABufferID picBufId = createBuffer(
230 context, VAPictureParameterBufferType, sizeof(pd->pparam), 1,
233 VABufferID iqMatrixBufId = createBuffer(
234 context, VAIQMatrixBufferType, sizeof(IQMatrix), 1, &pd->iqmatrix));
236 VABufferID huffTableBufId = createBuffer(
237 context, VAHuffmanTableBufferType, sizeof(HuffmanTable), 1,
240 ASSERT_NO_FAILURE(beginPicture(context, surfaces.front()));
241 ASSERT_NO_FAILURE(renderPicture(context, &picBufId));
242 ASSERT_NO_FAILURE(renderPicture(context, &iqMatrixBufId));
243 ASSERT_NO_FAILURE(renderPicture(context, &huffTableBufId));
244 ASSERT_NO_FAILURE(renderPicture(context, &sliceParamBufId));
245 ASSERT_NO_FAILURE(renderPicture(context, &sliceDataBufId));
246 ASSERT_NO_FAILURE(endPicture(context));
249 ASSERT_NO_FAILURE(deriveImage(surfaces.front(), image));
251 uint8_t *output = mapBuffer<uint8_t>(image.buf));
253 unsigned rwidth = ALIGN(image.width, 128);
255 ALIGN(image.height, 32)
256 + ALIGN(image.height / pd->pparam.components[0].v_sampling_factor, 32)
262 << "image : " << image.width << "x" << image.height
264 << "region : " << rwidth << "x" << rheight
266 << "planes : " << image.num_planes
268 << "offsets: " << image.offsets[0] << " " << image.offsets[1] << " " << image.offsets[2]
270 << "pitches: " << image.pitches[0] << " " << image.pitches[1] << " " << image.pitches[2]
273 EXPECT_EQ(3u, image.num_planes);
274 EXPECT_EQ(pd->pparam.picture_width, image.width);
275 EXPECT_EQ(pd->pparam.picture_height, image.height);
276 EXPECT_EQ(rwidth * rheight, image.data_size);
277 EXPECT_EQ(pd->fourcc, image.format.fourcc);
279 std::ostringstream oss;
280 printImageOutputTo(oss, image, output);
281 RecordProperty("Output", oss.str());
283 validateImageOutput(image, output);
285 // std::cout << oss.str();
287 unmapBuffer(image.buf);
289 destroyBuffer(huffTableBufId);
290 destroyBuffer(iqMatrixBufId);
291 destroyBuffer(picBufId);
292 destroyBuffer(sliceParamBufId);
293 destroyBuffer(sliceDataBufId);
296 destroyContext(context);
297 destroyConfig(config);
298 destroySurfaces(surfaces);
302 /** Teach Google Test how to print a TestPattern::SharedConst object */
303 void PrintTo(const TestPattern::SharedConst& t, std::ostream* os)
308 INSTANTIATE_TEST_CASE_P(
312 TestPattern::SharedConst(new TestPatternData<1>),
313 TestPattern::SharedConst(new TestPatternData<2>),
314 TestPattern::SharedConst(new TestPatternData<3>),
315 TestPattern::SharedConst(new TestPatternData<4>)
317 ::testing::Values("IMC3", "422H", "422V", "444P", "411P"))
320 } // namespace Decode