-
Notifications
You must be signed in to change notification settings - Fork 2
/
hdr.js
32 lines (25 loc) · 879 Bytes
/
hdr.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
import {lazystream} from '../util.js';
export function readMediaAttributes(input) {
const stream = lazystream(input);
const result = {
width: 0,
height: 0,
size: stream.size(),
mime: 'image/vnd.radiance',
};
for (const chunk of stream.overlappingChunks(64)) {
const content = chunk.buffer.toString();
const matches = content.match(/[-+][xy]\s+\d+\s/gi);
if (matches?.length === 2) {
for (const match of matches) {
const cleanMatch = match.toLowerCase().trim().slice(1);
const [axis, stringSize] = cleanMatch.split(/\s+/i);
if (axis === 'x') result.width = parseInt(stringSize);
if (axis === 'y') result.height = parseInt(stringSize);
}
break;
}
}
stream.close();
return result;
}