Skip to content

feat: add binary to pixel viewer #2999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion csfieldguide/static/interactives/pixel-viewer/js/pixel-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ $( document ).ready(function() {
$("input[id='rgb-hex-colour-code']").prop('checked', true);
} else if (colour_code_rep == 'hex') {
$("input[id='hex-colour-code']").prop('checked', true);
} else if (colour_code_rep == 'binary') {
$("input[id='binary-colour-code']").prop('checked', true);
} else if (colour_code_rep == 'brightness') {
$("input[id='brightness-colour-code']").prop('checked', true);
} else {
Expand Down Expand Up @@ -1112,6 +1114,9 @@ var paint = function(row, col, left, top, width, height, zoom) {
for (var i = 0; i < cell_lines.length; i++) {
if (colour_code_rep == 'rgb-hex') { // Shows colour codes in RGB using Hexadecimal
value = componentToHex(pixelData[i])
} else if (colour_code_rep == 'binary'){
context.font = (7 * zoom).toFixed(2) + 'px Consolas, Courier New, monospace';
value = decTobinary(pixelData[i])
} else { // Shows colour codes in RGB using Decimal
value = pixelData[i]
}
Expand All @@ -1131,6 +1136,10 @@ function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

function decTobinary(dec){
return (dec >>> 0).toString(2).padStart(8, '0');
}

var rect = container.getBoundingClientRect();
scroller.setPosition(rect.left + container.clientLeft, rect.top + container.clientTop);

Expand Down Expand Up @@ -1269,4 +1278,4 @@ function sum(array){
function showTooltips() {
$(zoomInBtn).tooltip('show');
$(zoomOutBtn).tooltip('show');
}
}
4 changes: 4 additions & 0 deletions csfieldguide/templates/interactives/pixel-viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ <h5>{% trans "Options" %}</h5>
<input class="form-check-input" type="radio" name="colourCode" value="brightness" id="brightness-colour-code">
<label class="form-check-label" for="brightness-colour-code">{% trans "Brightness (average)" %}</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="colourCode" value="binary" id="binary-colour-code">
<label class="form-check-label" for="binary-colour-code">{% trans "Binary (seperate RGB)" %}</label>
</div>
</div>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="configSelector" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Expand Down