Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[canvaskit] Detect animated WebP images #54418

Merged

Conversation

harryterkelsen
Copy link
Contributor

@harryterkelsen harryterkelsen commented Aug 7, 2024

Reads the WebP header to determine if the WebP image is animated or not. If it's not animated, we can use <img> tag decoding for less jank.

The WebP half of flutter/flutter#151911

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Aug 7, 2024
/// Reads the header of a WebP file to determine if it is animated or not.
///
/// See https://developers.google.com/speed/webp/docs/riff_container
class WebpHeaderReader {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I kinda like when these types of things are private, in their own library and just the functional thing as a top-level function bool isAnimated(bytes). With the class as private. One should only call isAnimated once, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. isAnimated isn't even exposed outside the file. It's an implementation detail of detectImageType

ImageType? expectedImageType;
final String testFileExtension =
testFile.substring(testFile.lastIndexOf('.') + 1);
switch (testFileExtension) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might could use switch expression here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Didn't know about this in the language

'avif' => ImageType.avif,
'bmp' => ImageType.bmp,
'png' => ImageType.png,
String() => null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

Suggested change
String() => null,
_ => null,

🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 39 to 41
final _WebpHeaderReader webpHeaderReader =
_WebpHeaderReader(data.buffer.asByteData());
if (webpHeaderReader.isAnimated()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final _WebpHeaderReader webpHeaderReader =
_WebpHeaderReader(data.buffer.asByteData());
if (webpHeaderReader.isAnimated()) {
if (_WebpHeaderReader(data.buffer.asByteData()).isAnimated()) {

compromise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh...not a biggy. I'm being picky

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2024
@auto-submit auto-submit bot merged commit 0520889 into flutter:main Aug 8, 2024
29 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 8, 2024
…153132)

flutter/engine@ef820aa...0520889

2024-08-08 [email protected] [canvaskit] Detect animated WebP images (flutter/engine#54418)
2024-08-08 [email protected] Roll Dart SDK from 067c7cfcbc8c to ff0404c72fc5 (1 revision) (flutter/engine#54455)
2024-08-08 [email protected] [Impeller] move aiks text tests to DL. (flutter/engine#54293)
2024-08-08 [email protected] Roll Skia from 0c6dd1e6ff8e to 4cff580721cf (20 revisions) (flutter/engine#54454)
2024-08-08 [email protected] Add a precision to the fragment shader (flutter/engine#54109)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, but this LGTM too!

bool _readWebpHeader() {
final String riffBytes = _readFourCC();

// Read file size byte.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one byte? 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get out of here with your snark! 😜

DBowen33 pushed a commit to DBowen33/flutter that referenced this pull request Aug 16, 2024
…lutter#153132)

flutter/engine@ef820aa...0520889

2024-08-08 [email protected] [canvaskit] Detect animated WebP images (flutter/engine#54418)
2024-08-08 [email protected] Roll Dart SDK from 067c7cfcbc8c to ff0404c72fc5 (1 revision) (flutter/engine#54455)
2024-08-08 [email protected] [Impeller] move aiks text tests to DL. (flutter/engine#54293)
2024-08-08 [email protected] Roll Skia from 0c6dd1e6ff8e to 4cff580721cf (20 revisions) (flutter/engine#54454)
2024-08-08 [email protected] Add a precision to the fragment shader (flutter/engine#54109)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…lutter#153132)

flutter/engine@ef820aa...0520889

2024-08-08 [email protected] [canvaskit] Detect animated WebP images (flutter/engine#54418)
2024-08-08 [email protected] Roll Dart SDK from 067c7cfcbc8c to ff0404c72fc5 (1 revision) (flutter/engine#54455)
2024-08-08 [email protected] [Impeller] move aiks text tests to DL. (flutter/engine#54293)
2024-08-08 [email protected] Roll Skia from 0c6dd1e6ff8e to 4cff580721cf (20 revisions) (flutter/engine#54454)
2024-08-08 [email protected] Add a precision to the fragment shader (flutter/engine#54109)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants