Skip to content

Instantly share code, notes, and snippets.

@dflemstr
Created January 12, 2010 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dflemstr/275451 to your computer and use it in GitHub Desktop.
Save dflemstr/275451 to your computer and use it in GitHub Desktop.
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