Skip to content

Commit 0987a67

Browse files
committed
split waterfall over multiple canvas elements to increase maximum fft resolution
1 parent cc385f8 commit 0987a67

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

htdocs/css/openwebrx.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,21 @@ input[type=range]:disabled {
294294
flex-grow: 1;
295295
}
296296

297+
#webrx-canvas-container div
298+
{
299+
position: relative;
300+
overflow: visible;
301+
width: 100%;
302+
}
303+
297304
#webrx-canvas-container canvas
298305
{
299306
position: absolute;
300307
border-style: none;
301308
image-rendering: crisp-edges;
302309
image-rendering: -webkit-optimize-contrast;
303-
width: 100%;
304310
height: 200px;
311+
pointer-events: none;
305312
}
306313

307314
#openwebrx-log-scroll

htdocs/openwebrx.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,22 +1226,30 @@ function color_between(first, second, percent) {
12261226
}
12271227

12281228

1229-
var canvas_context;
1229+
var canvas_max_width = 8192;
1230+
var canvas_subcontainer;
12301231
var canvases = [];
12311232
var canvas_default_height = 200;
12321233
var canvas_container;
12331234
var canvas_actual_line;
12341235

12351236
function add_canvas() {
1236-
var new_canvas = document.createElement("canvas");
1237-
new_canvas.width = fft_size;
1238-
new_canvas.height = canvas_default_height;
1239-
canvas_actual_line = canvas_default_height - 1;
1240-
new_canvas.openwebrx_top = (-canvas_default_height + 1);
1241-
new_canvas.style.top = new_canvas.openwebrx_top.toString() + "px";
1242-
canvas_context = new_canvas.getContext("2d");
1243-
canvas_container.appendChild(new_canvas);
1244-
canvases.push(new_canvas);
1237+
canvas_subcontainer = document.createElement("div");
1238+
var n = fft_size / canvas_max_width;
1239+
var w = 100 / n;
1240+
for (var i = 0; i < n; ++i) {
1241+
var new_canvas = document.createElement("canvas");
1242+
new_canvas.width = Math.min(fft_size, canvas_max_width);
1243+
new_canvas.height = canvas_default_height;
1244+
new_canvas.style.width = w + '%';
1245+
new_canvas.style.marginLeft = (w * i) + '%';
1246+
canvas_actual_line = canvas_default_height - 1;
1247+
canvas_subcontainer.appendChild(new_canvas);
1248+
}
1249+
canvas_subcontainer.openwebrx_top = (-canvas_default_height + 1);
1250+
canvas_subcontainer.style.top = canvas_subcontainer.openwebrx_top.toString() + "px";
1251+
canvas_container.appendChild(canvas_subcontainer);
1252+
canvases.push(canvas_subcontainer);
12451253
while (canvas_container && canvas_container.clientHeight + canvas_default_height * 2 < canvases.length * canvas_default_height) {
12461254
var c = canvases.shift();
12471255
if (!c) break;
@@ -1291,7 +1299,6 @@ function waterfall_init() {
12911299

12921300
function waterfall_add(data) {
12931301
if (!waterfall_setup_done) return;
1294-
var w = fft_size;
12951302

12961303
if (waterfall_measure_minmax_now) {
12971304
var levels = waterfall_measure_minmax_do(data);
@@ -1305,16 +1312,21 @@ function waterfall_add(data) {
13051312
waterfallColorsContinuous(level);
13061313
}
13071314

1308-
//Add line to waterfall image
1309-
var oneline_image = canvas_context.createImageData(w, 1);
1310-
for (var x = 0; x < w; x++) {
1311-
var color = waterfall_mkcolor(data[x]);
1312-
for (i = 0; i < 3; i++) oneline_image.data[x * 4 + i] = color[i];
1313-
oneline_image.data[x * 4 + 3] = 255;
1314-
}
1315+
//Add line to waterfall
1316+
var w = Math.min(fft_size, canvas_max_width);
1317+
for (var j = 0; j < fft_size / canvas_max_width; ++j) {
1318+
var canvas_context = canvas_subcontainer.childNodes[j].getContext("2d");
1319+
var oneline_image = canvas_context.createImageData(w, 1);
1320+
for (var x = 0; x < w; x++) {
1321+
var color = waterfall_mkcolor(data[x + canvas_max_width * j]);
1322+
for (i = 0; i < 3; i++) oneline_image.data[x * 4 + i] = color[i];
1323+
oneline_image.data[x * 4 + 3] = 255;
1324+
}
13151325

1316-
//Draw image
1317-
canvas_context.putImageData(oneline_image, 0, canvas_actual_line--);
1326+
//Draw image
1327+
canvas_context.putImageData(oneline_image, 0, canvas_actual_line);
1328+
}
1329+
--canvas_actual_line;
13181330
shift_canvases();
13191331
if (canvas_actual_line < 0) add_canvas();
13201332
}

0 commit comments

Comments
 (0)