From a30a5c4c6b56f91b57008310f1bb7425127e58fe Mon Sep 17 00:00:00 2001 From: plewka <46826037+plewka@users.noreply.github.com> Date: Wed, 24 Nov 2021 11:10:21 +0100 Subject: [PATCH] Support ESP+u8g2 with optional bitswap Somewhere (SPI Interface?) there is a MSB/LSB swap when using the converter with ESP32 and the U8g2 library which distorts the output. I checked with 1bit per pixel output but added an optional bitswap checkbox, a function to do optinal swap and added it to all output functions. The lvgl online converter has got the same problem. Maybe there is is something wrong with the u8g... Since endian is a traditional an generic issue I thought it's probably a nice feature inside the converter which at least works fine for me. --- index.html | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 71eb917..06d1b74 100644 --- a/index.html +++ b/index.html @@ -342,6 +342,13 @@ + +
+
+
+ +
+
Note: centering the image only works when using a canvas larger than the original image. @@ -474,7 +481,7 @@ // When we have the complete 8 bits, combine them into a hex value if(byteIndex < 0){ - var byteSet = number.toString(16); + var byteSet = bitswap(number).toString(16); if(byteSet.length == 1){ byteSet = "0"+byteSet; } var b = "0x"+byteSet; output_string += b + ", "; @@ -509,7 +516,7 @@ } byteIndex--; } - var byteSet = number.toString(16); + var byteSet = bitswap(number).toString(16); if (byteSet.length == 1){ byteSet = "0"+byteSet; } var b = "0x"+byteSet.toString(16); output_string += b + ", "; @@ -540,7 +547,7 @@ var firstByte = (rgb >> 8) & 0xff; var secondByte = rgb & 0xff; - var byteSet = rgb.toString(16); + var byteSet = bitswap(rgb).toString(16); while(byteSet.length < 4){ byteSet = "0" + byteSet; } output_string += "0x" + byteSet + ", "; @@ -570,7 +577,7 @@ var firstByte = (rgb >> 8) & 0xff; var secondByte = rgb & 0xff; - var byteSet = rgb.toString(16); + var byteSet = bitswap(rgb).toString(16); while(byteSet.length < 8){ byteSet = "0" + byteSet; } output_string += "0x" + byteSet + ", "; @@ -608,7 +615,7 @@ // When we have the complete 8 bits, combine them into a hex value if(byteIndex < 0){ - var byteSet = number.toString(16); + var byteSet = bitswap(number).toString(16); if(byteSet.length == 1){ byteSet = "0"+byteSet; } var b = "0x"+byteSet; output_string += b + ", "; @@ -1380,6 +1387,15 @@ return "unsigned char"; } } + function bitswap(b) { + if(settings["bitswap"]) + { + b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; + b = (b & 0xCC) >> 2 | (b & 0x33) << 2; + b = (b & 0xAA) >> 1 | (b & 0x55) << 1; + } + return b; + } // -- document.getElementById("outputFormat").value = "arduino";