Protocol expects now 8 pixels per byte

This commit is contained in:
frubi 2019-12-14 01:19:00 +01:00
parent 1a6bb33b98
commit d9209b854c
2 changed files with 37 additions and 16 deletions

View File

@ -123,7 +123,25 @@
header[5] = 0; header[5] = 0;
socket.send(header); socket.send(header);
socket.send(pixelBuffer);
buf = new Uint8Array((xMax * yMax) / 8);
group = 0;
n = 0;
shift = 7;
for (pixel of pixelBuffer) {
group |= (pixel << shift);
shift--;
if (shift < 0) {
buf[n] = group;
group = 0;
shift = 7;
n++;
}
}
socket.send(buf);
} }
function creatGUI() function creatGUI()

View File

@ -45,7 +45,9 @@ void ProtocolDL::newByte(uint8_t data)
break; break;
default: default:
image->set_pixel(source.x, source.y, data); for (int shift = 7; shift >= 0; shift--) {
byte pixel = (data >> shift) & 1;
image->set_pixel(source.x, source.y, pixel);
if(source.x == (source.width - 1) && source.y == (source.height - 1)) if(source.x == (source.width - 1) && source.y == (source.height - 1))
{ {
@ -64,6 +66,7 @@ void ProtocolDL::newByte(uint8_t data)
} }
} }
} }
}
break; break;
} }