Sprite wheeze
nemo (145) 2569 posts |
I have a technique to share. There will be pearl-clutching. Some OSes make it easy to paint in a chosen colour using a bilevel (2 colour) bitimage, where 1=paint a pixel and 0=don’t paint anything. RO can’t do that with a simple sprite with only AND, OR, EOR and NOT available. Not in one call anyway. You can set your translation table to be black pixels and white background, AND that onto the screen, then set the trans table to coloured pixels and black background and OR that on top. It works, but it’s a double-hit, and may be flickery too. RO can do it with a sprite mask (painting in the background colour), in which case your mask is the image, and the image pixels are… a complete waste, as they don’t get used (by the Paint Mask calls). Have a 20KB mask, you need to have 20KB of image too, to no purpose. Stupid Sprites. Well, there is a trick. Paint Mask won’t work if the sprite doesn’t have a mask (you just get a rectangle), but how does it know whether a sprite has a mask or not? Sprites comprise a header, an optional palette, the image, then an optional mask. The header contains offsets to the start of the image and the mask, and if there’s no mask, they are both the same. Aha! It turns out (quite properly) that Paint Mask doesn’t care about your image pixels, it only cares about the mask, if it’s there. And it knows it’s there because the image and mask offsets are different. So, (clutch your pearls now), after loading your bilevel maskless sprite, decrement the image offset (by four, if you’re feeling panicky). Paint Mask is now happy that there’s a mask (actually the image) and ignores the image (which is fortunate, cos it ain’t). Result: You can paint your mono sprite in whatever colour you like, single-hit. “But nemo,” I hear you exclaim, “wouldn’t that be absolutely ideal for pixel fonts?”… You may be on to something there. Who needs FontManager when you have four lines of BASIC and a 1K sprite? (Is there some other way of doing it that I’ve forgotten? I find myself reinventing things far too often) |
Rick Murray (539) 13861 posts |
I can’t help but think there is. Translation tables and such is hand in glove with ColourTrans, right? So what did they use in the RISC OS 2 and Arthur days?
What about 1 (dest=source) and 5 (dest=dest) plotting? |
nemo (145) 2569 posts |
Find a way to get 1=my_chosen_colour and 0=transparent in one hit. Sadly -1 in the palette does not mean transparent (and, fantastically annoying this is too, -1 returned from a colour mapping function isn’t transparent either). |