Skip to content

Commit badce8f

Browse files
committed
Making player skip unsupported and wrong files
1 parent 12e7e09 commit badce8f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

BinaryAnimationPlayer/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h2>Binary Animation Player</h2>
9595
const is332 = file.name.endsWith('.332');
9696
const is565 = file.name.endsWith('.565');
9797

98-
const isDeprecatedFormat = file.name.endsWith('.332') || file.name.endsWith('.565');
98+
const isDeprecatedFormat = is332 || is565;
9999
const filesignature = String.fromCharCode(
100100
view.getUint8(0),
101101
view.getUint8(1)
@@ -109,11 +109,15 @@ <h2>Binary Animation Player</h2>
109109
const w = isDeprecatedFormat ? view.getUint8(0) : view.getUint16(4, true);
110110
const h = isDeprecatedFormat ? view.getUint8(1) : view.getUint16(6, true);
111111
const pixelsPerFrame = w * h;
112-
const bpp = is565 || filetype === 'b2' ? 2 : 1;
112+
const bpp = (is565 || filetype === 'b2') ? 2 : (is332 || filetype === 'b1') ? 1 : -1;
113113
const totalDataBytes = buffer.byteLength - headerSize;
114114
const bytesPerFrame = pixelsPerFrame * bpp;
115115
const frames = Math.floor(totalDataBytes / bytesPerFrame);
116116

117+
if ((!isDeprecatedFormat && !filesignature === 'bA') || bpp === -1) {
118+
status.innerHTML = `<span style="color: #e74c3c;">Unsupported file format.</span>`;
119+
return;
120+
}
117121
meta = {headerSize, w, h, frames, bpp, view };
118122
currentBuffer = view;
119123

0 commit comments

Comments
 (0)