Created
January 11, 2010 18:04
-
-
Save dflemstr/274443 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
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 |
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
//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