Created
July 19, 2016 15:05
-
-
Save hageldave/d92ef9fea1df02dfc583d2842d650ce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
Img img = new Img(2048,2048); | |
img.fill(0xff000000); | |
Random r = new Random(); | |
img.forEach(px->{px.setG(r.nextInt(256));}); | |
Img copy = img.copy(); | |
int kernelSize = 21; | |
int minus = kernelSize/2; | |
int plus = kernelSize-minus; | |
int[] sums = new int[Math.max(img.getWidth(), img.getHeight())]; | |
Consumer<Pixel> blurH = px -> | |
{ | |
int x = px.getX(); | |
int y = px.getY(); | |
int sum = sums[y]; | |
if(x == 0){ | |
// init sum | |
for(int i = -minus; i < plus; i++){ | |
sum += Pixel.g(copy.getValue(x+i, y, Img.boundary_mode_mirror)); | |
} | |
} | |
// update sum | |
sum -= Pixel.g(copy.getValue(x-minus, y, Img.boundary_mode_mirror)); | |
sum += Pixel.g(copy.getValue(x+plus-1, y, Img.boundary_mode_mirror)); | |
sums[y] = sum; | |
px.setG(sum/kernelSize); | |
}; | |
// ImageSaver.saveImage(img.getRemoteBufferedImage(), new File("orig.png")); | |
long t = System.currentTimeMillis(); | |
Img.stream(img.rowSpliterator(), true).forEach(blurH); | |
System.out.println(System.currentTimeMillis()-t); | |
// ImageSaver.saveImage(img.getRemoteBufferedImage(), new File("blur.png")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment