Commit 8a91dcfb authored by Wan-Teh Chang's avatar Wan-Teh Chang Committed by Commit Bot

Remove the pending_decoded_image_ member

Remove the pending_decoded_image_ member of AVIFImageDecoder. It is
apparently intended to avoid calling avifDecoderNthImage() with index 0
twice. But libavif allows us to do that, and the second call will return
immediately.

Move the SetSize() call and size check out of DecodeImage() to the two
call sites.

Bug: 960620
Change-Id: I4c7beaed4ca5aa8040aa7b3cb2facd92e18eb38f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161871Reviewed-by: default avatarLeon Scroggins <scroggo@google.com>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Cr-Commit-Position: refs/heads/master@{#762028}
parent 8687ab28
...@@ -289,18 +289,15 @@ void AVIFImageDecoder::Decode(size_t index) { ...@@ -289,18 +289,15 @@ void AVIFImageDecoder::Decode(size_t index) {
return; return;
} }
if (frame_buffer_cache_.IsEmpty()) { const auto* image = decoder_->image;
// We're just decoding metadata. // All frames must be the same size.
DCHECK_EQ(index, 0u); if (Size() != IntSize(image->width, image->height)) {
pending_decoded_image_ = true; SetFailed();
return; return;
} }
pending_decoded_image_ = false;
ImageFrame& buffer = frame_buffer_cache_[index]; ImageFrame& buffer = frame_buffer_cache_[index];
DCHECK_NE(buffer.GetStatus(), ImageFrame::kFrameComplete); DCHECK_NE(buffer.GetStatus(), ImageFrame::kFrameComplete);
const auto* image = decoder_->image;
buffer.SetHasAlpha(!!image->alphaPlane); buffer.SetHasAlpha(!!image->alphaPlane);
if (decode_to_half_float_) if (decode_to_half_float_)
buffer.SetPixelFormat(ImageFrame::PixelFormat::kRGBA_F16); buffer.SetPixelFormat(ImageFrame::PixelFormat::kRGBA_F16);
...@@ -382,19 +379,21 @@ void AVIFImageDecoder::MaybeCreateDemuxer() { ...@@ -382,19 +379,21 @@ void AVIFImageDecoder::MaybeCreateDemuxer() {
} }
// We need to SetSize() to proceed, so decode the first frame. // We need to SetSize() to proceed, so decode the first frame.
Decode(0); if (!DecodeImage(0)) {
SetFailed();
return;
}
SetSize(decoder_->image->width, decoder_->image->height);
} }
bool AVIFImageDecoder::DecodeImage(size_t index) { bool AVIFImageDecoder::DecodeImage(size_t index) {
if (!pending_decoded_image_) { auto ret = avifDecoderNthImage(decoder_.get(), index);
auto ret = avifDecoderNthImage(decoder_.get(), index); if (ret != AVIF_RESULT_OK) {
if (ret != AVIF_RESULT_OK) { // We shouldn't be called more times than specified in
// We shouldn't be called more times than specified in // DecodeFrameCount(); possibly this should truncate if the initial
// DecodeFrameCount(); possibly this should truncate if the initial // count is wrong?
// count is wrong? DCHECK_NE(ret, AVIF_RESULT_NO_IMAGES_REMAINING);
DCHECK_NE(ret, AVIF_RESULT_NO_IMAGES_REMAINING); return false;
return false;
}
} }
const auto* image = decoder_->image; const auto* image = decoder_->image;
...@@ -402,11 +401,7 @@ bool AVIFImageDecoder::DecodeImage(size_t index) { ...@@ -402,11 +401,7 @@ bool AVIFImageDecoder::DecodeImage(size_t index) {
decode_to_half_float_ = decode_to_half_float_ =
is_high_bit_depth_ && is_high_bit_depth_ &&
high_bit_depth_decoding_option_ == kHighBitDepthToHalfFloat; high_bit_depth_decoding_option_ == kHighBitDepthToHalfFloat;
return true;
if (!IsSizeAvailable())
return SetSize(image->width, image->height);
// All frames must be the same size.
return Size() == IntSize(image->width, image->height);
} }
bool AVIFImageDecoder::UpdateColorTransform(const gfx::ColorSpace& src_cs, bool AVIFImageDecoder::UpdateColorTransform(const gfx::ColorSpace& src_cs,
......
...@@ -70,7 +70,6 @@ class PLATFORM_EXPORT AVIFImageDecoder final : public ImageDecoder { ...@@ -70,7 +70,6 @@ class PLATFORM_EXPORT AVIFImageDecoder final : public ImageDecoder {
const gfx::ColorSpace& frame_cs, const gfx::ColorSpace& frame_cs,
ImageFrame* buffer); ImageFrame* buffer);
bool pending_decoded_image_ = false;
bool is_high_bit_depth_ = false; bool is_high_bit_depth_ = false;
bool decode_to_half_float_ = false; bool decode_to_half_float_ = false;
size_t decoded_frame_count_ = 0; size_t decoded_frame_count_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment