-
Notifications
You must be signed in to change notification settings - Fork 4
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 #3 from msqtt/master
Change a lot, added gif animation feature. :P
- Loading branch information
Showing
12 changed files
with
256 additions
and
104 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pprof |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/orzation/bobibo" | ||
) | ||
|
||
var ( | ||
version string | ||
|
||
gif bool | ||
inverse bool | ||
scale float64 | ||
threshold int | ||
) | ||
|
||
func init() { | ||
flag.BoolVar(&gif, "g", false, "enable gif mode.") | ||
flag.BoolVar(&inverse, "v", false, "inverse the colors.") | ||
flag.Float64Var(&scale, "s", 0.5, "scale the size of arts. range: (0, +).") | ||
flag.IntVar(&threshold, "t", -1, "set the threshold of binarization. range: [-1, 255], -1 means gen by OTSU.") | ||
} | ||
|
||
func main() { | ||
if len(os.Args) <= 1 { | ||
fmt.Println("Please input a path of image.") | ||
fmt.Println("Or using help to print options.") | ||
fmt.Println("Or using version to print version.") | ||
fmt.Println(":P") | ||
os.Exit(1) | ||
} | ||
path := os.Args[1] | ||
if path == "help" { | ||
fmt.Println("Options:") | ||
fmt.Println(" -r reverse the char color.") | ||
fmt.Println(" -g enable gif analyzation, default: disable.") | ||
fmt.Println(" -s [d](0, +) set the scale of art. [default: 0.5]") | ||
fmt.Println(" -t [d][0, 255] set the threshold of binarization. [default: gen by ostu]") | ||
os.Exit(0) | ||
} else if path == "version" { | ||
fmt.Printf("BoBiBo %s :P\n", version) | ||
os.Exit(0) | ||
} | ||
f, err := os.Open(path) | ||
defer f.Close() | ||
flag.Parse() | ||
args := flag.Args() | ||
|
||
if err != nil { | ||
fmt.Println(err.Error()) | ||
if len(args) < 1 { | ||
fmt.Fprintln(os.Stderr, "Usage: bobibo [OPTION]... PARTERNS [FILE]...") | ||
fmt.Fprintln(os.Stderr, "Try 'bobibo --help' for more information.") | ||
os.Exit(1) | ||
} | ||
|
||
var gif, rever bool | ||
var scale float64 = 0.5 | ||
var threshold = -1 | ||
for i, v := range os.Args[2:] { | ||
switch v { | ||
case "-g": | ||
gif = true | ||
case "-r": | ||
rever = true | ||
case "-s": | ||
f, err := strconv.ParseFloat(os.Args[i+3], 64) | ||
if err != nil { | ||
fmt.Println("The range of scale must at (0, +).") | ||
os.Exit(1) | ||
} | ||
if f == 0 { | ||
fmt.Println("The range of scale must at (0, +).") | ||
os.Exit(1) | ||
} | ||
scale = f | ||
case "-t": | ||
i, err := strconv.ParseInt(os.Args[i+3], 10, 64) | ||
if err != nil { | ||
fmt.Println("The range of threshold must at [0, 255].") | ||
os.Exit(1) | ||
} | ||
if i < 0 || i > 255 { | ||
fmt.Println("The range of threshold must at [0, 255].") | ||
os.Exit(1) | ||
} | ||
threshold = int(i) | ||
opt := args[0] | ||
var imgFile *os.File | ||
|
||
switch opt { | ||
case "version": | ||
fmt.Printf("BoBiBo %s :P\n", version) | ||
return | ||
default: | ||
f, err := os.Open(opt) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "Open image error: ", err.Error()) | ||
} | ||
imgFile = f | ||
} | ||
|
||
out, err := bobibo.BoBiBo(f, gif, rever, scale, threshold) | ||
defer imgFile.Close() | ||
arts, err := bobibo.BoBiBo( | ||
imgFile, gif, inverse, | ||
bobibo.ScaleOpt(scale), | ||
bobibo.ThresholdOpt(threshold)) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
fmt.Fprintln(os.Stderr, "Bobibo error: ", err.Error()) | ||
imgFile.Close() | ||
os.Exit(1) | ||
} | ||
|
||
for e := range out { | ||
for _, v := range e { | ||
fmt.Printf("\r%s\n", v) | ||
} | ||
err = printArts(arts, gif) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "Print error: ", err.Error()) | ||
imgFile.Close() | ||
os.Exit(1) | ||
} | ||
} |
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
Oops, something went wrong.