Computer Science Canada [source code] Antialiasing - Blur Filter

Author:  Tony [ Sun Nov 09, 2003 12:35 am ]
Post subject:  [source code] Antialiasing - Blur Filter

This is a filter you can apply to images in turing to blur them. It used whatdotcolor and RGB module to calculate an average color of 9 pixels block and redraw pixel in that color, thus resulting in a blur.

 code: 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

A practical use for it - antialiasing 8)

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.

 Author: rizzix [ Sun Nov 09, 2003 12:41 am ] Post subject: nice we need more of these filters in turing...

 Author: thoughtful [ Sun Nov 09, 2003 11:43 am ] Post subject: Hey tony thats awsome! i would have gave you some bits if i had lots ) Looks jus like the blurs i use in my Fireworks!!!(a software like photoshop)

 Author: Catalyst [ Sun Nov 09, 2003 1:24 pm ] Post subject: heres another filter http://www.compsci.ca/v2/viewtopic.php?t=1131

 Author: thoughtful [ Sun Nov 09, 2003 4:00 pm ] Post subject: 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 ) 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!

Author:  Tony [ Sun Nov 09, 2003 4:24 pm ]
Post subject:

well technically
 code: 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

 Author: Catalyst [ Sun Nov 09, 2003 4:37 pm ] Post subject: you could also make a virtual frame buffer, rewrite all the draw functions and load the image binary urself

 Author: Tony [ Sun Nov 09, 2003 5:14 pm ] Post subject: that actually sounds like a good idea

 Author: Andy [ Sun Nov 09, 2003 5:18 pm ] Post subject: go whatdotcolor!

 Author: AsianSensation [ Sun Nov 09, 2003 6:59 pm ] Post subject: 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....

 Author: rizzix [ Mon Nov 10, 2003 12:15 am ] Post subject: Catalyst wrote:you could also make a virtual frame buffer, rewrite all the draw functions and load the image binary urself 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!

 Author: Tony [ Mon Nov 10, 2003 12:32 am ] Post subject: 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

 Author: rizzix [ Mon Nov 10, 2003 12:43 am ] Post subject: yea i'd agree.. but still it's worth it from a computer science point of view .. u know what i mean

 :