Skip to content

Instantly share code, notes, and snippets.

@valexey
Created May 23, 2013 01:42
Show Gist options
  • Save valexey/5632247 to your computer and use it in GitHub Desktop.
Save valexey/5632247 to your computer and use it in GitHub Desktop.
public class Blur {
final static int RED = 0;
final static int GREEN = 1;
final static int BLUE = 2;
final static int width = 640;
final static int height = 480;
final static int frames = 1000;
final static int N = 13;
private static int index(int x, int y, int color) {
return (y*width + x)*3 + color;
}
private static int unsigned(byte b) {
return b & 0xFF;
}
private static void blur(byte in[], byte out[]) {
for (int y=1; y<height-1; y++) {
for (int x=1; x<width-1; x++) {
for (int c = RED; c<=BLUE; c++)
out[index(x,y,c)] = (byte) ((unsigned(in[index(x,y-1,c)]) +
unsigned(in[index(x,y+1,c)]) +
unsigned(in[index(x-1,y,c)]) +
unsigned(in[index(x+1,y,c)])) /4);
}
}
}
public static void main(String argv[]) {
final int len = width * height * (BLUE+1);
byte a1[] = new byte[len];
byte a2[] = new byte[len];
System.out.println("start");
long time = System.currentTimeMillis();
for (int f = 0; f<frames; f++) {
for (int n = 0; n<N; n++) {
blur(a1,a2);
blur(a2,a1);
}
}
System.out.println(System.currentTimeMillis() - time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment