This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Make upscaling opt in for image decoding #19067
Merged
dnfield
merged 11 commits into
flutter:master
from
dnfield:instantiate_image_codec_upscale
Jun 18, 2020
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
48a1245
fix build
dnfield 8040abd
Fix doc
dnfield 9edb828
Merge remote-tracking branch 'upstream/master' into instantiate_image…
dnfield 4f55dae
Make upscaling opt-in
dnfield 67fe8c6
skip assertion related tests if asserts are disabled
dnfield b0f95d5
merge
dnfield b02feff
save before merging!
dnfield bf4afdb
merge and nit
dnfield f86b7e1
enum
dnfield c18d4f4
review
dnfield 2c3adfa
change default to true
dnfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,6 +364,7 @@ TEST_F(ImageDecoderFixtureTest, CanDecodeWithResizes) { | |
| ImageDecoder::ImageDescriptor image_descriptor; | ||
| image_descriptor.target_width = target_width; | ||
| image_descriptor.target_height = target_height; | ||
| image_descriptor.image_upscaling = ImageUpscalingMode::kNotAllowed; | ||
| image_descriptor.data = OpenFixtureAsSkData("DashInNooglerHat.jpg"); | ||
|
|
||
| ASSERT_TRUE(image_descriptor.data); | ||
|
|
@@ -463,6 +464,7 @@ TEST_F(ImageDecoderFixtureTest, CanResizeWithoutDecode) { | |
| ImageDecoder::ImageDescriptor image_descriptor; | ||
| image_descriptor.target_width = target_width; | ||
| image_descriptor.target_height = target_height; | ||
| image_descriptor.image_upscaling = ImageUpscalingMode::kNotAllowed; | ||
| image_descriptor.data = decompressed_data; | ||
| image_descriptor.decompressed_image_info = info; | ||
|
|
||
|
|
@@ -530,11 +532,51 @@ TEST(ImageDecoderTest, VerifySimpleDecoding) { | |
| ASSERT_TRUE(image != nullptr); | ||
| ASSERT_EQ(SkISize::Make(600, 200), image->dimensions()); | ||
|
|
||
| ASSERT_EQ(ImageFromCompressedData(data, 6, 2, fml::tracing::TraceFlow("")) | ||
| ASSERT_EQ(ImageFromCompressedData(data, 6, 2, ImageUpscalingMode::kNotAllowed, | ||
| fml::tracing::TraceFlow("")) | ||
| ->dimensions(), | ||
| SkISize::Make(6, 2)); | ||
| } | ||
|
|
||
| TEST(ImageDecoderTest, VerifySimpleDecodingNoUpscaling) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my comment earlier, a test case here about aspect ratio overwriting scales. So something like decode at 1200x100 with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| auto data = OpenFixtureAsSkData("Horizontal.jpg"); | ||
| auto image = SkImage::MakeFromEncoded(data); | ||
| ASSERT_TRUE(image != nullptr); | ||
| ASSERT_EQ(SkISize::Make(600, 200), image->dimensions()); | ||
|
|
||
| ASSERT_EQ( | ||
| ImageFromCompressedData(data, 900, 300, ImageUpscalingMode::kNotAllowed, | ||
| fml::tracing::TraceFlow("")) | ||
| ->dimensions(), | ||
| SkISize::Make(600, 200)); | ||
| } | ||
|
|
||
| TEST(ImageDecoderTest, VerifySimpleDecodingNoUpscalingOneDimension) { | ||
| auto data = OpenFixtureAsSkData("Horizontal.jpg"); | ||
| auto image = SkImage::MakeFromEncoded(data); | ||
| ASSERT_TRUE(image != nullptr); | ||
| ASSERT_EQ(SkISize::Make(600, 200), image->dimensions()); | ||
|
|
||
| ASSERT_EQ( | ||
| ImageFromCompressedData(data, 1200, 200, ImageUpscalingMode::kNotAllowed, | ||
| fml::tracing::TraceFlow("")) | ||
| ->dimensions(), | ||
| SkISize::Make(600, 200)); | ||
| } | ||
|
|
||
| TEST(ImageDecoderTest, VerifySimpleDecodingWithUpscaling) { | ||
| auto data = OpenFixtureAsSkData("Horizontal.jpg"); | ||
| auto image = SkImage::MakeFromEncoded(data); | ||
| ASSERT_TRUE(image != nullptr); | ||
| ASSERT_EQ(SkISize::Make(600, 200), image->dimensions()); | ||
|
|
||
| ASSERT_EQ( | ||
| ImageFromCompressedData(data, 900, 300, ImageUpscalingMode::kAllowed, | ||
| fml::tracing::TraceFlow("")) | ||
| ->dimensions(), | ||
| SkISize::Make(900, 300)); | ||
| } | ||
|
|
||
| TEST(ImageDecoderTest, VerifySubpixelDecodingPreservesExifOrientation) { | ||
| auto data = OpenFixtureAsSkData("Horizontal.jpg"); | ||
| auto image = SkImage::MakeFromEncoded(data); | ||
|
|
@@ -544,6 +586,7 @@ TEST(ImageDecoderTest, VerifySubpixelDecodingPreservesExifOrientation) { | |
| auto decode = [data](std::optional<uint32_t> target_width, | ||
| std::optional<uint32_t> target_height) { | ||
| return ImageFromCompressedData(data, target_width, target_height, | ||
| ImageUpscalingMode::kNotAllowed, | ||
| fml::tracing::TraceFlow("")); | ||
| }; | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for this one (admittedly obscure) use case: If the user explicitly wants to decode the image at a non-native aspect ratio, they would specify both the target width and height. Before, the decoder would always return images at that aspect ratio. Now, that aspect ratio will not be preserved if the dimensions along either axis exceed the intrinsic value.
I think a clarification of whether the scaling will be done in an aspect ratio preserving manner is warranted in the documentation as well as a test case in
image_decoder_unittests.cc(let's add a test even if decide not to preserve the aspect ratio just so the behavior is not undefined).If you do decide to preserve scale, you can account the specification of both in another conditional check here.
I know this is an obscure case, but let's avoid undefined behavior as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point.
My grand plan is to follow this up with another PR to add something to control how aspect ratios are or are not preserved. I was originally thinking that this could be separated out from that, but I think you're right that it can't.
I'll take a quick look at how much more complicated this PR gets to add that extra parameter, otherwise I'll look to clarify the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if a user wants that case they have to just set the
allowUpscalingbit to true right?But yes, we should document and test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we have sort of tacked on stuff to this original simple API in bits and pieces as we went along. This has understandably become a bit unwieldy.
Instead of doing all the design work to further update this API with additional options, I am fine if we just say "this will/won't preserve aspect ratio if both dimensions are specified" and add a test for this. As I said, my comment was more about the undefined behavior. This is still an improvement for a vast majority of the cases.
In the long run, an API that works with image descriptors without decompression is the way to go. But that is a lot more work to write and migrate to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there is a workaround. Let's just document and test the default. My only concern still is that since the default has changed, earlier, they didn't need to specify the argument but now they have to.
How about just preserving the aspect ratio while scaling down if both width and height are specified? That ought to be really straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the more I look at this, the more I think it's just a doc and test thing. Whether or how we add other aspect ratio parameters here will still be relevant to this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.