Skip to content

Commit

Permalink
Parse image metadata when all data is received
Browse files Browse the repository at this point in the history
Change AVIFImageDecoder::OnSetData() to parse the image metadata
automatically when all data is received. This meets the expectations of
ImageFrameGenerator::GetYUVAInfo() and
ImageFrameGenerator::DecodeToYUV().

In the ReadYUV() function in avif_image_decoder_test.cc, change the
IsSizeAvailable() call (which calls DecodeSize()) to
IsDecodedSizeAvailable() (which has no side effects) and call a few more
getter methods related to DecodeToYUV() to emulate the code in
ImageFrameGenerator::GetYUVAInfo() and
ImageFrameGenerator::DecodeToYUV().

Bug: 1149144
Bug: 1136922
Change-Id: I3790de99fd0e9745c4b3ab9555aa027f25a6d374
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2539329
Reviewed-by: Dale Curtis <[email protected]>
Reviewed-by: Peter Kasting <[email protected]>
Commit-Queue: Wan-Teh Chang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#827852}
GitOrigin-RevId: a3d98a6fa591c8d337812203e05eddcec78c6cdb
  • Loading branch information
wantehchang authored and copybara-github committed Nov 16, 2020
1 parent 16c5c4c commit 88f0676
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ void AVIFImageDecoder::OnSetData(SegmentReader* data) {
avif_io_data_.reader = data_.get();
avif_io_data_.all_data_received = all_data_received;
avif_io_.sizeHint = all_data_received ? data_->size() : kMaxAvifFileSize;

// ImageFrameGenerator::GetYUVAInfo() and ImageFrameGenerator::DecodeToYUV()
// assume that allow_decode_to_yuv_ and other image metadata are available
// after calling ImageDecoder::Create() with data_complete=true.
if (all_data_received)
ParseMetadata();
}

cc::YUVSubsampling AVIFImageDecoder::GetYUVSubsampling() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,12 @@ void ReadYUV(const char* file_name,
auto decoder = CreateAVIFDecoder();
decoder->SetData(data.get(), true);

ASSERT_TRUE(decoder->IsSizeAvailable());
ASSERT_TRUE(decoder->IsDecodedSizeAvailable());
ASSERT_TRUE(decoder->CanDecodeToYUV());
EXPECT_NE(decoder->GetYUVSubsampling(), cc::YUVSubsampling::kUnknown);
EXPECT_NE(decoder->GetYUVColorSpace(),
SkYUVColorSpace::kIdentity_SkYUVColorSpace);
EXPECT_EQ(decoder->GetYUVBitDepth(), bit_depth);

IntSize size = decoder->DecodedSize();
IntSize y_size = decoder->DecodedYUVSize(cc::YUVIndex::kY);
Expand Down

0 comments on commit 88f0676

Please sign in to comment.