Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing frame size during encoding #1069

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Two (failing) progressive encoding tests
  • Loading branch information
tongyuantongyu committed Mar 3, 2023
commit 86382ae2b07e1205f011a21eac27ce030aed5495
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ if(AVIF_ENABLE_GTEST)
add_test(NAME avifpng16bittest COMMAND avifpng16bittest ${CMAKE_CURRENT_SOURCE_DIR}/data/)

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

add_executable(avifreadimagetest gtest/avifreadimagetest.cc)
target_link_libraries(avifreadimagetest aviftest_helpers ${GTEST_LIBRARIES})
Expand Down
Binary file added tests/data/dog_1080p.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/dog_blur_1080p.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions tests/gtest/avifprogressivetest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
// SPDX-License-Identifier: BSD-2-Clause

#include "avif/avif.h"
#include "avifjpeg.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;

class ProgressiveTest : public testing::Test {
protected:
static constexpr uint32_t kImageSize = 256;
Expand Down Expand Up @@ -169,5 +175,67 @@ TEST_F(ProgressiveTest, TooFewLayers) {
AVIF_RESULT_INVALID_ARGUMENT);
}

TEST_F(ProgressiveTest, DimensionChangeLargeImageMultiThread) {
encoder_->speed = 6;
encoder_->maxThreads = 2;
encoder_->extraLayerCount = 1;

image_ = testutil::CreateImage(1920, 1080, 8, AVIF_PIXEL_FORMAT_YUV420,
AVIF_PLANES_YUV, AVIF_RANGE_FULL);

encoder_->scalingMode = {{1, 2}, {1, 2}};
ASSERT_EQ(avifEncoderAddImage(encoder_.get(), image_.get(), 1,
AVIF_ADD_IMAGE_FLAG_NONE),
AVIF_RESULT_OK);

encoder_->scalingMode = {{1, 1}, {1, 1}};
ASSERT_EQ(avifEncoderAddImage(encoder_.get(), image_.get(), 1,
AVIF_ADD_IMAGE_FLAG_NONE),
AVIF_RESULT_OK);

ASSERT_EQ(avifEncoderFinish(encoder_.get(), &encoded_avif_), AVIF_RESULT_OK);

TestDecode(1920, 1080);
}

TEST_F(ProgressiveTest, DimensionChangeLargeImageSlowSpeedDifferentImage) {
encoder_->speed = 2;
encoder_->maxThreads = 1;
encoder_->extraLayerCount = 1;

auto layer1 = testutil::ReadImage(
data_path, "dog_blur_1080p.jpg", AVIF_PIXEL_FORMAT_YUV420, 8,
AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, false, false, false);
auto layer2 = testutil::ReadImage(
data_path, "dog_1080p.jpg", AVIF_PIXEL_FORMAT_YUV420, 8,
AVIF_CHROMA_DOWNSAMPLING_AUTOMATIC, false, false, false);

encoder_->scalingMode = {{1, 2}, {1, 2}};
ASSERT_EQ(avifEncoderAddImage(encoder_.get(), layer1.get(), 1,
AVIF_ADD_IMAGE_FLAG_NONE),
AVIF_RESULT_OK);

encoder_->scalingMode = {{1, 1}, {1, 1}};
ASSERT_EQ(avifEncoderAddImage(encoder_.get(), layer2.get(), 1,
AVIF_ADD_IMAGE_FLAG_NONE),
AVIF_RESULT_OK);

ASSERT_EQ(avifEncoderFinish(encoder_.get(), &encoded_avif_), AVIF_RESULT_OK);

TestDecode(1920, 1080);
}

} // 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();
}