-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
129 lines (107 loc) · 3.68 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
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten hqx Demo</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<h2>Emscripten Hqx Demo</h2>
<a href="http://www.hiend3d.com/hq2x.html">Hq2x Homepage</a><br/>
<a href="https://github.com/yjh0502/hqx-js">Github Repository</a><br/>
<br/>
<a class="btn" href="#" onclick="upscale(2);">Hq2x</a>
<a class="btn" href="#" onclick="upscale(3);">Hq3x</a>
<a class="btn" href="#" onclick="upscale(4);">Hq4x</a>
<p id="text_time"></p>
</div>
<!--
<div>
<br/>
<input id="img_url" type="text" placeholder="Enter image Url here"/>
<a class="btn" href="#" onclick="updateImage();">Update Image</a>
</div>
-->
<div>
<table class="table">
<thead>
<tr>
<th>Original</th>
<th>Upscaled</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<canvas id="c1" width="6" height="6"></canvas>
</td>
<td>
<h5>Upscaled with Hqx</h5>
<canvas id="c2" width="512" height="128"></canvas>
<h5>Browser Upscaling</h5>
<img id="img_upscale" src="http://desti.ruree.net/hqx/img/test_original.gif"/>
</td>
</tr>
</tbody>
</table>
</div>
<script>
Module = {TOTAL_MEMORY:100000000};
</script>
<script type='text/javascript' src="src/hqx.js"></script>
<script>
var c1 = document.getElementById("c1");
var ctx1 = c1.getContext("2d");
var c2 = document.getElementById("c2");
var ctx2 = c2.getContext("2d");
var image = new Image();
image.onload = function() {
c1.width = image.width;
c1.height = image.height;
ctx1.drawImage(image, 0, 0);
upscale(4);
};
image.src = "http://desti.ruree.net/hqx/img/test_original.gif";
var updateImage = function() {
var text_url = document.getElementById('img_url');
image.src = text_url.value;
}
var upscale = function(ratio) {
var start = new Date().getTime();
var hqx_init = Module.cwrap("hqxInit");
var hqx_filter = Module.cwrap("hq" + ratio + "x_32", "number", ["number", "number", "number", "number"]);
hqx_init();
var origWidth = c1.width;
var origHeight = c1.height;
c2.width = origWidth * ratio;
c2.height = origHeight * ratio;
var setData = function(canvas, ctx, l, offset, count) {
var data = ctx.createImageData(canvas.width, canvas.height);
for(var i = 0; i < count; i++) {
var idx = i * 4;
data.data[idx+0] = l[idx+offset+0];
data.data[idx+1] = l[idx+offset+1];
data.data[idx+2] = l[idx+offset+2];
data.data[idx+3] = l[idx+offset+3];
}
ctx.putImageData(data, 0, 0);
}
var pixelCount = origWidth * origHeight;
var buf_from = Module._malloc(pixelCount * 4);
var buf_to = Module._malloc(pixelCount * 4 * (ratio * ratio));
var origData = ctx1.getImageData(0, 0, origWidth, origHeight);
Module.HEAPU8.set(origData.data, buf_from);
hqx_filter(buf_from, buf_to, origWidth, origHeight);
setData(c2, ctx2, Module.HEAPU8, buf_to, pixelCount * ratio * ratio);
var img_upscale = document.getElementById("img_upscale");
img_upscale.style.width = origWidth * ratio + "px";
img_upscale.style.height = origHeight * ratio + "px";
var time_taken = new Date().getTime() - start;
document.getElementById("text_time").innerText = "Time taken: " + (time_taken / 1000.0) + " seconds";
}
</script>
</body>
</html>