-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
59 lines (53 loc) · 1.31 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function info_pfm(
binaryData: ArrayBuffer
): [boolean, [number, number], number, number] {
const dataView = new DataView(binaryData);
let byteOffset = 0;
let line = "";
let isColored = false;
let width = 0;
let height = 0;
let scale = 0;
// Read the first line
while (true) {
const charCode = dataView.getUint8(byteOffset++);
if (charCode === 10) {
// Newline character
break;
}
line += String.fromCharCode(charCode);
}
// Check if the PFM is colored or not
if (line === "PF") {
isColored = true;
} else if (line !== "Pf") {
throw new Error("Invalid PFM format");
}
// Read the width and height
line = "";
while (true) {
const charCode = dataView.getUint8(byteOffset++);
if (charCode === 10) {
// Newline character
break;
}
line += String.fromCharCode(charCode);
}
const [widthStr, heightStr] = line.split(" ");
width = parseInt(widthStr);
height = parseInt(heightStr);
// Read the scale variable
line = "";
while (true) {
const charCode = dataView.getUint8(byteOffset++);
if (charCode === 10) {
// Newline character
break;
}
line += String.fromCharCode(charCode);
}
scale = parseFloat(line);
return [isColored, [width, height], scale, byteOffset];
}
export default info_pfm
// testing