Assignment done
This commit is contained in:
parent
690105b675
commit
1172d85dae
@ -41,8 +41,11 @@ object HorizontalBoxBlur extends HorizontalBoxBlurInterface {
|
|||||||
*/
|
*/
|
||||||
def blur(src: Img, dst: Img, from: Int, end: Int, radius: Int): Unit = {
|
def blur(src: Img, dst: Img, from: Int, end: Int, radius: Int): Unit = {
|
||||||
// TODO implement this method using the `boxBlurKernel` method
|
// TODO implement this method using the `boxBlurKernel` method
|
||||||
|
for(y <- from until end){
|
||||||
???
|
for(x <- 0 until src.width){
|
||||||
|
dst(x,y) = boxBlurKernel(src, x, y, radius)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Blurs the rows of the source image in parallel using `numTasks` tasks.
|
/** Blurs the rows of the source image in parallel using `numTasks` tasks.
|
||||||
@ -53,8 +56,10 @@ object HorizontalBoxBlur extends HorizontalBoxBlurInterface {
|
|||||||
*/
|
*/
|
||||||
def parBlur(src: Img, dst: Img, numTasks: Int, radius: Int): Unit = {
|
def parBlur(src: Img, dst: Img, numTasks: Int, radius: Int): Unit = {
|
||||||
// TODO implement using the `task` construct and the `blur` method
|
// TODO implement using the `task` construct and the `blur` method
|
||||||
|
val r = 0 to src.height by (src.height/(Math.min(numTasks, src.height)))
|
||||||
???
|
var ranges = r zip r.tail
|
||||||
|
val tasks = ranges.map( { case (from, to) => task(blur(src, dst, from, to, radius)) } )
|
||||||
|
tasks foreach {_.join}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,11 @@ object VerticalBoxBlur extends VerticalBoxBlurInterface {
|
|||||||
*/
|
*/
|
||||||
def blur(src: Img, dst: Img, from: Int, end: Int, radius: Int): Unit = {
|
def blur(src: Img, dst: Img, from: Int, end: Int, radius: Int): Unit = {
|
||||||
// TODO implement this method using the `boxBlurKernel` method
|
// TODO implement this method using the `boxBlurKernel` method
|
||||||
???
|
for(x <- from until end){
|
||||||
|
for(y <- 0 until src.height){
|
||||||
|
dst(x,y) = boxBlurKernel(src, x, y, radius)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Blurs the columns of the source image in parallel using `numTasks` tasks.
|
/** Blurs the columns of the source image in parallel using `numTasks` tasks.
|
||||||
@ -54,7 +58,10 @@ object VerticalBoxBlur extends VerticalBoxBlurInterface {
|
|||||||
*/
|
*/
|
||||||
def parBlur(src: Img, dst: Img, numTasks: Int, radius: Int): Unit = {
|
def parBlur(src: Img, dst: Img, numTasks: Int, radius: Int): Unit = {
|
||||||
// TODO implement using the `task` construct and the `blur` method
|
// TODO implement using the `task` construct and the `blur` method
|
||||||
???
|
val r = 0 to src.width by (src.width/(Math.min(numTasks, src.width)))
|
||||||
|
var ranges = r zip r.tail
|
||||||
|
val tasks = ranges.map( { case (from, to) => task(blur(src, dst, from, to, radius)) } )
|
||||||
|
tasks foreach {_.join}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,28 @@ package object scalashop extends BoxBlurKernelInterface {
|
|||||||
def boxBlurKernel(src: Img, x: Int, y: Int, radius: Int): RGBA = {
|
def boxBlurKernel(src: Img, x: Int, y: Int, radius: Int): RGBA = {
|
||||||
|
|
||||||
// TODO implement using while loops
|
// TODO implement using while loops
|
||||||
???
|
var r = 0
|
||||||
|
var g = 0
|
||||||
|
var b = 0
|
||||||
|
var a = 0
|
||||||
|
|
||||||
|
var count = 0
|
||||||
|
|
||||||
|
var xi = clamp(x-radius, 0, src.width-1)
|
||||||
|
while(xi<=clamp(x+radius, 0, src.width-1)) {
|
||||||
|
var yi = clamp(y-radius, 0, src.height-1)
|
||||||
|
while(yi<=clamp(y+radius, 0, src.height-1)) {
|
||||||
|
r = r + red(src(xi, yi))
|
||||||
|
g = g + green(src(xi, yi))
|
||||||
|
b = b + blue(src(xi, yi))
|
||||||
|
a = a + alpha(src(xi, yi))
|
||||||
|
count = count + 1
|
||||||
|
yi = yi + 1
|
||||||
|
}
|
||||||
|
xi = xi + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
rgba(r/count, g/count, b/count, a/count)
|
||||||
}
|
}
|
||||||
|
|
||||||
val forkJoinPool = new ForkJoinPool
|
val forkJoinPool = new ForkJoinPool
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user