Skip to content

Commit

Permalink
Merge pull request javl#51 from plewka/patch-1
Browse files Browse the repository at this point in the history
Support ESP+u8g2 with optional bitswap
  • Loading branch information
javl authored Mar 14, 2023
2 parents f16fa3c + a30a5c4 commit 12c6bae
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ <h2>2. Image Settings</h2>
<label for="flipVertically">vertically</label>
</div>
</div>

<div class="table-row">
<div class="table-cell"><label for="bitswap">Swap Bits in Byte</label></div>
<div class="table-cell">
<input id="bitswap" type="checkbox" onchange="updateBoolean('bitswap')">
</div>
</div>
</div>
<div class="note">
<i>Note: centering the image only works when using a canvas larger than the original image.</i>
Expand Down Expand Up @@ -477,7 +484,7 @@ <h2>4. Output</h2>

// 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 + ", ";
Expand Down Expand Up @@ -512,7 +519,7 @@ <h2>4. Output</h2>
}
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 + ", ";
Expand Down Expand Up @@ -543,7 +550,7 @@ <h2>4. Output</h2>
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 + ", ";

Expand Down Expand Up @@ -573,7 +580,7 @@ <h2>4. Output</h2>
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 + ", ";

Expand Down Expand Up @@ -611,7 +618,7 @@ <h2>4. Output</h2>

// 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 + ", ";
Expand Down Expand Up @@ -1389,6 +1396,15 @@ <h2>4. Output</h2>
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";
Expand Down

0 comments on commit 12c6bae

Please sign in to comment.