diff --git a/README.md b/README.md index 60f8842..50904b3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/file-renderer/index.js b/src/file-renderer/index.js index eca64c7..fa77679 100644 --- a/src/file-renderer/index.js +++ b/src/file-renderer/index.js @@ -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); diff --git a/src/format-readers/exp.js b/src/format-readers/exp.js new file mode 100644 index 0000000..58d29ae --- /dev/null +++ b/src/format-readers/exp.js @@ -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(); +} diff --git a/src/lib/FileViewer.svelte b/src/lib/FileViewer.svelte index d1a85f2..514606b 100644 --- a/src/lib/FileViewer.svelte +++ b/src/lib/FileViewer.svelte @@ -9,7 +9,7 @@ let rejectedFiles; let areAcceptedFilesRendered = false; const fileRequirements = { - supportedFormats: [".pes", ".dst", ".pec", ".jef"], + supportedFormats: [".pes", ".dst", ".pec", ".jef", ".exp"], maxSize: 700000, };