-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.html
279 lines (235 loc) · 7.01 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html>
<head>
<title>goMarkableStream</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
/* CSS styles for the layout */
body, html {
margin: 0;
padding: 0;
height: 100%;
}
#container {
position: relative;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
#canvas {
max-width: 100%;
max-height: 100%;
}
canvas.hidden {
display: none;
}
.sidebar {
width: 150px;
height: 100vh;
background-color: #f1f1f1;
position: fixed;
top: 0;
left: -140px;
transition: left 0.3s;
z-index: 2;
}
.sidebar.active {
left: 0;
}
.menu {
list-style: none;
padding: 0;
}
.menu li {
padding: 10px;
}
.menu li a {
text-decoration: none;
color: #000;
}
.menu li a:hover {
color: #ff0000;
}
.my-button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
border-radius: 4px;
}
</style>
</head>
<body>
<div id="menuContainer">
<div class="sidebar" id="sidebar">
<ul class="menu">
<li><button class="my-button">Rotate</button></li>
<li><button class="my-button">Screenshot</button></li>
</ul>
</div>
</div>
<canvas id="fixedCanvas" width="1872" height="1404" class="hidden"></canvas>
<div id="container">
<canvas id="canvas" width="1872" height="1404"></canvas>
</div>
<script>
const sidebar = document.querySelector('.sidebar');
sidebar.addEventListener('mouseover', function() {
sidebar.classList.add('active');
});
sidebar.addEventListener('mouseout', function() {
sidebar.classList.remove('active');
});
// Use the fixed-size canvas context to draw on the canvas
var fixedCanvas = document.getElementById("fixedCanvas");
var fixedContext = fixedCanvas.getContext("2d");
var resizableCanvas = document.getElementById("canvas");
var resizableContext = resizableCanvas.getContext("2d");
// Set the fill color
resizableContext.fillStyle = '#666666';
// Fill the canvas with the specified color
resizableContext.fillRect(0, 0, resizableCanvas.width, resizableCanvas.height);
function copyCanvasContent() {
resizableContext.drawImage(fixedCanvas, 0, 0, resizableCanvas.width, resizableCanvas.height);
}
// Set the rotation angle in degrees
//const rotationAngle = 270;
// Translate the canvas to the center point
//resizableContext.translate(resizableCanvas.width / 2, resizableCanvas.height / 2);
// Rotate the canvas by the specified angle
//resizableContext.rotate((rotationAngle * Math.PI) / 180);
// JavaScript code for working with the canvas element
function resizeCanvas() {
var canvas = document.getElementById("canvas");
var container = document.getElementById("container");
var aspectRatio = 1872 / 1404;
var containerWidth = container.offsetWidth;
var containerHeight = container.offsetHeight;
var containerAspectRatio = containerWidth / containerHeight;
if (containerAspectRatio > aspectRatio) {
canvas.style.width = containerHeight * aspectRatio + "px";
canvas.style.height = containerHeight + "px";
} else {
canvas.style.width = containerWidth + "px";
canvas.style.height = containerWidth / aspectRatio + "px";
}
// Use the canvas context to draw on the canvas
copyCanvasContent();
}
// Resize the canvas whenever the window is resized
window.addEventListener("resize", resizeCanvas);
// Initial call to resize the canvas
//resizeCanvas();
var protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
var socketURL = protocol + window.location.host + '/ws';
var socket = new WebSocket(socketURL);
socket.onopen = function() {
console.log("WebSocket connection established.");
};
socket.onmessage = function(event) {
var blob = event.data; // Received binary data as a Blob
var reader = new FileReader();
reader.onload = function() {
var arrayBuffer = reader.result; // ArrayBuffer representation of the Blob data
// Process the received binary data
processBinaryData(arrayBuffer);
};
reader.readAsArrayBuffer(blob);
};
function processBinaryData(data) {
// Create an ImageData object with the byte array length
var imageData = fixedContext.createImageData(fixedCanvas.width, fixedCanvas.height);
// Assuming each pixel is represented by 4 bytes (RGBA)
var uint8Array = new Uint8Array(data);
const pixels = [];
for (let i = 0; i < uint8Array.length; i++) {
const packedValue = uint8Array[i];
const value1 = packedValue >> 4; // Shift right by 4 positions to get the first 4-bit value
const value2 = packedValue & 0x0F; // Use bitwise AND with 0x0F (binary 00001111) to get the second 4-bit value
switch (value1) {
case 5:
imageData.data[i*8] = 255;
imageData.data[i*8+1] = 0;
imageData.data[i*8+2] = 0;
imageData.data[i*8+3] = 255;
break;
case 9:
imageData.data[i*8] = 0;
imageData.data[i*8+1] = 0;
imageData.data[i*8+2] = 255;
imageData.data[i*8+3] = 255;
break;
case 11:
imageData.data[i*8] = 125;
imageData.data[i*8+1] = 184;
imageData.data[i*8+2] = 86;
imageData.data[i*8+3] = 255;
break;
case 13:
imageData.data[i*8] = 255;
imageData.data[i*8+1] = 253;
imageData.data[i*8+2] = 84;
imageData.data[i*8+3] = 255;
break;
default:
imageData.data[i*8] = value1 * 17;
imageData.data[i*8+1] = value1 * 17;
imageData.data[i*8+2] = value1 * 17;
imageData.data[i*8+3] = 255;
break;
}
switch (value2) {
case 5:
imageData.data[i*8+4] = 255;
imageData.data[i*8+5] = 0;
imageData.data[i*8+6] = 0;
imageData.data[i*8+7] = 255;
break;
case 9:
imageData.data[i*8+4] = 0;
imageData.data[i*8+5] = 0;
imageData.data[i*8+6] = 255;
imageData.data[i*8+7] = 255;
break;
case 11:
imageData.data[i*8+4] = 125;
imageData.data[i*8+5] = 184;
imageData.data[i*8+6] = 86;
imageData.data[i*8+7] = 255;
break;
case 13:
imageData.data[i*8+4] = 255;
imageData.data[i*8+5] = 253;
imageData.data[i*8+6] = 84;
imageData.data[i*8+7] = 255;
break;
default:
imageData.data[i*8+4] = value2 * 17;
imageData.data[i*8+5] = value2 * 17;
imageData.data[i*8+6] = value2 * 17;
imageData.data[i*8+7] = 255;
break;
}
}
// Display the ImageData on the canvas
fixedContext.putImageData(imageData, 0, 0);
copyCanvasContent();
};
socket.onerror = function(event) {
console.log(event);
}
socket.onclose = function(event) {
console.log("WebSocket connection closed with code: " + event.code);
console.log("WebSocket connection closed with code: " + event);
};
</script>
</body>
</html>