Here it is. It will colorise an image and create a new image that has been colorised.
Blend modes are:
1-Standard (like setSpriteColor)
2-Additive (colours get brighter)
3-Standard preserving white (this only preserves pure white pixels)
4-Additive preserving black (this only preserves pure black)
It takes around 0.6 seconds to convert a 512x512 image on my laptop.
This might not be the best solution but it's pretty easy to play with
function colorizeImage(img1 as integer, red as float, green as float, blue as float, blendMode as integer)
rem create the memblock
mem1 = createMemblockFromImage(img1)
w = GetMemblockByte(mem1,0)+GetMemblockByte(mem1,1)*256
h = GetMemblockByte(mem1,4)+GetMemblockByte(mem1,5)*256
rem loop through pixels
s = w*h*4
for d=12 to s step 4
rem get current pixel data
for p=0 to 3
select p
case 0 : thisred# = GetMemblockByte(mem1,d+p) : endcase
case 1 : thisgreen# = GetMemblockByte(mem1,d+p) : endcase
case 2 : thisblue# = GetMemblockByte(mem1,d+p) : endcase
case 3 : alpha# = GetMemblockByte(mem1,d+p) : endcase
endselect
next
rem calulate new values
select blendMode
case 1
rem standard method
thisred# = thisred#*(red/255.0)
thisgreen# = thisgreen#*(green/255.0)
thisblue# = thisblue#*(blue/255.0)
endcase
case 2
rem additive
thisred# = thisred#+red
thisgreen# = thisgreen#+green
thisblue# = thisblue#+blue
if thisred#>255 then thisred# = 255
if thisgreen#>255 then thisgreen# = 255
if thisblue#>255 then thisblue# = 255
endcase
case 3
rem standard + preserve black and white
col = 1
if thisred#=255
if thisgreen#=255
if thisblue#=255
if alpha#>0
col = 0
endif
endif
endif
endif
if col=1
thisred# = thisred#*(red/255.0)
thisgreen# = thisgreen#*(green/255.0)
thisblue# = thisblue#*(blue/255.0)
endif
endcase
case 4
rem additive + preserve black
col = 1
if thisred#=0
if thisgreen#=0
if thisblue#=0
if alpha#>0
col = 0
endif
endif
endif
endif
if col=1
thisred# = thisred#+red
thisgreen# = thisgreen#+green
thisblue# = thisblue#+blue
if thisred#>255 then thisred# = 255
if thisgreen#>255 then thisgreen# = 255
if thisblue#>255 then thisblue# = 255
endif
endcase
endselect
rem apply changes
for p=0 to 3
select p
case 0 : SetMemblockByte(mem1,d+p,thisred#) : endcase
case 1 : SetMemblockByte(mem1,d+p,thisgreen#) : endcase
case 2 : SetMemblockByte(mem1,d+p,thisblue#) : endcase
case 3 : SetMemblockByte(mem1,d+p,alpha#) : endcase
endselect
next
next
img2 = createImageFromMemblock(mem1)
rem tidy up
deleteMemblock(mem1)
endfunction img2
This is the original image edited using this function for the above images:
this.mess = abs(sin(times#))