Merge pull request #2 from leomurca/feature/support_dst_format

Add support for DST format
This commit is contained in:
Leonardo Murça 2022-11-25 09:00:07 -03:00 committed by GitHub
commit d9a1d623df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import { jDataView } from "./jdataview"; import { jDataView } from "./jdataview";
import { pesRead } from "../format-readers/pes"; import { pesRead } from "../format-readers/pes";
import { dstRead } from "../format-readers/dst";
import { Pattern } from "./pattern"; import { Pattern } from "./pattern";
String.prototype.endsWith = function (suffix) { String.prototype.endsWith = function (suffix) {
@ -12,6 +13,8 @@ function displayFileText(filename, evt, canvas) {
filename = filename.toLowerCase(); filename = filename.toLowerCase();
if (filename.endsWith("pes")) { if (filename.endsWith("pes")) {
pesRead(view, pattern); pesRead(view, pattern);
} else if (filename.endsWith("dst")) {
dstRead(view, pattern);
} }
pattern.moveToPositive(); pattern.moveToPositive();
pattern.drawShape(canvas); pattern.drawShape(canvas);

107
src/format-readers/dst.js Normal file
View file

@ -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();
}

View file

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