-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[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
…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
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! 😜
…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
…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
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.