forked from google/libultrahdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
151 lines (131 loc) · 3.97 KB
/
index.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<html>
</body>
<script type="module" lang="js">
import libultrahdr from './build/libultrahdr-debug.js'
const getimage = (file) => {
return new Promise((resolve, reject) => {
const img = document.createElement('img')
img.onload = () => {
resolve(img)
}
var fr = new FileReader();
fr.onload = () => {
img.src = fr.result;
}
fr.readAsDataURL(file);
})
}
const getArrayBuffer = (file) => {
return new Promise((resolve, reject) => {
var fr = new FileReader();
fr.onload = () => {
resolve(fr.result);
}
fr.readAsArrayBuffer(file);
})
}
const downloadURL = (data, fileName) => {
var a;
a = document.createElement('a');
a.href = data;
a.download = fileName;
document.body.appendChild(a);
a.style = 'display: none';
a.click();
a.remove();
};
const downloadBlob = (data, fileName, mimeType) => {
var blob, url;
blob = new Blob([data], {
type: mimeType
});
url = window.URL.createObjectURL(blob);
downloadURL(url, fileName);
setTimeout(function () {
return window.URL.revokeObjectURL(url);
}, 1000);
};
const start = async () => {
const libraryInstance = await libultrahdr()
let width
let height
let sdr
let gainmap
let metadata
const appendGainmap = () => {
if (sdr && gainmap && width && height && metadata) {
const res = libraryInstance.appendGainMap(
width, height,
sdr , sdr.length,
gainmap, gainmap.length,
metadata.gainMapMax.reduce((p, n) => p + n, 0) / metadata.gainMapMax.length,
metadata.gainMapMin.reduce((p, n) => p + n, 0) / metadata.gainMapMin.length,
metadata.gamma.reduce((p, n) => p + n, 0) / metadata.gamma.length,
metadata.offsetSdr.reduce((p, n) => p + n, 0) / metadata.offsetSdr.length,
metadata.offsetHdr.reduce((p, n) => p + n, 0) / metadata.offsetHdr.length,
metadata.hdrCapacityMin,
metadata.hdrCapacityMax
)
downloadBlob(res, 'packed-gainmap.jpg', 'image/jpeg')
}
}
document.getElementById('sdr').onchange = async (e) => {
const file = e.currentTarget.files[0]
const img = await getimage(file)
width = img.width
height = img.height
const arrBuffer = await file.arrayBuffer();
const byteArray = new Uint8Array(arrBuffer);
sdr = byteArray
appendGainmap()
}
document.getElementById('gainmap').onchange = async (e) => {
const file = e.currentTarget.files[0]
const arrBuffer = await file.arrayBuffer();
const byteArray = new Uint8Array(arrBuffer);
gainmap = byteArray
appendGainmap()
}
document.getElementById('metadata').onchange = async (e) => {
const file = e.currentTarget.files[0]
const fr = new FileReader();
fr.onload = (e) => {
metadata = JSON.parse(e.target.result);
appendGainmap()
}
fr.readAsText(file);
}
document.getElementById('unpack-gainmap').onclick = async (e) => {
const file = document.getElementById('packedGainmap').files[0]
const buf = new Uint8Array(await getArrayBuffer(file))
const res = libraryInstance.extractJpegR(buf, buf.length)
console.log(res)
if (res.success) {
downloadBlob(res.sdr, 'unpacked-sdr.jpg', 'image/jpeg')
downloadBlob(res.gainMap, 'unpacked-gainmap.jpg', 'image/jpeg')
} else {
console.error(res.errorMessage)
}
}
}
start()
</script>
<h1>libultrahdr wasm testbed</h1>
<h2>test encoding</h2>
<div>
SDR
<input type="file" id="sdr" accept="image/jpeg" />
GAINMAP
<input type="file" id="gainmap" accept="image/jpeg" />
METADATA
<input type="file" id="metadata" accept="application/json" />
</div>
<br />
<h2>test decoding</h2>
<div>
packed gainmap:
<input type="file" id="packedGainmap" accept="image/jpeg" />
<button id="unpack-gainmap">UNPACK GAINMAP</button>
</div>
<body>
</html>