Hi everyone, long time no see...
I decided to give it a go too...
Here's some code I wrote a while ago, which some may remember from the code snippets.
Blending images together:
`setup
sync on : sync rate 0
`Create media (the 2 memblocks that have to be blended
box 0,0,256,256,rgb(255,0,0),rgb(0,255,0),rgb(0,0,255),rgb(255,255,255)
get image 1,0,0,256,256,1 : make memblock from image 1,1
ink rgb(255,0,0),0 : box 0,0,256,256
get image 2,0,0,256,256,1 : make memblock from image 2,2
BlendImageMemblocks(1, 2, 3, 50.0)
make image from memblock 3,3
perc# = 50.0
do
cls
`Controls
if upkey() = 1
inc perc#, 0.5
if perc# > 100.0 then perc# = 100.0
BlendImageMemblocks(1,2,3,perc#)
make image from memblock 3,3
endif
if downkey()
dec perc#, 0.5
if perc# < 0.0 then perc# = 0.0
BlendImageMemblocks(1,2,3,perc#)
make image from memblock 3,3
endif
`Output
paste image 3, 0, 0
ink rgb(255,255,255),0
text 0,400,"press up/down to slowly fade between the images..."
text 0,420, left$(str$(perc#+0.05),4) + "%"
sync
loop
`Function
function BlendImageMemblocks(Mem1, Mem2, RetMem, percent#)
`Get data
Width = memblock dword(Mem1, 0)
Height = memblock dword(Mem1, 4)
`setup teh returned memblock
if memblock exist(RetMem)=0 then make memblock RetMem, 12 + (Width*Height*4)
write memblock dword RetMem, 0, Width
write memblock dword RetMem, 4, Height
write memblock dword RetMem, 8, 32
`blend
for y = 1 to Height
for x = 1 to Width
pos = 12 + ((y-1)*Width*4) + ((x-1)*4)
difblue# = (memblock byte(Mem2, pos) - memblock byte(Mem1, pos))
difgreen# = (memblock byte(Mem2, pos+1) - memblock byte(Mem1, pos+1))
difred# = (memblock byte(Mem2, pos+2) - memblock byte(Mem1, pos+2))
blue = memblock byte(Mem1, pos) + int(difblue# / 100.0 * percent#)
green = memblock byte(Mem1, pos+1) + int(difgreen#/ 100.0 * percent#)
red = memblock byte(Mem1, pos+2) + int(difred# / 100.0 * percent#)
write memblock byte RetMem, pos, blue
write memblock byte RetMem, pos+1, green
write memblock byte RetMem, pos+2, red
write memblock byte RetMem, pos+3, 255
next x
next y
endfunction
Blending images with a map (like ImageTrans):
`setup
sync on : sync rate 0
`Create media (the 2 memblocks that have to be blended and the map)
`Create 2 images to blend
ink rgb(255,0,0),0 : box 0,0,128,128 : get image 1,0,0,128,128,1 : make memblock from image 1,1
ink rgb(0,255,0),0 : box 0,0,128,128 : get image 2,0,0,128,128,1 : make memblock from image 2,2
`Create map
box 0,0,128,128,rgb(0,0,0),rgb(0,0,0),rgb(0,0,0),rgb(255,255,255)
get image 3,0,0,128,128,1 : make memblock from image 3,3
`Create output
BlendMapImageMemblocks(1,2,4,3)
make image from memblock 4,4
do
cls
`Output
paste image 1, 0, 0 : paste image 2,129,0 : paste image 3,258,0
ink rgb(255,255,255),0
center text 64,64,"Img 1"
center text 193,64,"Img 2"
center text 322,64,"Greyscale map"
text 5, 185, "Output:"
paste image 4,0,200
sync
loop
function BlendMapImageMemblocks(Mem1, Mem2, RetMem, Map)
`Get data
Width = memblock dword(Mem1, 0)
Height = memblock dword(Mem1, 4)
`setup teh returned memblock
if memblock exist(RetMem)=0 then make memblock RetMem, 12 + (Width*Height*4)
write memblock dword RetMem, 0, Width
write memblock dword RetMem, 4, Height
write memblock dword RetMem, 8, 32
`blend
for y = 1 to Height
for x = 1 to Width
pos = 12 + ((y-1)*Width*4) + ((x-1)*4)
difblue# = (memblock byte(Mem2, pos) - memblock byte(Mem1, pos))
difgreen# = (memblock byte(Mem2, pos+1) - memblock byte(Mem1, pos+1))
difred# = (memblock byte(Mem2, pos+2) - memblock byte(Mem1, pos+2))
blue = memblock byte(Mem1, pos) + int(difblue# / 255.0 * memblock byte(Map, pos))
green = memblock byte(Mem1, pos+1) + int(difgreen#/ 255.0 * memblock byte(Map, pos+1))
red = memblock byte(Mem1, pos+2) + int(difred# / 255.0 * memblock byte(Map, pos+2))
write memblock byte RetMem, pos, blue
write memblock byte RetMem, pos+1, green
write memblock byte RetMem, pos+2, red
write memblock byte RetMem, pos+3, 255
next x
next y
endfunction
[EDIT] Does someone has an algorithm for blurring? Not code, just the theory behind it. thx in advance...
It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.