|
Author |
Topic: RealTime blur (well on my computer attleast) (Read 2198 times) |
|
Mathatan
|
RealTime blur (well on my computer attleast)
« on: Jun 19th, 2003, 2:12pm » |
|
Hiya! I was practising the use of Proce55ing and made a quite fast blurring method. Because I wanted to get the method work as fast as it could (for realtime purposes) I left the masking and filters out. Alltough I did make another method, which is a bit more thorough. Anyway heres the method: void blurFast(int startX, int startY, int sizeX, int sizeY, int sampleSize, int sampleDensity, int iteration, boolean borders) { int stopX=startX+sizeX; int stopY=startY+sizeY; int[] colors = new int[4]; color fcolor; int locationX=0, locationY=0, foo=0; int[] npixels= new int[screenX*screenY]; System.arraycopy(pixels, 0, npixels, 0, screenX*screenY); if(sampleSize/sampleDensity>1) sampleSize/=sampleDensity; while(iteration-->0) { for(int pixX=startX; pixX<stopX; pixX++) for(int pixY=startY; pixY<stopY; pixY++) { if(pixX>screenX) foo=screenX*(pixY-1)+(pixX-iteration); else foo=screenX*(pixY)+(pixX-iteration); colors[0]=0; colors[1]=0; colors[2]=0; colors[3]=0; for(int i=-(sampleSize+1/2)*sampleDensity; i<(sampleSize+1/2)*sampleDensity; i+=sampleDensity) for(int j=-(sampleSize+1/2)*sampleDensity; j<(sampleSize+1/2)*sampleDensity; j+=sampleDensity) { locationX=pixX+i; locationY=pixY+j; if(locationX>=screenX) locationX-=screenX; if(locationY>=screenY) locationY-=screenY; fcolor=getPixel(locationX, locationY); colors[0]+=red(fcolor); colors[1]+=green(fcolor); colors[2]+=blue(fcolor); colors[3]++; } npixels[foo]=color(colors[0]/colors[3], colors[1]/colors[3], colors[2]/colors[3]); } System.arraycopy(npixels, 0, pixels, 0, screenX*screenY); } if(borders) { drawLine(startX, startY+1, 0, sizeX+1); drawLine(startX, startY+1+sizeY, 0, sizeX+1); drawLine(startX+1, startY, 90, sizeY+1); drawLine(startX+1+sizeX, startY, 90, sizeY+1); } } void drawLine(int startX, int startY, float rotation, int length) { int endX=1, endY=1; float rotX=1*cos(radians(rotation)), rotY=1*sin(radians(rotation)); for(int i=1; i<=length; i++) { endX=int(startX+(rotX*i))%screenX; endY=int(startY+(rotY*i))%screenY; if(endX<0) endX+=screenX; if(endY<0) endY+=screenY; point(endX, endY); } } If you're interested to see it on action (with some other stuff also) check http://koti.mbnet.fi/mathatan/temp/WIP/Java/RealTimeBlur/ If you have got any suggestions or improvement (as I'm just a beginner) please let me know..
|
« Last Edit: Jun 19th, 2003, 3:50pm by Mathatan » |
|
|
|
|
|