Skip to content

Commit

Permalink
Add avifGetRGBAPixel() -> avifSetRGBAPixel() test
Browse files Browse the repository at this point in the history
Make sure the behaviors and rounding implementations of
avifGetRGBAPixel() and avifSetRGBAPixel() match exactly.
  • Loading branch information
y-guyon committed Oct 13, 2023
1 parent 163ee01 commit 7a07e72
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/gtest/avifrgbtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ TEST_P(SetGetRGBATest, SetGetTest) {
EXPECT_EQ(pixel_read[3], pixel_one[3]);
}

TEST_P(SetGetRGBATest, GradientTest) {
const int rgb_depth = std::get<0>(GetParam());
const avifRGBFormat rgb_format = std::get<1>(GetParam());
const bool is_float = std::get<2>(GetParam());

// Only used for convenience to generate RGB values.
testutil::AvifImagePtr yuv =
testutil::CreateImage(/*width=*/13, /*height=*/17, /*depth=*/8,
AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL);
testutil::FillImageGradient(yuv.get());

testutil::AvifRgbImage input_rgb(yuv.get(), rgb_depth, rgb_format);
testutil::AvifRgbImage output_rgb(yuv.get(), rgb_depth, rgb_format);
input_rgb.isFloat = is_float;
output_rgb.isFloat = is_float;
ASSERT_EQ(avifImageYUVToRGB(yuv.get(), &input_rgb), AVIF_RESULT_OK);

avifRGBColorSpaceInfo color_space;
ASSERT_TRUE(avifGetRGBColorSpaceInfo(&input_rgb, &color_space));

for (uint32_t j = 0; j < input_rgb.height; ++j) {
for (uint32_t i = 0; i < input_rgb.width; ++i) {
float pixel[4];
avifGetRGBAPixel(&input_rgb, i, j, &color_space, pixel);
avifSetRGBAPixel(&output_rgb, i, j, &color_space, pixel);
}
}
EXPECT_TRUE(testutil::AreImagesEqual(input_rgb, output_rgb));
}

INSTANTIATE_TEST_SUITE_P(
NonFloatNonRgb565, SetGetRGBATest,
Combine(/*rgb_depth=*/Values(8, 10, 12, 16),
Expand Down

0 comments on commit 7a07e72

Please sign in to comment.