aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/calculateGifLength.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/calculateGifLength.js
parent376fadcca3a1b5c32a3361b2843c6c576237a1a3 (diff)
Prettified Code!
Diffstat (limited to 'webAO/utils/calculateGifLength.js')
-rw-r--r--webAO/utils/calculateGifLength.js44
1 files changed, 23 insertions, 21 deletions
diff --git a/webAO/utils/calculateGifLength.js b/webAO/utils/calculateGifLength.js
index eccfc77..d8f64c1 100644
--- a/webAO/utils/calculateGifLength.js
+++ b/webAO/utils/calculateGifLength.js
@@ -1,29 +1,31 @@
/* eslint no-bitwise: "off" */
/**
- * Adds up the frame delays to find out how long a GIF is
- * I totally didn't steal this
- * @param {data} gifFile the GIF data
- */
+ * Adds up the frame delays to find out how long a GIF is
+ * I totally didn't steal this
+ * @param {data} gifFile the GIF data
+ */
const calculateGifLength = (gifFile) => {
- const d = new Uint8Array(gifFile);
- // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/
- // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt
- let duration = 0;
- for (let i = 0; i < d.length; i++) {
- // Find a Graphic Control Extension hex(21F904__ ____ __00)
- if (d[i] === 0x21
- && d[i + 1] === 0xF9
- && d[i + 2] === 0x04
- && d[i + 7] === 0x00) {
- // Swap 5th and 6th bytes to get the delay per frame
- const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF);
+ const d = new Uint8Array(gifFile);
+ // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/
+ // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt
+ let duration = 0;
+ for (let i = 0; i < d.length; i++) {
+ // Find a Graphic Control Extension hex(21F904__ ____ __00)
+ if (
+ d[i] === 0x21 &&
+ d[i + 1] === 0xf9 &&
+ d[i + 2] === 0x04 &&
+ d[i + 7] === 0x00
+ ) {
+ // Swap 5th and 6th bytes to get the delay per frame
+ const delay = (d[i + 5] << 8) | (d[i + 4] & 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 * 10;
+ }
+ return duration * 10;
};
export default calculateGifLength;