Switch to prettier default config of using double quotes
This commit is contained in:
parent
24875d989b
commit
bd68eb6940
@ -4,16 +4,16 @@ module.exports = {
|
|||||||
es2021: true,
|
es2021: true,
|
||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
extends: ['airbnb-base', 'prettier'],
|
extends: ["airbnb-base", "prettier"],
|
||||||
overrides: [],
|
overrides: [],
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
ecmaVersion: 'latest',
|
ecmaVersion: "latest",
|
||||||
sourceType: 'module',
|
sourceType: "module",
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
'import/extensions': [2, 'always'],
|
"import/extensions": [2, "always"],
|
||||||
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
|
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
|
||||||
'no-param-reassign': ['error', { props: false }],
|
"no-param-reassign": ["error", { props: false }],
|
||||||
'no-bitwise': ['error', { allow: ['<<', '&'] }],
|
"no-bitwise": ["error", { allow: ["<<", "&"] }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
38
main.js
38
main.js
@ -24,14 +24,14 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import PBM from './src/pbm.js';
|
import PBM from "./src/pbm.js";
|
||||||
|
|
||||||
const thumbnailCanvas = document.getElementById('thumbnail-canvas');
|
const thumbnailCanvas = document.getElementById("thumbnail-canvas");
|
||||||
const thumbnailContext = thumbnailCanvas.getContext('2d');
|
const thumbnailContext = thumbnailCanvas.getContext("2d");
|
||||||
const imageCanvas = document.getElementById('image-canvas');
|
const imageCanvas = document.getElementById("image-canvas");
|
||||||
const imageContext = imageCanvas.getContext('2d');
|
const imageContext = imageCanvas.getContext("2d");
|
||||||
const paletteCanvas = document.getElementById('palette-canvas');
|
const paletteCanvas = document.getElementById("palette-canvas");
|
||||||
const paletteContext = paletteCanvas.getContext('2d');
|
const paletteContext = paletteCanvas.getContext("2d");
|
||||||
|
|
||||||
let currentPalettePage = 0;
|
let currentPalettePage = 0;
|
||||||
let image = null;
|
let image = null;
|
||||||
@ -97,8 +97,8 @@ function loadImage(buffer) {
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('imagefile').addEventListener(
|
document.getElementById("imagefile").addEventListener(
|
||||||
'change',
|
"change",
|
||||||
(e) => {
|
(e) => {
|
||||||
const imageFile = e.target.files[0];
|
const imageFile = e.target.files[0];
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
@ -116,24 +116,24 @@ document.getElementById('imagefile').addEventListener(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Palette navigation
|
// Palette navigation
|
||||||
document.getElementById('paletteLeft').addEventListener('click', () => {
|
document.getElementById("paletteLeft").addEventListener("click", () => {
|
||||||
if (currentPalettePage === 0) {
|
if (currentPalettePage === 0) {
|
||||||
currentPalettePage = 3;
|
currentPalettePage = 3;
|
||||||
} else {
|
} else {
|
||||||
currentPalettePage -= 1;
|
currentPalettePage -= 1;
|
||||||
}
|
}
|
||||||
document.getElementById('palettePageLabel').innerText =
|
document.getElementById("palettePageLabel").innerText =
|
||||||
currentPalettePage + 1;
|
currentPalettePage + 1;
|
||||||
drawPalette();
|
drawPalette();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('paletteRight').addEventListener('click', () => {
|
document.getElementById("paletteRight").addEventListener("click", () => {
|
||||||
if (currentPalettePage === 3) {
|
if (currentPalettePage === 3) {
|
||||||
currentPalettePage = 0;
|
currentPalettePage = 0;
|
||||||
} else {
|
} else {
|
||||||
currentPalettePage += 1;
|
currentPalettePage += 1;
|
||||||
}
|
}
|
||||||
document.getElementById('palettePageLabel').innerText =
|
document.getElementById("palettePageLabel").innerText =
|
||||||
currentPalettePage + 1;
|
currentPalettePage + 1;
|
||||||
drawPalette();
|
drawPalette();
|
||||||
});
|
});
|
||||||
@ -145,11 +145,11 @@ function cycleColors(now) {
|
|||||||
if (!range.lastTime) range.lastTime = now;
|
if (!range.lastTime) range.lastTime = now;
|
||||||
|
|
||||||
if (now - range.lastTime > range.rate / cycleSpeed) {
|
if (now - range.lastTime > range.rate / cycleSpeed) {
|
||||||
if (range.direction === 'forward') {
|
if (range.direction === "forward") {
|
||||||
// Move last color to first position
|
// Move last color to first position
|
||||||
const lastColor = image.palette.splice(range.high, 1)[0];
|
const lastColor = image.palette.splice(range.high, 1)[0];
|
||||||
image.palette.splice(range.low, 0, lastColor);
|
image.palette.splice(range.low, 0, lastColor);
|
||||||
} else if (range.direction === 'reverse') {
|
} else if (range.direction === "reverse") {
|
||||||
// Move first color to last position
|
// Move first color to last position
|
||||||
const firstColor = image.palette.splice(range.low, 1)[0];
|
const firstColor = image.palette.splice(range.low, 1)[0];
|
||||||
image.palette.splice(range.high, 0, firstColor);
|
image.palette.splice(range.high, 0, firstColor);
|
||||||
@ -169,13 +169,13 @@ function animate(now) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById('cyclingSpeedSlider')
|
.getElementById("cyclingSpeedSlider")
|
||||||
.addEventListener('input', (evt) => {
|
.addEventListener("input", (evt) => {
|
||||||
cycleSpeed = evt.target.value;
|
cycleSpeed = evt.target.value;
|
||||||
document.getElementById('cyclingSpeedLabel').innerText = cycleSpeed;
|
document.getElementById("cyclingSpeedLabel").innerText = cycleSpeed;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('cycleColors').addEventListener('click', () => {
|
document.getElementById("cycleColors").addEventListener("click", () => {
|
||||||
if (running) {
|
if (running) {
|
||||||
running = false;
|
running = false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ class BinaryStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readString(length) {
|
readString(length) {
|
||||||
let string = '';
|
let string = "";
|
||||||
|
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
const byte = this.dataView.getUint8(this.index + i);
|
const byte = this.dataView.getUint8(this.index + i);
|
||||||
|
|||||||
20
src/pbm.js
20
src/pbm.js
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import BinaryStream from './binarystream.js';
|
import BinaryStream from "./binarystream.js";
|
||||||
|
|
||||||
class PBM {
|
class PBM {
|
||||||
constructor(arrayBuffer) {
|
constructor(arrayBuffer) {
|
||||||
@ -81,7 +81,7 @@ class PBM {
|
|||||||
const formatId = this.binaryStream.readString(4);
|
const formatId = this.binaryStream.readString(4);
|
||||||
|
|
||||||
// Validate chunk according to notes on https://en.wikipedia.org/wiki/ILBM
|
// Validate chunk according to notes on https://en.wikipedia.org/wiki/ILBM
|
||||||
if (chunkId !== 'FORM') {
|
if (chunkId !== "FORM") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid chunkId: "${chunkId}" at byte ${this.binaryStream.index}. Expected "FORM".`
|
`Invalid chunkId: "${chunkId}" at byte ${this.binaryStream.index}. Expected "FORM".`
|
||||||
);
|
);
|
||||||
@ -95,7 +95,7 @@ class PBM {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formatId !== 'PBM ') {
|
if (formatId !== "PBM ") {
|
||||||
throw new Error(`Invalid formatId: "${formatId}". Expected "PBM ".`);
|
throw new Error(`Invalid formatId: "${formatId}". Expected "PBM ".`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,23 +105,23 @@ class PBM {
|
|||||||
chunkLength = this.binaryStream.readUint32BE();
|
chunkLength = this.binaryStream.readUint32BE();
|
||||||
|
|
||||||
switch (chunkId) {
|
switch (chunkId) {
|
||||||
case 'BMHD':
|
case "BMHD":
|
||||||
this.parseBMHD();
|
this.parseBMHD();
|
||||||
break;
|
break;
|
||||||
case 'CMAP':
|
case "CMAP":
|
||||||
this.parseCMAP();
|
this.parseCMAP();
|
||||||
break;
|
break;
|
||||||
case 'DPPS':
|
case "DPPS":
|
||||||
// NOTE(m): Ignore unknown DPPS chunk of size 110 bytes
|
// NOTE(m): Ignore unknown DPPS chunk of size 110 bytes
|
||||||
this.binaryStream.jump(110);
|
this.binaryStream.jump(110);
|
||||||
break;
|
break;
|
||||||
case 'CRNG':
|
case "CRNG":
|
||||||
this.parseCRNG();
|
this.parseCRNG();
|
||||||
break;
|
break;
|
||||||
case 'TINY':
|
case "TINY":
|
||||||
this.parseTINY(chunkLength);
|
this.parseTINY(chunkLength);
|
||||||
break;
|
break;
|
||||||
case 'BODY':
|
case "BODY":
|
||||||
this.parseBODY(chunkLength);
|
this.parseBODY(chunkLength);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -191,7 +191,7 @@ class PBM {
|
|||||||
this.cyclingRanges.push({
|
this.cyclingRanges.push({
|
||||||
rate,
|
rate,
|
||||||
active: (flags & activeBitMask) !== 0,
|
active: (flags & activeBitMask) !== 0,
|
||||||
direction: (flags & directionBitMask) !== 0 ? 'reverse' : 'forward',
|
direction: (flags & directionBitMask) !== 0 ? "reverse" : "forward",
|
||||||
low,
|
low,
|
||||||
high,
|
high,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,46 +25,46 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect, test } from 'vitest';
|
import { expect, test } from "vitest";
|
||||||
|
|
||||||
import PBM from '../src/pbm.js';
|
import PBM from "../src/pbm.js";
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require("fs");
|
||||||
|
|
||||||
test('Successfully parse a PBM file', () => {
|
test("Successfully parse a PBM file", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new PBM(data.buffer);
|
new PBM(data.buffer);
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Fail to parse a PBM file with an invalid chunk id', () => {
|
test("Fail to parse a PBM file with an invalid chunk id", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/INVALID_CHUNK_ID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/INVALID_CHUNK_ID.LBM");
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new PBM(data.buffer);
|
new PBM(data.buffer);
|
||||||
}).toThrowError(/^Invalid chunkId: "FARM" at byte 12. Expected "FORM".$/);
|
}).toThrowError(/^Invalid chunkId: "FARM" at byte 12. Expected "FORM".$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Fail to parse a PBM file with an invalid chunk length', () => {
|
test("Fail to parse a PBM file with an invalid chunk length", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/INVALID_CHUNK_LENGTH.LBM');
|
const data = fs.readFileSync("./tests/fixtures/INVALID_CHUNK_LENGTH.LBM");
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new PBM(data.buffer);
|
new PBM(data.buffer);
|
||||||
}).toThrowError(/^Invalid chunk length: 7070 bytes. Expected 7012 bytes.$/);
|
}).toThrowError(/^Invalid chunk length: 7070 bytes. Expected 7012 bytes.$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Fail to parse an IFF file that is not a PBM file', () => {
|
test("Fail to parse an IFF file that is not a PBM file", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/SEASCAPE.LBM');
|
const data = fs.readFileSync("./tests/fixtures/SEASCAPE.LBM");
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new PBM(data.buffer);
|
new PBM(data.buffer);
|
||||||
}).toThrowError(/^Invalid formatId: "ILBM". Expected "PBM ".$/);
|
}).toThrowError(/^Invalid formatId: "ILBM". Expected "PBM ".$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parse a PBM bitmap header', () => {
|
test("Parse a PBM bitmap header", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
const image = new PBM(data.buffer);
|
const image = new PBM(data.buffer);
|
||||||
|
|
||||||
expect(image.width).toStrictEqual(640);
|
expect(image.width).toStrictEqual(640);
|
||||||
@ -82,23 +82,23 @@ test('Parse a PBM bitmap header', () => {
|
|||||||
expect(image.pageHeight).toStrictEqual(480);
|
expect(image.pageHeight).toStrictEqual(480);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parse PBM palette information', () => {
|
test("Parse PBM palette information", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
const image = new PBM(data.buffer);
|
const image = new PBM(data.buffer);
|
||||||
|
|
||||||
expect(image.palette.length).toStrictEqual(256);
|
expect(image.palette.length).toStrictEqual(256);
|
||||||
expect(image.palette[10]).toStrictEqual([87, 255, 87]);
|
expect(image.palette[10]).toStrictEqual([87, 255, 87]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parse PBM color cycling information', () => {
|
test("Parse PBM color cycling information", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
const image = new PBM(data.buffer);
|
const image = new PBM(data.buffer);
|
||||||
|
|
||||||
expect(image.cyclingRanges.length).toStrictEqual(16);
|
expect(image.cyclingRanges.length).toStrictEqual(16);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parse PBM thumbnail', () => {
|
test("Parse PBM thumbnail", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
const image = new PBM(data.buffer);
|
const image = new PBM(data.buffer);
|
||||||
|
|
||||||
expect(image.thumbnail.width).toStrictEqual(80);
|
expect(image.thumbnail.width).toStrictEqual(80);
|
||||||
@ -106,8 +106,8 @@ test('Parse PBM thumbnail', () => {
|
|||||||
expect(image.thumbnail.size).toStrictEqual(4800);
|
expect(image.thumbnail.size).toStrictEqual(4800);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Decode PBM thumbnail pixel data', () => {
|
test("Decode PBM thumbnail pixel data", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
const image = new PBM(data.buffer);
|
const image = new PBM(data.buffer);
|
||||||
|
|
||||||
expect(image.thumbnail.pixelData.length).toStrictEqual(4800);
|
expect(image.thumbnail.pixelData.length).toStrictEqual(4800);
|
||||||
@ -116,8 +116,8 @@ test('Decode PBM thumbnail pixel data', () => {
|
|||||||
expect(image.palette[14]).toStrictEqual([255, 255, 87]);
|
expect(image.palette[14]).toStrictEqual([255, 255, 87]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Decode PBM image pixel data', () => {
|
test("Decode PBM image pixel data", () => {
|
||||||
const data = fs.readFileSync('./tests/fixtures/VALID.LBM');
|
const data = fs.readFileSync("./tests/fixtures/VALID.LBM");
|
||||||
const image = new PBM(data.buffer);
|
const image = new PBM(data.buffer);
|
||||||
|
|
||||||
expect(image.pixelData.length).toStrictEqual(307_200);
|
expect(image.pixelData.length).toStrictEqual(307_200);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user