Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : Blit and transparent PNG

Posted: 02:01am
17 Nov 2025
Copy link to clipboard
LeoNicolas
Guru


Hello

I'm working on a new game port for the CMM2, that I'll reveal soon. I'm playing a lot with the blit command to use in this new game. I have a question for the experts . Is there a way to make the blit command only copy the non transparent pixels? Something like in Gimp or Photoshop, when I paste an image over other one and I can see the original image through transparent areas of the pasted image.

I know I can used page 0 and 1 to apply transparencies, but if I have 5 or 10 images that I want to stack to compose another image, I think using these two pages will not work.
I also know that I can use sprites, but in this case, it is a little hard to control the sprites layers, because there is no way to specify the z order. It needs to be controller by the way the sprites are shown.

Here a wrote a small example. I want to render the circle over the rectangle making the rectangle visible through the circle centre, and also making the black parts disappear.

Let's use this PNG. The black area is transparent in the PNG, and it is saved as 8 bpc RGBA



When I run this program...


option explicit

mode 7,12 ' 320x240 / 12 bits

page write 2: cls 0
load png "test.png", 2

page write 0: cls rgb(255, 243, 185)

blit 84,0, 46,46, 96,96, 2
blit 0,0, 52,54, 84,82, 2


the result is:



The transparent areas from the PNG are copied as black by the blit command, overwriting the back image and background.
Edited 2025-11-17 15:46 by LeoNicolas
 
Posted: 05:48am
17 Nov 2025
Copy link to clipboard
LeoNicolas
Guru


I found the solution. I can use the sprite write command to copy the pixels like a blit command, but respecting the transparency.


option explicit

page write 1: cls 0
page write 0: cls rgb(255, 243, 185)

mode 7,12,rgb(255, 243, 185) ' 320x240 / 12 bits

page write 2: cls 0
load png "test.png",,,0

sprite read 1,82,0,100,100,2
sprite read 2, 0,0,74,74,2

page write 0

sprite write 1,72,72
sprite write 2,84,82


And this is the result:


 
Posted: 07:32am
17 Nov 2025
Copy link to clipboard
Volhout
Guru

Hi Leo,

On picomite(VGA) there are typical only 2 layers. The N layer is on bottom, and has no transparency. The L layer is projected onto N, and knows 1 color of transparency.

Following BLIT commands are omitting the transparency color.







I think there will be a lot of commonality with CMM2, since Petscii Robots uses them, and this game is made to run on CMM2 by Peter.

Volhout
Edited 2025-11-17 17:33 by Volhout
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025