Add exp format support

This commit is contained in:
Leonardo Murça 2022-12-02 18:49:27 -03:00
parent e3e3c3eabe
commit 357679f03c
4 changed files with 55 additions and 2 deletions

View file

@ -5,6 +5,6 @@ Available at https://embroideryviewer.xyz.
![Demo](/demo.gif)
Current supported formats: **.pes, .dst, .pec and .jef**.
Current supported formats: **.pes, .dst, .pec, .jef and .exp**.
Inspired by https://github.com/redteam316/html5-embroidery.git.

View file

@ -4,6 +4,7 @@ import { dstRead } from "../format-readers/dst";
import { Pattern } from "./pattern";
import { pecRead } from "../format-readers/pec";
import { jefRead } from "../format-readers/jef";
import { expRead } from "../format-readers/exp";
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
@ -21,6 +22,8 @@ function displayFileText(filename, evt, canvas) {
pecRead(view, pattern);
} else if (filename.endsWith("jef")) {
jefRead(view, pattern);
} else if (filename.endsWith("exp")) {
expRead(view, pattern);
}
pattern.moveToPositive();
pattern.drawShape(canvas);

50
src/format-readers/exp.js Normal file
View file

@ -0,0 +1,50 @@
import { stitchTypes } from "../file-renderer/pattern";
function expDecode(input) {
return input > 128 ? -(~input & 255) - 1 : input;
}
export function expRead(file, pattern) {
let b0 = 0,
b1 = 0,
dx = 0,
dy = 0,
flags = 0,
i = 0,
byteCount = file.byteLength;
while (i < byteCount) {
flags = stitchTypes.normal;
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
if (b0 === -128) {
if (b1 & 1) {
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
flags = stitchTypes.stop;
} else if (b1 === 2 || b1 === 4) {
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
flags = stitchTypes.trim;
} else if (b1 === -128) {
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
b0 = 0;
b1 = 0;
flags = stitchTypes.trim;
}
}
dx = expDecode(b0);
dy = expDecode(b1);
pattern.addStitchRel(dx, dy, flags, true);
}
pattern.addStitchRel(0, 0, stitchTypes.end);
pattern.invertPatternVertical();
}

View file

@ -9,7 +9,7 @@
let rejectedFiles;
let areAcceptedFilesRendered = false;
const fileRequirements = {
supportedFormats: [".pes", ".dst", ".pec", ".jef"],
supportedFormats: [".pes", ".dst", ".pec", ".jef", ".exp"],
maxSize: 700000,
};