Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MarlinFirmware/MarlinDocumentation.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/_tools
diff options
context:
space:
mode:
authorScott Lahteine <github@thinkyhead.com>2018-02-25 00:21:32 +0300
committerScott Lahteine <github@thinkyhead.com>2018-02-25 00:21:32 +0300
commitda28a7dd7c6afe7f9fd25bc32889c2de8295a993 (patch)
tree6fef79d97eb0c8ee8649918137a816d557fb3f98 /_tools
parent717bb21b695e074c78acf436adc919b31a620954 (diff)
Bitmap threshold based on mid-range of pixel colors
Diffstat (limited to '_tools')
-rw-r--r--_tools/u8glib/converter.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/_tools/u8glib/converter.js b/_tools/u8glib/converter.js
index a65d85ab..0d6c113e 100644
--- a/_tools/u8glib/converter.js
+++ b/_tools/u8glib/converter.js
@@ -246,12 +246,23 @@ var bitmap_converter = function() {
tdat = tref.data;
}
+ //
// Convert the image to B/W by threshold.
// If rendering also update the ImageData.data.
+ //
+
+ var lo_thr = 127, hi_thr = 127;
+ for (var i = 0; i < data.length; i += 4) {
+ var gray = grayscale(data.slice(i, i+3));
+ if (gray < lo_thr) lo_thr = gray;
+ if (gray > hi_thr) hi_thr = gray;
+ }
+ var mid_thr = (lo_thr + hi_thr) / 2;
+
var out = [];
for (var i = 0; i < data.length; i += 4) {
var gray = grayscale(data.slice(i, i+3)),
- pixon = data[i+3] > 63 && is_lit == (gray > 127),
+ pixon = data[i+3] > 63 && is_lit == (gray > mid_thr),
pixel = is_inv != pixon,
c = pixel ? lcd_on : lcd_off;
out.push(pixel);