aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/calculateWebpLength.js
diff options
context:
space:
mode:
authorstonedDiscord <stonedDiscord@users.noreply.github.com>2024-11-20 13:04:14 +0000
committerGitHub Action <actions@github.com>2024-11-20 13:04:14 +0000
commitb8283b373caa2ac198497a8dd466bf494d81982a (patch)
tree23de734e7ab5c093ace1d1a8fec716bb7603bdbf /webAO/utils/calculateWebpLength.js
parent376fadcca3a1b5c32a3361b2843c6c576237a1a3 (diff)
Prettified Code!
Diffstat (limited to 'webAO/utils/calculateWebpLength.js')
-rw-r--r--webAO/utils/calculateWebpLength.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/webAO/utils/calculateWebpLength.js b/webAO/utils/calculateWebpLength.js
index e81a77b..76a69e3 100644
--- a/webAO/utils/calculateWebpLength.js
+++ b/webAO/utils/calculateWebpLength.js
@@ -1,24 +1,26 @@
/* eslint no-bitwise: "off" */
const calculateWebpLength = (webpFile) => {
- const d = new Uint8Array(webpFile);
- // https://developers.google.com/speed/webp/docs/riff_container#animation
- let duration = 0;
- for (let i = 0; i < d.length; i++) {
- // Find ANMF header (41 4E 4D 46)
- if (d[i] === 0x41
- && d[i + 1] === 0x4E
- && d[i + 2] === 0x4D
- && d[i + 3] === 0x46) {
- // Swap 5th and 6th bytes to get the delay per frame
- const delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF);
+ const d = new Uint8Array(webpFile);
+ // https://developers.google.com/speed/webp/docs/riff_container#animation
+ let duration = 0;
+ for (let i = 0; i < d.length; i++) {
+ // Find ANMF header (41 4E 4D 46)
+ if (
+ d[i] === 0x41 &&
+ d[i + 1] === 0x4e &&
+ d[i + 2] === 0x4d &&
+ d[i + 3] === 0x46
+ ) {
+ // Swap 5th and 6th bytes to get the delay per frame
+ const delay = (d[i + 21] << 8) | (d[i + 20] & 0xff);
- // Should be aware browsers have a minimum frame delay
- // e.g. 6ms for IE, 2ms modern browsers (50fps)
- duration += delay < 2 ? 10 : delay;
- }
+ // Should be aware browsers have a minimum frame delay
+ // e.g. 6ms for IE, 2ms modern browsers (50fps)
+ duration += delay < 2 ? 10 : delay;
}
- return duration;
+ }
+ return duration;
};
export default calculateWebpLength;