Created
January 12, 2010 18:28
-
-
Save dflemstr/275451 to your computer and use it in GitHub Desktop.
This file contains 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
package se.dflemstr.imgproc.passes | |
import java.awt.image.BufferedImage | |
import se.dflemstr.imgproc.graphics.Texture | |
object NearestNeighbor extends Pass { | |
val title = "Nearest Neighbor interpolation detection" | |
val description = "A pass that highlights duplicate pixels in an image." | |
def output = { | |
val image = input asImage | |
val newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB) | |
val red = Color(1, 1, 0, 0) | |
for { | |
x <- 0 until width | |
y <- 0 until height | |
src = image(x, y) | |
} { | |
val candidates = for { | |
dx <- -1 to 1 | |
if(dx != 0) | |
dy <- -1 to 1 | |
if(dy != 0) | |
newx = x + dx | |
if(newx > -1 && newx < width) | |
newy = y + dy | |
if(newy > -1 && newy < height) | |
} yield image(newx, newy) | |
val newcolor = if(candidates contains src) | |
(src + red) / 2 | |
else | |
src | |
newImage(x, y) = newcolor | |
} | |
Texture fromImage newImage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment