-
Notifications
You must be signed in to change notification settings - Fork 6k
[canvaskit] Detect animated WebP images #54418
[canvaskit] Detect animated WebP images #54418
Conversation
| /// 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 { |
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.
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?
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.
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) { |
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.
might could use switch expression here?
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.
Nice! Didn't know about this in the language
| 'avif' => ImageType.avif, | ||
| 'bmp' => ImageType.bmp, | ||
| 'png' => ImageType.png, | ||
| String() => null, |
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.
or
| String() => null, | |
| _ => null, |
🤷
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.
done
| final _WebpHeaderReader webpHeaderReader = | ||
| _WebpHeaderReader(data.buffer.asByteData()); | ||
| if (webpHeaderReader.isAnimated()) { |
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.
| final _WebpHeaderReader webpHeaderReader = | |
| _WebpHeaderReader(data.buffer.asByteData()); | |
| if (webpHeaderReader.isAnimated()) { | |
| if (_WebpHeaderReader(data.buffer.asByteData()).isAnimated()) { |
compromise?
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.
meh...not a biggy. I'm being picky
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.
done
flutter/engine@ef820aa...0520889 2024-08-08 1961493+harryterkelsen@users.noreply.github.com [canvaskit] Detect animated WebP images (flutter/engine#54418) 2024-08-08 skia-flutter-autoroll@skia.org Roll Dart SDK from 067c7cfcbc8c to ff0404c72fc5 (1 revision) (flutter/engine#54455) 2024-08-08 jonahwilliams@google.com [Impeller] move aiks text tests to DL. (flutter/engine#54293) 2024-08-08 skia-flutter-autoroll@skia.org Roll Skia from 0c6dd1e6ff8e to 4cff580721cf (20 revisions) (flutter/engine#54454) 2024-08-08 robert.ancell@canonical.com 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 jsimmons@google.com,rmistry@google.com,zra@google.com 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
mdebbar
left a comment
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.
Sorry for the late review, but this LGTM too!
| bool _readWebpHeader() { | ||
| final String riffBytes = _readFourCC(); | ||
|
|
||
| // Read file size byte. |
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.
Only one byte? 🙂
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.
get out of here with your snark! 😜
…3132) flutter/engine@ef820aa...0520889 2024-08-08 1961493+harryterkelsen@users.noreply.github.com [canvaskit] Detect animated WebP images (flutter/engine#54418) 2024-08-08 skia-flutter-autoroll@skia.org Roll Dart SDK from 067c7cfcbc8c to ff0404c72fc5 (1 revision) (flutter/engine#54455) 2024-08-08 jonahwilliams@google.com [Impeller] move aiks text tests to DL. (flutter/engine#54293) 2024-08-08 skia-flutter-autoroll@skia.org Roll Skia from 0c6dd1e6ff8e to 4cff580721cf (20 revisions) (flutter/engine#54454) 2024-08-08 robert.ancell@canonical.com 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 jsimmons@google.com,rmistry@google.com,zra@google.com 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
…3132) flutter/engine@ef820aa...0520889 2024-08-08 1961493+harryterkelsen@users.noreply.github.com [canvaskit] Detect animated WebP images (flutter/engine#54418) 2024-08-08 skia-flutter-autoroll@skia.org Roll Dart SDK from 067c7cfcbc8c to ff0404c72fc5 (1 revision) (flutter/engine#54455) 2024-08-08 jonahwilliams@google.com [Impeller] move aiks text tests to DL. (flutter/engine#54293) 2024-08-08 skia-flutter-autoroll@skia.org Roll Skia from 0c6dd1e6ff8e to 4cff580721cf (20 revisions) (flutter/engine#54454) 2024-08-08 robert.ancell@canonical.com 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 jsimmons@google.com,rmistry@google.com,zra@google.com 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
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
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.