Skip to content

Instantly share code, notes, and snippets.

@dflemstr
Created January 11, 2010 18:04
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/274443 to your computer and use it in GitHub Desktop.
Save dflemstr/274443 to your computer and use it in GitHub Desktop.
object SomeRandomPass extends Pass {
val title = "Stuff"
val description = "Stuff"
//Magie: dieser Code fügt zwei Methoden zur Klasse BufferedImage hinzu
//Tu dies in dein Pass herein unter "val description = ..." um es zu aktivieren
case class Color(a: Int, r: Int, g: Int, b: Int)
implicit def addColorAccessTo(img: BufferedImage) = new {
def apply(x: Int, y: Int) = {
val color = img.getRGB(x, y)
Color(color >> 24, (color >> 16) & 255, (color >> 8) & 255, color & 255)
}
def update(x: Int, y: Int, color: Color) =
img.setRGB(x, y, (color.a << 24 ) |
((color.r << 16) & 255) |
((color.g << 8 ) & 255) |
( color.b & 255))
}
//Unten ist ein Beispiel
//continued: Beispiel
def output = {
val image = input asImage
val Color(a, r, g, b) = image(x, y) //a, r, g und b (sind alles typ Int) enthalten jetzt die Farbenwerte
val col = image(x, y) //col ist jetzt eine Farbe
println(col.a)
println(col.r)
println(col.g)
println(col.b)
//etc
//Farbe zurückschreiben
image(x, y) = col
image(x, y) = Color(255, 126, 156, 218)
//Jetzt musst du nie wieder setRGB benutzen!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment