diff --git a/CHANGELOG.md b/CHANGELOG.md index f55d3eeabf..7b22e7e2a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 possibility encoder may crash when given certain configuration or input. * Add imageSequenceTrackPresent flag to the avifDecoder struct. * avifImageScale() function was made part of the public ABI. +* Add avif_cxx.h as a C++ header with basic functionality. ### Changed * Update aom.cmd: v3.7.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a1df863cd..26a00a9843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -873,7 +873,7 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libavif.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) - install(FILES include/avif/avif.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/avif") + install(FILES include/avif/avif.h include/avif/avif_cxx.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/avif") endif() # --------------------------------------------------------------------------------------- diff --git a/include/avif/avif_cxx.h b/include/avif/avif_cxx.h new file mode 100644 index 0000000000..8a9fd2bfae --- /dev/null +++ b/include/avif/avif_cxx.h @@ -0,0 +1,33 @@ +// Copyright 2023 Google LLC +// SPDX-License-Identifier: BSD-2-Clause + +#ifndef AVIF_AVIF_CXX_H +#define AVIF_AVIF_CXX_H + +#if !defined(__cplusplus) +#error "This a C++ only header. Use avif/avif.h for C." +#endif + +#include + +#include "avif/avif.h" + +namespace avif +{ + +// Struct to call the destroy functions in a unique_ptr. +struct UniquePtrDeleter +{ + void operator()(avifEncoder * encoder) const { avifEncoderDestroy(encoder); } + void operator()(avifDecoder * decoder) const { avifDecoderDestroy(decoder); } + void operator()(avifImage * image) const { avifImageDestroy(image); } +}; + +// Use these unique_ptr to ensure the structs are automatically destroyed. +using EncoderPtr = std::unique_ptr; +using DecoderPtr = std::unique_ptr; +using ImagePtr = std::unique_ptr; + +} // namespace avif + +#endif // AVIF_AVIF_CXX_H diff --git a/tests/gtest/are_images_equal.cc b/tests/gtest/are_images_equal.cc index 74613fcc74..c7a7de2fce 100644 --- a/tests/gtest/are_images_equal.cc +++ b/tests/gtest/are_images_equal.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-2-Clause // Compares two files and returns whether they are the same once decoded. +#include #include #include @@ -14,7 +15,7 @@ #include #endif -using libavif::testutil::AvifImagePtr; +using avif::ImagePtr; MAIN() { INIT_ARGV() @@ -24,9 +25,8 @@ MAIN() { << " file1 file2 ignore_alpha_flag [psnr_threshold]" << std::endl; return 2; } - AvifImagePtr decoded[2] = { - AvifImagePtr(avifImageCreateEmpty(), avifImageDestroy), - AvifImagePtr(avifImageCreateEmpty(), avifImageDestroy)}; + ImagePtr decoded[2] = {ImagePtr(avifImageCreateEmpty()), + ImagePtr(avifImageCreateEmpty())}; if (!decoded[0] || !decoded[1]) { std::cerr << "Cannot create AVIF images." << std::endl; return 2; @@ -60,8 +60,8 @@ MAIN() { bool ignore_alpha = std::stoi(argv[3]) != 0; if (argc == 4) { - if (!libavif::testutil::AreImagesEqual(*decoded[0], *decoded[1], - ignore_alpha)) { + if (!avif::testutil::AreImagesEqual(*decoded[0], *decoded[1], + ignore_alpha)) { std::cerr << "Images " << argv[1] << " and " << argv[2] << " are different." << std::endl; return 1; @@ -69,8 +69,7 @@ MAIN() { std::cout << "Images " << argv[1] << " and " << argv[2] << " are identical." << std::endl; } else { - auto psnr = - libavif::testutil::GetPsnr(*decoded[0], *decoded[1], ignore_alpha); + auto psnr = avif::testutil::GetPsnr(*decoded[0], *decoded[1], ignore_alpha); if (psnr < std::stod(argv[4])) { std::cerr << "PSNR: " << psnr << ", images " << argv[1] << " and " << argv[2] << " are not similar." << std::endl; diff --git a/tests/gtest/avif_fuzztest_dec.cc b/tests/gtest/avif_fuzztest_dec.cc index ff46af19e4..13a3b541bd 100644 --- a/tests/gtest/avif_fuzztest_dec.cc +++ b/tests/gtest/avif_fuzztest_dec.cc @@ -12,7 +12,7 @@ using ::fuzztest::Arbitrary; -namespace libavif { +namespace avif { namespace testutil { namespace { @@ -20,10 +20,10 @@ ::testing::Environment* const kStackLimitEnv = SetStackLimitTo512x1024Bytes(); //------------------------------------------------------------------------------ -void Decode(const std::string& arbitrary_bytes, AvifDecoderPtr decoder) { +void Decode(const std::string& arbitrary_bytes, DecoderPtr decoder) { ASSERT_NE(GetSeedDataDir(), nullptr); // Make sure seeds are available. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); const avifResult result = avifDecoderReadMemory( decoder.get(), decoded.get(), @@ -43,4 +43,4 @@ FUZZ_TEST(DecodeAvifTest, Decode) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_dec_incr.cc b/tests/gtest/avif_fuzztest_dec_incr.cc index 1dec16181d..14a339a2f2 100644 --- a/tests/gtest/avif_fuzztest_dec_incr.cc +++ b/tests/gtest/avif_fuzztest_dec_incr.cc @@ -14,7 +14,7 @@ using ::fuzztest::Arbitrary; -namespace libavif { +namespace avif { namespace testutil { namespace { @@ -48,7 +48,7 @@ void DecodeIncr(const std::string& arbitrary_bytes, bool is_persistent, bool give_size_hint, bool use_nth_image_api) { ASSERT_NE(GetSeedDataDir(), nullptr); // Make sure seeds are available. - AvifImagePtr reference(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr reference(avifImageCreateEmpty()); ASSERT_NE(reference.get(), nullptr); DecoderInput data = {reinterpret_cast(arbitrary_bytes.data()), @@ -58,7 +58,7 @@ void DecodeIncr(const std::string& arbitrary_bytes, bool is_persistent, .persistent = AVIF_TRUE, .data = &data}; - AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder.get(), nullptr); avifDecoderSetIO(decoder.get(), &io); @@ -95,4 +95,4 @@ FUZZ_TEST(DecodeAvifFuzzTest, DecodeIncr) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_enc_dec.cc b/tests/gtest/avif_fuzztest_enc_dec.cc index 78b5e8d194..0b727f3b2c 100644 --- a/tests/gtest/avif_fuzztest_enc_dec.cc +++ b/tests/gtest/avif_fuzztest_enc_dec.cc @@ -9,15 +9,14 @@ #include "fuzztest/fuzztest.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace testutil { namespace { ::testing::Environment* const kStackLimitEnv = SetStackLimitTo512x1024Bytes(); -void EncodeDecodeValid(AvifImagePtr image, AvifEncoderPtr encoder, - AvifDecoderPtr decoder) { - AvifImagePtr decoded_image(avifImageCreateEmpty(), avifImageDestroy); +void EncodeDecodeValid(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder) { + ImagePtr decoded_image(avifImageCreateEmpty()); ASSERT_NE(image.get(), nullptr); ASSERT_NE(encoder.get(), nullptr); ASSERT_NE(decoder.get(), nullptr); @@ -53,4 +52,4 @@ FUZZ_TEST(EncodeDecodeAvifFuzzTest, EncodeDecodeValid) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_enc_dec_anim.cc b/tests/gtest/avif_fuzztest_enc_dec_anim.cc index 2a1d012274..cf9269248e 100644 --- a/tests/gtest/avif_fuzztest_enc_dec_anim.cc +++ b/tests/gtest/avif_fuzztest_enc_dec_anim.cc @@ -10,7 +10,7 @@ #include "fuzztest/fuzztest.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace testutil { namespace { @@ -23,12 +23,12 @@ struct FrameOptions { // Encodes an animation and decodes it. // For simplicity, there is only one source image, all frames are identical. -void EncodeDecodeAnimation(AvifImagePtr frame, +void EncodeDecodeAnimation(ImagePtr frame, const std::vector& frame_options, - AvifEncoderPtr encoder, AvifDecoderPtr decoder) { + EncoderPtr encoder, DecoderPtr decoder) { ASSERT_NE(encoder, nullptr); ASSERT_NE(decoder, nullptr); - AvifImagePtr decoded_image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded_image(avifImageCreateEmpty()); ASSERT_NE(decoded_image, nullptr); const int num_frames = static_cast(frame_options.size()); @@ -98,4 +98,4 @@ FUZZ_TEST(EncodeDecodeAvifFuzzTest, EncodeDecodeAnimation) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_enc_dec_experimental.cc b/tests/gtest/avif_fuzztest_enc_dec_experimental.cc index 20a2ba19be..24431ec8cb 100644 --- a/tests/gtest/avif_fuzztest_enc_dec_experimental.cc +++ b/tests/gtest/avif_fuzztest_enc_dec_experimental.cc @@ -13,7 +13,7 @@ #include "fuzztest/fuzztest.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace testutil { namespace { @@ -44,9 +44,8 @@ void CheckGainMapMetadataMatches(const avifGainMapMetadata& actual, } } -void EncodeDecodeValid(AvifImagePtr image, AvifEncoderPtr encoder, - AvifDecoderPtr decoder) { - AvifImagePtr decoded_image(avifImageCreateEmpty(), avifImageDestroy); +void EncodeDecodeValid(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder) { + ImagePtr decoded_image(avifImageCreateEmpty()); ASSERT_NE(image.get(), nullptr); ASSERT_NE(encoder.get(), nullptr); ASSERT_NE(decoder.get(), nullptr); @@ -97,8 +96,8 @@ void EncodeDecodeValid(AvifImagePtr image, AvifEncoderPtr encoder, // Note that avifGainMapMetadata is passed as a byte array // because the C array fields in the struct seem to prevent fuzztest from // handling it natively. -AvifImagePtr AddGainMapToImage( - AvifImagePtr image, AvifImagePtr gainMap, +ImagePtr AddGainMapToImage( + ImagePtr image, ImagePtr gainMap, const std::array& metadata) { image->gainMap.image = gainMap.release(); std::memcpy(&image->gainMap.metadata, metadata.data(), metadata.size()); @@ -118,4 +117,4 @@ FUZZ_TEST(EncodeDecodeAvifFuzzTest, EncodeDecodeValid) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_enc_dec_incr.cc b/tests/gtest/avif_fuzztest_enc_dec_incr.cc index 8bac0c680b..ca27497244 100644 --- a/tests/gtest/avif_fuzztest_enc_dec_incr.cc +++ b/tests/gtest/avif_fuzztest_enc_dec_incr.cc @@ -17,21 +17,21 @@ using ::fuzztest::Arbitrary; using ::fuzztest::InRange; -namespace libavif { +namespace avif { namespace testutil { namespace { ::testing::Environment* const kStackLimitEnv = SetStackLimitTo512x1024Bytes(); // Encodes an image into an AVIF grid then decodes it. -void EncodeDecodeGridValid(AvifImagePtr image, AvifEncoderPtr encoder, - AvifDecoderPtr decoder, uint32_t grid_cols, +void EncodeDecodeGridValid(ImagePtr image, EncoderPtr encoder, + DecoderPtr decoder, uint32_t grid_cols, uint32_t grid_rows, bool is_encoded_data_persistent, bool give_size_hint_to_decoder) { ASSERT_NE(image, nullptr); ASSERT_NE(encoder, nullptr); - const std::vector cells = + const std::vector cells = ImageToGrid(image.get(), grid_cols, grid_rows); if (cells.empty()) return; const uint32_t cell_width = cells.front()->width; @@ -59,10 +59,9 @@ void EncodeDecodeGridValid(AvifImagePtr image, AvifEncoderPtr encoder, avifEncoderFinish(encoder.get(), &encoded_data); ASSERT_EQ(finish_result, AVIF_RESULT_OK) << avifResultToString(finish_result); - DecodeNonIncrementallyAndIncrementally(encoded_data, decoder.get(), - is_encoded_data_persistent, - give_size_hint_to_decoder, - /*useNthImageApi=*/true, cell_height); + DecodeNonIncrementallyAndIncrementally( + encoded_data, decoder.get(), is_encoded_data_persistent, + give_size_hint_to_decoder, /*use_nth_image_api=*/true, cell_height); } FUZZ_TEST(EncodeDecodeAvifFuzzTest, EncodeDecodeGridValid) @@ -75,4 +74,4 @@ FUZZ_TEST(EncodeDecodeAvifFuzzTest, EncodeDecodeGridValid) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_enc_dec_incr_experimental.cc b/tests/gtest/avif_fuzztest_enc_dec_incr_experimental.cc index e24f139f70..a7666c412d 100644 --- a/tests/gtest/avif_fuzztest_enc_dec_incr_experimental.cc +++ b/tests/gtest/avif_fuzztest_enc_dec_incr_experimental.cc @@ -17,21 +17,21 @@ using ::fuzztest::Arbitrary; using ::fuzztest::InRange; -namespace libavif { +namespace avif { namespace testutil { namespace { ::testing::Environment* const kStackLimitEnv = SetStackLimitTo512x1024Bytes(); // Encodes an image into an AVIF grid then decodes it. -void EncodeDecodeGridValid(AvifImagePtr image, AvifEncoderPtr encoder, - AvifDecoderPtr decoder, uint32_t grid_cols, +void EncodeDecodeGridValid(ImagePtr image, EncoderPtr encoder, + DecoderPtr decoder, uint32_t grid_cols, uint32_t grid_rows, bool is_encoded_data_persistent, bool give_size_hint_to_decoder) { ASSERT_NE(image, nullptr); ASSERT_NE(encoder, nullptr); - const std::vector cells = + const std::vector cells = ImageToGrid(image.get(), grid_cols, grid_rows); if (cells.empty()) return; const uint32_t cell_width = cells.front()->width; @@ -42,7 +42,7 @@ void EncodeDecodeGridValid(AvifImagePtr image, AvifEncoderPtr encoder, const avifImage* gain_map = image->gainMap.image; if (gain_map != nullptr) { - std::vector gain_map_cells = + std::vector gain_map_cells = ImageToGrid(gain_map, grid_cols, grid_rows); if (gain_map_cells.empty()) return; ASSERT_EQ(gain_map_cells.size(), cells.size()); @@ -97,8 +97,8 @@ void EncodeDecodeGridValid(AvifImagePtr image, AvifEncoderPtr encoder, // Note that avifGainMapMetadata is passed as a byte array // because the C array fields in the struct seem to prevent fuzztest from // handling it natively. -AvifImagePtr AddGainMapToImage( - AvifImagePtr image, AvifImagePtr gainMap, +ImagePtr AddGainMapToImage( + ImagePtr image, ImagePtr gainMap, const std::array& metadata) { image->gainMap.image = gainMap.release(); std::memcpy(&image->gainMap.metadata, metadata.data(), metadata.size()); @@ -122,4 +122,4 @@ FUZZ_TEST(EncodeDecodeAvifFuzzTest, EncodeDecodeGridValid) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_helpers.cc b/tests/gtest/avif_fuzztest_helpers.cc index 7d7c38cdc5..d5d8338a31 100644 --- a/tests/gtest/avif_fuzztest_helpers.cc +++ b/tests/gtest/avif_fuzztest_helpers.cc @@ -16,26 +16,25 @@ #include "fuzztest/fuzztest.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace testutil { namespace { //------------------------------------------------------------------------------ -AvifImagePtr CreateAvifImage(size_t width, size_t height, int depth, - avifPixelFormat pixel_format, bool has_alpha, - const uint8_t* samples) { - AvifImagePtr image( - avifImageCreate(static_cast(width), - static_cast(height), depth, pixel_format), - avifImageDestroy); +ImagePtr CreateAvifImage(size_t width, size_t height, int depth, + avifPixelFormat pixel_format, bool has_alpha, + const uint8_t* samples) { + ImagePtr image(avifImageCreate(static_cast(width), + static_cast(height), depth, + pixel_format)); if (image.get() == nullptr) { return image; } if (avifImageAllocatePlanes(image.get(), has_alpha ? AVIF_PLANES_ALL : AVIF_PLANES_YUV) != AVIF_RESULT_OK) { - return AvifImagePtr(nullptr, nullptr); + return nullptr; } for (avifChannelIndex c : @@ -56,26 +55,26 @@ AvifImagePtr CreateAvifImage(size_t width, size_t height, int depth, } // namespace -AvifImagePtr CreateAvifImage8b(size_t width, size_t height, - avifPixelFormat pixel_format, bool has_alpha, - const std::vector& samples) { +ImagePtr CreateAvifImage8b(size_t width, size_t height, + avifPixelFormat pixel_format, bool has_alpha, + const std::vector& samples) { return CreateAvifImage(width, height, 8, pixel_format, has_alpha, samples.data()); } -AvifImagePtr CreateAvifImage16b(size_t width, size_t height, int depth, - avifPixelFormat pixel_format, bool has_alpha, - const std::vector& samples) { +ImagePtr CreateAvifImage16b(size_t width, size_t height, int depth, + avifPixelFormat pixel_format, bool has_alpha, + const std::vector& samples) { return CreateAvifImage(width, height, depth, pixel_format, has_alpha, reinterpret_cast(samples.data())); } -AvifEncoderPtr CreateAvifEncoder(avifCodecChoice codec_choice, int max_threads, - int min_quantizer, int max_quantizer, - int min_quantizer_alpha, - int max_quantizer_alpha, int tile_rows_log2, - int tile_cols_log2, int speed) { - AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); +EncoderPtr CreateAvifEncoder(avifCodecChoice codec_choice, int max_threads, + int min_quantizer, int max_quantizer, + int min_quantizer_alpha, int max_quantizer_alpha, + int tile_rows_log2, int tile_cols_log2, + int speed) { + EncoderPtr encoder(avifEncoderCreate()); if (encoder.get() == nullptr) { return encoder; } @@ -94,15 +93,15 @@ AvifEncoderPtr CreateAvifEncoder(avifCodecChoice codec_choice, int max_threads, return encoder; } -AvifDecoderPtr CreateAvifDecoder(avifCodecChoice codec_choice, int max_threads, - avifDecoderSource requested_source, - bool allow_progressive, bool allow_incremental, - bool ignore_exif, bool ignore_xmp, - uint32_t image_size_limit, - uint32_t image_dimension_limit, - uint32_t image_count_limit, - avifStrictFlags strict_flags) { - AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); +DecoderPtr CreateAvifDecoder(avifCodecChoice codec_choice, int max_threads, + avifDecoderSource requested_source, + bool allow_progressive, bool allow_incremental, + bool ignore_exif, bool ignore_xmp, + uint32_t image_size_limit, + uint32_t image_dimension_limit, + uint32_t image_count_limit, + avifStrictFlags strict_flags) { + DecoderPtr decoder(avifDecoderCreate()); if (decoder.get() == nullptr) { return decoder; } @@ -120,14 +119,12 @@ AvifDecoderPtr CreateAvifDecoder(avifCodecChoice codec_choice, int max_threads, return decoder; } -AvifImagePtr AvifImageToUniquePtr(avifImage* image) { - return AvifImagePtr(image, avifImageDestroy); -} +ImagePtr AvifImageToUniquePtr(avifImage* image) { return ImagePtr(image); } #if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP) -AvifDecoderPtr AddGainMapOptionsToDecoder(AvifDecoderPtr decoder, - bool enable_parsing_gain_map_metadata, - bool enable_decoding_gain_map) { +DecoderPtr AddGainMapOptionsToDecoder(DecoderPtr decoder, + bool enable_parsing_gain_map_metadata, + bool enable_decoding_gain_map) { decoder->enableParsingGainMapMetadata = enable_parsing_gain_map_metadata; decoder->enableDecodingGainMap = enable_decoding_gain_map; // Do not fuzz 'ignoreColorAndAlpha' since most tests assume that if the @@ -262,4 +259,4 @@ std::vector GetTestImagesContents( //------------------------------------------------------------------------------ } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avif_fuzztest_helpers.h b/tests/gtest/avif_fuzztest_helpers.h index 47a7ccee38..268b4e2be9 100644 --- a/tests/gtest/avif_fuzztest_helpers.h +++ b/tests/gtest/avif_fuzztest_helpers.h @@ -14,36 +14,35 @@ #include "fuzztest/fuzztest.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace testutil { //------------------------------------------------------------------------------ // C++ wrapper for scoped memory management of C API objects. // Exposed for convenient fuzztest reproducer output. -AvifImagePtr CreateAvifImage8b(size_t width, size_t height, - avifPixelFormat pixel_format, bool has_alpha, - const std::vector& samples); -AvifImagePtr CreateAvifImage16b(size_t width, size_t height, int depth, - avifPixelFormat pixel_format, bool has_alpha, - const std::vector& samples); -AvifEncoderPtr CreateAvifEncoder(avifCodecChoice codec_choice, int max_threads, - int min_quantizer, int max_quantizer, - int min_quantizer_alpha, - int max_quantizer_alpha, int tile_rows_log2, - int tile_cols_log2, int speed); -AvifDecoderPtr CreateAvifDecoder(avifCodecChoice codec_choice, int max_threads, - avifDecoderSource requested_source, - bool allow_progressive, bool allow_incremental, - bool ignore_exif, bool ignore_xmp, - uint32_t image_size_limit, - uint32_t image_dimension_limit, - uint32_t image_count_limit, - avifStrictFlags strict_flags); +ImagePtr CreateAvifImage8b(size_t width, size_t height, + avifPixelFormat pixel_format, bool has_alpha, + const std::vector& samples); +ImagePtr CreateAvifImage16b(size_t width, size_t height, int depth, + avifPixelFormat pixel_format, bool has_alpha, + const std::vector& samples); +EncoderPtr CreateAvifEncoder(avifCodecChoice codec_choice, int max_threads, + int min_quantizer, int max_quantizer, + int min_quantizer_alpha, int max_quantizer_alpha, + int tile_rows_log2, int tile_cols_log2, int speed); +DecoderPtr CreateAvifDecoder(avifCodecChoice codec_choice, int max_threads, + avifDecoderSource requested_source, + bool allow_progressive, bool allow_incremental, + bool ignore_exif, bool ignore_xmp, + uint32_t image_size_limit, + uint32_t image_dimension_limit, + uint32_t image_count_limit, + avifStrictFlags strict_flags); #if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP) -AvifDecoderPtr AddGainMapOptionsToDecoder(AvifDecoderPtr decoder, - bool enable_parsing_gain_map_metadata, - bool enable_decoding_gain_map); +DecoderPtr AddGainMapOptionsToDecoder(DecoderPtr decoder, + bool enable_parsing_gain_map_metadata, + bool enable_decoding_gain_map); #endif //------------------------------------------------------------------------------ @@ -102,12 +101,12 @@ inline auto ArbitraryAvifImage16b() { fuzztest::Arbitrary()); } -// Generator for an arbitrary AvifImagePtr. +// Generator for an arbitrary ImagePtr. inline auto ArbitraryAvifImage() { return fuzztest::OneOf(ArbitraryAvifImage8b(), ArbitraryAvifImage16b()); } -// Generator for an arbitrary AvifEncoderPtr. +// Generator for an arbitrary EncoderPtr. inline auto ArbitraryAvifEncoder() { const auto codec_choice = fuzztest::ElementOf( {AVIF_CODEC_CHOICE_AUTO, AVIF_CODEC_CHOICE_AOM}); @@ -132,7 +131,7 @@ inline auto ArbitraryAvifEncoder() { speed); } -// Generator for an arbitrary AvifEncoderPtr with base options fuzzed (i.e. +// Generator for an arbitrary EncoderPtr with base options fuzzed (i.e. // without "experimental" options hidden behind compile flags). inline auto ArbitraryBaseAvifDecoder() { // MAX_NUM_THREADS from libaom/aom_util/aom_thread.h @@ -160,7 +159,7 @@ inline auto ArbitraryBaseAvifDecoder() { } #if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP) -// Generator for an arbitrary AvifEncoderPtr with base options and gain map +// Generator for an arbitrary EncoderPtr with base options and gain map // options fuzzed, with the exception of 'ignoreColorAndAlpha' (because it would // break most tests' assumptions). inline auto ArbitraryAvifDecoderWithGainMapOptions() { @@ -170,12 +169,12 @@ inline auto ArbitraryAvifDecoderWithGainMapOptions() { /*enable_decoding_gain_map=*/fuzztest::Arbitrary()); } -// Generator for an arbitrary AvifDecoderPtr. +// Generator for an arbitrary DecoderPtr. inline auto ArbitraryAvifDecoder() { return ArbitraryAvifDecoderWithGainMapOptions(); } #else -// Generator for an arbitrary AvifDecoderPtr. +// Generator for an arbitrary DecoderPtr. inline auto ArbitraryAvifDecoder() { return ArbitraryBaseAvifDecoder(); } #endif // AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP @@ -215,7 +214,7 @@ const char* GetSeedDataDir(); std::vector GetTestImagesContents( size_t max_file_size, const std::vector& image_formats); -// Generator for an arbitrary AvifImagePtr that uses test image files as seeds. +// Generator for an arbitrary ImagePtr that uses test image files as seeds. // Uses the 'TEST_DATA_DIR' environment variable to load the seeds. // If TEST_DATA_DIR is not set, no seeds are used. // Tests that use this should ASSERT_NE(GetSeedDataDir(), nullptr) @@ -233,6 +232,6 @@ inline auto ArbitraryImageWithSeeds( //------------------------------------------------------------------------------ } // namespace testutil -} // namespace libavif +} // namespace avif #endif // LIBAVIF_TESTS_OSS_FUZZ_AVIF_FUZZTEST_HELPERS_H_ diff --git a/tests/gtest/avif_fuzztest_read_image.cc b/tests/gtest/avif_fuzztest_read_image.cc index 1ffaea2c0c..c13ce8fd3a 100644 --- a/tests/gtest/avif_fuzztest_read_image.cc +++ b/tests/gtest/avif_fuzztest_read_image.cc @@ -18,7 +18,7 @@ using ::fuzztest::Arbitrary; using ::fuzztest::ElementOf; -namespace libavif { +namespace avif { namespace testutil { namespace { @@ -57,7 +57,7 @@ void ReadImageFile(const std::string& arbitrary_bytes, uint32_t out_depth; avifAppSourceTiming timing; - testutil::AvifImagePtr avif_image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr avif_image(avifImageCreateEmpty()); avif_image->matrixCoefficients = matrix_coefficients; const avifAppFileFormat file_format = avifReadImage( @@ -125,4 +125,4 @@ FUZZ_TEST(ReadImageFuzzTest, ReadImageFile) } // namespace } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifallocationtest.cc b/tests/gtest/avifallocationtest.cc index c9b8b910a3..d44b2430c8 100644 --- a/tests/gtest/avifallocationtest.cc +++ b/tests/gtest/avifallocationtest.cc @@ -8,7 +8,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { void TestAllocation(uint32_t width, uint32_t height, uint32_t depth, @@ -21,7 +21,7 @@ void TestAllocation(uint32_t width, uint32_t height, uint32_t depth, AVIF_PIXEL_FORMAT_YUV400}) { for (avifPlanesFlag planes : {AVIF_PLANES_YUV, AVIF_PLANES_A, AVIF_PLANES_ALL}) { - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); image->width = width; image->height = height; @@ -95,7 +95,7 @@ TEST(DISABLED_AllocationTest, OutOfMemory) { void TestEncoding(uint32_t width, uint32_t height, uint32_t depth, avifResult expected_result) { - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); image->width = width; image->height = height; @@ -135,7 +135,7 @@ void TestEncoding(uint32_t width, uint32_t height, uint32_t depth, image->alphaPlane = bytes; // Try to encode. - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; testutil::AvifRwData encoded_avif; @@ -197,4 +197,4 @@ TEST(AvifAllocTest, Extremes) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifalphanoispetest.cc b/tests/gtest/avifalphanoispetest.cc index f2d60b20be..d7963a70d9 100644 --- a/tests/gtest/avifalphanoispetest.cc +++ b/tests/gtest/avifalphanoispetest.cc @@ -5,7 +5,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -17,7 +17,7 @@ TEST(AvifDecodeTest, AlphaNoIspe) { } // See https://github.com/AOMediaCodec/libavif/pull/745. const char* file_name = "alpha_noispe.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderSetIOFile(decoder.get(), (std::string(data_path) + file_name).c_str()), @@ -36,7 +36,7 @@ TEST(AvifDecodeTest, AlphaNoIspe) { } } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -46,6 +46,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifalphapremtest.cc b/tests/gtest/avifalphapremtest.cc index 3ab3e48ca5..5c8bf8eefd 100644 --- a/tests/gtest/avifalphapremtest.cc +++ b/tests/gtest/avifalphapremtest.cc @@ -5,7 +5,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { //------------------------------------------------------------------------------ @@ -25,14 +25,14 @@ TEST(AlphaMultiplyTest, OpaqueIsNoOp) { } // YUVA. - testutil::AvifImagePtr opaque_alpha = testutil::CreateImage( + ImagePtr opaque_alpha = testutil::CreateImage( 1024, 1024, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); const uint32_t yuva[] = {255, 255, 255, 255}; testutil::FillImagePlain(opaque_alpha.get(), yuva); opaque_alpha->alphaPremultiplied = premultiplied_input; // View on YUV (no alpha), to make sure the color values are identical. - testutil::AvifImagePtr no_alpha(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr no_alpha(avifImageCreateEmpty()); ASSERT_NE(no_alpha, nullptr); const avifCropRect rect = {0, 0, opaque_alpha->width, opaque_alpha->height}; ASSERT_EQ(avifImageSetViewRect(no_alpha.get(), opaque_alpha.get(), &rect), @@ -64,4 +64,4 @@ TEST(AlphaMultiplyTest, OpaqueIsNoOp) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifanimationtest.cc b/tests/gtest/avifanimationtest.cc index b7e2a3fb3c..3178e9a3a5 100644 --- a/tests/gtest/avifanimationtest.cc +++ b/tests/gtest/avifanimationtest.cc @@ -5,7 +5,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -16,7 +16,7 @@ TEST(AvifDecodeTest, AnimatedImage) { GTEST_SKIP() << "AV1 Codec unavailable, skip test."; } const char* file_name = "colors-animated-8bpc.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderSetIOFile(decoder.get(), (std::string(data_path) + file_name).c_str()), @@ -36,7 +36,7 @@ TEST(AvifDecodeTest, AnimatedImageWithSourceSetToPrimaryItem) { GTEST_SKIP() << "AV1 Codec unavailable, skip test."; } const char* file_name = "colors-animated-8bpc.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderSetIOFile(decoder.get(), (std::string(data_path) + file_name).c_str()), @@ -59,7 +59,7 @@ TEST(AvifDecodeTest, AnimatedImageWithSourceSetToPrimaryItem) { } } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -69,6 +69,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifavmtest.cc b/tests/gtest/avifavmtest.cc index 8366271ab9..a1041dd8e5 100644 --- a/tests/gtest/avifavmtest.cc +++ b/tests/gtest/avifavmtest.cc @@ -8,7 +8,7 @@ using testing::Combine; using testing::Values; -namespace libavif { +namespace avif { namespace { class AvmTest : public testing::TestWithParam< @@ -22,21 +22,21 @@ TEST_P(AvmTest, EncodeDecode) { const avifPixelFormat format = std::get<3>(GetParam()); const bool alpha = std::get<4>(GetParam()); - testutil::AvifImagePtr image = testutil::CreateImage( + ImagePtr image = testutil::CreateImage( width, height, depth, format, alpha ? AVIF_PLANES_ALL : AVIF_PLANES_YUV); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->codecChoice = AVIF_CODEC_CHOICE_AVM; testutil::AvifRwData encoded; ASSERT_EQ(avifEncoderWrite(encoder.get(), image.get(), &encoded), AVIF_RESULT_OK); - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); // No need to set AVIF_CODEC_CHOICE_AVM. The decoder should recognize AV2. ASSERT_EQ(avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, @@ -87,21 +87,21 @@ TEST(AvmTest, Av1StillWorksWhenAvmIsEnabled) { } // avm is the only AV2 codec, so the default codec will be an AV1 one. - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/64, /*height=*/64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; ASSERT_EQ(avifEncoderWrite(encoder.get(), image.get(), &encoded), AVIF_RESULT_OK); - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size), @@ -118,4 +118,4 @@ TEST(AvmTest, Av1StillWorksWhenAvmIsEnabled) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifbasictest.cc b/tests/gtest/avifbasictest.cc index 2d3f0c22f9..7a08621e7a 100644 --- a/tests/gtest/avifbasictest.cc +++ b/tests/gtest/avifbasictest.cc @@ -5,25 +5,25 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { TEST(BasicTest, EncodeDecode) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/12, /*height=*/34, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result); - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); result = avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size); @@ -42,4 +42,4 @@ TEST(BasicTest, EncodeDecode) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifchangesettingtest.cc b/tests/gtest/avifchangesettingtest.cc index 159787a731..e23b75fbf1 100644 --- a/tests/gtest/avifchangesettingtest.cc +++ b/tests/gtest/avifchangesettingtest.cc @@ -8,7 +8,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { void TestEncodeDecode(avifCodecChoice codec, @@ -19,14 +19,14 @@ void TestEncodeDecode(avifCodecChoice codec, } constexpr uint32_t kImageSize = 512; - testutil::AvifImagePtr image = testutil::CreateImage( - kImageSize, kImageSize, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, - AVIF_PLANES_YUV, AVIF_RANGE_FULL); + ImagePtr image = testutil::CreateImage(kImageSize, kImageSize, /*depth=*/8, + AVIF_PIXEL_FORMAT_YUV420, + AVIF_PLANES_YUV, AVIF_RANGE_FULL); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); // Encode - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->codecChoice = codec; encoder->speed = AVIF_SPEED_FASTEST; @@ -80,7 +80,7 @@ void TestEncodeDecode(avifCodecChoice codec, ASSERT_EQ(avifEncoderFinish(encoder.get(), &encodedAvif), AVIF_RESULT_OK); // Decode - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); // The second frame is set to have far better quality, @@ -124,14 +124,14 @@ TEST(ChangeSettingTest, UnchangeableSetting) { } constexpr uint32_t kImageSize = 512; - testutil::AvifImagePtr image = testutil::CreateImage( - kImageSize, kImageSize, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, - AVIF_PLANES_YUV, AVIF_RANGE_FULL); + ImagePtr image = testutil::CreateImage(kImageSize, kImageSize, /*depth=*/8, + AVIF_PIXEL_FORMAT_YUV420, + AVIF_PLANES_YUV, AVIF_RANGE_FULL); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); // Encode - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->codecChoice = AVIF_CODEC_CHOICE_AOM; encoder->speed = AVIF_SPEED_FASTEST; @@ -167,15 +167,15 @@ TEST(ChangeSettingTest, UnchangeableImageColorRange) { } constexpr uint32_t kImageSize = 512; - testutil::AvifImagePtr image = testutil::CreateImage( - kImageSize, kImageSize, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, - AVIF_PLANES_YUV, AVIF_RANGE_FULL); + ImagePtr image = testutil::CreateImage(kImageSize, kImageSize, /*depth=*/8, + AVIF_PIXEL_FORMAT_YUV420, + AVIF_PLANES_YUV, AVIF_RANGE_FULL); ASSERT_NE(image, nullptr); const uint32_t yuva[] = {128, 128, 128, 255}; testutil::FillImagePlain(image.get(), yuva); // Encode - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->codecChoice = AVIF_CODEC_CHOICE_AOM; encoder->speed = AVIF_SPEED_FASTEST; @@ -204,15 +204,15 @@ TEST(ChangeSettingTest, UnchangeableImageChromaSamplePosition) { } constexpr uint32_t kImageSize = 512; - testutil::AvifImagePtr image = testutil::CreateImage( - kImageSize, kImageSize, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, - AVIF_PLANES_YUV, AVIF_RANGE_FULL); + ImagePtr image = testutil::CreateImage(kImageSize, kImageSize, /*depth=*/8, + AVIF_PIXEL_FORMAT_YUV420, + AVIF_PLANES_YUV, AVIF_RANGE_FULL); ASSERT_NE(image, nullptr); const uint32_t yuva[] = {128, 128, 128, 255}; testutil::FillImagePlain(image.get(), yuva); // Encode - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->codecChoice = AVIF_CODEC_CHOICE_AOM; encoder->speed = AVIF_SPEED_FASTEST; @@ -237,4 +237,4 @@ TEST(ChangeSettingTest, UnchangeableImageChromaSamplePosition) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifcllitest.cc b/tests/gtest/avifcllitest.cc index 0416069789..c7c7f18b39 100644 --- a/tests/gtest/avifcllitest.cc +++ b/tests/gtest/avifcllitest.cc @@ -5,11 +5,11 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { TEST(ClliTest, Simple) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/8, /*height=*/8, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_YUV); ASSERT_NE(image, nullptr); @@ -21,8 +21,7 @@ TEST(ClliTest, Simple) { image->clli.maxPALL = static_cast(max_pic_average_light_level); const testutil::AvifRwData encoded = testutil::Encode(image.get()); - const testutil::AvifImagePtr decoded = - testutil::Decode(encoded.data, encoded.size); + const ImagePtr decoded = testutil::Decode(encoded.data, encoded.size); ASSERT_NE(decoded, nullptr); ASSERT_EQ(decoded->clli.maxCLL, image->clli.maxCLL); ASSERT_EQ(decoded->clli.maxPALL, image->clli.maxPALL); @@ -31,4 +30,4 @@ TEST(ClliTest, Simple) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifcodectest.cc b/tests/gtest/avifcodectest.cc index ce67e721a6..22690e866b 100644 --- a/tests/gtest/avifcodectest.cc +++ b/tests/gtest/avifcodectest.cc @@ -5,7 +5,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { class CodecTest : public testing::TestWithParam< @@ -22,13 +22,13 @@ TEST_P(CodecTest, EncodeDecode) { } // AVIF_CODEC_CHOICE_SVT requires dimensions to be at least 64 pixels. - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/64, /*height=*/64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->codecChoice = encoding_codec; encoder->quality = encoder->qualityAlpha = 90; // Small loss. @@ -36,10 +36,10 @@ TEST_P(CodecTest, EncodeDecode) { ASSERT_EQ(avifEncoderWrite(encoder.get(), image.get(), &encoded), AVIF_RESULT_OK); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->codecChoice = decoding_codec; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size), @@ -58,4 +58,4 @@ INSTANTIATE_TEST_SUITE_P( AVIF_CODEC_CHOICE_LIBGAV1))); } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifcolrtest.cc b/tests/gtest/avifcolrtest.cc index dd04aac22a..7f57ac3b45 100644 --- a/tests/gtest/avifcolrtest.cc +++ b/tests/gtest/avifcolrtest.cc @@ -7,7 +7,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { constexpr int kMaxTransferCharacteristic = 18; @@ -111,4 +111,4 @@ TEST(TransferCharacteristicsTest, ToGammaHasCorrectShape) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifconitest.cc b/tests/gtest/avifconitest.cc index f547bc482f..a4079fa54f 100644 --- a/tests/gtest/avifconitest.cc +++ b/tests/gtest/avifconitest.cc @@ -8,7 +8,7 @@ using ::testing::Combine; using ::testing::Values; -namespace libavif { +namespace avif { namespace { //------------------------------------------------------------------------------ @@ -32,7 +32,7 @@ TEST_P(AvifCondensedImageBoxTest, SimpleOpaque) { const bool create_clli = std::get<9>(GetParam()); const avifTransformFlags create_transform_flags = std::get<10>(GetParam()); - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(width, height, depth, format, planes, range); ASSERT_NE(image, nullptr); testutil::FillImageGradient(image.get()); // The pixels do not matter. @@ -85,7 +85,7 @@ TEST_P(AvifCondensedImageBoxTest, SimpleOpaque) { // Encode. testutil::AvifRwData encoded_coni; - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; encoder->headerFormat = AVIF_HEADER_REDUCED; @@ -93,7 +93,7 @@ TEST_P(AvifCondensedImageBoxTest, SimpleOpaque) { AVIF_RESULT_OK); // Decode. - const testutil::AvifImagePtr decoded_coni = + const ImagePtr decoded_coni = testutil::Decode(encoded_coni.data, encoded_coni.size); ASSERT_NE(decoded_coni, nullptr); @@ -104,7 +104,7 @@ TEST_P(AvifCondensedImageBoxTest, SimpleOpaque) { // At least 200 bytes should be saved. EXPECT_LT(encoded_coni.size, encoded_meta.size - 200); - const testutil::AvifImagePtr decoded_meta = + const ImagePtr decoded_meta = testutil::Decode(encoded_meta.data, encoded_meta.size); ASSERT_NE(decoded_meta, nullptr); @@ -161,4 +161,4 @@ INSTANTIATE_TEST_SUITE_P( //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifdecodetest.cc b/tests/gtest/avifdecodetest.cc index 2d8b937fe1..285d9d3c0b 100644 --- a/tests/gtest/avifdecodetest.cc +++ b/tests/gtest/avifdecodetest.cc @@ -5,7 +5,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -17,7 +17,7 @@ TEST(AvifDecodeTest, ColorGridAlphaNoGrid) { } // Test case from https://github.com/AOMediaCodec/libavif/issues/1203. const char* file_name = "color_grid_alpha_nogrid.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderSetIOFile(decoder.get(), (std::string(data_path) + file_name).c_str()), @@ -31,7 +31,7 @@ TEST(AvifDecodeTest, ColorGridAlphaNoGrid) { } } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -41,6 +41,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifgainmaptest.cc b/tests/gtest/avifgainmaptest.cc index 6d885f6e0f..5bf903cc67 100644 --- a/tests/gtest/avifgainmaptest.cc +++ b/tests/gtest/avifgainmaptest.cc @@ -3,14 +3,20 @@ #include #include +#include +#include +#include +#include +#include #include "avif/avif.h" +#include "avif/avif_cxx.h" #include "avif/internal.h" #include "avifincrtest_helpers.h" #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { using ::testing::Values; @@ -63,23 +69,23 @@ avifGainMapMetadata GetTestGainMapMetadata(bool base_rendition_is_hdr) { return metadata; } -testutil::AvifImagePtr CreateTestImageWithGainMap(bool base_rendition_is_hdr) { - testutil::AvifImagePtr image = +ImagePtr CreateTestImageWithGainMap(bool base_rendition_is_hdr) { + ImagePtr image = testutil::CreateImage(/*width=*/12, /*height=*/34, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL); if (image == nullptr) { - return {nullptr, nullptr}; + return nullptr; } image->transferCharacteristics = (avifTransferCharacteristics)(base_rendition_is_hdr ? AVIF_TRANSFER_CHARACTERISTICS_SMPTE2084 : AVIF_TRANSFER_CHARACTERISTICS_SRGB); testutil::FillImageGradient(image.get()); - testutil::AvifImagePtr gain_map = + ImagePtr gain_map = testutil::CreateImage(/*width=*/6, /*height=*/17, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_YUV); if (gain_map == nullptr) { - return {nullptr, nullptr}; + return nullptr; } testutil::FillImageGradient(gain_map.get()); image->gainMap.image = gain_map.release(); // 'image' now owns the gain map. @@ -99,17 +105,16 @@ testutil::AvifImagePtr CreateTestImageWithGainMap(bool base_rendition_is_hdr) { } TEST(GainMapTest, EncodeDecodeBaseImageSdr) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = AVIF_TRUE; decoder->enableParsingGainMapMetadata = AVIF_TRUE; @@ -156,19 +161,18 @@ TEST(GainMapTest, EncodeDecodeBaseImageSdr) { } TEST(GainMapTest, EncodeDecodeBaseImageHdr) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/true); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/true); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = AVIF_TRUE; decoder->enableParsingGainMapMetadata = AVIF_TRUE; @@ -195,8 +199,7 @@ TEST(GainMapTest, EncodeDecodeBaseImageHdr) { } TEST(GainMapTest, EncodeDecodeMetadataSameDenominator) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/true); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/true); const uint32_t kDenominator = 1000; image->gainMap.metadata.baseHdrHeadroomD = kDenominator; @@ -209,16 +212,16 @@ TEST(GainMapTest, EncodeDecodeMetadataSameDenominator) { image->gainMap.metadata.gainMapMaxD[c] = kDenominator; } - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = AVIF_FALSE; decoder->enableParsingGainMapMetadata = AVIF_TRUE; @@ -233,8 +236,7 @@ TEST(GainMapTest, EncodeDecodeMetadataSameDenominator) { } TEST(GainMapTest, EncodeDecodeMetadataAllChannelsIdentical) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/true); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/true); for (int c = 0; c < 3; ++c) { image->gainMap.metadata.baseOffsetN[c] = 1; @@ -249,16 +251,16 @@ TEST(GainMapTest, EncodeDecodeMetadataAllChannelsIdentical) { image->gainMap.metadata.gainMapMaxD[c] = 10; } - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = AVIF_FALSE; decoder->enableParsingGainMapMetadata = AVIF_TRUE; @@ -273,7 +275,7 @@ TEST(GainMapTest, EncodeDecodeMetadataAllChannelsIdentical) { } TEST(GainMapTest, EncodeDecodeGrid) { - std::vector cells; + std::vector cells; std::vector cell_ptrs; std::vector gain_map_ptrs; constexpr int kGridCols = 2; @@ -285,14 +287,14 @@ TEST(GainMapTest, EncodeDecodeGrid) { GetTestGainMapMetadata(/*base_rendition_is_hdr=*/true); for (int i = 0; i < kGridCols * kGridRows; ++i) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(kCellWidth, kCellHeight, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); image->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SMPTE2084; // PQ testutil::FillImageGradient(image.get()); - testutil::AvifImagePtr gain_map = + ImagePtr gain_map = testutil::CreateImage(kCellWidth / 2, kCellHeight / 2, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_YUV); ASSERT_NE(gain_map, nullptr); @@ -307,7 +309,7 @@ TEST(GainMapTest, EncodeDecodeGrid) { cells.push_back(std::move(image)); } - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = @@ -319,9 +321,9 @@ TEST(GainMapTest, EncodeDecodeGrid) { ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = AVIF_TRUE; decoder->enableParsingGainMapMetadata = AVIF_TRUE; @@ -330,13 +332,13 @@ TEST(GainMapTest, EncodeDecodeGrid) { ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << decoder->diag.error; - testutil::AvifImagePtr merged = testutil::CreateImage( + ImagePtr merged = testutil::CreateImage( static_cast(decoded->width), static_cast(decoded->height), decoded->depth, decoded->yuvFormat, AVIF_PLANES_ALL); ASSERT_EQ(testutil::MergeGrid(kGridCols, kGridRows, cell_ptrs, merged.get()), AVIF_RESULT_OK); - testutil::AvifImagePtr merged_gain_map = + ImagePtr merged_gain_map = testutil::CreateImage(static_cast(decoded->gainMap.image->width), static_cast(decoded->gainMap.image->height), decoded->gainMap.image->depth, @@ -367,7 +369,7 @@ TEST(GainMapTest, EncodeDecodeGrid) { } TEST(GainMapTest, InvalidGrid) { - std::vector cells; + std::vector cells; std::vector cell_ptrs; constexpr int kGridCols = 2; constexpr int kGridRows = 2; @@ -376,14 +378,14 @@ TEST(GainMapTest, InvalidGrid) { GetTestGainMapMetadata(/*base_rendition_is_hdr=*/true); for (int i = 0; i < kGridCols * kGridRows; ++i) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/64, /*height=*/100, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); image->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SMPTE2084; // PQ testutil::FillImageGradient(image.get()); - testutil::AvifImagePtr gain_map = + ImagePtr gain_map = testutil::CreateImage(/*width=*/64, /*height=*/100, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_YUV); ASSERT_NE(gain_map, nullptr); @@ -397,7 +399,7 @@ TEST(GainMapTest, InvalidGrid) { cells.push_back(std::move(image)); } - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; @@ -433,14 +435,14 @@ TEST(GainMapTest, InvalidGrid) { } TEST(GainMapTest, SequenceNotSupported) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/64, /*height=*/100, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); image->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SMPTE2084; // PQ testutil::FillImageGradient(image.get()); - testutil::AvifImagePtr gain_map = + ImagePtr gain_map = testutil::CreateImage(/*width=*/64, /*height=*/100, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_YUV); ASSERT_NE(gain_map, nullptr); @@ -448,7 +450,7 @@ TEST(GainMapTest, SequenceNotSupported) { // 'image' now owns the gain map. image->gainMap.image = gain_map.release(); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; // Add a first frame. @@ -467,11 +469,10 @@ TEST(GainMapTest, SequenceNotSupported) { } TEST(GainMapTest, IgnoreGainMap) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); ASSERT_NE(image, nullptr); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); @@ -479,9 +480,9 @@ TEST(GainMapTest, IgnoreGainMap) { << avifResultToString(result) << " " << encoder->diag.error; // Decode image, with enableDecodingGainMap false by default. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); result = avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size); @@ -499,11 +500,10 @@ TEST(GainMapTest, IgnoreGainMap) { } TEST(GainMapTest, IgnoreGainMapButReadMetadata) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); ASSERT_NE(image, nullptr); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); @@ -511,9 +511,9 @@ TEST(GainMapTest, IgnoreGainMapButReadMetadata) { << avifResultToString(result) << " " << encoder->diag.error; // Decode image, with enableDecodingGainMap false by default. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableParsingGainMapMetadata = AVIF_TRUE; // Read gain map metadata. result = avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, @@ -533,20 +533,19 @@ TEST(GainMapTest, IgnoreGainMapButReadMetadata) { } TEST(GainMapTest, IgnoreColorAndAlpha) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); ASSERT_NE(image, nullptr); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); // Decode just the gain map. decoder->ignoreColorAndAlpha = AVIF_TRUE; @@ -575,18 +574,17 @@ TEST(GainMapTest, IgnoreColorAndAlpha) { } TEST(GainMapTest, IgnoreAll) { - testutil::AvifImagePtr image = - CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); + ImagePtr image = CreateTestImageWithGainMap(/*base_rendition_is_hdr=*/false); ASSERT_NE(image, nullptr); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); // Ignore both the main image and the gain map. decoder->ignoreColorAndAlpha = AVIF_TRUE; @@ -611,22 +609,22 @@ TEST(GainMapTest, IgnoreAll) { TEST(GainMapTest, NoGainMap) { // Create a simple image without a gain map. - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/12, /*height=*/34, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); image->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SRGB; testutil::FillImageGradient(image.get()); - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); testutil::AvifRwData encoded; avifResult result = avifEncoderWrite(encoder.get(), image.get(), &encoded); ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result) << " " << encoder->diag.error; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); // Enable gain map decoding. decoder->enableDecodingGainMap = AVIF_TRUE; @@ -647,7 +645,7 @@ TEST(GainMapTest, NoGainMap) { TEST(GainMapTest, DecodeGainMapGrid) { const std::string path = std::string(data_path) + "color_grid_gainmap_different_grid.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = true; decoder->enableParsingGainMapMetadata = true; @@ -686,9 +684,9 @@ TEST(GainMapTest, DecodeGainMapGrid) { TEST(GainMapTest, DecodeColorGridGainMapNoGrid) { const std::string path = std::string(data_path) + "color_grid_alpha_grid_gainmap_nogrid.avif"; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = true; decoder->enableParsingGainMapMetadata = true; @@ -709,9 +707,9 @@ TEST(GainMapTest, DecodeColorGridGainMapNoGrid) { TEST(GainMapTest, DecodeColorNoGridGainMapGrid) { const std::string path = std::string(data_path) + "color_nogrid_alpha_nogrid_gainmap_grid.avif"; - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = true; decoder->enableParsingGainMapMetadata = true; @@ -840,12 +838,12 @@ TEST(GainMapTest, CreateTestImages) { { const std::string path = std::string(data_path) + "seine_sdr_gainmap_srgb.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = true; decoder->enableParsingGainMapMetadata = true; - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); avifResult result = avifDecoderReadFile(decoder.get(), image.get(), path.c_str()); @@ -872,18 +870,17 @@ TEST(GainMapTest, CreateTestImages) { // Generate seine_hdr_gainmap_srgb.avif and seine_hdr_gainmap_small_srgb.avif { - testutil::AvifImagePtr hdr_image = + ImagePtr hdr_image = testutil::DecodFile(std::string(data_path) + "seine_hdr_srgb.avif"); ASSERT_NE(hdr_image, nullptr); const std::string sdr_path = std::string(data_path) + "seine_sdr_gainmap_srgb.avif"; - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = true; decoder->enableParsingGainMapMetadata = true; - testutil::AvifImagePtr sdr_with_gainmap(avifImageCreateEmpty(), - avifImageDestroy); + ImagePtr sdr_with_gainmap(avifImageCreateEmpty()); ASSERT_NE(sdr_with_gainmap, nullptr); avifResult result = avifDecoderReadFile( decoder.get(), sdr_with_gainmap.get(), sdr_path.c_str()); @@ -944,10 +941,9 @@ void ToneMapImageAndCompareToReference( SCOPED_TRACE("hdr_headroom: " + std::to_string(hdr_headroom)); testutil::AvifRgbImage tone_mapped_rgb(base_image, out_depth, out_rgb_format); - testutil::AvifImagePtr tone_mapped( + ImagePtr tone_mapped( avifImageCreate(tone_mapped_rgb.width, tone_mapped_rgb.height, - tone_mapped_rgb.depth, AVIF_PIXEL_FORMAT_YUV444), - avifImageDestroy); + tone_mapped_rgb.depth, AVIF_PIXEL_FORMAT_YUV444)); tone_mapped->transferCharacteristics = out_transfer_characteristics; tone_mapped->colorPrimaries = base_image->colorPrimaries; tone_mapped->matrixCoefficients = base_image->matrixCoefficients; @@ -993,16 +989,16 @@ TEST_P(ToneMapTest, ToneMapImage) { const float min_psnr = std::get<6>(GetParam()); const float max_psnr = std::get<7>(GetParam()); - testutil::AvifImagePtr reference_image = {nullptr, nullptr}; + ImagePtr reference_image = nullptr; if (!source.empty()) { reference_image = testutil::DecodFile(std::string(data_path) + reference); } // Load the source image (that should contain a gain map). const std::string path = std::string(data_path) + source; - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); decoder->enableDecodingGainMap = true; decoder->enableParsingGainMapMetadata = true; @@ -1139,10 +1135,10 @@ TEST_P(CreateGainMapTest, Create) { const std::string sdr_image_name = "seine_sdr_gainmap_srgb.avif"; const std::string hdr_image_name = "seine_hdr_gainmap_srgb.avif"; - testutil::AvifImagePtr sdr_image = + ImagePtr sdr_image = testutil::DecodFile(std::string(data_path) + sdr_image_name); ASSERT_NE(sdr_image, nullptr); - testutil::AvifImagePtr hdr_image = + ImagePtr hdr_image = testutil::DecodFile(std::string(data_path) + hdr_image_name); ASSERT_NE(hdr_image, nullptr); @@ -1152,10 +1148,8 @@ TEST_P(CreateGainMapTest, Create) { (uint32_t)std::round((float)sdr_image->height / downscaling), 1u); avifGainMap gain_map; memset(&gain_map, 0, sizeof(gain_map)); - testutil::AvifImagePtr gain_map_image( - avifImageCreate(gain_map_width, gain_map_height, gain_map_depth, - gain_map_format), - avifImageDestroy); + ImagePtr gain_map_image(avifImageCreate(gain_map_width, gain_map_height, + gain_map_depth, gain_map_format)); gain_map.image = gain_map_image.get(); avifDiagnostics diag; @@ -1261,7 +1255,7 @@ INSTANTIATE_TEST_SUITE_P( /*min_psnr=*/35.0f, /*max_psnr=*/45.0f))); } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -1271,6 +1265,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifgridapitest.cc b/tests/gtest/avifgridapitest.cc index 9c78ed42df..82c57230e6 100644 --- a/tests/gtest/avifgridapitest.cc +++ b/tests/gtest/avifgridapitest.cc @@ -8,7 +8,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // One AVIF cell in an AVIF grid. @@ -19,7 +19,7 @@ struct Cell { avifResult EncodeDecodeGrid(const std::vector>& cell_rows, avifPixelFormat yuv_format) { // Construct a grid. - std::vector cell_images; + std::vector cell_images; cell_images.reserve(cell_rows.size() * cell_rows.front().size()); for (const std::vector& cell_row : cell_rows) { assert(cell_row.size() == cell_rows.front().size()); @@ -34,7 +34,7 @@ avifResult EncodeDecodeGrid(const std::vector>& cell_rows, } // Encode the grid image (losslessly for easy pixel-by-pixel comparison). - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); if (!encoder) { return AVIF_RESULT_OUT_OF_MEMORY; } @@ -61,8 +61,8 @@ avifResult EncodeDecodeGrid(const std::vector>& cell_rows, } // Decode the grid image. - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + ImagePtr image(avifImageCreateEmpty()); + DecoderPtr decoder(avifDecoderCreate()); if (!image || !decoder) { return AVIF_RESULT_OUT_OF_MEMORY; } @@ -73,7 +73,7 @@ avifResult EncodeDecodeGrid(const std::vector>& cell_rows, } // Reconstruct the input image by merging all cells into a single avifImage. - testutil::AvifImagePtr grid = testutil::CreateImage( + ImagePtr grid = testutil::CreateImage( static_cast(image->width), static_cast(image->height), /*depth=*/8, yuv_format, AVIF_PLANES_ALL); const int num_rows = (int)cell_rows.size(); @@ -223,9 +223,9 @@ TEST(GridApiTest, CellsOfDifferentDimensions) { //------------------------------------------------------------------------------ TEST(GridApiTest, SameMatrixCoefficients) { - testutil::AvifImagePtr cell_0 = testutil::CreateImage( + ImagePtr cell_0 = testutil::CreateImage( 64, 64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); - testutil::AvifImagePtr cell_1 = testutil::CreateImage( + ImagePtr cell_1 = testutil::CreateImage( 1, 64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(cell_0, nullptr); ASSERT_NE(cell_1, nullptr); @@ -238,7 +238,7 @@ TEST(GridApiTest, SameMatrixCoefficients) { cell_0->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601; cell_1->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601; - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; const avifImage* cell_image_ptrs[2] = {cell_0.get(), cell_1.get()}; @@ -252,9 +252,9 @@ TEST(GridApiTest, SameMatrixCoefficients) { } TEST(GridApiTest, DifferentMatrixCoefficients) { - testutil::AvifImagePtr cell_0 = testutil::CreateImage( + ImagePtr cell_0 = testutil::CreateImage( 64, 64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); - testutil::AvifImagePtr cell_1 = testutil::CreateImage( + ImagePtr cell_1 = testutil::CreateImage( 1, 64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(cell_0, nullptr); ASSERT_NE(cell_1, nullptr); @@ -267,7 +267,7 @@ TEST(GridApiTest, DifferentMatrixCoefficients) { cell_0->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601; cell_1->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_UNSPECIFIED; - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; // Encoding should fail. @@ -279,4 +279,4 @@ TEST(GridApiTest, DifferentMatrixCoefficients) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifimagetest.cc b/tests/gtest/avifimagetest.cc index 43954ebcc4..44e9cefc65 100644 --- a/tests/gtest/avifimagetest.cc +++ b/tests/gtest/avifimagetest.cc @@ -8,18 +8,17 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { TEST(AvifImageTest, CreateEmpty) { - testutil::AvifImagePtr empty(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr empty(avifImageCreateEmpty()); EXPECT_NE(empty, nullptr); } bool IsValidAvifImageCreate(uint32_t width, uint32_t height, uint32_t depth, avifPixelFormat format) { - testutil::AvifImagePtr image(avifImageCreate(width, height, depth, format), - avifImageDestroy); + ImagePtr image(avifImageCreate(width, height, depth, format)); return image != nullptr; } @@ -41,7 +40,7 @@ TEST(AvifImageTest, Invalid) { } TEST(AvifImageTest, WriteImage) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/12, /*height=*/34, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); @@ -51,4 +50,4 @@ TEST(AvifImageTest, WriteImage) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifincrtest.cc b/tests/gtest/avifincrtest.cc index 18d6a887c2..a8e3b89e13 100644 --- a/tests/gtest/avifincrtest.cc +++ b/tests/gtest/avifincrtest.cc @@ -15,7 +15,7 @@ using testing::Bool; using testing::Combine; using testing::Values; -namespace libavif { +namespace avif { namespace { //------------------------------------------------------------------------------ @@ -45,9 +45,9 @@ testutil::AvifRwData ReadFile(const char* file_name) { TEST(IncrementalTest, Decode) { const testutil::AvifRwData encoded_avif = ReadFile("sofa_grid1x5_420.avif"); ASSERT_NE(encoded_avif.size, 0u); - testutil::AvifImagePtr reference(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr reference(avifImageCreateEmpty()); ASSERT_NE(reference, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), reference.get(), encoded_avif.data, encoded_avif.size), @@ -83,11 +83,11 @@ TEST_P(IncrementalTest, EncodeDecode) { const bool use_nth_image_api = std::get<6>(GetParam()); // Load an image. It does not matter that it comes from an AVIF file. - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); const testutil::AvifRwData image_bytes = ReadFile("sofa_grid1x5_420.avif"); ASSERT_NE(image_bytes.size, 0u); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), image.get(), image_bytes.data, image_bytes.size), @@ -139,7 +139,7 @@ INSTANTIATE_TEST_SUITE_P(SinglePixel, IncrementalTest, //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -149,6 +149,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifincrtest_helpers.cc b/tests/gtest/avifincrtest_helpers.cc index 42d53ae8a8..3fef504182 100644 --- a/tests/gtest/avifincrtest_helpers.cc +++ b/tests/gtest/avifincrtest_helpers.cc @@ -14,7 +14,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace testutil { namespace { @@ -206,7 +206,7 @@ void EncodeAsGrid(const avifImage& image, uint32_t grid_cols, *cell_height = image.height / grid_rows; } - std::vector cell_images; + std::vector cell_images; cell_images.reserve(grid_cols * grid_rows); for (uint32_t row = 0, i_cell = 0; row < grid_rows; ++row) { for (uint32_t col = 0; col < grid_cols; ++col, ++i_cell) { @@ -219,14 +219,14 @@ void EncodeAsGrid(const avifImage& image, uint32_t grid_cols, cell.height = ((cell.y + *cell_height) <= image.height) ? *cell_height : (image.height - cell.y); - cell_images.emplace_back(avifImageCreateEmpty(), avifImageDestroy); + cell_images.emplace_back(avifImageCreateEmpty()); ASSERT_NE(cell_images.back(), nullptr); ASSERT_EQ(avifImageSetViewRect(cell_images.back().get(), &image, &cell), AVIF_RESULT_OK); } } - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; // Just here to match libavif API. @@ -258,7 +258,7 @@ void EncodeRectAsIncremental(const avifImage& image, uint32_t width, uint32_t height, bool create_alpha_if_none, bool flat_cells, avifRWData* output, uint32_t* cell_width, uint32_t* cell_height) { - AvifImagePtr sub_image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr sub_image(avifImageCreateEmpty()); ASSERT_NE(sub_image, nullptr); ASSERT_LE(width, image.width); ASSERT_LE(height, image.height); @@ -364,7 +364,7 @@ void DecodeNonIncrementallyAndIncrementally( const avifRWData& encoded_avif, avifDecoder* decoder, bool is_persistent, bool give_size_hint, bool use_nth_image_api, uint32_t cell_height, bool enable_fine_incremental_check, bool expect_whole_file_read) { - AvifImagePtr reference(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr reference(avifImageCreateEmpty()); ASSERT_NE(reference, nullptr); decoder->allowIncremental = AVIF_FALSE; ASSERT_EQ(avifDecoderReadMemory(decoder, reference.get(), encoded_avif.data, @@ -379,4 +379,4 @@ void DecodeNonIncrementallyAndIncrementally( //------------------------------------------------------------------------------ } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifincrtest_helpers.h b/tests/gtest/avifincrtest_helpers.h index e8f938ff8b..fa4d35d236 100644 --- a/tests/gtest/avifincrtest_helpers.h +++ b/tests/gtest/avifincrtest_helpers.h @@ -8,7 +8,7 @@ #include "avif/avif.h" -namespace libavif { +namespace avif { namespace testutil { // Encodes a portion of the image to be decoded incrementally. @@ -42,6 +42,6 @@ void DecodeNonIncrementallyAndIncrementally( bool expect_whole_file_read = true); } // namespace testutil -} // namespace libavif +} // namespace avif #endif // LIBAVIF_TESTS_AVIFINCRTEST_HELPERS_H_ diff --git a/tests/gtest/avifiostatstest.cc b/tests/gtest/avifiostatstest.cc index 8e9d776026..4a1695d1fc 100644 --- a/tests/gtest/avifiostatstest.cc +++ b/tests/gtest/avifiostatstest.cc @@ -10,7 +10,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -21,8 +21,7 @@ const char* data_path = nullptr; bool GetIoStatsFromEncode(avifIOStats& encoder_io_stats, int quality, int qualityAlpha, bool translucent, int num_frames = 1, bool encode_as_grid = false) { - testutil::AvifImagePtr image = - testutil::ReadImage(data_path, "paris_exif_xmp_icc.jpg"); + ImagePtr image = testutil::ReadImage(data_path, "paris_exif_xmp_icc.jpg"); AVIF_CHECK(image != nullptr); if (translucent) { // Make up some alpha from luma. @@ -31,7 +30,7 @@ bool GetIoStatsFromEncode(avifIOStats& encoder_io_stats, int quality, AVIF_CHECK(!image->imageOwnsAlphaPlane); } - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); AVIF_CHECK(encoder != nullptr); encoder->speed = AVIF_SPEED_FASTEST; encoder->quality = quality; @@ -39,14 +38,12 @@ bool GetIoStatsFromEncode(avifIOStats& encoder_io_stats, int quality, for (int frame = 0; frame < num_frames; ++frame) { if (encode_as_grid) { const avifCropRect left_rect = {0, 0, image->width / 2, image->height}; - testutil::AvifImagePtr left_cell(avifImageCreateEmpty(), - avifImageDestroy); + ImagePtr left_cell(avifImageCreateEmpty()); AVIF_CHECK(avifImageSetViewRect(left_cell.get(), image.get(), &left_rect) == AVIF_RESULT_OK); const avifCropRect right_rect = {image->width / 2, 0, image->width / 2, image->height}; - testutil::AvifImagePtr right_cell(avifImageCreateEmpty(), - avifImageDestroy); + ImagePtr right_cell(avifImageCreateEmpty()); AVIF_CHECK(avifImageSetViewRect(right_cell.get(), image.get(), &right_rect) == AVIF_RESULT_OK); const std::array pointers = {left_cell.get(), @@ -72,7 +69,7 @@ bool GetIoStatsFromEncode(avifIOStats& encoder_io_stats, int quality, encoder_io_stats = encoder->ioStats; // Make sure decoding gives the same stats. - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); AVIF_CHECK(decoder != nullptr); AVIF_CHECK(avifDecoderSetIOMemory(decoder.get(), encoded.data, encoded.size) == AVIF_RESULT_OK); @@ -143,7 +140,7 @@ TEST(IoStatsTest, GridAnimation) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -153,6 +150,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifjpeggainmaptest.cc b/tests/gtest/avifjpeggainmaptest.cc index e88a6fa9d0..efad8cff34 100644 --- a/tests/gtest/avifjpeggainmaptest.cc +++ b/tests/gtest/avifjpeggainmaptest.cc @@ -8,7 +8,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -75,7 +75,7 @@ TEST(JpegTest, ReadJpegWithGainMap) { "paris_exif_xmp_gainmap_littleendian.jpg"}) { SCOPED_TRACE(filename); - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, filename, AVIF_PIXEL_FORMAT_YUV444, 8, AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, /*ignore_icc=*/false, /*ignore_exif=*/false, @@ -102,7 +102,7 @@ TEST(JpegTest, ReadJpegWithGainMap) { } TEST(JpegTest, IgnoreGainMap) { - const testutil::AvifImagePtr image = testutil::ReadImage( + const ImagePtr image = testutil::ReadImage( data_path, "paris_exif_xmp_gainmap_littleendian.jpg", AVIF_PIXEL_FORMAT_YUV444, 8, AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, /*ignore_icc=*/false, /*ignore_exif=*/false, @@ -307,7 +307,7 @@ TEST(JpegTest, EmptyXMP) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -317,6 +317,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/aviflosslesstest.cc b/tests/gtest/aviflosslesstest.cc index b75a5c650d..85dcf567ca 100644 --- a/tests/gtest/aviflosslesstest.cc +++ b/tests/gtest/aviflosslesstest.cc @@ -6,7 +6,7 @@ #include "avifutil.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -18,7 +18,7 @@ TEST(BasicTest, EncodeDecodeMatrixCoefficients) { {"paris_icc_exif_xmp.png", "paris_exif_xmp_icc.jpg"}) { // Read a ground truth image with default matrix coefficients. const std::string file_path = std::string(data_path) + file_name; - const testutil::AvifImagePtr ground_truth_image = + const ImagePtr ground_truth_image = testutil::ReadImage(data_path, file_name); for (auto matrix_coefficient : { @@ -28,7 +28,7 @@ TEST(BasicTest, EncodeDecodeMatrixCoefficients) { AVIF_MATRIX_COEFFICIENTS_IDENTITY, AVIF_MATRIX_COEFFICIENTS_YCGCO }) { // Read a ground truth image but ask for certain matrix coefficients. - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); image->matrixCoefficients = (avifMatrixCoefficients)matrix_coefficient; const avifAppFileFormat file_format = avifReadImage( @@ -52,7 +52,7 @@ TEST(BasicTest, EncodeDecodeMatrixCoefficients) { ASSERT_NE(file_format, AVIF_APP_FILE_FORMAT_UNKNOWN); // Encode. - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; encoder->quality = AVIF_QUALITY_LOSSLESS; @@ -63,9 +63,9 @@ TEST(BasicTest, EncodeDecodeMatrixCoefficients) { ASSERT_EQ(result, AVIF_RESULT_OK) << avifResultToString(result); // Decode to RAM. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); result = avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size); @@ -77,7 +77,7 @@ TEST(BasicTest, EncodeDecodeMatrixCoefficients) { const std::string temp_file = "decoded_default.png"; const std::string tmp_path = temp_dir + temp_file; ASSERT_TRUE(testutil::WriteImage(decoded.get(), tmp_path.c_str())); - const testutil::AvifImagePtr decoded_default = + const ImagePtr decoded_default = testutil::ReadImage(temp_dir.c_str(), temp_file.c_str()); // Verify that the ground truth and decoded images are the same. @@ -100,7 +100,7 @@ TEST(BasicTest, EncodeDecodeMatrixCoefficients) { } } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -110,6 +110,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifmetadatatest.cc b/tests/gtest/avifmetadatatest.cc index 2f7c68366c..e7914bf917 100644 --- a/tests/gtest/avifmetadatatest.cc +++ b/tests/gtest/avifmetadatatest.cc @@ -1,10 +1,14 @@ // Copyright 2022 Google LLC // SPDX-License-Identifier: BSD-2-Clause +#include #include +#include +#include #include #include "avif/avif.h" +#include "avif/avif_cxx.h" #include "avifjpeg.h" #include "avifpng.h" #include "aviftest_helpers.h" @@ -14,7 +18,7 @@ using ::testing::Bool; using ::testing::Combine; using ::testing::Values; -namespace libavif { +namespace avif { namespace { //------------------------------------------------------------------------------ @@ -36,7 +40,7 @@ TEST_P(AvifMetadataTest, EncodeDecode) { const bool use_exif = std::get<1>(GetParam()); const bool use_xmp = std::get<2>(GetParam()); - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/12, /*height=*/34, /*depth=*/10, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); ASSERT_NE(image, nullptr); @@ -67,7 +71,7 @@ TEST_P(AvifMetadataTest, EncodeDecode) { } // Encode. - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); ASSERT_NE(encoder, nullptr); encoder->speed = AVIF_SPEED_FASTEST; testutil::AvifRwData encoded_avif; @@ -75,9 +79,9 @@ TEST_P(AvifMetadataTest, EncodeDecode) { AVIF_RESULT_OK); // Decode. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), decoded.get(), encoded_avif.data, encoded_avif.size), @@ -102,19 +106,19 @@ INSTANTIATE_TEST_SUITE_P(All, AvifMetadataTest, //------------------------------------------------------------------------------ // Jpeg and PNG metadata tests -testutil::AvifImagePtr WriteAndReadImage(const avifImage& image, - const std::string& file_name) { +ImagePtr WriteAndReadImage(const avifImage& image, + const std::string& file_name) { const std::string file_path = testing::TempDir() + file_name; if (file_name.substr(file_name.size() - 4) == ".png") { if (!avifPNGWrite(file_path.c_str(), &image, /*requestedDepth=*/0, AVIF_CHROMA_UPSAMPLING_AUTOMATIC, /*compressionLevel=*/0)) { - return {nullptr, nullptr}; + return nullptr; } } else { if (!avifJPEGWrite(file_path.c_str(), &image, /*jpegQuality=*/100, AVIF_CHROMA_UPSAMPLING_AUTOMATIC)) { - return {nullptr, nullptr}; + return nullptr; } } return testutil::ReadImage(testing::TempDir().c_str(), file_name.c_str()); @@ -130,7 +134,7 @@ TEST_P(MetadataTest, ReadWriteReadCompare) { const bool use_exif = std::get<2>(GetParam()); const bool use_xmp = std::get<3>(GetParam()); - const testutil::AvifImagePtr image = testutil::ReadImage( + const ImagePtr image = testutil::ReadImage( data_path, file_name, AVIF_PIXEL_FORMAT_NONE, 0, AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, !use_icc, !use_exif, !use_xmp); ASSERT_NE(image, nullptr); @@ -160,7 +164,7 @@ TEST_P(MetadataTest, ReadWriteReadCompare) { // Writing and reading that same metadata should give the same bytes. for (const std::string extension : {".png", ".jpg"}) { - const testutil::AvifImagePtr temp_image = + const ImagePtr temp_image = WriteAndReadImage(*image, file_name + extension); ASSERT_NE(temp_image, nullptr); ASSERT_TRUE(testutil::AreByteSequencesEqual(image->icc, temp_image->icc)); @@ -178,8 +182,7 @@ INSTANTIATE_TEST_SUITE_P( // Verify all parsers lead exactly to the same metadata bytes. TEST(MetadataTest, Compare) { - const testutil::AvifImagePtr ref = - testutil::ReadImage(data_path, "paris_icc_exif_xmp.png"); + const ImagePtr ref = testutil::ReadImage(data_path, "paris_icc_exif_xmp.png"); ASSERT_NE(ref, nullptr); EXPECT_GT(ref->exif.size, 0u); EXPECT_GT(ref->xmp.size, 0u); @@ -187,8 +190,7 @@ TEST(MetadataTest, Compare) { for (const char* file_name : {"paris_exif_xmp_icc.jpg", "paris_icc_exif_xmp_at_end.png"}) { - const testutil::AvifImagePtr image = - testutil::ReadImage(data_path, file_name); + const ImagePtr image = testutil::ReadImage(data_path, file_name); ASSERT_NE(image, nullptr); EXPECT_TRUE(testutil::AreByteSequencesEqual(image->exif, ref->exif)); EXPECT_TRUE(testutil::AreByteSequencesEqual(image->xmp, ref->xmp)); @@ -216,7 +218,7 @@ TEST(MetadataTest, DecoderParseICC) { //------------------------------------------------------------------------------ TEST(MetadataTest, ExifButDefaultIrotImir) { - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "paris_exif_xmp_icc.jpg"); ASSERT_NE(image, nullptr); // The Exif metadata contains orientation information: 1. @@ -227,8 +229,7 @@ TEST(MetadataTest, ExifButDefaultIrotImir) { const testutil::AvifRwData encoded = testutil::Encode(image.get(), AVIF_SPEED_FASTEST); - const testutil::AvifImagePtr decoded = - testutil::Decode(encoded.data, encoded.size); + const ImagePtr decoded = testutil::Decode(encoded.data, encoded.size); ASSERT_NE(decoded, nullptr); // No irot/imir after decoding because 1 maps to default no irot/imir. @@ -239,7 +240,7 @@ TEST(MetadataTest, ExifButDefaultIrotImir) { } TEST(MetadataTest, ExifOrientation) { - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "paris_exif_orientation_5.jpg"); ASSERT_NE(image, nullptr); // The Exif metadata contains orientation information: 5. @@ -251,8 +252,7 @@ TEST(MetadataTest, ExifOrientation) { const testutil::AvifRwData encoded = testutil::Encode(image.get(), AVIF_SPEED_FASTEST); - const testutil::AvifImagePtr decoded = - testutil::Decode(encoded.data, encoded.size); + const ImagePtr decoded = testutil::Decode(encoded.data, encoded.size); ASSERT_NE(decoded, nullptr); // irot/imir are expected. @@ -264,7 +264,7 @@ TEST(MetadataTest, ExifOrientation) { EXPECT_EQ(decoded->imir.axis, 0u); // Exif orientation is kept in JPEG export. - testutil::AvifImagePtr temp_image = + ImagePtr temp_image = WriteAndReadImage(*image, "paris_exif_orientation_5.jpg"); ASSERT_NE(temp_image, nullptr); EXPECT_TRUE(testutil::AreByteSequencesEqual(image->exif, temp_image->exif)); @@ -285,7 +285,7 @@ TEST(MetadataTest, ExifOrientation) { } TEST(MetadataTest, ExifOrientationAndForcedImir) { - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "paris_exif_orientation_5.jpg"); ASSERT_NE(image, nullptr); // The Exif metadata contains orientation information: 5. @@ -297,8 +297,7 @@ TEST(MetadataTest, ExifOrientationAndForcedImir) { const testutil::AvifRwData encoded = testutil::Encode(image.get(), AVIF_SPEED_FASTEST); - const testutil::AvifImagePtr decoded = - testutil::Decode(encoded.data, encoded.size); + const ImagePtr decoded = testutil::Decode(encoded.data, encoded.size); ASSERT_NE(decoded, nullptr); // Exif orientation is still there but irot/imir do not match it. @@ -309,7 +308,7 @@ TEST(MetadataTest, ExifOrientationAndForcedImir) { // Exif orientation is set equivalent to irot/imir in JPEG export. // Existing Exif orientation is overwritten. - const testutil::AvifImagePtr temp_image = + const ImagePtr temp_image = WriteAndReadImage(*image, "paris_exif_orientation_2.jpg"); ASSERT_NE(temp_image, nullptr); EXPECT_FALSE(testutil::AreByteSequencesEqual(image->exif, temp_image->exif)); @@ -319,7 +318,7 @@ TEST(MetadataTest, ExifOrientationAndForcedImir) { } TEST(MetadataTest, RotatedJpegBecauseOfIrotImir) { - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "paris_exif_orientation_5.jpg"); ASSERT_NE(image, nullptr); EXPECT_EQ(avifImageSetMetadataExif(image.get(), nullptr, 0), @@ -331,7 +330,7 @@ TEST(MetadataTest, RotatedJpegBecauseOfIrotImir) { EXPECT_EQ(image->imir.axis, 0u); // No Exif metadata to store the orientation: the samples should be rotated. - const testutil::AvifImagePtr temp_image = + const ImagePtr temp_image = WriteAndReadImage(*image, "paris_exif_orientation_5.jpg"); ASSERT_NE(temp_image, nullptr); EXPECT_EQ(temp_image->exif.size, 0u); @@ -343,7 +342,7 @@ TEST(MetadataTest, RotatedJpegBecauseOfIrotImir) { } TEST(MetadataTest, ExifIfdOffsetLoopingTo8) { - const testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); + const ImagePtr image(avifImageCreateEmpty()); ASSERT_NE(image, nullptr); const uint8_t kBadExifPayload[128] = { 'M', 'M', 0, 42, // TIFF header @@ -365,7 +364,7 @@ TEST(MetadataTest, ExifIfdOffsetLoopingTo8) { //------------------------------------------------------------------------------ TEST(MetadataTest, ExtendedXMP) { - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "dog_exif_extended_xmp_icc.jpg"); ASSERT_NE(image, nullptr); ASSERT_NE(image->xmp.size, 0u); @@ -373,21 +372,19 @@ TEST(MetadataTest, ExtendedXMP) { size_t{65503}); // Fits in a single JPEG APP1 marker. for (const char* temp_file_name : {"dog.png", "dog.jpg"}) { - const testutil::AvifImagePtr temp_image = - WriteAndReadImage(*image, temp_file_name); + const ImagePtr temp_image = WriteAndReadImage(*image, temp_file_name); ASSERT_NE(temp_image, nullptr); EXPECT_TRUE(testutil::AreByteSequencesEqual(image->xmp, temp_image->xmp)); } } TEST(MetadataTest, MultipleExtendedXMPAndAlternativeGUIDTag) { - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "paris_extended_xmp.jpg"); ASSERT_NE(image, nullptr); ASSERT_GT(image->xmp.size, size_t{65536 * 2}); - testutil::AvifImagePtr temp_image = - WriteAndReadImage(*image, "paris_extended_xmp.png"); + ImagePtr temp_image = WriteAndReadImage(*image, "paris_extended_xmp.png"); ASSERT_NE(temp_image, nullptr); EXPECT_TRUE(testutil::AreByteSequencesEqual(image->xmp, temp_image->xmp)); @@ -402,8 +399,7 @@ TEST(MetadataTest, MultipleExtendedXMPAndAlternativeGUIDTag) { // Regression test for https://github.com/AOMediaCodec/libavif/issues/1333. // Coverage for avifImageFixXMP(). TEST(MetadataTest, XMPWithTrailingNullCharacter) { - testutil::AvifImagePtr jpg = - testutil::ReadImage(data_path, "paris_xmp_trailing_null.jpg"); + ImagePtr jpg = testutil::ReadImage(data_path, "paris_xmp_trailing_null.jpg"); ASSERT_NE(jpg, nullptr); ASSERT_NE(jpg->xmp.size, 0u); // avifJPEGRead() should strip the trailing null character. @@ -414,7 +410,7 @@ TEST(MetadataTest, XMPWithTrailingNullCharacter) { jpg->xmp.data[jpg->xmp.size - 1] = '\0'; testutil::WriteImage(jpg.get(), (testing::TempDir() + "xmp_trailing_null.png").c_str()); - const testutil::AvifImagePtr png = + const ImagePtr png = testutil::ReadImage(testing::TempDir().c_str(), "xmp_trailing_null.png"); ASSERT_NE(png, nullptr); ASSERT_NE(png->xmp.size, 0u); @@ -426,7 +422,7 @@ TEST(MetadataTest, XMPWithTrailingNullCharacter) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -436,6 +432,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifopaquetest.cc b/tests/gtest/avifopaquetest.cc index 5a48526f93..4889477963 100644 --- a/tests/gtest/avifopaquetest.cc +++ b/tests/gtest/avifopaquetest.cc @@ -5,15 +5,15 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { TEST(OpaqueTest, AlphaAndNoAlpha) { for (bool alpha_is_opaque : {false, true}) { for (int depth : {8, 10, 12}) { - testutil::AvifImagePtr alpha = testutil::CreateImage( + ImagePtr alpha = testutil::CreateImage( 1, 1, depth, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); - testutil::AvifImagePtr no_alpha = testutil::CreateImage( + ImagePtr no_alpha = testutil::CreateImage( 1, 1, depth, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_YUV); const uint32_t max_value = (1u << depth) - 1; @@ -28,4 +28,4 @@ TEST(OpaqueTest, AlphaAndNoAlpha) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifpng16bittest.cc b/tests/gtest/avifpng16bittest.cc index 1f31018085..65cdd88297 100644 --- a/tests/gtest/avifpng16bittest.cc +++ b/tests/gtest/avifpng16bittest.cc @@ -1,17 +1,20 @@ // Copyright 2022 Google LLC // SPDX-License-Identifier: BSD-2-Clause +#include +#include #include #include #include #include "avif/avif.h" +#include "avif/avif_cxx.h" #include "avifpng.h" #include "aviftest_helpers.h" #include "avifutil.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -20,10 +23,10 @@ const char* data_path = nullptr; //------------------------------------------------------------------------------ // Reads samples with an expected bit depth. -testutil::AvifImagePtr ReadImageLosslessBitDepth(const std::string& path, - uint32_t bit_depth) { - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); - if (!image) return {nullptr, nullptr}; +ImagePtr ReadImageLosslessBitDepth(const std::string& path, + uint32_t bit_depth) { + ImagePtr image(avifImageCreateEmpty()); + if (!image) return nullptr; // Lossless. image->yuvRange = AVIF_RANGE_FULL; image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_IDENTITY; @@ -37,7 +40,7 @@ testutil::AvifImagePtr ReadImageLosslessBitDepth(const std::string& path, image.get(), &output_depth, /*sourceTiming=*/nullptr, /*frameIter=*/nullptr) == AVIF_APP_FILE_FORMAT_UNKNOWN) { - return {nullptr, nullptr}; + return nullptr; } EXPECT_EQ(output_depth, bit_depth); EXPECT_EQ(image->depth, bit_depth); @@ -67,7 +70,7 @@ double GetSampleValueSpread(const avifImage& image, avifChannelIndex channel) { TEST(BitDepthTest, Png16b) { // Read 16-bit image. - testutil::AvifImagePtr original = + ImagePtr original = ReadImageLosslessBitDepth(std::string(data_path) + "weld_16bit.png", 16); ASSERT_NE(original, nullptr); // More than 75% of possible sample values are present in each channel. @@ -82,8 +85,7 @@ TEST(BitDepthTest, Png16b) { ASSERT_TRUE(avifPNGWrite(file_path.c_str(), original.get(), original->depth, AVIF_CHROMA_UPSAMPLING_AUTOMATIC, /*compressionLevel=*/0)); - testutil::AvifImagePtr image = - ReadImageLosslessBitDepth(file_path, original->depth); + ImagePtr image = ReadImageLosslessBitDepth(file_path, original->depth); ASSERT_NE(image, nullptr); // They should match exactly. @@ -93,7 +95,7 @@ TEST(BitDepthTest, Png16b) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -103,6 +105,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifprogressivetest.cc b/tests/gtest/avifprogressivetest.cc index 5d72c360b6..4cb92daf62 100644 --- a/tests/gtest/avifprogressivetest.cc +++ b/tests/gtest/avifprogressivetest.cc @@ -5,7 +5,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { class ProgressiveTest : public testing::Test { @@ -51,10 +51,10 @@ class ProgressiveTest : public testing::Test { // quality layer is more similar. } - testutil::AvifEncoderPtr encoder_{avifEncoderCreate(), avifEncoderDestroy}; - testutil::AvifDecoderPtr decoder_{avifDecoderCreate(), avifDecoderDestroy}; + EncoderPtr encoder_{avifEncoderCreate()}; + DecoderPtr decoder_{avifDecoderCreate()}; - testutil::AvifImagePtr image_ = + ImagePtr image_ = testutil::CreateImage(kImageSize, kImageSize, 8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_YUV, AVIF_RANGE_FULL); @@ -170,4 +170,4 @@ TEST_F(ProgressiveTest, TooFewLayers) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifrangetest.cc b/tests/gtest/avifrangetest.cc index da0556a845..b769560a68 100644 --- a/tests/gtest/avifrangetest.cc +++ b/tests/gtest/avifrangetest.cc @@ -9,7 +9,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { enum class InputType { kStillImage, kGrid, kAnimation }; @@ -18,13 +18,13 @@ enum class InputType { kStillImage, kGrid, kAnimation }; // in the "colr" box and in the AV1 OBU payload (in the "mdat" box). avifResult GenerateEncodedData(avifRange range, InputType input_type, testutil::AvifRwData* encoded) { - testutil::AvifImagePtr image = + ImagePtr image = testutil::CreateImage(/*width=*/64, /*height=*/64, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL, range); AVIF_CHECKERR(image != nullptr, AVIF_RESULT_OUT_OF_MEMORY); testutil::FillImageGradient(image.get()); // Pixel values do not matter. - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); AVIF_CHECKERR(encoder != nullptr, AVIF_RESULT_OUT_OF_MEMORY); if (input_type == InputType::kStillImage) { AVIF_CHECKRES(avifEncoderWrite(encoder.get(), image.get(), encoded)); @@ -84,9 +84,9 @@ TEST_P(RangeTest, DifferentVideoRangeInColrAndMdat) { // If colour information is supplied in both this [colr] box, and also in // the video bitstream, this box takes precedence, and over-rides the // information in the bitstream. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size), @@ -115,9 +115,9 @@ TEST_P(RangeTest, MissingColr) { } while (colr_box != encoded.data + encoded.size); // Make sure the AV1 OBU range is kept. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); + DecoderPtr decoder(avifDecoderCreate()); ASSERT_NE(decoder, nullptr); ASSERT_EQ(avifDecoderReadMemory(decoder.get(), decoded.get(), encoded.data, encoded.size), @@ -132,4 +132,4 @@ INSTANTIATE_TEST_SUITE_P( InputType::kAnimation))); } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifreadimagetest.cc b/tests/gtest/avifreadimagetest.cc index 80464631ec..b72d42b88e 100644 --- a/tests/gtest/avifreadimagetest.cc +++ b/tests/gtest/avifreadimagetest.cc @@ -9,7 +9,7 @@ #include "gtest/gtest.h" #include "iccmaker.h" -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -29,11 +29,11 @@ bool AreSamplesEqualForAllReadSettings(const char* file_name1, AVIF_CHROMA_DOWNSAMPLING_FASTEST, AVIF_CHROMA_DOWNSAMPLING_BEST_QUALITY, AVIF_CHROMA_DOWNSAMPLING_AVERAGE}) { - const testutil::AvifImagePtr image1 = testutil::ReadImage( + const ImagePtr image1 = testutil::ReadImage( data_path, file_name1, requested_format, requested_depth, chroma_downsampling, kIgnoreMetadata, kIgnoreMetadata, kIgnoreMetadata); - const testutil::AvifImagePtr image2 = testutil::ReadImage( + const ImagePtr image2 = testutil::ReadImage( data_path, file_name2, requested_format, requested_depth, chroma_downsampling, kIgnoreMetadata, kIgnoreMetadata, kIgnoreMetadata); @@ -58,8 +58,8 @@ TEST(PngTest, ReadAllSubsamplingsAndAllBitDepths) { // Verify we can read a PNG file with PNG_COLOR_TYPE_PALETTE and a tRNS chunk. TEST(PngTest, PaletteColorTypeWithTrnsChunk) { - const testutil::AvifImagePtr image = testutil::ReadImage( - data_path, "draw_points.png", AVIF_PIXEL_FORMAT_YUV444, 8); + const ImagePtr image = testutil::ReadImage(data_path, "draw_points.png", + AVIF_PIXEL_FORMAT_YUV444, 8); ASSERT_NE(image, nullptr); EXPECT_EQ(image->width, 33u); EXPECT_EQ(image->height, 11u); @@ -69,7 +69,7 @@ TEST(PngTest, PaletteColorTypeWithTrnsChunk) { // Verify we can read a PNG file with PNG_COLOR_TYPE_RGB and a tRNS chunk // after a PLTE chunk. TEST(PngTest, RgbColorTypeWithTrnsAfterPlte) { - const testutil::AvifImagePtr image = testutil::ReadImage( + const ImagePtr image = testutil::ReadImage( data_path, "circle-trns-after-plte.png", AVIF_PIXEL_FORMAT_YUV444, 8); ASSERT_NE(image, nullptr); EXPECT_EQ(image->width, 100u); @@ -81,7 +81,7 @@ TEST(PngTest, RgbColorTypeWithTrnsAfterPlte) { // before a PLTE chunk. libpng considers the tRNS chunk as invalid and ignores // it, so the decoded image should have no alpha. TEST(PngTest, RgbColorTypeWithTrnsBeforePlte) { - const testutil::AvifImagePtr image = testutil::ReadImage( + const ImagePtr image = testutil::ReadImage( data_path, "circle-trns-before-plte.png", AVIF_PIXEL_FORMAT_YUV444, 8); ASSERT_NE(image, nullptr); EXPECT_EQ(image->width, 100u); @@ -283,7 +283,7 @@ TEST(PngTest, GeneratedICCHash) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -293,6 +293,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifrgbtest.cc b/tests/gtest/avifrgbtest.cc index 791f628693..faaf47aba3 100644 --- a/tests/gtest/avifrgbtest.cc +++ b/tests/gtest/avifrgbtest.cc @@ -10,7 +10,7 @@ using ::testing::Combine; using ::testing::Values; -namespace libavif { +namespace avif { namespace { class SetGetRGBATest @@ -23,9 +23,8 @@ TEST_P(SetGetRGBATest, SetGetTest) { const bool is_float = std::get<2>(GetParam()); // Unused yuv image, simply needed to initialize the rgb image. - testutil::AvifImagePtr yuv( - avifImageCreate(/*width=*/13, /*height=*/17, 8, AVIF_PIXEL_FORMAT_YUV444), - avifImageDestroy); + ImagePtr yuv(avifImageCreate(/*width=*/13, /*height=*/17, 8, + AVIF_PIXEL_FORMAT_YUV444)); testutil::AvifRgbImage rgb(yuv.get(), rgb_depth, rgb_format); rgb.isFloat = is_float; @@ -88,7 +87,7 @@ TEST_P(SetGetRGBATest, GradientTest) { const bool is_float = std::get<2>(GetParam()); // Only used for convenience to generate RGB values. - testutil::AvifImagePtr yuv = + ImagePtr yuv = testutil::CreateImage(/*width=*/13, /*height=*/17, /*depth=*/8, AVIF_PIXEL_FORMAT_YUV444, AVIF_PLANES_ALL); testutil::FillImageGradient(yuv.get()); @@ -134,4 +133,4 @@ INSTANTIATE_TEST_SUITE_P( /*is_float=*/Values(true))); } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifrgbtoyuvtest.cc b/tests/gtest/avifrgbtoyuvtest.cc index b5f99af9d1..afe7aa8a68 100644 --- a/tests/gtest/avifrgbtoyuvtest.cc +++ b/tests/gtest/avifrgbtoyuvtest.cc @@ -15,7 +15,7 @@ using ::testing::Combine; using ::testing::Range; using ::testing::Values; -namespace libavif { +namespace avif { namespace { //------------------------------------------------------------------------------ @@ -131,8 +131,7 @@ void ConvertWholeRange(int rgb_depth, int yuv_depth, avifRGBFormat rgb_format, // to test all these possibilities. static constexpr int width = 4; static constexpr int height = 4; - testutil::AvifImagePtr yuv( - avifImageCreate(width, height, yuv_depth, yuv_format), avifImageDestroy); + ImagePtr yuv(avifImageCreate(width, height, yuv_depth, yuv_format)); ASSERT_NE(yuv, nullptr); yuv->matrixCoefficients = matrix_coefficients; yuv->yuvRange = yuv_range; @@ -248,9 +247,7 @@ void ConvertWholeBuffer(int rgb_depth, int yuv_depth, avifRGBFormat rgb_format, int64_t num_diffs = 0; for (int width : {1, 2, 127}) { for (int height : {1, 2, 251}) { - testutil::AvifImagePtr yuv( - avifImageCreate(width, height, yuv_depth, yuv_format), - avifImageDestroy); + ImagePtr yuv(avifImageCreate(width, height, yuv_depth, yuv_format)); ASSERT_NE(yuv, nullptr); yuv->matrixCoefficients = matrix_coefficients; yuv->yuvRange = yuv_range; @@ -760,8 +757,7 @@ TEST_P(YUVToRGBThreadingTest, TestIdentical) { return; } - testutil::AvifImagePtr yuv( - avifImageCreate(width, height, yuv_depth, yuv_format), avifImageDestroy); + ImagePtr yuv(avifImageCreate(width, height, yuv_depth, yuv_format)); ASSERT_NE(yuv, nullptr); yuv->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601; yuv->yuvRange = AVIF_RANGE_FULL; @@ -840,4 +836,4 @@ INSTANTIATE_TEST_SUITE_P( /*has_alpha=*/Bool())); } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avifscaletest.cc b/tests/gtest/avifscaletest.cc index 652e36a601..c55124168d 100644 --- a/tests/gtest/avifscaletest.cc +++ b/tests/gtest/avifscaletest.cc @@ -12,7 +12,7 @@ using testing::Combine; using testing::Values; -namespace libavif { +namespace avif { namespace { // Used to pass the data folder path to the GoogleTest suites. @@ -32,7 +32,7 @@ TEST_P(ScaleTest, Roundtrip) { const avifPixelFormat yuv_format = std::get<1>(GetParam()); const bool create_alpha = std::get<2>(GetParam()); - const testutil::AvifImagePtr image = + const ImagePtr image = testutil::ReadImage(data_path, "paris_exif_xmp_icc.jpg", yuv_format, bit_depth, AVIF_CHROMA_DOWNSAMPLING_BEST_QUALITY, kIgnoreMetadata, kIgnoreMetadata, kIgnoreMetadata); @@ -44,7 +44,7 @@ TEST_P(ScaleTest, Roundtrip) { image->imageOwnsAlphaPlane = false; } - testutil::AvifImagePtr scaled_image(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr scaled_image(avifImageCreateEmpty()); ASSERT_NE(scaled_image, nullptr); ASSERT_EQ(avifImageCopy(scaled_image.get(), image.get(), AVIF_PLANES_ALL), AVIF_RESULT_OK); @@ -79,7 +79,7 @@ INSTANTIATE_TEST_SUITE_P( /*create_alpha=*/Values(true, false))); TEST(ScaleTest, LargerThanDefaultLimits) { - const testutil::AvifImagePtr image = testutil::ReadImage( + const ImagePtr image = testutil::ReadImage( data_path, "paris_exif_xmp_icc.jpg", AVIF_PIXEL_FORMAT_YUV420, 8, AVIF_CHROMA_DOWNSAMPLING_BEST_QUALITY, kIgnoreMetadata, kIgnoreMetadata, kIgnoreMetadata); @@ -96,7 +96,7 @@ TEST(ScaleTest, LargerThanDefaultLimits) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -106,6 +106,6 @@ int main(int argc, char** argv) { << std::endl; return 1; } - libavif::data_path = argv[1]; + avif::data_path = argv[1]; return RUN_ALL_TESTS(); } diff --git a/tests/gtest/avifstreamtest.cc b/tests/gtest/avifstreamtest.cc index af94bb8281..79ff8b0ce9 100644 --- a/tests/gtest/avifstreamtest.cc +++ b/tests/gtest/avifstreamtest.cc @@ -10,7 +10,7 @@ #include "aviftest_helpers.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { //------------------------------------------------------------------------------ @@ -207,4 +207,4 @@ TEST(StreamTest, Roundtrip) { //------------------------------------------------------------------------------ } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/aviftest_helpers.cc b/tests/gtest/aviftest_helpers.cc index b7b28359b1..2cff4a3805 100644 --- a/tests/gtest/aviftest_helpers.cc +++ b/tests/gtest/aviftest_helpers.cc @@ -9,15 +9,17 @@ #include #include #include +#include #include #include #include "avif/avif.h" +#include "avif/avif_cxx.h" #include "avif/internal.h" #include "avifpng.h" #include "avifutil.h" -namespace libavif { +namespace avif { namespace testutil { //------------------------------------------------------------------------------ @@ -62,17 +64,16 @@ RgbChannelOffsets GetRgbChannelOffsets(avifRGBFormat format) { //------------------------------------------------------------------------------ -AvifImagePtr CreateImage(int width, int height, int depth, - avifPixelFormat yuv_format, avifPlanesFlags planes, - avifRange yuv_range) { - AvifImagePtr image(avifImageCreate(width, height, depth, yuv_format), - avifImageDestroy); +ImagePtr CreateImage(int width, int height, int depth, + avifPixelFormat yuv_format, avifPlanesFlags planes, + avifRange yuv_range) { + ImagePtr image(avifImageCreate(width, height, depth, yuv_format)); if (!image) { - return {nullptr, nullptr}; + return nullptr; } image->yuvRange = yuv_range; if (avifImageAllocatePlanes(image.get(), planes) != AVIF_RESULT_OK) { - return {nullptr, nullptr}; + return nullptr; } return image; } @@ -350,8 +351,7 @@ bool AreImagesEqual(const avifRGBImage& image1, const avifRGBImage& image2) { } avifResult MergeGrid(int grid_cols, int grid_rows, - const std::vector& cells, - avifImage* merged) { + const std::vector& cells, avifImage* merged) { std::vector ptrs(cells.size()); for (size_t i = 0; i < cells.size(); ++i) { ptrs[i] = cells[i].get(); @@ -369,7 +369,7 @@ avifResult MergeGrid(int grid_cols, int grid_rows, const uint32_t grid_height = (grid_rows - 1) * tile_height + cells.back()->height; - testutil::AvifImagePtr view(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr view(avifImageCreateEmpty()); AVIF_CHECKERR(view, AVIF_RESULT_OUT_OF_MEMORY); avifCropRect rect = {}; @@ -396,13 +396,13 @@ avifResult MergeGrid(int grid_cols, int grid_rows, //------------------------------------------------------------------------------ -AvifImagePtr ReadImage(const char* folder_path, const char* file_name, - avifPixelFormat requested_format, int requested_depth, - avifChromaDownsampling chroma_downsampling, - avifBool ignore_icc, avifBool ignore_exif, - avifBool ignore_xmp, avifBool allow_changing_cicp, - avifBool ignore_gain_map) { - testutil::AvifImagePtr image(avifImageCreateEmpty(), avifImageDestroy); +ImagePtr ReadImage(const char* folder_path, const char* file_name, + avifPixelFormat requested_format, int requested_depth, + avifChromaDownsampling chroma_downsampling, + avifBool ignore_icc, avifBool ignore_exif, + avifBool ignore_xmp, avifBool allow_changing_cicp, + avifBool ignore_gain_map) { + ImagePtr image(avifImageCreateEmpty()); if (!image || avifReadImage((std::string(folder_path) + file_name).c_str(), requested_format, requested_depth, chroma_downsampling, @@ -410,7 +410,7 @@ AvifImagePtr ReadImage(const char* folder_path, const char* file_name, ignore_gain_map, image.get(), /*outDepth=*/nullptr, /*sourceTiming=*/nullptr, /*frameIter=*/nullptr) == AVIF_APP_FILE_FORMAT_UNKNOWN) { - return {nullptr, nullptr}; + return nullptr; } return image; } @@ -428,7 +428,7 @@ bool WriteImage(const avifImage* image, const char* file_path) { } AvifRwData Encode(const avifImage* image, int speed, int quality) { - testutil::AvifEncoderPtr encoder(avifEncoderCreate(), avifEncoderDestroy); + EncoderPtr encoder(avifEncoderCreate()); if (!encoder) return {}; encoder->speed = speed; encoder->quality = quality; @@ -443,24 +443,24 @@ AvifRwData Encode(const avifImage* image, int speed, int quality) { return bytes; } -AvifImagePtr Decode(const uint8_t* bytes, size_t num_bytes) { - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); +ImagePtr Decode(const uint8_t* bytes, size_t num_bytes) { + ImagePtr decoded(avifImageCreateEmpty()); + DecoderPtr decoder(avifDecoderCreate()); if (!decoded || !decoder || (avifDecoderReadMemory(decoder.get(), decoded.get(), bytes, num_bytes) != AVIF_RESULT_OK)) { - return {nullptr, nullptr}; + return nullptr; } return decoded; } -AvifImagePtr DecodFile(const std::string& path) { - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); - testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy); +ImagePtr DecodFile(const std::string& path) { + ImagePtr decoded(avifImageCreateEmpty()); + DecoderPtr decoder(avifDecoderCreate()); if (!decoded || !decoder || (avifDecoderReadFile(decoder.get(), decoded.get(), path.c_str()) != AVIF_RESULT_OK)) { - return {nullptr, nullptr}; + return nullptr; } return decoded; } @@ -517,8 +517,8 @@ avifIO* AvifIOCreateLimitedReader(avifIO* underlyingIO, uint64_t clamp) { //------------------------------------------------------------------------------ -std::vector ImageToGrid(const avifImage* image, - uint32_t grid_cols, uint32_t grid_rows) { +std::vector ImageToGrid(const avifImage* image, uint32_t grid_cols, + uint32_t grid_rows) { if (image->width < grid_cols || image->height < grid_rows) return {}; // Round up, to make sure all samples are used by exactly one cell. @@ -535,7 +535,7 @@ std::vector ImageToGrid(const avifImage* image, cell_height = image->height / grid_rows; } - std::vector cells; + std::vector cells; for (uint32_t row = 0; row < grid_rows; ++row) { for (uint32_t col = 0; col < grid_cols; ++col) { avifCropRect rect{col * cell_width, row * cell_height, cell_width, @@ -550,7 +550,7 @@ std::vector ImageToGrid(const avifImage* image, if (rect.y + rect.height > image->height) { rect.height = image->height - rect.y; } - cells.emplace_back(avifImageCreateEmpty(), avifImageDestroy); + cells.emplace_back(avifImageCreateEmpty()); if (avifImageSetViewRect(cells.back().get(), image, &rect) != AVIF_RESULT_OK) { return {}; @@ -561,10 +561,10 @@ std::vector ImageToGrid(const avifImage* image, } std::vector UniquePtrToRawPtr( - const std::vector& unique_ptrs) { + const std::vector& unique_ptrs) { std::vector rawPtrs; rawPtrs.reserve(unique_ptrs.size()); - for (const AvifImagePtr& unique_ptr : unique_ptrs) { + for (const ImagePtr& unique_ptr : unique_ptrs) { rawPtrs.emplace_back(unique_ptr.get()); } return rawPtrs; @@ -573,4 +573,4 @@ std::vector UniquePtrToRawPtr( //------------------------------------------------------------------------------ } // namespace testutil -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/aviftest_helpers.h b/tests/gtest/aviftest_helpers.h index 16774694a8..9a0ca0dd83 100644 --- a/tests/gtest/aviftest_helpers.h +++ b/tests/gtest/aviftest_helpers.h @@ -5,14 +5,16 @@ #define LIBAVIF_TESTS_AVIFTEST_HELPERS_H_ #include +#include #include #include #include #include #include "avif/avif.h" +#include "avif/avif_cxx.h" -namespace libavif { +namespace avif { namespace testutil { //------------------------------------------------------------------------------ @@ -38,12 +40,6 @@ static const std::array kSampleXmp = { //------------------------------------------------------------------------------ // Memory management -using AvifImagePtr = std::unique_ptr; -using AvifEncoderPtr = - std::unique_ptr; -using AvifDecoderPtr = - std::unique_ptr; - class AvifRwData : public avifRWData { public: AvifRwData() : avifRWData{nullptr, 0} {} @@ -69,9 +65,9 @@ struct RgbChannelOffsets { RgbChannelOffsets GetRgbChannelOffsets(avifRGBFormat format); // Creates an image. Returns null in case of memory failure. -AvifImagePtr CreateImage(int width, int height, int depth, - avifPixelFormat yuv_format, avifPlanesFlags planes, - avifRange yuv_range = AVIF_RANGE_FULL); +ImagePtr CreateImage(int width, int height, int depth, + avifPixelFormat yuv_format, avifPlanesFlags planes, + avifRange yuv_range = AVIF_RANGE_FULL); // Set all pixels of each plane of an image. void FillImagePlain(avifImage* image, const uint32_t yuva[4]); @@ -103,7 +99,7 @@ double GetPsnr(const avifImage& image1, const avifImage& image2, // Merges the given image grid cells into a single image. avifResult MergeGrid(int grid_cols, int grid_rows, - const std::vector& cells, avifImage* merged); + const std::vector& cells, avifImage* merged); avifResult MergeGrid(int grid_cols, int grid_rows, const std::vector& cells, avifImage* merged); @@ -113,15 +109,15 @@ avifResult MergeGrid(int grid_cols, int grid_rows, // Reads the image named file_name located in directory at folder_path. // Returns nullptr in case of error. -AvifImagePtr ReadImage( - const char* folder_path, const char* file_name, - avifPixelFormat requested_format = AVIF_PIXEL_FORMAT_NONE, - int requested_depth = 0, - avifChromaDownsampling chroma_downsampling = - AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, - avifBool ignore_icc = false, avifBool ignore_exif = false, - avifBool ignore_xmp = false, avifBool allow_changing_cicp = true, - avifBool ignore_gain_map = false); +ImagePtr ReadImage(const char* folder_path, const char* file_name, + avifPixelFormat requested_format = AVIF_PIXEL_FORMAT_NONE, + int requested_depth = 0, + avifChromaDownsampling chroma_downsampling = + AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, + avifBool ignore_icc = false, avifBool ignore_exif = false, + avifBool ignore_xmp = false, + avifBool allow_changing_cicp = true, + avifBool ignore_gain_map = false); // Convenient wrapper around avifPNGWrite() for debugging purposes. // Do not remove. bool WriteImage(const avifImage* image, const char* file_path); @@ -133,11 +129,11 @@ AvifRwData Encode(const avifImage* image, int speed = AVIF_SPEED_DEFAULT, // Decodes the bytes to an image with default parameters. // Returns nullptr in case of error. -AvifImagePtr Decode(const uint8_t* bytes, size_t num_bytes); +ImagePtr Decode(const uint8_t* bytes, size_t num_bytes); // Decodes the file to an image with default parameters. // Returns nullptr in case of error. -AvifImagePtr DecodFile(const std::string& path); +ImagePtr DecodFile(const std::string& path); // Returns true if an AV1 encoder is available. bool Av1EncoderAvailable(); @@ -162,16 +158,16 @@ avifIO* AvifIOCreateLimitedReader(avifIO* underlyingIO, uint64_t clamp); // Splits the input image into grid_cols*grid_rows views to be encoded as a // grid. Returns an empty vector if the input image cannot be split that way. -std::vector ImageToGrid(const avifImage* image, - uint32_t grid_cols, uint32_t grid_rows); +std::vector ImageToGrid(const avifImage* image, uint32_t grid_cols, + uint32_t grid_rows); // Converts a unique_ptr array to a raw pointer array as needed by libavif API. std::vector UniquePtrToRawPtr( - const std::vector& unique_ptrs); + const std::vector& unique_ptrs); //------------------------------------------------------------------------------ } // namespace testutil -} // namespace libavif +} // namespace avif #endif // LIBAVIF_TESTS_AVIFTEST_HELPERS_H_ diff --git a/tests/gtest/avifutilstest.cc b/tests/gtest/avifutilstest.cc index cd6b1f5f2c..b5da9cd065 100644 --- a/tests/gtest/avifutilstest.cc +++ b/tests/gtest/avifutilstest.cc @@ -6,7 +6,7 @@ #include "avif/internal.h" #include "gtest/gtest.h" -namespace libavif { +namespace avif { namespace { // Converts a double value to a fraction, and checks that the difference @@ -144,4 +144,4 @@ TEST(ToFractionTest, BadValues) { } } // namespace -} // namespace libavif +} // namespace avif diff --git a/tests/gtest/avify4mtest.cc b/tests/gtest/avify4mtest.cc index 376dc0600d..ad89c19257 100644 --- a/tests/gtest/avify4mtest.cc +++ b/tests/gtest/avify4mtest.cc @@ -12,7 +12,7 @@ using testing::Combine; using testing::Values; -namespace libavif { +namespace avif { namespace { class Y4mTest @@ -33,7 +33,7 @@ TEST_P(Y4mTest, EncodeDecode) { << height << "_" << bit_depth << "_" << yuv_format << "_" << yuv_range << "_" << create_alpha; - testutil::AvifImagePtr image = testutil::CreateImage( + ImagePtr image = testutil::CreateImage( width, height, bit_depth, yuv_format, create_alpha ? AVIF_PLANES_ALL : AVIF_PLANES_YUV, yuv_range); ASSERT_NE(image, nullptr); @@ -48,7 +48,7 @@ TEST_P(Y4mTest, EncodeDecode) { testutil::FillImagePlain(image.get(), yuva); ASSERT_TRUE(y4mWrite(file_path.str().c_str(), image.get())); - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); ASSERT_TRUE(y4mRead(file_path.str().c_str(), decoded.get(), /*sourceTiming=*/nullptr, /*iter=*/nullptr)); @@ -68,7 +68,7 @@ TEST_P(Y4mTest, OutOfRange) { << height << "_" << bit_depth << "_" << yuv_format << "_" << yuv_range << "_" << create_alpha; - testutil::AvifImagePtr image = testutil::CreateImage( + ImagePtr image = testutil::CreateImage( width, height, bit_depth, yuv_format, create_alpha ? AVIF_PLANES_ALL : AVIF_PLANES_YUV, yuv_range); ASSERT_NE(image, nullptr); @@ -85,7 +85,7 @@ TEST_P(Y4mTest, OutOfRange) { // to avoid computation with unexpected sample values. However, it does not // respect the limited ("video") range because the libavif API just passes // that tag along, it is ignored by the compression algorithm. - testutil::AvifImagePtr decoded(avifImageCreateEmpty(), avifImageDestroy); + ImagePtr decoded(avifImageCreateEmpty()); ASSERT_NE(decoded, nullptr); ASSERT_TRUE(y4mRead(file_path.str().c_str(), decoded.get(), /*sourceTiming=*/nullptr, /*iter=*/nullptr)); @@ -116,4 +116,4 @@ INSTANTIATE_TEST_SUITE_P(AlphaCombinations, Y4mTest, /*create_alpha=*/Values(true))); } // namespace -} // namespace libavif +} // namespace avif