Hi - there might be something fancy you can do at https://graphics.stanford.edu/~seander/bithacks.html which will allow you to extract every odd/even bit. Either that or a 256-entry lookup table (to get 4 bits from the 8).
Your other (much easier!) option is to use the 'drawImage' command to split out just the right bits for you. Normally it'd map 1:1 for 1/2 bit images, but if you specify a palette you can choose what color everything should map to:
var g_both=Graphics.createArrayBuffer(264, 176, 2, {msb: true});
g_both.setColor(2).drawLine(0,0,264,176);
var img_both = g_both.asImage();
var g_one=Graphics.createArrayBuffer(264, 176, 1, {msb: true});
img_both.palette = new Uint16Array([0,0,1,1]);
g_one.drawImage(img_both);
// now g_one has bits set for colors 2,3
img_both.palette = new Uint16Array([0,1,0,0]);
g_one.drawImage(img_both);
// now g_one has bits set for color 1 only
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi - there might be something fancy you can do at https://graphics.stanford.edu/~seander/bithacks.html which will allow you to extract every odd/even bit. Either that or a 256-entry lookup table (to get 4 bits from the 8).
Your other (much easier!) option is to use the 'drawImage' command to split out just the right bits for you. Normally it'd map 1:1 for 1/2 bit images, but if you specify a palette you can choose what color everything should map to: