Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [source code] Antialiasing - Blur Filter
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: 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 Embarassed 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 Very Happy


A practical use for it - antialiasing 8)
Posted Image, might have been reduced in size. Click Image to view fullscreen.

You can antialias just about anything, even your text Very Happy
Posted Image, might have been reduced in size. Click Image to view fullscreen.

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.



blur2.JPG
 Description:
preview2
 Filesize:  13.92 KB
 Viewed:  9109 Time(s)

blur2.JPG



blur.JPG
 Description:
preview
 Filesize:  16.03 KB
 Viewed:  9107 Time(s)

blur.JPG


Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Sun Nov 09, 2003 12:41 am   Post subject: (No subject)

nice Smile

we need more of these filters in turing...
thoughtful




PostPosted: Sun Nov 09, 2003 11:43 am   Post subject: (No subject)

Hey tony thats awsome! i would have gave you some bits if i had lots Smile) Twisted Evil Twisted Evil Twisted Evil

Looks jus like the blurs i use in my Fireworks!!!(a software like photoshop)
Catalyst




PostPosted: Sun Nov 09, 2003 1:24 pm   Post subject: (No subject)

heres another filter
http://www.compsci.ca/v2/viewtopic.php?t=1131
thoughtful




PostPosted: Sun Nov 09, 2003 4:00 pm   Post subject: (No 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 Smile) 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! Razz
Tony




PostPosted: Sun Nov 09, 2003 4:24 pm   Post subject: (No 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 Rolling Eyes
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Catalyst




PostPosted: Sun Nov 09, 2003 4:37 pm   Post subject: (No subject)

you could also make a virtual frame buffer, rewrite all the draw functions and load the image binary urself Laughing
Tony




PostPosted: Sun Nov 09, 2003 5:14 pm   Post subject: (No subject)

that actually sounds like a good idea Thinking
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sun Nov 09, 2003 5:18 pm   Post subject: (No subject)

go whatdotcolor!
AsianSensation




PostPosted: Sun Nov 09, 2003 6:59 pm   Post subject: (No 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....
rizzix




PostPosted: Mon Nov 10, 2003 12:15 am   Post subject: (No subject)

Catalyst wrote:
you could also make a virtual frame buffer, rewrite all the draw functions and load the image binary urself Laughing



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




PostPosted: Mon Nov 10, 2003 12:32 am   Post subject: (No 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 Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rizzix




PostPosted: Mon Nov 10, 2003 12:43 am   Post subject: (No subject)

yea i'd agree.. but still it's worth it from a computer science point of view .. u know what i mean
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: