Hi Robot
I had tried to make the black opaque once before using a code snippet nearly identicle to yours, however it did not work. Just seeing that code snippet you posted got me thinking why it didn't work. I investigated it and now have a colour key command for all DBC users - Horay. In other words you can now have perfect black, rgb(0,0,0) displayed on screen while making another colour transparent.
These are the new altered functions
`note: you must be in 32 bit colour mode to use these functions.
function ChangeColourKey(InputImage,OutputImage,Colour,ChangeBlack)
make memblock from image 256,InputImage
if ChangeBlack = 0
for index = 12 to get memblock size(256) - 1 step 4
if memblock dword(256,index) = Colour then write memblock byte 256,index + 3,0
next index
else
for index = 12 to get memblock size(256) - 1 step 4
if memblock dword(256,index) = 0 then write memblock byte 256,index + 3,255
if memblock dword(256,index) = Colour then write memblock byte 256,index + 3,0
next index
endif
make image from memblock OutputImage,256
delete memblock 256
endfunction
function OpaqueBlack(InputImage,OutputImage)
make memblock from image 256,InputImage
for index = 12 to get memblock size(256) - 1 step 4
if memblock dword(256,index) = 0 then write memblock byte 256,index + 3,255
next index
make image from memblock OutputImage,256
delete memblock 256
endfunction
Set the ChangeBlack to anything other than 0 to make black not transparent. I also included a function to just set black opaque.
Here is the example program updated
`make a box that has a white border, then an inner black border
`then a red box in the middle
cls rgb(255,255,255)
ink rgb(0,0,0),rgb(0,0,0)
box 20,20,108,108
ink rgb(255,0,0),rgb(0,0,0)
box 40,40,88,88
get image 1,0,0,128,128,1
ink rgb(255,255,255),rgb(0,0,0)
cls rgb(0,0,255)
paste image 1,0,0,1
OpaqueBlack(1,1)
ChangeColourKey(1,2,rgb(255,0,0),1)
paste image 1,0,150,1
paste image 2,0,300,1
text 150,0,"This is what happens to a normal image with black in"
text 150,20,"it with transparency on."
text 150,150,"This image has true black even though transparency"
text 150,170,"is on. This how the image looked when it was created."
text 150,300,"This image has true black while the red part is transparent."
text 150,450,"Press any key to exit."
sync
wait key
delete image 1
delete image 2
end
`note: you must be in 32 bit colour mode to use these functions.
function ChangeColourKey(InputImage,OutputImage,Colour,ChangeBlack)
make memblock from image 256,InputImage
if ChangeBlack = 0
for index = 12 to get memblock size(256) - 1 step 4
if memblock dword(256,index) = Colour then write memblock byte 256,index + 3,0
next index
else
for index = 12 to get memblock size(256) - 1 step 4
if memblock dword(256,index) = 0 then write memblock byte 256,index + 3,255
if memblock dword(256,index) = Colour then write memblock byte 256,index + 3,0
next index
endif
make image from memblock OutputImage,256
delete memblock 256
endfunction
function OpaqueBlack(InputImage,OutputImage)
make memblock from image 256,InputImage
for index = 12 to get memblock size(256) - 1 step 4
if memblock dword(256,index) = 0 then write memblock byte 256,index + 3,255
next index
make image from memblock OutputImage,256
delete memblock 256
endfunction
Note that I've only tested this in DBP so could you tell me if it works (I think it should). Anyway hope it helps you.