Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[source code] Antialiasing - Blur Filter
Author Message
Tony

Posted: 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.

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

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

Tony's programming blog. DWITE - a programming contest.

rizzix

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

nice

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

Posted: 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 )

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

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

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

Posted: 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 )

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!
Tony

Posted: 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
Tony's programming blog. DWITE - a programming contest.
Catalyst

Posted: 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
Tony

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

that actually sounds like a good idea
Tony's programming blog. DWITE - a programming contest.

Andy

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

go whatdotcolor!
AsianSensation

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

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

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

Posted: 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
Tony's programming blog. DWITE - a programming contest.
rizzix

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 13 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: