Commit cad12d1a authored by Madeleine Barowsky's avatar Madeleine Barowsky Committed by Commit Bot

Blink: Refactor ImageDecoder::DecodeToYUV API to be analagous to Decode.

Changes return type of DecodeToYUV from bool to void and passes errors
through Failed().

Bug: 900589
Change-Id: If9e9b81d1516eeb7504f79e67a9a77cad4c36151
Reviewed-on: https://chromium-review.googlesource.com/c/1477814
Commit-Queue: Madeleine Barowsky <mbarowsky@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633772}
parent 136f566e
......@@ -178,9 +178,8 @@ bool ImageFrameGenerator::DecodeToYUV(SegmentReader* data,
std::make_unique<ImagePlanes>(planes, row_bytes);
decoder->SetImagePlanes(std::move(image_planes));
DCHECK(decoder->CanDecodeToYUV());
if (decoder->DecodeToYUV()) {
decoder->DecodeToYUV();
if (!decoder->Failed()) {
// TODO(crbug.com/910276): Set this properly for alpha support.
SetHasAlpha(index, false);
return true;
......
......@@ -325,7 +325,9 @@ class PLATFORM_EXPORT ImageDecoder {
}
virtual bool CanDecodeToYUV() { return false; }
virtual bool DecodeToYUV() { return false; }
// Should only be called if CanDecodeToYuv() returns true, in which case
// the subclass of ImageDecoder must override this method.
virtual void DecodeToYUV() { NOTREACHED(); }
virtual void SetImagePlanes(std::unique_ptr<ImagePlanes>) {}
protected:
......
......@@ -922,28 +922,31 @@ bool JPEGImageDecoder::ShouldGenerateAllSizes() const {
}
bool JPEGImageDecoder::CanDecodeToYUV() {
// TODO(crbug.com/919627): Re-enable the code below once JPEG YUV decoding is
// finished.
// TODO(crbug.com/919627): Right now |decode_to_yuv_for_testing_| is false by
// default and is only set true for unit tests. Remove it once
// JPEG YUV decoding is finished and YUV decoding doesn't need to be disabled
// outside of tests.
//
// Returning false here is a bit deceptive because the JPEG decoder does
// support YUV. But the rest of the infrastructure at levels above the decoder
// is not quite there yet to handle the resulting JPEG YUV data,
// so for now we disable that path.
return false;
//
// Calling IsSizeAvailable() ensures the reader is created and the output
// color space is set.
// return IsSizeAvailable() && reader_->Info()->out_color_space == JCS_YCbCr;
return decode_to_yuv_for_testing_ && IsSizeAvailable() &&
reader_->Info()->out_color_space == JCS_YCbCr;
}
bool JPEGImageDecoder::DecodeToYUV() {
if (!HasImagePlanes())
return false;
void JPEGImageDecoder::DecodeToYUV() {
DCHECK(HasImagePlanes());
DCHECK(CanDecodeToYUV());
{
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Decode Image",
"imageType", "JPEG");
Decode(false);
}
return !Failed();
}
void JPEGImageDecoder::SetImagePlanes(
......
......@@ -47,7 +47,7 @@ class PLATFORM_EXPORT JPEGImageDecoder final : public ImageDecoder {
IntSize DecodedYUVSize(int component) const override;
size_t DecodedYUVWidthBytes(int component) const override;
bool CanDecodeToYUV() override;
bool DecodeToYUV() override;
void DecodeToYUV() override;
void SetImagePlanes(std::unique_ptr<ImagePlanes>) override;
std::vector<SkISize> GetSupportedDecodeSizes() const override;
bool HasImagePlanes() const { return image_planes_.get(); }
......@@ -63,6 +63,9 @@ class PLATFORM_EXPORT JPEGImageDecoder final : public ImageDecoder {
void SetDecodedSize(unsigned width, unsigned height);
void SetSupportedDecodeSizes(std::vector<SkISize> sizes);
void SetDecodeToYuvForTesting(bool decode_to_yuv) {
decode_to_yuv_for_testing_ = decode_to_yuv;
}
private:
// ImageDecoder:
......@@ -78,6 +81,7 @@ class PLATFORM_EXPORT JPEGImageDecoder final : public ImageDecoder {
std::unique_ptr<ImagePlanes> image_planes_;
IntSize decoded_size_;
std::vector<SkISize> supported_decode_sizes_;
bool decode_to_yuv_for_testing_ = false;
DISALLOW_COPY_AND_ASSIGN(JPEGImageDecoder);
};
......
......@@ -51,7 +51,7 @@ static const size_t kLargeEnoughSize = 1000 * 1000;
namespace {
std::unique_ptr<ImageDecoder> CreateJPEGDecoder(size_t max_decoded_bytes) {
std::unique_ptr<JPEGImageDecoder> CreateJPEGDecoder(size_t max_decoded_bytes) {
return std::make_unique<JPEGImageDecoder>(
ImageDecoder::kAlphaNotPremultiplied, ColorBehavior::TransformToSRGB(),
max_decoded_bytes);
......@@ -89,8 +89,10 @@ void ReadYUV(size_t max_decoded_bytes,
scoped_refptr<SharedBuffer> data = ReadFile(image_file_path);
ASSERT_TRUE(data);
std::unique_ptr<ImageDecoder> decoder = CreateJPEGDecoder(max_decoded_bytes);
std::unique_ptr<JPEGImageDecoder> decoder =
CreateJPEGDecoder(max_decoded_bytes);
decoder->SetData(data.get(), true);
decoder->SetDecodeToYuvForTesting(true);
// Setting a dummy ImagePlanes object signals to the decoder that we want to
// do YUV decoding.
......@@ -134,7 +136,8 @@ void ReadYUV(size_t max_decoded_bytes,
std::make_unique<ImagePlanes>(planes, row_bytes);
decoder->SetImagePlanes(std::move(image_planes));
ASSERT_TRUE(decoder->DecodeToYUV());
decoder->DecodeToYUV();
ASSERT_TRUE(!decoder->Failed());
}
// Tests failure on a too big image.
......@@ -262,8 +265,9 @@ TEST(JPEGImageDecoderTest, yuv) {
scoped_refptr<SharedBuffer> data = ReadFile(jpeg_file);
ASSERT_TRUE(data);
std::unique_ptr<ImageDecoder> decoder = CreateJPEGDecoder(230 * 230 * 4);
std::unique_ptr<JPEGImageDecoder> decoder = CreateJPEGDecoder(230 * 230 * 4);
decoder->SetData(data.get(), true);
decoder->SetDecodeToYuvForTesting(true);
std::unique_ptr<ImagePlanes> image_planes = std::make_unique<ImagePlanes>();
decoder->SetImagePlanes(std::move(image_planes));
......
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