You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Argh. so you have to send one byte for 8 pixels of green, and one byte for 8 pixels of red?

    I actually updated graphics to handle 2 bit colour (if you try one of the pre-release binaries), but that does the bits all next to each other.

    So... If you assume that we'd use Graphics, and the bits are RGRGRGRG in a byte, I guess each byte is conveniently a set of 4 pixels, so you could actually just hard-code the 16 bytes:

    var a = new Uint8Array(Graphics.buffer);
    display([
    a[9],a[1],
    a[11],a[3],
    a[13],a[5],
    a[15],a[7],
    a[8],a[0],
    a[10],a[2],
    a[12],a[4],
    a[14],a[6],
    ]);
    

    And then you 'just' have to figure out a way of un-interleaving each pair of bytes - from: RGRGRGRGRGRGRGRG into RRRRRRRRGGGGGGGG.

    There are some fun bit hacks that can do things like this using multiply, & and shift - although I only see a way to interleave on that site - not un-interleave.

    It should be possible. Assuming we start with aAbBcCdD and you want to get ABCD:

    x &= 0b01010101; // mask out just the bits we want ( 0A0B0C0D )
    x *= 0b0011; // this makes ( AABBCCDD )
    x &= 0b01100110; // mask out again ( 0AB00CD0 )
    x *= 0b0101; // this makes ( ABABCDCD0 )
    x &= 0b01111000; // mask out again ( 0ABCD000 )
    x >>= 3; // shift back ( 0000ABCD )
    

    And you have 64 bits to play with, so you should be able to do at least 8 pixels in red and green at once (maybe 16 ;).

    All good fun - if you're into that kind of stuff :)

About

Avatar for Gordon @Gordon started