aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/calculateApngLength.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/calculateApngLength.js
parent376fadcca3a1b5c32a3361b2843c6c576237a1a3 (diff)
Prettified Code!
Diffstat (limited to 'webAO/utils/calculateApngLength.js')
-rw-r--r--webAO/utils/calculateApngLength.js52
1 files changed, 27 insertions, 25 deletions
diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js
index ab8682a..5d4ea7e 100644
--- a/webAO/utils/calculateApngLength.js
+++ b/webAO/utils/calculateApngLength.js
@@ -1,30 +1,32 @@
/**
- * Adds up the chunk delays to find out how long a APNG is
- * @param {data} apngFile the APNG data
- */
+ * Adds up the chunk delays to find out how long a APNG is
+ * @param {data} apngFile the APNG data
+ */
const calculateApngLength = (apngFile) => {
- const d = new Uint8Array(apngFile);
- // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
- let duration = 0;
- for (let i = 0; i < d.length; i++) {
- // Find fcTL header (66 63 54 4C)
- if (d[i] === 0x66
- && d[i + 1] === 0x63
- && d[i + 2] === 0x54
- && d[i + 3] === 0x4C) {
- // numerator and denominator
- const delayNum = Number(d[i + 23]);
- const delayDen = Number(d[i + 25]);
- let delay;
- // minimum is 100ms
- if (delayDen === 0) {
- delay = delayNum / 100;
- } else {
- delay = delayNum / delayDen;
- }
- duration += delay;
- }
+ const d = new Uint8Array(apngFile);
+ // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
+ let duration = 0;
+ for (let i = 0; i < d.length; i++) {
+ // Find fcTL header (66 63 54 4C)
+ if (
+ d[i] === 0x66 &&
+ d[i + 1] === 0x63 &&
+ d[i + 2] === 0x54 &&
+ d[i + 3] === 0x4c
+ ) {
+ // numerator and denominator
+ const delayNum = Number(d[i + 23]);
+ const delayDen = Number(d[i + 25]);
+ let delay;
+ // minimum is 100ms
+ if (delayDen === 0) {
+ delay = delayNum / 100;
+ } else {
+ delay = delayNum / delayDen;
+ }
+ duration += delay;
}
- return duration * 10;
+ }
+ return duration * 10;
};
export default calculateApngLength;