-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from poslegm/master
Autocrop changes
- Loading branch information
Showing
3 changed files
with
26 additions
and
20 deletions.
There are no files selected for viewing
30 changes: 18 additions & 12 deletions
30
scrimage-core/src/main/scala/com/sksamuel/scrimage/AutocropOps.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
package com.sksamuel.scrimage | ||
|
||
import scala.annotation.tailrec | ||
|
||
object AutocropOps { | ||
|
||
type PixelsExtractor = (Int, Int, Int, Int) => Array[Pixel] | ||
|
||
def scanright(color: Color, height: Int, col: Int, f: PixelsExtractor): Int = { | ||
if (PixelTools.uniform(color, f(col, 0, 1, height))) scanright(color, height, col + 1, f) | ||
else col | ||
@tailrec | ||
final def scanright(color: Color, height: Int, width: Int, col: Int, f: PixelsExtractor): Int = { | ||
if (col == width || !PixelTools.uniform(color, f(col, 0, 1, height))) col | ||
else scanright(color, height, width, col + 1, f) | ||
} | ||
|
||
def scanleft(color: Color, height: Int, col: Int, f: PixelsExtractor): Int = { | ||
if (PixelTools.uniform(color, f(col, 0, 1, height))) scanleft(color, height, col - 1, f) | ||
else col | ||
@tailrec | ||
final def scanleft(color: Color, height: Int, width: Int, col: Int, f: PixelsExtractor): Int = { | ||
if (col == 0 || !PixelTools.uniform(color, f(col, 0, 1, height))) col | ||
else scanleft(color, height, width, col - 1, f) | ||
} | ||
|
||
def scandown(color: Color, width: Int, row: Int, f: PixelsExtractor): Int = { | ||
if (PixelTools.uniform(color, f(0, row, width, 1))) scandown(color, width, row + 1, f) | ||
else row | ||
@tailrec | ||
final def scandown(color: Color, height: Int, width: Int, row: Int, f: PixelsExtractor): Int = { | ||
if (row == height || !PixelTools.uniform(color, f(0, row, width, 1))) row | ||
else scandown(color, height, width, row + 1, f) | ||
} | ||
|
||
def scanup(color: Color, width: Int, row: Int, f: PixelsExtractor): Int = { | ||
if (PixelTools.uniform(color, f(0, row, width, 1))) scanup(color, width, row - 1, f) | ||
else row | ||
@tailrec | ||
final def scanup(color: Color, height: Int, width: Int, row: Int, f: PixelsExtractor): Int = { | ||
if (row == 0 || !PixelTools.uniform(color, f(0, row, width, 1))) row | ||
else scanup(color, height, width, row - 1, f) | ||
} | ||
} |
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
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