forked from SidOfc/leather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdr.js
More file actions
34 lines (28 loc) · 874 Bytes
/
hdr.js
File metadata and controls
34 lines (28 loc) · 874 Bytes
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
import {lazystream} from '../util.js';
export function attributes(input) {
const stream = lazystream(input);
const result = {
width: 0,
height: 0,
size: stream.size(),
mime: 'image/vnd.radiance',
};
while (stream.more()) {
const line = stream.takeLine().toString();
if (line.match(/[-+][xy]/i)) {
const parts = line
.split(' ')
.map((part) => part.replace(/[^a-z0-9]/gi, '').toUpperCase());
if (parts[0] === 'Y') {
result.width = parseInt(parts[3], 10);
result.height = parseInt(parts[1], 10);
} else {
result.width = parseInt(parts[1], 10);
result.height = parseInt(parts[3], 10);
}
break;
}
}
stream.close();
return result;
}