Skip to content

Commit

Permalink
Add test for animated image decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshvg committed Sep 18, 2023
1 parent c1312cf commit 8097738
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ if(AVIF_ENABLE_GTEST)
target_include_directories(avifalphapremtest PRIVATE ${GTEST_INCLUDE_DIRS})
add_test(NAME avifalphapremtest COMMAND avifalphapremtest)

add_executable(avifanimationtest gtest/avifanimationtest.cc)
target_link_libraries(avifanimationtest aviftest_helpers ${GTEST_LIBRARIES})
target_include_directories(avifanimationtest PRIVATE ${GTEST_INCLUDE_DIRS})
add_test(NAME avifanimationtest COMMAND avifanimationtest ${CMAKE_CURRENT_SOURCE_DIR}/data/)

add_executable(avifbasictest gtest/avifbasictest.cc)
target_link_libraries(avifbasictest aviftest_helpers ${GTEST_BOTH_LIBRARIES})
target_include_directories(avifbasictest PRIVATE ${GTEST_INCLUDE_DIRS})
Expand Down
18 changes: 18 additions & 0 deletions tests/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,24 @@ Source: Same pixels as `color_grid_alpha_nogrid.avif` encoded with
[`cavif-rs`](https://github.com/kornelski/cavif-rs) with the
[alpha `ispe` fix](https://github.com/kornelski/avif-serialize/pull/4) removed.

## Animated Images

### File [colors-animated-8bpc.avif](colors-animated-8bpc.avif)

![](colors-animated-8bpc.avif)

License: [same as libavif](https://github.com/AOMediaCodec/libavif/blob/main/LICENSE)

Source: Random colors generated with ffmpeg.

An animated AVIF image file with the following attributes:
* Width: 150
* Height: 150
* Alpha present: No
* YUV Format: 420
* Repetition Count: 0
* Frame count: 5

# Other Test Files

### File [sRGB2014.icc](sRGB2014.icc)
Expand Down
Binary file added tests/data/colors-animated-8bpc.avif
Binary file not shown.
46 changes: 46 additions & 0 deletions tests/gtest/avifanimationtest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2023 Google LLC
// SPDX-License-Identifier: BSD-2-Clause

#include "avif/avif.h"
#include "aviftest_helpers.h"
#include "gtest/gtest.h"

namespace libavif {
namespace {

// Used to pass the data folder path to the GoogleTest suites.
const char* data_path = nullptr;

TEST(AvifDecodeTest, AnimatedImage) {
if (!testutil::Av1DecoderAvailable()) {
GTEST_SKIP() << "AV1 Codec unavailable, skip test.";
}
const char* file_name = "colors-animated-8bpc.avif";
testutil::AvifDecoderPtr decoder(avifDecoderCreate(), avifDecoderDestroy);
ASSERT_NE(decoder, nullptr);
ASSERT_EQ(avifDecoderSetIOFile(decoder.get(),
(std::string(data_path) + file_name).c_str()),
AVIF_RESULT_OK);
ASSERT_EQ(avifDecoderParse(decoder.get()), AVIF_RESULT_OK);
EXPECT_EQ(decoder->alphaPresent, AVIF_FALSE);
EXPECT_EQ(decoder->imageCount, 5);
EXPECT_EQ(decoder->repetitionCount, 0);
for (int i = 0; i < 5; ++i) {
EXPECT_EQ(avifDecoderNextImage(decoder.get()), AVIF_RESULT_OK);
}
}

} // namespace
} // namespace libavif

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
if (argc != 2) {
std::cerr << "There must be exactly one argument containing the path to "
"the test data folder"
<< std::endl;
return 1;
}
libavif::data_path = argv[1];
return RUN_ALL_TESTS();
}

0 comments on commit 8097738

Please sign in to comment.