
-----------------------------------
Tony
Sun Nov 09, 2003 12:35 am

[source code] Antialiasing - Blur Filter
-----------------------------------
This is a filter you can apply to images in turing to blur them. It used whatdotcolor :oops: and RGB module to calculate an average color of 9 pixels block and redraw pixel in that color, thus resulting in a blur.


procedure Blur()
var d:array 1..maxx, 1..maxy of int %vertual image, holds pixel colors
var c:int:=255 %just a variable for color
var cr,cb,cg:array 1..9 of real %temporary colors
var acr,acb,acg:real %used for average color calculation

for x:1..maxx
for y:1..maxy
d(x,y):=whatdotcolor(x,y) %records pixel colors
end for
end for

for x:2..maxx-1
for y:2..maxy-1

RGB.GetColor(d(x-1,y-1),cr(1),cg(1),cb(1))
RGB.GetColor(d(x,y-1),cr(2),cg(2),cb(2))
RGB.GetColor(d(x+1,y-1),cr(3),cg(3),cb(3))
RGB.GetColor(d(x-1,y),cr(4),cg(4),cb(4))
RGB.GetColor(d(x,y),cr(5),cg(5),cb(5))
RGB.GetColor(d(x+1,y),cr(6),cg(6),cb(6))
RGB.GetColor(d(x-1,y+1),cr(7),cg(7),cb(7))
RGB.GetColor(d(x,y+1),cr(8),cg(8),cb(8))
RGB.GetColor(d(x+1,y+1),cr(9),cg(9),cb(9))

acr:=0
for i:1..9
acr+=cr(i)
end for
acr:=acr/9 %average color

acg:=0
for i:1..9
acg+=cg(i)
end for
acg:=acg/9 %average color

acb:=0
for i:1..9
acb+=cb(i)
end for
acb:=acb/9 %average color


RGB.SetColor(c,acr,acg,acb) %create the new color
Draw.Dot(x,y,c) %draw that color
end for
end for

end Blur


filter itself is way too slow to generate real-time images for games, but if you need some turing created images blured, thats the way to go :D


A practical use for it - antialiasing 8)
http://www.compsci.ca/bbs/files/blur2.jpg

You can antialias just about anything, even your text :D
http://www.compsci.ca/bbs/files/blur.jpg

You might have to redraw parts of your image on top of the blured background to regain lost details.

Also Note: apparently filter doesn't work for certain colors that are you'd think are in 255 strandart pallet:? "blue" doesn't work for example.
"blue" doesn't work because it's color (1 on 255 scale) is being used as a value to store temporary value. change c=1 to c=255 to fix the problem.

-----------------------------------
rizzix
Sun Nov 09, 2003 12:41 am


-----------------------------------
nice :)

we need more of these filters in turing...

-----------------------------------
thoughtful
Sun Nov 09, 2003 11:43 am


-----------------------------------
Hey tony thats awsome! i would have gave you some bits if i had lots :))  :twisted:  :twisted:  :twisted: 

Looks jus like the blurs i use in my Fireworks!!!(a software like photoshop)

-----------------------------------
Catalyst
Sun Nov 09, 2003 1:24 pm


-----------------------------------
heres another filter
http://www.compsci.ca/v2/viewtopic.php?t=1131

-----------------------------------
thoughtful
Sun Nov 09, 2003 4:00 pm


-----------------------------------
tony bro, if you apply the filter  to a picture it gets all grayscale and stuff. I guess this is because whatdotcolor doesnt return RGB values...Why don't you write a module that does:) this will be sweet :)) :idea:

Edit:-well now i read the end of the post and realized that you already mentioned your filter's limitations but still please someone make the RGB module!! My hopes are high for catalyst!  :P

-----------------------------------
Tony
Sun Nov 09, 2003 4:24 pm


-----------------------------------
well technically

var c:int

for r:1..255
   for g:1..255
      for b:1..255
         c:= RGB.AddColor(r/255,b/255,g/255)
      end for
   end for
end for


should add a bunch more colors to the pallet... but it will take forever to load and would still not solve the problem if the image loaded uses a pallet with more then 255^3 colors :roll:

-----------------------------------
Catalyst
Sun Nov 09, 2003 4:37 pm


-----------------------------------
you could also make a virtual frame buffer, rewrite all the draw functions and load the image binary urself  :lol:

-----------------------------------
Tony
Sun Nov 09, 2003 5:14 pm


-----------------------------------
that actually sounds like a good idea :think:

-----------------------------------
Andy
Sun Nov 09, 2003 5:18 pm


-----------------------------------
go whatdotcolor!

-----------------------------------
AsianSensation
Sun Nov 09, 2003 6:59 pm


-----------------------------------
trust dodge to be stupid, you know, come to think of it, if someone did a search for the keyword whatdotcolor, I'm pretty sure in all of those posts, dodge would have some comments....

-----------------------------------
rizzix
Mon Nov 10, 2003 12:15 am


-----------------------------------
you could also make a virtual frame buffer, rewrite all the draw functions and load the image binary urself  :lol:


 what is super usefull is if someone created a library to load bmp files.. unlike the turing functions it should let me read each pixel directly from the file itself... 

if u can do this i can give u transparency etc and more!

-----------------------------------
Tony
Mon Nov 10, 2003 12:32 am


-----------------------------------
well BMPs seem to have the easiest file format to read and try to load it yourself...

but then again, every function you write in turing just slows everything down. Damn it... someone should walk over to Tom's house and force him to allow us to run .DLLs :lol:

-----------------------------------
rizzix
Mon Nov 10, 2003 12:43 am


-----------------------------------
yea i'd agree..  but still it's worth it from a computer science point of view .. u know what i mean
