@@ -34,26 +34,31 @@ class ProgressiveTest : public testing::Test {
3434 }
3535
3636 void TestDecode (uint8_t * data, size_t size, uint32_t expect_width,
37- uint32_t expect_height) {
37+ uint32_t expect_height, bool expect_alpha = false ) {
3838 ASSERT_EQ (avifDecoderSetIOMemory (decoder_.get (), data, size),
3939 AVIF_RESULT_OK);
4040 ASSERT_EQ (avifDecoderParse (decoder_.get ()), AVIF_RESULT_OK);
4141 ASSERT_EQ (decoder_->progressiveState , AVIF_PROGRESSIVE_STATE_ACTIVE);
4242 ASSERT_EQ (static_cast <uint32_t >(decoder_->imageCount ),
4343 encoder_->extraLayerCount + 1 );
44+ EXPECT_EQ (decoder_->alphaPresent , expect_alpha);
4445
4546 for (uint32_t layer = 0 ; layer < encoder_->extraLayerCount + 1 ; ++layer) {
4647 ASSERT_EQ (avifDecoderNextImage (decoder_.get ()), AVIF_RESULT_OK);
4748 // libavif scales frame automatically.
4849 ASSERT_EQ (decoder_->image ->width , expect_width);
4950 ASSERT_EQ (decoder_->image ->height , expect_height);
51+ if (expect_alpha) {
52+ ASSERT_NE (decoder_->image ->alphaPlane , nullptr );
53+ }
5054 // TODO(wtc): Check avifDecoderNthImageMaxExtent().
5155 }
5256 }
5357
54- void TestDecode (uint32_t expect_width, uint32_t expect_height) {
58+ void TestDecode (uint32_t expect_width, uint32_t expect_height,
59+ bool expect_alpha = false ) {
5560 TestDecode (encoded_avif_.data , encoded_avif_.size , expect_width,
56- expect_height);
61+ expect_height, expect_alpha );
5762
5863 // TODO(wtc): Check decoder_->image and image_ are similar, and better
5964 // quality layer is more similar.
@@ -147,6 +152,41 @@ TEST_F(ProgressiveTest, DimensionChange) {
147152 TestDecode (kImageSize , kImageSize );
148153}
149154
155+ TEST_F (ProgressiveTest, DimensionChangeWithAlpha) {
156+ if (avifLibYUVVersion () == 0 ) {
157+ GTEST_SKIP () << " libyuv not available, skip test." ;
158+ }
159+
160+ const auto image =
161+ testutil::CreateImage (kImageSize , kImageSize , 8 , AVIF_PIXEL_FORMAT_YUV444,
162+ AVIF_PLANES_ALL, AVIF_RANGE_FULL);
163+ ASSERT_NE (image, nullptr );
164+ testutil::FillImageGradient (image.get ());
165+
166+ encoder_->extraLayerCount = 2 ;
167+ encoder_->quality = 100 ;
168+ encoder_->scalingMode = {{1 , 2 }, {1 , 2 }};
169+
170+ ASSERT_EQ (avifEncoderAddImage (encoder_.get (), image.get (), 1 ,
171+ AVIF_ADD_IMAGE_FLAG_NONE),
172+ AVIF_RESULT_OK);
173+
174+ // Encode the small image twice to verify frame buffer reallocation
175+ // behavior during decode
176+ ASSERT_EQ (avifEncoderAddImage (encoder_.get (), image.get (), 1 ,
177+ AVIF_ADD_IMAGE_FLAG_NONE),
178+ AVIF_RESULT_OK);
179+
180+ encoder_->scalingMode = {{1 , 1 }, {1 , 1 }};
181+ ASSERT_EQ (avifEncoderAddImage (encoder_.get (), image.get (), 1 ,
182+ AVIF_ADD_IMAGE_FLAG_NONE),
183+ AVIF_RESULT_OK);
184+
185+ ASSERT_EQ (avifEncoderFinish (encoder_.get (), &encoded_avif_), AVIF_RESULT_OK);
186+
187+ TestDecode (kImageSize , kImageSize , /* expect_alpha=*/ true );
188+ }
189+
150190TEST_F (ProgressiveTest, LayeredGrid) {
151191 encoder_->extraLayerCount = 1 ;
152192 encoder_->quality = 21 ;
0 commit comments