-
Notifications
You must be signed in to change notification settings - Fork 2
/
fit.js
35 lines (28 loc) · 817 Bytes
/
fit.js
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
import {lazystream} from '../util.js';
export function readMediaAttributes(input) {
const stream = lazystream(input);
const result = {
width: 0,
height: 0,
size: stream.size(),
mime: 'image/fits',
};
while (stream.more()) {
const header = stream.take(30);
const label = header.subarray(0, 8);
if (label.includes('NAXIS1')) {
result.width = parseInt(header.subarray(22, 30));
} else if (label.includes('NAXIS2')) {
result.height = parseInt(header.subarray(22, 30));
break;
} else if (
label.includes('NAXIS') &&
parseInt(header.subarray(22, 30)) < 2
) {
break;
}
stream.skip(50);
}
stream.close();
return result;
}