ImageProcessingInformation / !function() {.js
biesnejuil's picture
Upload !function() {.js
dea78e6 verified
!function() {
"use strict";
function t(t) {
return new Uint8Array(t)
}
function e(...t) {
console.log(...t)
}
function n(t, e) {
e || (e = t < 256 ? 2 : 4);
let n = "";
for (let r = 0; r < e; r++)
n = "0123456789ABCDEF"[15 & t] + n,
t >>= 4;
return n
}
const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function a(t) {
let e,
n,
a,
o,
s,
c,
i,
l,
d = 0,
f = 0;
const u = [];
if (t) {
do {
o = r.indexOf(t.charAt(d++)),
s = r.indexOf(t.charAt(d++)),
c = r.indexOf(t.charAt(d++)),
i = r.indexOf(t.charAt(d++)),
l = o << 18 | s << 12 | c << 6 | i,
e = l >> 16 & 255,
n = l >> 8 & 255,
a = 255 & l,
u[f++] = e,
64 !== c && (u[f++] = n),
64 !== i && (u[f++] = a)
} while (d < t.length);
return new Uint8Array(u)
}
}
const o = "nibble",
s = ["2mg", "d13", "do", "dsk", "po", "nib"],
c = [0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15],
i = [0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15],
l = [0, 10, 7, 4, 1, 11, 8, 5, 2, 12, 9, 6, 3],
d = [171, 173, 174, 175, 181, 182, 183, 186, 187, 189, 190, 191, 214, 215, 218, 219, 221, 222, 223, 234, 235, 237, 238, 239, 245, 246, 247, 250, 251, 253, 254, 255],
f = [150, 151, 154, 155, 157, 158, 159, 166, 167, 171, 172, 173, 174, 175, 178, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 203, 205, 206, 207, 211, 214, 215, 217, 218, 219, 220, 221, 222, 223, 229, 230, 231, 233, 234, 235, 236, 237, 238, 239, 242, 243, 244, 245, 246, 247, 249, 250, 251, 252, 253, 254, 255];
function u(t) {
let e = 170 & t,
n = 85 & t;
return e >>= 1, e |= 170, n |= 170, [e, n]
}
function h(t, e, n, r) {
let a,
o = [];
a = 0 === n ? 128 : 0 === e ? 40 : 38;
for (let t = 0; t < a; t++)
o.push(255);
const s = t ^ e ^ n;
o = o.concat([213, 170, 150]),
o = o.concat(u(t)),
o = o.concat(u(e)),
o = o.concat(u(n)),
o = o.concat(u(s)),
o = o.concat([222, 170, 235]);
for (let t = 0; t < 5; t++)
o.push(255);
o = o.concat([213, 170, 173]);
const c = [];
for (let t = 0; t < 342; t++)
c[t] = 0;
let i = 85;
for (let t = 257; t >= 0; t--) {
let e = r[t % 256],
n = c[0 + i];
n = n << 1 | 1 & e,
e >>= 1,
n = n << 1 | 1 & e,
e >>= 1,
c[86 + t] = e,
c[0 + i] = n,
--i < 0 && (i = 85)
}
let l = 0;
for (let t = 0; t < 342; t++) {
const e = c[t];
o.push(f[l ^ e]),
l = e
}
return o.push(f[l]), o = o.concat([222, 170, 235]), o.push(255), o
}
function w(t, e, n, r) {
let a,
o = [];
a = 0 === n ? 128 : 0 === e ? 40 : 38;
for (let t = 0; t < a; t++)
o.push(255);
const s = t ^ e ^ n;
o = o.concat([213, 170, 181]),
o = o.concat(u(t)),
o = o.concat(u(e)),
o = o.concat(u(n)),
o = o.concat(u(s)),
o = o.concat([222, 170, 235]);
for (let t = 0; t < 5; t++)
o.push(255);
o = o.concat([213, 170, 173]);
const c = [];
let i = 0;
for (let t = 50; t >= 0; t--) {
const e = r[i] >> 3,
n = 7 & r[i];
i++;
const a = r[i] >> 3,
o = 7 & r[i];
i++;
const s = r[i] >> 3,
l = 7 & r[i];
i++;
const d = r[i] >> 3,
f = 7 & r[i];
i++;
const u = r[i] >> 3,
h = 7 & r[i];
i++,
c[t + 0] = e,
c[t + 51] = a,
c[t + 102] = s,
c[t + 153] = d,
c[t + 204] = u,
c[t + 256] = n << 2 | (4 & f) >> 1 | (4 & h) >> 2,
c[t + 307] = o << 2 | 2 & f | (2 & h) >> 1,
c[t + 358] = l << 2 | (1 & f) << 1 | 1 & h
}
c[255] = r[i] >> 3,
c[409] = 7 & r[i];
let l = 0;
for (let t = 409; t >= 256; t--) {
const e = c[t];
o.push(d[l ^ e]),
l = e
}
for (let t = 0; t < 256; t++) {
const e = c[t];
o.push(d[l ^ e]),
l = e
}
return o.push(d[l]), o = o.concat([222, 170, 235]), o.push(255), o
}
var g;
function m(t, e) {
let n = 0,
r = !0;
for (; e < t.length && (t[e] ? (n = n << 1 | 1, r = !1) : r || (n <<= 1), !(128 & n));)
e += 1;
return {
nibble: n,
offset: e
}
}
function b(e) {
const {data: n, name: r, side: a, rawData: s, volume: i, readOnly: l} = e,
d = {
format: "dsk",
encoding: o,
metadata: {
name: r,
side: a
},
volume: i,
readOnly: l,
tracks: []
};
for (let e = 0; e < 35; e++) {
let r = [];
for (let t = 0; t < 16; t++) {
const a = c[t];
let o;
if (s) {
const t = 256 * (16 * e + a);
o = new Uint8Array(s.slice(t, t + 256))
} else {
if (!n)
throw new Error("Requires data or rawData");
o = new Uint8Array(n[e][a])
}
r = r.concat(h(i, e, t, o))
}
d.tracks[e] = t(r)
}
return d
}
function k(t) {
const {data: e, name: n, side: r, rawData: a, volume: s, readOnly: c} = t,
i = {
format: "nib",
encoding: o,
metadata: {
name: n,
side: r
},
volume: s || 254,
readOnly: c || !1,
tracks: []
};
for (let t = 0; t < 35; t++) {
let n;
if (a) {
const e = 6656 * t;
n = new Uint8Array(a.slice(e, e + 6656))
} else {
if (!e)
throw new Error("Requires data or rawData");
n = e[t][0]
}
i.tracks[t] = n
}
return i
}
function y(e) {
const {data: n, name: r, side: a, rawData: s, volume: c, readOnly: l} = e,
d = {
format: "po",
encoding: o,
metadata: {
name: r,
side: a
},
volume: c || 254,
tracks: [],
readOnly: l || !1
};
for (let e = 0; e < 35; e++) {
let r = [];
for (let t = 0; t < 16; t++) {
const a = i[t];
let o;
if (s) {
const t = 256 * (16 * e + a);
o = new Uint8Array(s.slice(t, t + 256))
} else {
if (!n)
throw new Error("Requires data or rawData");
o = n[e][a]
}
r = r.concat(h(c, e, t, o))
}
d.tracks[e] = t(r)
}
return d
}
!function(t) {
t[t.START_OF_FIELD_MARKER_FIRST_NIBBLE = 0] = "START_OF_FIELD_MARKER_FIRST_NIBBLE",
t[t.START_OF_FIELD_MARKER_SECOND_NIBBLE = 1] = "START_OF_FIELD_MARKER_SECOND_NIBBLE",
t[t.FIELD_TYPE_MARKER = 2] = "FIELD_TYPE_MARKER",
t[t.ADDRESS_FIELD = 3] = "ADDRESS_FIELD",
t[t.ADDRESS_FIELD_13 = 4] = "ADDRESS_FIELD_13",
t[t.DATA_FIELD_6AND2 = 5] = "DATA_FIELD_6AND2",
t[t.DATA_FIELD_5AND3 = 6] = "DATA_FIELD_5AND3"
}(g || (g = {})),
Error,
Error,
Error;
var D;
function p(t, e, n) {
const r = new Uint8Array(t.buffer.slice(t.byteOffset + e, t.byteOffset + n));
return String.fromCharCode(...r)
}
!function(t) {
t[t.DOS = 0] = "DOS",
t[t.ProDOS = 1] = "ProDOS",
t[t.NIB = 2] = "NIB"
}(D || (D = {}));
class E {
constructor(t)
{
this.sides = 0,
this.bootSector = 0,
this.bitTiming = 0,
this.compatibleHardware = 0,
this.requiredRAM = 0,
this.largestTrack = 0,
this.version = t.getUint8(0),
this.diskType = t.getUint8(1),
this.writeProtected = t.getUint8(2),
this.synchronized = t.getUint8(3),
this.cleaned = t.getUint8(4),
this.creator = p(t, 5, 37),
this.version > 1 && (this.sides = t.getUint8(37), this.bootSector = t.getUint8(38), this.bitTiming = t.getUint8(39), this.compatibleHardware = t.getUint16(40, !0), this.requiredRAM = t.getUint16(42, !0), this.largestTrack = t.getUint16(44, !0))
}
}
class A {
constructor(t)
{
this.trackMap = [];
for (let e = 0; e < 160; e++)
this.trackMap.push(t.getUint8(e))
}
}
class O {}
class _ extends O {
constructor(t)
{
super(),
this.rawTracks = [],
this.tracks = [];
for (let e = 0, n = 0; n < t.byteLength; n += 6656, e++) {
let r = [];
const a = [],
o = t.buffer.slice(t.byteOffset + n, t.byteOffset + n + 6656),
s = new Uint8Array(o),
c = new DataView(o).getUint16(6648, !0);
for (let t = 0; t < c; t++) {
const e = t >> 3,
n = 7 - (7 & t);
a[t] = s[e] >> n & 1 ? 1 : 0
}
r = [];
let i = 0;
for (; i < a.length;) {
const t = m(a, i);
if (!t.nibble)
break;
r.push(t.nibble),
i = t.offset + 1
}
this.tracks[e] = new Uint8Array(r),
this.rawTracks[e] = new Uint8Array(a)
}
}
}
class S extends O {
constructor(t)
{
let e;
for (super(), this.trks = [], e = 0; e < 160; e++) {
const n = t.getUint16(8 * e, !0),
r = t.getUint16(8 * e + 2, !0),
a = t.getUint32(8 * e + 4, !0);
if (0 === a)
break;
this.trks.push({
startBlock: n,
blockCount: r,
bitCount: a
})
}
this.tracks = [],
this.rawTracks = [];
const n = t.buffer;
for (e = 0; e < this.trks.length; e++) {
const t = this.trks[e];
let r = [];
const a = [],
o = 512 * t.startBlock,
s = o + 512 * t.blockCount,
c = n.slice(o, s),
i = new Uint8Array(c);
for (let e = 0; e < t.bitCount; e++) {
const t = e >> 3,
n = 7 - (7 & e);
a[e] = i[t] >> n & 1 ? 1 : 0
}
r = [];
let l = 0;
for (; l < a.length;) {
const t = m(a, l);
if (!t.nibble)
break;
r.push(t.nibble),
l = t.offset + 1
}
this.tracks[e] = new Uint8Array(r),
this.rawTracks[e] = new Uint8Array(a)
}
}
}
class U {
constructor(t)
{
const e = p(t, 0, t.byteLength).split("\n");
this.values = e.reduce((function(t, e) {
const n = e.split("\t");
return t[n[0]] = n[1], t
}), {})
}
}
function I(t, r) {
let a = null;
switch (t) {
case "2mg":
a = function(t) {
let e,
{rawData: n} = t;
if (!n)
throw new Error("Requires rawData");
const {bytes: r, format: a, offset: o, readOnly: s, volume: c} = function(t) {
const e = new DataView(t),
n = new TextDecoder("ascii"),
r = n.decode(t.slice(0, 4));
if ("2IMG" !== r)
throw new Error(`Unrecognized 2mg signature: ${r}`);
const a = n.decode(t.slice(4, 8)),
o = e.getInt16(8, !0);
if (64 !== o)
throw new Error(`2mg header length is incorrect ${o} !== 64`);
const s = e.getInt32(12, !0),
c = e.getInt32(16, !0),
i = e.getInt32(20, !0),
l = e.getInt32(24, !0),
d = e.getInt32(28, !0),
f = e.getInt32(32, !0),
u = e.getInt32(36, !0),
h = e.getInt32(40, !0),
w = e.getInt32(44, !0);
if (s === D.ProDOS && 512 * i !== d)
throw new Error(`2mg blocks does not match disk data length: ${i} * 512 !== ${d}`);
if (l < o)
throw new Error(`2mg data offset is less than header length: ${l} < ${o}`);
if (l + d > e.byteLength)
throw new Error(`2mg data extends beyond disk image: ${l} + ${d} > ${e.byteLength}`);
const g = l + d;
if (f && f < g)
throw new Error(`2mg comment is before the end of the disk data: ${f} < ${l} + ${d}`);
const m = f ? f + u : g;
if (m > e.byteLength)
throw new Error(`2mg comment extends beyond disk image: ${m} > ${e.byteLength}`);
if (h && h < m)
throw new Error(`2mg creator data is before the end of the comment: ${h} < ${m}`);
const b = h ? h + w : m;
if (b > e.byteLength)
throw new Error(`2mg creator data extends beyond disk image: ${b} > ${e.byteLength}`);
const k = {};
f && (k.comment = new TextDecoder("utf-8").decode(new Uint8Array(t, f, u))),
h && (k.creatorData = new Uint8Array(t, h, w));
const y = 0 != (2147483648 & c);
let p = s === D.DOS ? 254 : 0;
return 256 & c && (p = 255 & c), Object.assign({
bytes: d,
creator: a,
format: s,
offset: l,
readOnly: y,
volume: p
}, k)
}(n);
switch (n = n.slice(o, o + r), t = Object.assign(Object.assign({}, t), {
rawData: n,
readOnly: s,
volume: c
}), a) {
case D.ProDOS:
e = y(t);
break;
case D.NIB:
e = k(t);
break;
case D.DOS:
default:
e = b(t)
}
return e
}(r);
break;
case "d13":
a = function(t) {
const {data: e, name: n, side: r, rawData: a, volume: s, readOnly: c} = t,
i = {
format: "d13",
encoding: o,
metadata: {
name: n,
side: r
},
volume: s,
readOnly: c,
tracks: []
};
if (!e && !a)
throw new Error("data or rawData required");
for (let t = 0; t < 35; t++) {
let n = [];
for (let r = 0; r < 13; r++) {
const o = l[r];
let c;
if (a) {
const e = 256 * (13 * t + o);
c = new Uint8Array(a.slice(e, e + 256))
} else {
if (!e)
throw new Error("Requires data or rawData");
c = e[t][o]
}
n = n.concat(w(s, t, o, c))
}
i.tracks.push(new Uint8Array(n))
}
return i
}(r);
break;
case "do":
case "dsk":
a = b(r);
break;
case "nib":
a = k(r);
break;
case "po":
a = y(r);
break;
case "woz":
a = function(t) {
const {rawData: r} = t;
if (!r)
throw new Error("Requires rawData");
const a = new DataView(r, 0);
let o,
s = 0;
const c = {};
function i() {
if (s >= a.byteLength)
return null;
const t = a.getUint32(s, !0),
e = a.getUint32(s + 4, !0),
n = new DataView(a.buffer, s + 8, e);
return s += e + 8, {
type: t,
size: e,
data: n
}
}
if (function() {
switch (a.getUint32(0, !0)) {
case 828002135:
o = 1;
break;
case 844779351:
o = 2;
break;
default:
return !1
}
return 168626943 === a.getUint32(4, !0)
}()) {
s = 12;
let t = i();
for (; t;) {
switch (t.type) {
case 1330007625:
c.info = new E(t.data);
break;
case 1346456916:
c.tmap = new A(t.data);
break;
case 1397445204:
c.trks = 1 === o ? new _(t.data) : new S(t.data);
break;
case 1096041805:
c.meta = new U(t.data);
break;
case 1414091351:
break;
default:
e("Unsupported chunk", n(t.type, 8))
}
t = i()
}
} else
e("Invalid woz header");
const {meta: l, tmap: d, trks: f, info: u} = c;
return {
encoding: "bitstream",
format: "woz",
trackMap: (null == d ? void 0 : d.trackMap) || [],
rawTracks: (null == f ? void 0 : f.rawTracks) || [],
readOnly: !0,
metadata: {
name: (null == l ? void 0 : l.values.title) || t.name,
side: (null == l ? void 0 : l.values.side_name) || (null == l ? void 0 : l.values.side)
},
info: u
}
}(r)
}
return a
}
e("Worker loaded"),
addEventListener("message", (n => {
e("Worker started", n.type);
const r = n.data,
{driveNo: l} = r.payload;
let d = null;
switch (r.type) {
case "PROCESS_BINARY":
{
const {fmt: t, options: e} = r.payload;
d = I(t, e)
}break;
case "PROCESS_JSON_DISK":
{
const {jsonDisk: t} = r.payload;
d = function(t) {
const e = t.type,
n = t.readOnly,
r = t.name,
o = t.disk;
if (c = e, s.includes(c)) {
let s;
if ("base64" === t.encoding) {
s = [];
for (let e = 0; e < t.data.length; e++)
if (s[e] = [], "nib" === t.type)
s[e][0] = a(t.data[e]);
else
for (let n = 0; n < t.data[e].length; n++)
s[e][n] = a(t.data[e][n])
} else
s = t.data;
return I(e, {
volume: t.volume || 254,
readOnly: n,
name: r,
side: o,
data: s
})
}
return null;
var c
}(t)
}break;
case "PROCESS_JSON":
{
const {json: e} = r.payload;
d = function(e) {
const n = [],
r = JSON.parse(e),
l = r.volume || 254,
d = r.readOnly || !1;
for (let e = 0; e < r.data.length; e++) {
let o = [];
for (let t = 0; t < r.data[e].length; t++) {
const n = "po" === r.type ? i[t] : c[t],
s = a(r.data[e][n]);
o = o.concat(h(l, e, t, s))
}
n[e] = t(o)
}
if (f = r.type, !s.includes(f))
throw new Error(`JSON disks of type ${r.type} are not supported`);
var f;
return {
volume: l,
format: r.type,
encoding: o,
metadata: {
name: r.name
},
tracks: n,
readOnly: d
}
}(e)
}
}
const f = {
type: "DISK_PROCESSED",
payload: {
driveNo: l,
disk: d
}
};
self.postMessage(f),
e("Worker complete", n.type)
}))
}();
//# sourceMappingURL=format_worker.bundle.js.map