I just had an idea for faster 320x240 graphics. I don't know if anyone's interested but:
The problem is that 320x240x16bpp is way too big to fit into RAM, so when you're writing each pixel has to be sent over pretty much one at a time. Not only that but you probably don't care about all 16 bits and would be happy with a few less.
What if you could store the data at a lower bit depth and expand it up as you sent it to the display? Well, you can...
The code below converts 1bpp graphics into 16bpp, one line at a time.
var g = Graphics.createArrayBuffer(16,16,1);
g.drawLine(0,0,15,15);
// convert ABCDEFGH into AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH
function expand(b) {
return (((b&0x11)*0x000F00F)&0x000F000F) |
(((b&0x22)*0x0078078)&0x00F000F0) |
(((b&0x44)*0x03C03C0)&0x0F000F00) |
(((b&0x88)*0x1E01E00)&0xF000F000);
}
function flip() {
var w = g.getWidth()>>3; // 8 bit, 1 BPP
var h = g.getHeight();
var b;
for (var y=0;y<h;y++) {
b = new Uint32Array(new Uint8Array(g.buffer,y*w,w)).map(expand); // 1 bit to 4 bit
b = new Uint32Array(new Uint8Array(b.buffer)).map(expand); // 4 bit to 16 bit
console.log(b);
//spi.write(b.buffer);
}
}
flip();
It's not that fast right now - it's only a proof of concept - but the 'expand' function could be a bit of inline assembler which would help matters no end.
The other option is to add something to Espruino itself - specifically SPI.write already has the ability to specify {data: ..., count:#} as an argument. What if you could also specify {data: g.buffer, fromBits:2, toBits:16, : lookup:[0,255,65280,65535]}, then you could actually do palletted graphics?
Having said all that, g.fillRect is currently going as fast as possible - so if that is running too slow for you then this wouldn't help I'm afraid.
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,
I just had an idea for faster 320x240 graphics. I don't know if anyone's interested but:
The problem is that 320x240x16bpp is way too big to fit into RAM, so when you're writing each pixel has to be sent over pretty much one at a time. Not only that but you probably don't care about all 16 bits and would be happy with a few less.
What if you could store the data at a lower bit depth and expand it up as you sent it to the display? Well, you can...
The code below converts 1bpp graphics into 16bpp, one line at a time.
It's not that fast right now - it's only a proof of concept - but the 'expand' function could be a bit of inline assembler which would help matters no end.
The other option is to add something to Espruino itself - specifically
SPI.write
already has the ability to specify{data: ..., count:#}
as an argument. What if you could also specify{data: g.buffer, fromBits:2, toBits:16, : lookup:[0,255,65280,65535]}
, then you could actually do palletted graphics?Having said all that,
g.fillRect
is currently going as fast as possible - so if that is running too slow for you then this wouldn't help I'm afraid.