Skip to content

Commit

Permalink
move Uint8ArrayToStr method in Utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 21, 2024
1 parent 55d0faa commit e327d52
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 138 deletions.
2 changes: 1 addition & 1 deletion dist/ARToolkitNFT.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ARToolkitNFT_simd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ARToolkitNFT_td.js

Large diffs are not rendered by default.

47 changes: 3 additions & 44 deletions src/ARToolkitNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ export class ARToolkitNFT implements IARToolkitNFT {
this.FS.unlink(prefixTemp + ".fset");
this.FS.unlink(prefixTemp + ".fset3");

let hexStrIset = this.Uint8ArrayToStr(contentIsetUint8);
let hexStrFset = this.Uint8ArrayToStr(contentFsetUint8);
let hexStrFset3 = this.Uint8ArrayToStr(contentFset3Uint8);
let hexStrIset = Utils.Uint8ArrayToStr(contentIsetUint8);
let hexStrFset = Utils.Uint8ArrayToStr(contentFsetUint8);
let hexStrFset3 = Utils.Uint8ArrayToStr(contentFset3Uint8);

let contentIset = new Uint8Array(
hexStrIset.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)),
Expand Down Expand Up @@ -497,47 +497,6 @@ export class ARToolkitNFT implements IARToolkitNFT {
return isZFT;
}

private Uint8ArrayToStr(array: any) {
let out, i, len, c;
let char2, char3;

out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
);
break;
}
}

return out;
}

// ---------------------------------------------------------------------------

// implementation
Expand Down
47 changes: 3 additions & 44 deletions src/ARToolkitNFT_simd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ export class ARToolkitNFT implements IARToolkitNFT {
this.FS.unlink(prefixTemp + ".fset");
this.FS.unlink(prefixTemp + ".fset3");

let hexStrIset = this.Uint8ArrayToStr(contentIsetUint8);
let hexStrFset = this.Uint8ArrayToStr(contentFsetUint8);
let hexStrFset3 = this.Uint8ArrayToStr(contentFset3Uint8);
let hexStrIset = Utils.Uint8ArrayToStr(contentIsetUint8);
let hexStrFset = Utils.Uint8ArrayToStr(contentFsetUint8);
let hexStrFset3 = Utils.Uint8ArrayToStr(contentFset3Uint8);

let contentIset = new Uint8Array(
hexStrIset.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)),
Expand Down Expand Up @@ -496,47 +496,6 @@ export class ARToolkitNFT implements IARToolkitNFT {
return isZFT;
}

private Uint8ArrayToStr(array: any) {
let out, i, len, c;
let char2, char3;

out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
);
break;
}
}

return out;
}

// ---------------------------------------------------------------------------

// implementation
Expand Down
47 changes: 3 additions & 44 deletions src/ARToolkitNFT_td.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ export class ARToolkitNFT implements IARToolkitNFT {
this.FS.unlink(prefixTemp + ".fset");
this.FS.unlink(prefixTemp + ".fset3");

let hexStrIset = this.Uint8ArrayToStr(contentIsetUint8);
let hexStrFset = this.Uint8ArrayToStr(contentFsetUint8);
let hexStrFset3 = this.Uint8ArrayToStr(contentFset3Uint8);
let hexStrIset = Utils.Uint8ArrayToStr(contentIsetUint8);
let hexStrFset = Utils.Uint8ArrayToStr(contentFsetUint8);
let hexStrFset3 = Utils.Uint8ArrayToStr(contentFset3Uint8);

let contentIset = new Uint8Array(
hexStrIset.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)),
Expand Down Expand Up @@ -495,47 +495,6 @@ export class ARToolkitNFT implements IARToolkitNFT {
return isZFT;
}

private Uint8ArrayToStr(array: any) {
let out, i, len, c;
let char2, char3;

out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
);
break;
}
}

return out;
}

// ---------------------------------------------------------------------------

// implementation
Expand Down
41 changes: 41 additions & 0 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,45 @@ export default class Utils {
}
return data;
}

static Uint8ArrayToStr(array: any) {
let out, i, len, c;
let char2, char3;

out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
);
break;
}
}

return out;
}
}
1 change: 0 additions & 1 deletion types/src/ARToolkitNFT.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export declare class ARToolkitNFT implements IARToolkitNFT {
loadCamera(urlOrData: Uint8Array | string): Promise<number>;
addNFTMarkers(urls: Array<string | Array<string>>, callback: (filename: number[]) => void, onError2: (errorNumber: number) => void): Array<number>;
private checkZFT;
private Uint8ArrayToStr;
private _storeDataFile;
private ajax;
}
1 change: 0 additions & 1 deletion types/src/ARToolkitNFT_simd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export declare class ARToolkitNFT implements IARToolkitNFT {
loadCamera(urlOrData: Uint8Array | string): Promise<number>;
addNFTMarkers(urls: Array<string | Array<string>>, callback: (filename: number[]) => void, onError2: (errorNumber: number) => void): Array<number>;
private checkZFT;
private Uint8ArrayToStr;
private _storeDataFile;
private ajax;
}
1 change: 0 additions & 1 deletion types/src/ARToolkitNFT_td.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export declare class ARToolkitNFT implements IARToolkitNFT {
loadCamera(urlOrData: Uint8Array | string): Promise<number>;
addNFTMarkers(urls: Array<string | Array<string>>, callback: (filename: number[]) => void, onError2: (errorNumber: number) => void): Array<number>;
private checkZFT;
private Uint8ArrayToStr;
private _storeDataFile;
private ajax;
}
1 change: 1 addition & 0 deletions types/src/Utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default class Utils {
static fetchRemoteData(url: string): Promise<Uint8Array>;
static fetchRemoteDataCallback(url: string, callback: any): Promise<any>;
static string2Uint8Data(string: string): Uint8Array;
static Uint8ArrayToStr(array: any): string;
}

0 comments on commit e327d52

Please sign in to comment.