From 47994aa124a9fe699aced07e634a2a9e02dacdfa Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Fri, 22 May 2026 20:11:47 +0530 Subject: [PATCH] Use std::array for pixel buffers in avifrgbtest Replaces raw `float[4]` pixel buffers in tests/gtest/avifrgbtest.cc with `std::array`, passing `.data()` to `avifSetRGBAPixel` and `avifGetRGBAPixel`. This is a small code-quality cleanup that stands on its own; it was split out of the `-Wunsafe-buffer-usage` opt-in PR at the reviewer's request. --- tests/gtest/avifrgbtest.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/gtest/avifrgbtest.cc b/tests/gtest/avifrgbtest.cc index faaf47aba3..8af4440bf7 100644 --- a/tests/gtest/avifrgbtest.cc +++ b/tests/gtest/avifrgbtest.cc @@ -1,6 +1,7 @@ // Copyright 2023 Google LLC // SPDX-License-Identifier: BSD-2-Clause +#include #include #include "avif/internal.h" @@ -40,18 +41,18 @@ TEST_P(SetGetRGBATest, SetGetTest) { epsilon = 0.0005f; // Half precision floats are not that precise. } - float pixel_read[4]; + std::array pixel_read; for (uint32_t j = 0; j < rgb.height; ++j) { for (uint32_t i = 0; i < rgb.width; ++i) { // Generate some arbitrary pixel values. - const float pixel_to_write[4] = { + const std::array pixel_to_write = { 0.0f + static_cast(i) / rgb.width, 0.5f + static_cast(j) / (rgb.height * 2), 1.0f - static_cast(i + j) / ((rgb.width + rgb.height) * 2), 1.0f - static_cast(i) / rgb.width}; - avifSetRGBAPixel(&rgb, i, j, &color_space, pixel_to_write); - avifGetRGBAPixel(&rgb, i, j, &color_space, pixel_read); + avifSetRGBAPixel(&rgb, i, j, &color_space, pixel_to_write.data()); + avifGetRGBAPixel(&rgb, i, j, &color_space, pixel_read.data()); EXPECT_NEAR(pixel_read[0], pixel_to_write[0], epsilon); EXPECT_NEAR(pixel_read[1], pixel_to_write[1], epsilon); EXPECT_NEAR(pixel_read[2], pixel_to_write[2], epsilon); @@ -64,17 +65,17 @@ TEST_P(SetGetRGBATest, SetGetTest) { } // Check that 0 maps to 0 and 1.0f maps to 1.0f. - const float pixel_zero[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - avifSetRGBAPixel(&rgb, 0, 0, &color_space, pixel_zero); - avifGetRGBAPixel(&rgb, 0, 0, &color_space, pixel_read); + const std::array pixel_zero = {0.0f, 0.0f, 0.0f, 1.0f}; + avifSetRGBAPixel(&rgb, 0, 0, &color_space, pixel_zero.data()); + avifGetRGBAPixel(&rgb, 0, 0, &color_space, pixel_read.data()); EXPECT_EQ(pixel_read[0], pixel_zero[0]); EXPECT_EQ(pixel_read[1], pixel_zero[1]); EXPECT_EQ(pixel_read[2], pixel_zero[2]); EXPECT_EQ(pixel_read[3], pixel_zero[3]); - const float pixel_one[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - avifSetRGBAPixel(&rgb, 0, 0, &color_space, pixel_one); - avifGetRGBAPixel(&rgb, 0, 0, &color_space, pixel_read); + const std::array pixel_one = {1.0f, 1.0f, 1.0f, 1.0f}; + avifSetRGBAPixel(&rgb, 0, 0, &color_space, pixel_one.data()); + avifGetRGBAPixel(&rgb, 0, 0, &color_space, pixel_read.data()); EXPECT_EQ(pixel_read[0], pixel_one[0]); EXPECT_EQ(pixel_read[1], pixel_one[1]); EXPECT_EQ(pixel_read[2], pixel_one[2]); @@ -103,9 +104,9 @@ TEST_P(SetGetRGBATest, GradientTest) { 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); + std::array pixel; + avifGetRGBAPixel(&input_rgb, i, j, &color_space, pixel.data()); + avifSetRGBAPixel(&output_rgb, i, j, &color_space, pixel.data()); } } EXPECT_TRUE(testutil::AreImagesEqual(input_rgb, output_rgb));