BPP and createArrayBuffer changing colours #5697
Replies: 1 comment
-
Posted at 2023-01-18 by @halemmerich I have had this exact problem on imageclock while working with 4 bit. Copying over my solution from there yields the correct result, but it seems a bit complicated. It essentially uses a palette to force the colors to be correct. I suspect there is an easier way.
Edit: The forum search links in the comments are somehow autogenerated from the #colorvalues Posted at 2023-01-19 by Sir_Indy Thanks for your help @halemmerich, that does work, but I agree it feels like there could be a simpler solution. Posted at 2023-01-19 by @gfwilliams Ok, just to try and strip this down to the actual problem, it's this?
The issue is that when drawing a 3bpp image onto a 8bpp image, Espruino doesn't really know what to do about mapping colours - so it just copies the numeric color value straight across. As @halemmerich noted, the best method is really to try and use a 4bpp graphics (which saves a bunch of memory over 8bpp), and to then explicitly tell Espruino what color palette to use for it (because normally for 4bpp it uses the Mac color palette). His code works great, but you can also use
I've just added some color mappings from 3->4 and 3->8 bit into the Espruino firmware, and this should fix your original code on 8 bit, and will work on 4 bit too ... but then it'll fail on older firmwares. If you use my or @halemmerich's code then at least it'll be backwards compatible. It's also worth adding that Posted at 2023-01-19 by @gfwilliams ... and yes, having a 3bpp arraybuffer graphics would probably be preferable for memory usage and for ensuring a nice clean color mapping. But doing unaligned 3 bit memory accesses is not super easy (or fast), so right now ArrayBuffer graphics only supports BPPs that are byte-aligned (1,2,4,8,16,24,32). Posted at 2023-01-20 by Sir_Indy Thanks for explaining that Gordon, I think I understand better now. The new color mapping will be helpful to make sure no one else trips up on this in the future, but you're right, I'll do it with a palette so it works more broadly. Posted at 2023-01-23 by Sir_Indy So now I've got colours working correctly (thanks again Hal and Gordon), I need to work on speed. See code below, but in the emulator, doing a full screen wipe takes ~6ms/frame. Exactly the same on the actual B2 takes ~228ms/frame, i.e. very very slow. Is there anything I can do to speed this up, or is that just how long it takes to draw the whole screen? Doing only part of the screen definitely speeds things up, but not enough to look smooth.
Posted at 2023-01-24 by @gfwilliams Which bit is slow for you? The It's not helping that you have an image double the size of the screen - and it'll be iterating through every pixel (even the ones that are offscreen) I think. You could have just a single fullscreen graphics (for the new screen) and could then use It seems slightly counter-intuitive, but you could also use http://www.espruino.com/Reference#l_Graphics_drawImages to draw just the single image, but just in the small area that's new. ... so for instance if you scroll by 8 pixels, you do It's slightly slower than drawImage but it allows you to render just an area of the image, which could help in this case Posted at 2023-01-31 by Sir_Indy Thanks for your suggestions Gordon, I tried them all, but in the end redrawing the entire screen was too slow to look good. Your Posted at 2023-02-01 by @gfwilliams
Ahh - you can use Oh well, glad you got something workable anyway |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-01-18 by Sir_Indy
Hi All,
I'm hoping someone can help me understand BPP better. I'm testing out a simple animation, based on the Slope Clock, to slide the current contents of the screen off, and show a new screen. I've had this running in the emulator, but some of the colours are wrong.
It should show BLACK text (wibble) on GREEN, then replace it with WHITE text (flibble) on RED.
When I take a screenshot of the screen with
g.asImage
, and put it in the image buffer withdrawImage
, the colour changes from GREEN to BLUE.I'm sure it's a simple fix somewhere, but I'm stuck!
This is the code I've been trying:
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions