Skip to content

Commit 3a84add

Browse files
committed
split waterfall over multiple canvas elements to increase maximum fft resolution
1 parent 97f3642 commit 3a84add

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
@@ -1229,22 +1229,30 @@ function color_between(first, second, percent) {
12291229
}
12301230

12311231

1232-
var canvas_context;
1232+
var canvas_max_width = 8192;
1233+
var canvas_subcontainer;
12331234
var canvases = [];
12341235
var canvas_default_height = 200;
12351236
var canvas_container;
12361237
var canvas_actual_line;
12371238

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

12951303
function waterfall_add(data) {
12961304
if (!waterfall_setup_done) return;
1297-
var w = fft_size;
12981305

12991306
if (waterfall_measure_minmax_now) {
13001307
var levels = waterfall_measure_minmax_do(data);
@@ -1308,16 +1315,21 @@ function waterfall_add(data) {
13081315
waterfallColorsContinuous(level);
13091316
}
13101317

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

1319-
//Draw image
1320-
canvas_context.putImageData(oneline_image, 0, canvas_actual_line--);
1329+
//Draw image
1330+
canvas_context.putImageData(oneline_image, 0, canvas_actual_line);
1331+
}
1332+
--canvas_actual_line;
13211333
shift_canvases();
13221334
if (canvas_actual_line < 0) add_canvas();
13231335
}

0 commit comments

Comments
 (0)