diff --git a/src/file-renderer/index.js b/src/file-renderer/index.js index 06819aa..39ad778 100644 --- a/src/file-renderer/index.js +++ b/src/file-renderer/index.js @@ -1,5 +1,6 @@ import { jDataView } from "./jdataview"; import { pesRead } from "../format-readers/pes"; +import { dstRead } from "../format-readers/dst"; import { Pattern } from "./pattern"; String.prototype.endsWith = function (suffix) { @@ -12,6 +13,8 @@ function displayFileText(filename, evt, canvas) { filename = filename.toLowerCase(); if (filename.endsWith("pes")) { pesRead(view, pattern); + } else if (filename.endsWith("dst")) { + dstRead(view, pattern); } pattern.moveToPositive(); pattern.drawShape(canvas); diff --git a/src/format-readers/dst.js b/src/format-readers/dst.js new file mode 100644 index 0000000..8da4fd9 --- /dev/null +++ b/src/format-readers/dst.js @@ -0,0 +1,107 @@ +// @ts-nocheck +import { stitchTypes } from "../file-renderer/pattern"; + +function decodeExp(b2) { + let returnCode = 0; + if (b2 === 0xf3) { + return stitchTypes.end; + } + if ((b2 & 0xc3) === 0xc3) { + return stitchTypes.trim | stitchTypes.stop; + } + if (b2 & 0x80) { + returnCode |= stitchTypes.trim; + } + if (b2 & 0x40) { + returnCode |= stitchTypes.stop; + } + return returnCode; +} + +export function dstRead(file, pattern) { + let flags, + x, + y, + prevJump = false, + thisJump = false, + b = [], + byteCount = file.byteLength; + file.seek(512); + + while (file.tell() < byteCount - 3) { + b[0] = file.getUint8(); + b[1] = file.getUint8(); + b[2] = file.getUint8(); + x = 0; + y = 0; + if (b[0] & 0x01) { + x += 1; + } + if (b[0] & 0x02) { + x -= 1; + } + if (b[0] & 0x04) { + x += 9; + } + if (b[0] & 0x08) { + x -= 9; + } + if (b[0] & 0x80) { + y += 1; + } + if (b[0] & 0x40) { + y -= 1; + } + if (b[0] & 0x20) { + y += 9; + } + if (b[0] & 0x10) { + y -= 9; + } + if (b[1] & 0x01) { + x += 3; + } + if (b[1] & 0x02) { + x -= 3; + } + if (b[1] & 0x04) { + x += 27; + } + if (b[1] & 0x08) { + x -= 27; + } + if (b[1] & 0x80) { + y += 3; + } + if (b[1] & 0x40) { + y -= 3; + } + if (b[1] & 0x20) { + y += 27; + } + if (b[1] & 0x10) { + y -= 27; + } + if (b[2] & 0x04) { + x += 81; + } + if (b[2] & 0x08) { + x -= 81; + } + if (b[2] & 0x20) { + y += 81; + } + if (b[2] & 0x10) { + y -= 81; + } + flags = decodeExp(b[2]); + thisJump = flags & stitchTypes.jump; + if (prevJump) { + flags |= stitchTypes.jump; + } + pattern.addStitchRel(x, y, flags, true); + prevJump = thisJump; + } + pattern.addStitchRel(0, 0, stitchTypes.end, true); + pattern.invertPatternVertical(); +} diff --git a/src/lib/FileViewer.svelte b/src/lib/FileViewer.svelte index d158974..31050d4 100644 --- a/src/lib/FileViewer.svelte +++ b/src/lib/FileViewer.svelte @@ -9,7 +9,7 @@ let rejectedFiles; let areAcceptedFilesRendered = false; const fileRequirements = { - supportedFormats: [".pes"], + supportedFormats: [".pes", ".dst"], maxSize: 700000, }; @@ -54,7 +54,7 @@

Max file size is {fileRequirements.maxSize / 1000}kb. Accepted formats: - {fileRequirements.supportedFormats.join(",")}. + {fileRequirements.supportedFormats.join(", ")}.