From 01a97d04a14f2e4225d60ddd2ae7295c51c76ed0 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 7 May 2020 15:37:09 +0100 Subject: [PATCH] Well, that was a failed experiment. We will probably come back to multithreading the renderer here, but for now we don't actually need it I don't think. --- package-lock.json | 2 +- src/Subcommands/image/Terrain50Renderer.mjs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 057a87c..1c4ca22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "terrain50-cli", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/Subcommands/image/Terrain50Renderer.mjs b/src/Subcommands/image/Terrain50Renderer.mjs index 5503225..4798bb1 100644 --- a/src/Subcommands/image/Terrain50Renderer.mjs +++ b/src/Subcommands/image/Terrain50Renderer.mjs @@ -6,7 +6,8 @@ import encode from 'image-encode'; import l from '../../Helpers/Log.mjs'; class Terrain50Renderer { - constructor(in_scale_factor) { + constructor(in_scale_factor, in_domain = "auto") { + this.colour_domain = in_domain; this.scale_factor = in_scale_factor; this.colour_scale = chroma.scale([ "#333333", @@ -26,15 +27,22 @@ class Terrain50Renderer { * @return {ArrayBuffer} A canvas with the image rendered on it. */ async do_render(terrain) { - let min = terrain.min_value, max = terrain.max_value; - let colour_domain = this.colour_scale.domain([ - min, max - ]); + let colour_domain = null; + if(this.colour_domain === "auto") { + let min = terrain.min_value, max = terrain.max_value; + colour_domain = this.colour_scale.domain([ + min, max + ]); + l.log(`[Terrain50Renderer] Automatic colour domain: ${min} - ${max}`); + } + else { + colour_domain = this.colour_scale.domain(this.colour_domain); + l.log(`[Terrain50Renderer] Static colour domain: ${this.colour_domain[0]} - ${this.colour_domain[1]}`); + } let width = Math.floor(terrain.meta.ncols / this.scale_factor), height = Math.floor(terrain.meta.nrows / this.scale_factor); - l.log(`[Terrain50Renderer] Colour domain: ${min} - ${max}`); l.log(`[Terrain50Renderer] Dimensions: ${width}x${height}`); // Create the image