made mask stretch to image size
This commit is contained in:
parent
6df1a451ec
commit
683fbd912f
@ -115,15 +115,14 @@ object ImageFilters {
|
||||
val maskHeight: Int = if (maskWidth == 0) 0 else maskImg(0).length
|
||||
|
||||
colorFilter(a, (col, x, y, width, height) => {
|
||||
if (x >= maskWidth || y >= maskHeight) col
|
||||
else {
|
||||
val factor: Double = maskImg(x)(y)/255.0
|
||||
new Color(
|
||||
(col.getRed * factor).toInt,
|
||||
(col.getGreen * factor).toInt,
|
||||
(col.getBlue * factor).toInt
|
||||
)
|
||||
}
|
||||
val maskX: Int = (x.toDouble / width * maskWidth).toInt
|
||||
val maskY: Int = (y.toDouble / height * maskHeight).toInt
|
||||
val factor: Double = maskImg(maskX)(maskY)/255.0
|
||||
new Color(
|
||||
(col.getRed * factor).toInt,
|
||||
(col.getGreen * factor).toInt,
|
||||
(col.getBlue * factor).toInt
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,9 @@ object ImageProcessingApp extends App {
|
||||
val org = new ImageGraphics(imageFile, "Original", -768, -512)
|
||||
val sepia = new ImageGraphics(imageFile, "Sepia", -256, -512)
|
||||
val noise = new ImageGraphics(imageFile, "Noise", 256, -512)
|
||||
val mask = new ImageGraphics("./res/mask.png", "Mask", -256, -256)
|
||||
val masked = new ImageGraphics(imageFile, "Masked", 256, -256)
|
||||
sepia.setPixelsColor(ImageFilters.sepia(org.getPixelsColor()))
|
||||
noise.setPixelsColor(ImageFilters.noise(org.getPixelsColor(), 50))
|
||||
masked.setPixelsColor(ImageFilters.mask(org.getPixelsColor(), mask.getPixelsBW()))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user