Yes this is certainly possible, I've even coded an example to show you.
`You may notice COLOUR1 is not as big a value as the other colours this is
`because DBP treats the colour rgb(0,0,0) as transparent when grabbing an
`image, so the transparency byte is 0 and hence the number is not as big.
`Therefore if you are loading an image with an alpha channel, such as a
`png image, true black for that image is the number 4278190080 if the
`black is fully opaque.
`COLOUR1 = black
`COLOUR2 = dark grey
`COLOUR3 = light grey
`COLOUR4 = white
#constant COLOUR1 0
#constant COLOUR2 4284769380
#constant COLOUR3 4291348680
#constant COLOUR4 4294967295
iTime1 as integer
iTime2 as integer
iTime3 as integer
set display mode 1024,768,32
sync on
sync rate 0
sync
box 25,25,175,175,COLOUR2,COLOUR2,COLOUR2,COLOUR2
box 50,50,150,150,COLOUR3,COLOUR3,COLOUR3,COLOUR3
box 75,75,125,125,COLOUR4,COLOUR4,COLOUR4,COLOUR4
get image 1,0,0,200,200,1
iTime1 = timer()
fnChangeColour(1,2,rgb(0,255,0),rgb(0,150,0),rgb(0,100,0),rgb(0,200,0))
iTime2 = timer() - iTime1
iTime1 = timer()
fnChangeColour(1,3,rgb(0,200,255),rgb(255,150,0),rgb(50,200,50),rgb(255,255,0))
iTime3 = timer() - iTime1
iTime1 = iTime2 + iTime3
cls rgb(100,0,0)
paste image 1,0,20,0
paste image 2,300,20,0
paste image 3,300,260,0
text 0,0,"Original Image"
text 300,0,"First Image Changed"
text 300,240,"Second Image Changed"
text 0,240,"Time to change first image " + str$(iTime2) + "ms"
text 0,260,"Time to change second image " + str$(iTime3) + "ms"
text 0,280,"Total time for both images " + str$(iTime1) + "ms"
text 0,320,"Press any key to quit"
sync
wait key
delete image 1
delete image 2
delete image 3
end
function fnChangeColour(iInputImage as integer,iOutputImage as integer,dwColour1 as dword,dwColour2 as dword,dwColour3 as dword,dwColour4 as dword)
make memblock from image 1,iInputImage
iMemSize = get memblock size(1) - 1
for iIndex1 = 12 to iMemSize step 4
if memblock dword(1,iIndex1) = COLOUR1
write memblock dword 1,iIndex1,dwColour1
else
if memblock dword(1,iIndex1) = COLOUR2
write memblock dword 1,iIndex1,dwColour2
else
if memblock dword(1,iIndex1) = COLOUR3
write memblock dword 1,iIndex1,dwColour3
else
if memblock dword(1,iIndex1) = COLOUR4 then write memblock dword 1,iIndex1,dwColour4
endif
endif
endif
next iIndex1
make image from memblock iOutputImage,1
delete memblock 1
endfunction
Note: The code must be run in 32 bit colour mode to work, due to how colour data is stored in different colour modes.
The code works by making an image into a memblock; the memblock is then scanned for certain colour values of pixels which are stored as dwords (4 bytes). If that certain colour is found then it changes that value to a specified colour value. The memblock is then made back into an image to be used.
There is only one problem with this method and that is it could be slow if you are doing many images, or if the images are large. This would mean you might have to have loading screens. One way to get around this is use the above code to change your image to your specific colours and save the images. Then just use the newly created images in your game - it will not save space but it means you might not have to having loading screens.
Anyways hope it helps.